コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 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
 }
コード例 #6
0
 public bool SaveIdentity(string name, IdentityKey identityKey)
 {
     if (this.OnsaveIdentity != null)
     {
         return(this.OnsaveIdentity(name, identityKey.serialize()));
     }
     return(false);
 }
コード例 #7
0
        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));
        }
コード例 #8
0
 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()
     });
 }
コード例 #9
0
ファイル: Store.cs プロジェクト: mrumler/Signal-Windows
        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()));
            }
        }
コード例 #10
0
ファイル: CryptoUtils.cs プロジェクト: gema-arta/UWPX-Client
        /// <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());
        }
コード例 #11
0
        /// <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());
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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());
        }
コード例 #14
0
ファイル: Store.cs プロジェクト: zez3/Signal-Windows
 public bool SaveIdentity(SignalProtocolAddress address, IdentityKey identityKey)
 {
     LibsignalDBContext.SaveIdentityLocked(address, Base64.EncodeBytes(identityKey.serialize())).Wait(); //TODO wait is bad
     return(true);
 }
コード例 #15
0
 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();
 }
コード例 #16
0
		public void setLocalIdentityKey(IdentityKey identityKey)
		{
			this.sessionStructure = this.sessionStructure.ToBuilder()
														 .SetLocalIdentityPublic(ByteString.CopyFrom(identityKey.serialize()))
														 .Build();
		}
コード例 #17
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            IdentityKey pubKey = (IdentityKey)value;

            writer.WriteValue(Base64.EncodeBytesWithoutPadding(pubKey.serialize()));
        }
コード例 #18
0
 public void setRemoteIdentityKey(IdentityKey identityKey)
 {
     sessionStructure = sessionStructure.ToBuilder()
                        .SetRemoteIdentityPublic(ByteString.CopyFrom(identityKey.serialize()))
                        .Build();
 }
コード例 #19
0
ファイル: Store.cs プロジェクト: mrumler/Signal-Windows
 public bool SaveIdentity(SignalProtocolAddress address, IdentityKey identityKey)
 {
     LibsignalDBContext.SaveIdentityLocked(address, Base64.encodeBytes(identityKey.serialize()));
     return(true);
 }
コード例 #20
0
ファイル: SessionState.cs プロジェクト: jmue/libaxolotl-uwp
 public void setLocalIdentityKey(IdentityKey identityKey)
 {
     this.sessionStructure = this.sessionStructure.ToBuilder()
                             .SetLocalIdentityPublic(ByteString.CopyFrom(identityKey.serialize()))
                             .Build();
 }
コード例 #21
0
 public void setLocalIdentityKey(IdentityKey identityKey)
 {
     this.sessionStructure.LocalIdentityPublic = ByteString.CopyFrom(identityKey.serialize());
 }