public KeyExchangeMessage(uint messageVersion, uint sequence, uint flags, ECPublicKey baseKey, byte[] baseKeySignature, ECPublicKey ratchetKey, IdentityKey identityKey) { this.supportedVersion = CiphertextMessage.CURRENT_VERSION; this.version = messageVersion; this.sequence = sequence; this.flags = flags; this.baseKey = baseKey; this.baseKeySignature = baseKeySignature; this.ratchetKey = ratchetKey; this.identityKey = identityKey; byte[] version = { ByteUtil.intsToByteHighAndLow((int)this.version, (int)this.supportedVersion) }; WhisperProtos.KeyExchangeMessage.Builder builder = WhisperProtos.KeyExchangeMessage .CreateBuilder() .SetId((sequence << 5) | flags) //(sequence << 5) | flags .SetBaseKey(ByteString.CopyFrom(baseKey.serialize())) .SetRatchetKey(ByteString.CopyFrom(ratchetKey.serialize())) .SetIdentityKey(ByteString.CopyFrom(identityKey.serialize())); if (messageVersion >= 3) { builder.SetBaseKeySignature(ByteString.CopyFrom(baseKeySignature)); } this.serialized = ByteUtil.combine(version, builder.Build().ToByteArray()); }
public PreKeyWhisperMessage(uint messageVersion, uint registrationId, May<uint> preKeyId, uint signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey, WhisperMessage message) { this.version = messageVersion; this.registrationId = registrationId; this.preKeyId = preKeyId; this.signedPreKeyId = signedPreKeyId; this.baseKey = baseKey; this.identityKey = identityKey; this.message = message; WhisperProtos.PreKeyWhisperMessage.Builder builder = WhisperProtos.PreKeyWhisperMessage.CreateBuilder() .SetSignedPreKeyId(signedPreKeyId) .SetBaseKey(ByteString.CopyFrom(baseKey.serialize())) .SetIdentityKey(ByteString.CopyFrom(identityKey.serialize())) .SetMessage(ByteString.CopyFrom(message.serialize())) .SetRegistrationId(registrationId); if (preKeyId.HasValue) // .isPresent() { builder.SetPreKeyId(preKeyId.ForceGetValue()); // get() } byte[] versionBytes = { ByteUtil.intsToByteHighAndLow((int)this.version, (int)CURRENT_VERSION) }; byte[] messageBytes = builder.Build().ToByteArray(); this.serialized = ByteUtil.combine(versionBytes, messageBytes); }
public PreKeySignalMessage(uint messageVersion, uint registrationId, May <uint> preKeyId, uint signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey, SignalMessage message) { this.version = messageVersion; this.registrationId = registrationId; this.preKeyId = preKeyId; this.signedPreKeyId = signedPreKeyId; this.baseKey = baseKey; this.identityKey = identityKey; this.message = message; PreKeySignalMessage preKeySignalMessage = new PreKeySignalMessage { SignedPreKeyId = signedPreKeyId, BaseKey = ByteString.CopyFrom(baseKey.serialize()), IdentityKey = ByteString.CopyFrom(identityKey.serialize()), Message = ByteString.CopyFrom(message.serialize()), RegistrationId = registrationId }; if (preKeyId.HasValue) // .isPresent() { preKeySignalMessage.PreKeyId = preKeyId.ForceGetValue(); // get() } byte[] versionBytes = { ByteUtil.intsToByteHighAndLow((int)this.version, (int)CURRENT_VERSION) }; byte[] messageBytes = preKeySignalMessage.ToByteArray(); this.serialized = ByteUtil.combine(versionBytes, messageBytes); }
public PreKeySignalMessage(uint messageVersion, uint registrationId, May <uint> preKeyId, uint signedPreKeyId, ECPublicKey baseKey, IdentityKey identityKey, SignalMessage message) { this.version = messageVersion; this.registrationId = registrationId; this.preKeyId = preKeyId; this.signedPreKeyId = signedPreKeyId; this.baseKey = baseKey; this.identityKey = identityKey; this.message = message; WhisperProtos.PreKeySignalMessage.Builder builder = WhisperProtos.PreKeySignalMessage.CreateBuilder() .SetSignedPreKeyId(signedPreKeyId) .SetBaseKey(ByteString.CopyFrom(baseKey.serialize())) .SetIdentityKey(ByteString.CopyFrom(identityKey.serialize())) .SetMessage(ByteString.CopyFrom(message.serialize())) .SetRegistrationId(registrationId); if (preKeyId.HasValue) // .isPresent() { builder.SetPreKeyId(preKeyId.ForceGetValue()); // get() } byte[] versionBytes = { ByteUtil.intsToByteHighAndLow((int)this.version, (int)CURRENT_VERSION) }; byte[] messageBytes = builder.Build().ToByteArray(); this.serialized = ByteUtil.combine(versionBytes, messageBytes); }
public bool IsTrustedIdentity(string name, IdentityKey identityKey) { if (this.OnisTrustedIdentity != null) { return(this.OnisTrustedIdentity(name, identityKey.serialize())); } return(false); // FIXME: this isn't correct workaround only }
public bool SaveIdentity(string name, IdentityKey identityKey) { if (this.OnsaveIdentity != null) { return(this.OnsaveIdentity(name, identityKey.serialize())); } return(false); }
public long SaveIdentity(long recipientId, IdentityKey identityKey) { String identityKeyString = Base64.encodeBytes(identityKey.serialize()); // TODO: real mac var identity = new Identity() { RecipientId = recipientId, Key = identityKeyString, Mac = Base64.encode(identityKeyString) }; return(conn.InsertOrReplace(identity)); }
public void setIdentityKey(string name, IdentityKey identityKey, string accountId) { dB.InsertOrReplace(new IdentityKeyTable() { id = IdentityKeyTable.generateId(name, accountId), name = name, accountId = accountId, identityKey = identityKey.serialize() }); }
public bool IsTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) { if (direction == Direction.RECEIVING) { return(true); } string savedIdentity = LibsignalDBContext.GetIdentityLocked(address.Name); if (savedIdentity == null) { return(true); } else { //TODO compare timestamps & firstUse, see Signal-Android impl string identity = Base64.encodeBytes(identityKey.serialize()); return(savedIdentity == Base64.encodeBytes(identityKey.serialize())); } }
/// <summary> /// Generates the OMEMO fingerprint for displaying as a QR code. /// </summary> /// <param name="key">The identity public key.</param> /// <param name="bareJid">The bare JID the fingerprint belongs to.</param> /// <param name="deviceId">The OMEMO device id the fingerprint belongs to.</param> /// <returns>A string representation of the fingerprint concatenated with JID and device id.</returns> public static string generateOmemoQrCodeFingerprint(IdentityKey key, string bareJid, uint deviceId) { StringBuilder sb = new StringBuilder("xmpp:"); sb.Append(bareJid); sb.Append("?omemo-sid-"); sb.Append(deviceId); sb.Append('='); sb.Append(byteArrayToHexString(key.serialize())); return(sb.ToString()); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="account"></param> /// <returns></returns> public static string generateOmemoQrCodeFingerprint(IdentityKey key, XMPPAccount account) { StringBuilder sb = new StringBuilder("xmpp:"); sb.Append(account.getBareJid()); sb.Append("?omemo-sid-"); sb.Append(account.omemoDeviceId); sb.Append('='); sb.Append(byteArrayToHexString(key.serialize())); return(sb.ToString()); }
public static void generateCurve25519IdentityKeys() { //MasterCipher masterCipher = new MasterCipher(masterSecret); ECKeyPair djbKeyPair = Curve.generateKeyPair(); IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey()); byte[] djbPrivateKey = /*masterCipher.encryptKey(*/ djbKeyPair.getPrivateKey().serialize() /*)*/; save(IDENTITY_PUBLIC_KEY_DJB_PREF, System.Convert.ToBase64String(djbIdentityKey.serialize())); save(IDENTITY_PRIVATE_KEY_DJB_PREF, System.Convert.ToBase64String(djbPrivateKey)); }
public bool SaveIdentity(SignalProtocolAddress address, IdentityKey identityKey) { LibsignalDBContext.SaveIdentityLocked(address, Base64.EncodeBytes(identityKey.serialize())).Wait(); //TODO wait is bad return(true); }
public ScannableFingerprint(int version, string localStableIdentifier, IdentityKey localIdentityKey, string remoteStableIdentifier, IdentityKey remoteIdentityKey) { this.combinedFingerprint = CombinedFingerprint.CreateBuilder() .SetVersion((uint)version) .SetLocalFingerprint(FingerprintData.CreateBuilder() .SetIdentifier(ByteString.CopyFrom(Encoding.UTF8.GetBytes(localStableIdentifier))) .SetPublicKey(ByteString.CopyFrom(localIdentityKey.serialize()))) .SetRemoteFingerprint(FingerprintData.CreateBuilder() .SetIdentifier(ByteString.CopyFrom(Encoding.UTF8.GetBytes(remoteStableIdentifier))) .SetPublicKey(ByteString.CopyFrom(remoteIdentityKey.serialize()))) .Build(); }
public void setLocalIdentityKey(IdentityKey identityKey) { this.sessionStructure = this.sessionStructure.ToBuilder() .SetLocalIdentityPublic(ByteString.CopyFrom(identityKey.serialize())) .Build(); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { IdentityKey pubKey = (IdentityKey)value; writer.WriteValue(Base64.EncodeBytesWithoutPadding(pubKey.serialize())); }
public void setRemoteIdentityKey(IdentityKey identityKey) { sessionStructure = sessionStructure.ToBuilder() .SetRemoteIdentityPublic(ByteString.CopyFrom(identityKey.serialize())) .Build(); }
public bool SaveIdentity(SignalProtocolAddress address, IdentityKey identityKey) { LibsignalDBContext.SaveIdentityLocked(address, Base64.encodeBytes(identityKey.serialize())); return(true); }
public void setLocalIdentityKey(IdentityKey identityKey) { this.sessionStructure.LocalIdentityPublic = ByteString.CopyFrom(identityKey.serialize()); }