Skip to content

Commit

Permalink
Fix bugs in the peers UI and didauth service
Browse files Browse the repository at this point in the history
  • Loading branch information
cipres authored and cipres committed Oct 30, 2020
1 parent 344d132 commit 2713f6c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion galacteek/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# ..............................................................................
#

__version__ = '0.4.37'
__version__ = '0.4.38'

from galacteek.core.asynclib import * # noqa
from galacteek.core import glogger
Expand Down
3 changes: 3 additions & 0 deletions galacteek/core/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ async def createIpIdentifier(self, ipfsop,
self.userInfo.curIdentity['personDid']
)

if passphrase:
await ipid.unlock(rsaPassphrase=passphrase)

return ipid

@ipfsOp
Expand Down
14 changes: 9 additions & 5 deletions galacteek/core/schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
QWebEngineUrlScheme.ViewSourceAllowed

defaultLocalSchemeFlags = defaultSchemeFlags | QWebEngineUrlScheme.LocalScheme
serviceWorkersFlags = \
defaultSchemeFlags | QWebEngineUrlScheme.ServiceWorkersAllowed


# Registered URL schemes
Expand Down Expand Up @@ -132,35 +134,37 @@ def initializeSchemes():
declareUrlScheme(
SCHEME_DWEB,
syntax=QWebEngineUrlScheme.Syntax.Path,
flags=serviceWorkersFlags
)

declareUrlScheme(
SCHEME_DWEBGW,
syntax=QWebEngineUrlScheme.Syntax.Path,
flags=defaultSchemeFlags
flags=serviceWorkersFlags
)

declareUrlScheme(
SCHEME_FS,
syntax=QWebEngineUrlScheme.Syntax.Path,
flags=defaultSchemeFlags
flags=serviceWorkersFlags
)

declareUrlScheme(
SCHEME_IPFS,
syntax=QWebEngineUrlScheme.Syntax.Host,
flags=defaultSchemeFlags
flags=serviceWorkersFlags
)

declareUrlScheme(
SCHEME_IPNS,
syntax=QWebEngineUrlScheme.Syntax.Host,
flags=defaultSchemeFlags
flags=serviceWorkersFlags
)

declareUrlScheme(
SCHEME_ENS,
syntax=QWebEngineUrlScheme.Syntax.Host
syntax=QWebEngineUrlScheme.Syntax.Host,
flags=serviceWorkersFlags
)

declareUrlScheme(
Expand Down
4 changes: 3 additions & 1 deletion galacteek/did/ipid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,9 @@ async def didAuthPerform(self, ipfsop, streamCtx, ipid, token=None):
json=req) as resp:

if resp.status != HTTPOk.status_code:
raise Exception('DID Auth error')
payload = await resp.json()
log.debug('Error payload: {payload}')
raise Exception(f'DID Auth error: code {resp.status}')

payload = await resp.json()

Expand Down
18 changes: 10 additions & 8 deletions galacteek/ipfs/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from jwcrypto import jwt
from jwcrypto.common import json_encode

from galacteek.core.asynccache import selfcachedcoromethod
from galacteek.ipfs.wrappers import ipfsOp
from galacteek.ipfs.cidhelpers import cidValid
from galacteek.core.asynclib import asyncReadFile
Expand Down Expand Up @@ -56,7 +55,7 @@ async def pubKeyCid(self, ipfsop):

async def privJwk(self):
try:
privKey = await self.__privateKey()
privKey = await self._privateKey()
pem = privKey.export_key(pkcs=8)
key = jwk.JWK()
key.import_from_pem(pem)
Expand Down Expand Up @@ -100,7 +99,7 @@ async def encrypt(self, data, pubKey, sessionKey=None, cacheKey=False):

async def decrypt(self, data):
return await self.rsaExec.decryptData(BytesIO(data),
await self.__privateKey())
await self._privateKey())

@ipfsOp
async def storeSelf(self, op, data, offline=False, wrap=False):
Expand Down Expand Up @@ -152,7 +151,7 @@ async def encryptJsonToMfs(self, op, obj, mfsPath):

@ipfsOp
async def decryptIpfsObject(self, op, data):
privKey = await self.__privateKey()
privKey = await self._privateKey()
try:
decrypted = await self.rsaExec.decryptData(BytesIO(data), privKey)
if decrypted:
Expand Down Expand Up @@ -189,12 +188,12 @@ async def decryptMfsJson(self, op, path):
@ipfsOp
async def pssSign(self, op, message):
return await self.rsaExec.pssSign(
message, await self.__privateKey())
message, await self._privateKey())

@ipfsOp
async def pssSignImport(self, op, message, pin=False):
signed = await self.rsaExec.pssSign(
message, await self.__privateKey())
message, await self._privateKey())

if signed:
try:
Expand Down Expand Up @@ -233,8 +232,11 @@ async def privKeyUnlock(self, passphrase=None):
self.debug(f'Key cache size: {len(self._privKeyCache)}')
return key

@selfcachedcoromethod('_privKeyCache')
async def __privateKey(self, key=0):
async def _privateKey(self, key=0):
pKey = self._privKeyCache.get(key)
if pKey:
return pKey

return await self.rsaExec.importKey(
await asyncReadFile(self.privKeyPath)
)
Expand Down
14 changes: 10 additions & 4 deletions galacteek/ipfs/p2pservices/didauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ async def authPss(self, ipfsop, request):
raise Exception(f'Invalid DIDAuth token {token}')
except Exception as err:
self.message(f'authPss error: {err}')
return await self.msgError()
return await self.msgError(error='Invalid token or schema')

did = js.get('did')
if not didIdentRe.match(did):
return await self.msgError()
return await self.msgError(error=f'Invalid DID: {did}')

self.message(
f'Received DID auth challenge request for DID: {did}')
Expand All @@ -153,10 +153,16 @@ async def authPss(self, ipfsop, request):
# one we currently use
return await self.msgError(error='Invalid DID')

privKey = curProfile._didKeyStore._privateKeyForDid(did)
if not privKey:
rsaAgent = await currentIpid.rsaAgentGet(ipfsop)
if not rsaAgent:
return await self.msgError()

privKey = await rsaAgent._privateKey()

if not privKey:
return await self.msgError(
error=f'Invalid key for DID: {did}')

try:
signed = await self.rsaExecutor.pssSign(
js['challenge'].encode(),
Expand Down
1 change: 1 addition & 0 deletions galacteek/ui/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ def __init__(self, showCancel=False, parent=None):

self.ui.useIpidPassphrase.stateChanged.connect(self.onUsePassphrase)
self.ui.useIpidPassphrase.setCheckState(Qt.Checked)
self.ui.useIpidPassphrase.setCheckState(Qt.Unchecked)

self.ui.ipidRsaPassphrase.setEchoMode(QLineEdit.Password)
self.ui.ipidRsaPassphraseVerif.setEchoMode(QLineEdit.Password)
Expand Down
4 changes: 2 additions & 2 deletions galacteek/ui/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def mimeData(self, indexes):
for idx in indexes:
idxPeer = self.index(idx.row(), 1, idx.parent())
if idxPeer.isValid():
peer = self.data(idxPeer)
peer = self.data(idxPeer, Qt.DisplayRole)
mimedata.setUrls([QUrl('galacteekpeer:{}'.format(peer))])
break

Expand Down Expand Up @@ -388,7 +388,7 @@ def flags(self, index):

def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.rootItem.data(section)
return self.rootItem.data(section, role)

return None

Expand Down

0 comments on commit 2713f6c

Please sign in to comment.