Пример #1
0
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        /// <summary>
        /// Loads all OMEMO keys from the given store.
        /// </summary>
        /// <param name="omemoStore">A persistent store for all the OMEMO related data (e.g. device ids and keys).</param>
        /// <returns>Returns true on success.</returns>
        public bool loadOmemoKeys(IOmemoStore omemoStore)
        {
            if (!omemoKeysGenerated)
            {
                Logger.Error("Failed to load OMEMO keys for: " + getBareJid() + " - run generateOmemoKeys() first!");
                return(false);
            }

            OMEMO_PRE_KEYS.Clear();
            OMEMO_PRE_KEYS.AddRange(omemoStore.LoadPreKeys());
            if (OMEMO_PRE_KEYS.Count <= 0)
            {
                Logger.Error("Failed to load OMEMO prekeys for: " + getBareJid());
                return(false);
            }

            omemoSignedPreKeyPair = omemoStore.LoadSignedPreKey(omemoSignedPreKeyId);
            if (omemoSignedPreKeyPair is null)
            {
                Logger.Error("Failed to load OMEMO signed prekey pair for: " + getBareJid());
                return(false);
            }

            Logger.Info("Successfully loaded OMEMO keys for: " + getBareJid());
            return(true);
        }
Пример #2
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--
        /// <summary>
        /// Basic Constructor
        /// </summary>
        /// <history>
        /// 06/08/2018 Created [Fabian Sauter]
        /// </history>
        public OmemoHelper(XmppConnection connection, IOmemoStore omemoStore)
        {
            CONNECTION  = connection;
            OMEMO_STORE = omemoStore;

            OMEMO_SESSIONS = new Dictionary <string, OmemoSession>();
            MESSAGE_CACHE  = new Dictionary <string, Tuple <List <OmemoMessageMessage>, OmemoSessionBuildHelper> >();

            reset();
        }
Пример #3
0
 /// <summary>
 /// Stores all OMEMO keys in the given store.
 /// </summary>
 /// <param name="omemoStore">A persistent store for all the OMEMO related data (e.g. device ids and keys).</param>
 /// <returns>Returns true on success.</returns>
 public bool storeOmemoKeys(IOmemoStore omemoStore)
 {
     if (!checkOmemoKeys())
     {
         Logger.Error("Failed to save OMEMO keys for: " + getBareJid());
         return(false);
     }
     omemoStore.StoreSignedPreKey(omemoSignedPreKeyId, omemoSignedPreKeyPair);
     omemoStore.StorePreKeys(OMEMO_PRE_KEYS);
     return(true);
 }
Пример #4
0
        public void replaceOmemoPreKey(uint preKeyId, IOmemoStore omemoStore)
        {
            // Remove key:
            foreach (PreKeyRecord key in OMEMO_PRE_KEYS)
            {
                if (key.getId() == preKeyId)
                {
                    OMEMO_PRE_KEYS.Remove(key);
                    omemoStore.RemovePreKey(preKeyId);
                    break;
                }
            }

            // Generate new key:
            PreKeyRecord newKey = KeyHelper.generatePreKeys(preKeyId, 1)[0];

            OMEMO_PRE_KEYS.Add(newKey);
            omemoStore.StorePreKey(newKey.getId(), newKey);
            omemoBundleInfoAnnounced = false;
        }
Пример #5
0
        /// <summary>
        /// Enables OMEMO encryption for messages for this
        /// Has to be enabled before connecting.
        /// </summary>
        /// <param name="omemoStore">A persistent store for all the OMEMO related data (e.g. device ids and keys).</param>
        /// <returns>Returns true on success.</returns>
        public bool EnableOmemo(IOmemoStore omemoStore)
        {
            if (state != ConnectionState.DISCONNECTED)
            {
                throw new InvalidOperationException(LOGGER_TAG + "Unable to enable OMEMO. state != " + ConnectionState.DISCONNECTED.ToString() + " - " + state.ToString());
            }

            // Load OMEMO keys for the current account:
            if (!account.omemoKeysGenerated)
            {
                Logger.Error(LOGGER_TAG + "Failed to enable OMEMO for account: " + account.getBareJid() + " - generate OMEMO keys first!");
                omemoHelper = null;
                return(false);
            }
            else if (!account.loadOmemoKeys(omemoStore))
            {
                omemoHelper = null;
                return(false);
            }
            omemoHelper = new OmemoHelper(this, omemoStore);
            return(true);
        }
Пример #6
0
 /// <summary>
 /// Enables OMEMO encryption for messages for this connection.
 /// Has to be enabled before connecting.
 /// </summary>
 /// <param name="omemoStore">A persistent store for all the OMEMO related data (e.g. device ids and keys).</param>
 /// <returns>Returns true on success.</returns>
 public bool enableOmemo(IOmemoStore omemoStore)
 {
     return(connection.EnableOmemo(omemoStore));
 }
Пример #7
0
 /// <summary>
 /// Validates if the given identity public key should be trusted.
 /// </summary>
 /// <param name="address">The signal protocol address corresponding to the given public identity key.</param>
 /// <param name="publicKey">The public identity key we want to validate.</param>
 /// <param name="omemoStore">The OMEMO store that keeps all OMEMO related keys.</param>
 /// <returns>True if we trust else false.</returns>
 private Task <bool> isFingerprintTrustedAsync(SignalProtocolAddress address, ECPublicKey publicKey, IOmemoStore omemoStore)
 {
     return(Task.Run(() =>
     {
         OmemoFingerprint fingerprint = omemoStore.LoadFingerprint(address);
         if (!(fingerprint is null))
         {
             if (!fingerprint.checkIdentityKey(publicKey))
             {
                 Logger.Warn("Received not OMEMO encrypted message with a not matching public identity key from: " + address.ToString());
                 return false;
             }
             fingerprint.lastSeen = DateTime.Now;
         }