finished pub encrypt function
This commit is contained in:
parent
cb3015652a
commit
24540abe6b
@ -154,6 +154,11 @@ class API:
|
|||||||
if len(response) == 0:
|
if len(response) == 0:
|
||||||
response = 'none'
|
response = 'none'
|
||||||
resp = Response(response)
|
resp = Response(response)
|
||||||
|
elif action == 'kex':
|
||||||
|
response = ','.join(self._core.listPeers())
|
||||||
|
if len(response) == 0:
|
||||||
|
response = 'none'
|
||||||
|
resp = Response(response)
|
||||||
else:
|
else:
|
||||||
resp = Response("")
|
resp = Response("")
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ class OnionrCommunicate:
|
|||||||
pexCount += 1
|
pexCount += 1
|
||||||
if pexTimer == pexCount:
|
if pexTimer == pexCount:
|
||||||
self.getNewPeers()
|
self.getNewPeers()
|
||||||
|
pexCount = 0
|
||||||
if heartBeatRate == heartBeatTimer:
|
if heartBeatRate == heartBeatTimer:
|
||||||
logger.debug('Communicator heartbeat')
|
logger.debug('Communicator heartbeat')
|
||||||
heartBeatTimer = 0
|
heartBeatTimer = 0
|
||||||
@ -92,15 +93,19 @@ class OnionrCommunicate:
|
|||||||
peersCheck = 5 # Amount of peers to ask for new peers + keys
|
peersCheck = 5 # Amount of peers to ask for new peers + keys
|
||||||
peersChecked = 0
|
peersChecked = 0
|
||||||
peerList = list(self._core.listAdders()) # random ordered list of peers
|
peerList = list(self._core.listAdders()) # random ordered list of peers
|
||||||
logger.warn(len(peerList))
|
|
||||||
newKeys = []
|
newKeys = []
|
||||||
newAdders = []
|
newAdders = []
|
||||||
|
if len(peerList) > 0:
|
||||||
|
maxN = len(peerList) - 1
|
||||||
|
else:
|
||||||
|
peersCheck = 0
|
||||||
|
maxN = 0
|
||||||
|
|
||||||
if len(peerList) > peersCheck:
|
if len(peerList) > peersCheck:
|
||||||
peersCheck = len(peerList)
|
peersCheck = len(peerList)
|
||||||
|
|
||||||
while peersCheck > peersChecked:
|
while peersCheck > peersChecked:
|
||||||
i = random.randint(0, len(peerList))
|
i = random.randint(0, maxN)
|
||||||
logger.info('Using ' + peerList[i] + ' to find new peers')
|
logger.info('Using ' + peerList[i] + ' to find new peers')
|
||||||
try:
|
try:
|
||||||
newAdders = self.performGet('pex', peerList[i])
|
newAdders = self.performGet('pex', peerList[i])
|
||||||
|
@ -60,11 +60,21 @@ class OnionrCrypto:
|
|||||||
retData = key.sign(data.encode())
|
retData = key.sign(data.encode())
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
def pubKeyEncrypt(self, data, peer):
|
def pubKeyEncrypt(self, data, pubkey, anonymous=False):
|
||||||
'''Encrypt to a peers public key (Curve25519, taken from Ed25519 pubkey)'''
|
'''Encrypt to a public key (Curve25519, taken from base32 Ed25519 pubkey)'''
|
||||||
return
|
retVal = ''
|
||||||
|
if self.privKey != None and not anonymous:
|
||||||
|
ownKey = nacl.signing.SigningKey(seed=self.privKey, encoder=nacl.encoding.Base32Encoder())
|
||||||
|
key = nacl.signing.VerifyKey(key=pubkey, encoder=nacl.encoding.Base32Encoder).to_curve25519_public_key()
|
||||||
|
ourBox = nacl.public.Box(ownKey, key)
|
||||||
|
retVal = ourBox.encrypt(data.encode(), encoder=nacl.encoding.RawEncoder)
|
||||||
|
elif anonymous:
|
||||||
|
key = nacl.signing.VerifyKey(key=pubkey, encoder=nacl.encoding.Base32Encoder).to_curve25519_public_key()
|
||||||
|
anonBox = nacl.public.SealedBox(key)
|
||||||
|
retVal = anonBox.encrypt(data.encode(), encoder=nacl.encoding.RawEncoder)
|
||||||
|
return retVal
|
||||||
|
|
||||||
def pubKeyEncrypt(self, data, peer):
|
def pubKeyDecrypt(self, data, peer):
|
||||||
'''pubkey decrypt (Curve25519, taken from Ed25519 pubkey)'''
|
'''pubkey decrypt (Curve25519, taken from Ed25519 pubkey)'''
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user