/** * Build a new session from a received {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage}. * * After a session is constructed in this way, the embedded {@link org.whispersystems.libaxolotl.protocol.WhisperMessage} * can be decrypted. * * @param message The received {@link org.whispersystems.libaxolotl.protocol.PreKeyWhisperMessage}. * @throws org.whispersystems.libaxolotl.InvalidKeyIdException when there is no local * {@link org.whispersystems.libaxolotl.state.PreKeyRecord} * that corresponds to the PreKey ID in * the message. * @throws org.whispersystems.libaxolotl.InvalidKeyException when the message is formatted incorrectly. * @throws org.whispersystems.libaxolotl.UntrustedIdentityException when the {@link IdentityKey} of the sender is untrusted. */ /*package*/ internal May <uint> Process(SessionRecord sessionRecord, PreKeyWhisperMessage message) { uint messageVersion = message.GetMessageVersion(); IdentityKey theirIdentityKey = message.GetIdentityKey(); May <uint> unsignedPreKeyId; if (!identityKeyStore.IsTrustedIdentity(remoteAddress.GetName(), theirIdentityKey)) { throw new UntrustedIdentityException(remoteAddress.GetName(), theirIdentityKey); } switch (messageVersion) { case 2: unsignedPreKeyId = ProcessV2(sessionRecord, message); break; case 3: unsignedPreKeyId = ProcessV3(sessionRecord, message); break; default: throw new Exception("Unknown version: " + messageVersion); } identityKeyStore.SaveIdentity(remoteAddress.GetName(), theirIdentityKey); return(unsignedPreKeyId); }
public IdentityKeyPair(byte[] serialized) { try { IdentityKeyPairStructure structure = IdentityKeyPairStructure.ParseFrom(serialized); this.publicKey = new IdentityKey(structure.PublicKey.ToByteArray(), 0); this.privateKey = Curve.DecodePrivatePoint(structure.PrivateKey.ToByteArray()); } catch (InvalidProtocolBufferException e) { throw new InvalidKeyException(e); } }
public IdentityKeyPair(IdentityKey publicKey, ECPrivateKey privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; }