Exemplo n.º 1
0
 async def decrypt(self, provisionEnvelope):
     masterEphemeral = Curve.decodePoint(provisionEnvelope.publicKey)
     message = provisionEnvelope.body
     if message[0] != 1:
         raise ValueError("Bad version number on ProvisioningMessage")
     iv = message[1:16 + 1]
     mac = message[-32:]
     ivAndCiphertext = message[:-32]
     ciphertext = message[16 + 1:-32]
     ecRes = Curve.calculateAgreement(masterEphemeral,
                                      self.keyPair.privateKey)
     data = HKDF.createFor(3).deriveSecrets(
         ecRes, b"TextSecure Provisioning Message", 64)
     keyOne, keyTwo = data[:32], data[32:]
     await crypto.verifyMAC(ivAndCiphertext, keyTwo, mac)
     plaintext = AESCipher(keyOne, iv).decrypt(ciphertext)
     provisionMessage = protobufs.ProvisionMessage()
     provisionMessage.ParseFromString(plaintext)
     privateKey = provisionMessage.identityKeyPrivate
     publicKey = Curve.generatePublicKey(privateKey)
     return {
         "identityKeyPair":
         ECKeyPair(DjbECPublicKey(publicKey), DjbECPrivateKey(privateKey)),
         "addr":
         provisionMessage.addr,
         "provisioningCode":
         provisionMessage.provisioningCode,
         "userAgent":
         provisionMessage.userAgent
     }
Exemplo n.º 2
0
 async def getKeysForAddr(self, addr, device_id='*'):
     res = await self.request(call='keys', urn=f'/{addr}/{device_id}')
     res['identityKey'] = IdentityKey(b64decode(res['identityKey']),
                                      offset=0)
     for device in res['devices']:
         if device['preKey']:
             raw = b64decode(device['preKey']['publicKey'])
             device['preKey']['publicKey'] = Curve.decodePoint(raw)
         raw = b64decode(device['signedPreKey']['publicKey'])
         device['signedPreKey']['publicKey'] = Curve.decodePoint(raw)
         device['signedPreKey']['signature'] = \
             b64decode(device['signedPreKey']['signature'])
     return res
Exemplo n.º 3
0
 def __init__(self):
     self.trustedKeys = {}
     identityKeyPairKeys = Curve.generateKeyPair()
     self.identityKeyPair = IdentityKeyPair(
         IdentityKey(identityKeyPairKeys.getPublicKey()),
         identityKeyPairKeys.getPrivateKey())
     self.localRegistrationId = KeyHelper.generateRegistrationId()
Exemplo n.º 4
0
 def getPublicKey(self):
     if not self.keyPair:
         self.keyPair = Curve.generateKeyPair()
     return self.keyPair.publicKey
Exemplo n.º 5
0
 async def encrypt(self, theirPublicKey, message):
     ourKeyPair = Curve.generateKeyPair()
     sharedSecret = Curve.calculateAgreement(theirPublicKey,
                                             ourKeyPair.privateKey)
     '''