public TextSecureAxolotlStore()
        {
            connection = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), AXOLOTLDB_PATH);

            this.preKeyStore = new TextSecurePreKeyStore(connection);
            this.signedPreKeyStore = new TextSecurePreKeyStore(connection);
            this.identityKeyStore = new TextSecureIdentityKeyStore(connection);
            this.sessionStore = new TextSecureSessionStore(connection);
        }
		/**
         * Construct a SessionCipher for encrypt/decrypt operations on a session.
         * In order to use SessionCipher, a session must have already been created
         * and stored using {@link SessionBuilder}.
         *
         * @param  sessionStore The {@link SessionStore} that contains a session for this recipient.
         * @param  remoteAddress  The remote address that messages will be encrypted to or decrypted from.
         */
		public SessionCipher(SessionStore sessionStore, PreKeyStore preKeyStore,
							 SignedPreKeyStore signedPreKeyStore, IdentityKeyStore identityKeyStore,
							 AxolotlAddress remoteAddress)
		{
			this.sessionStore = sessionStore;
			this.preKeyStore = preKeyStore;
			this.remoteAddress = remoteAddress;
			this.sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
													 identityKeyStore, remoteAddress);
		}
Example #3
0
 /**
  * Construct a SessionCipher for encrypt/decrypt operations on a session.
  * In order to use SessionCipher, a session must have already been created
  * and stored using {@link SessionBuilder}.
  *
  * @param  sessionStore The {@link SessionStore} that contains a session for this recipient.
  * @param  remoteAddress  The remote address that messages will be encrypted to or decrypted from.
  */
 public SessionCipher(SessionStore sessionStore, PreKeyStore preKeyStore,
                      SignedPreKeyStore signedPreKeyStore, IdentityKeyStore identityKeyStore,
                      SignalProtocolAddress remoteAddress)
 {
     this.sessionStore  = sessionStore;
     this.preKeyStore   = preKeyStore;
     this.remoteAddress = remoteAddress;
     sessionBuilder     = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
                                             identityKeyStore, remoteAddress);
 }
 /**
  * Constructs a SessionBuilder.
  *
  * @param sessionStore The {@link org.whispersystems.libsignal.state.SessionStore} to store the constructed session in.
  * @param preKeyStore The {@link  org.whispersystems.libsignal.state.PreKeyStore} where the client's local {@link org.whispersystems.libsignal.state.PreKeyRecord}s are stored.
  * @param identityKeyStore The {@link org.whispersystems.libsignal.state.IdentityKeyStore} containing the client's identity key information.
  * @param remoteAddress The address of the remote user to build a session with.
  */
 public SessionBuilder(SessionStore sessionStore,
                       PreKeyStore preKeyStore,
                       SignedPreKeyStore signedPreKeyStore,
                       IdentityKeyStore identityKeyStore,
                       SignalProtocolAddress remoteAddress)
 {
     this.sessionStore      = sessionStore;
     this.preKeyStore       = preKeyStore;
     this.signedPreKeyStore = signedPreKeyStore;
     this.identityKeyStore  = identityKeyStore;
     this.remoteAddress     = remoteAddress;
 }
 /**
  * Constructs a SessionBuilder.
  *
  * @param sessionStore The {@link org.whispersystems.libaxolotl.state.SessionStore} to store the constructed session in.
  * @param preKeyStore The {@link  org.whispersystems.libaxolotl.state.PreKeyStore} where the client's local {@link org.whispersystems.libaxolotl.state.PreKeyRecord}s are stored.
  * @param identityKeyStore The {@link org.whispersystems.libaxolotl.state.IdentityKeyStore} containing the client's identity key information.
  * @param remoteAddress The address of the remote user to build a session with.
  */
 public SessionBuilder(SessionStore sessionStore,
                       PreKeyStore preKeyStore,
                       SignedPreKeyStore signedPreKeyStore,
                       IdentityKeyStore identityKeyStore,
                       AxolotlAddress remoteAddress)
 {
     this.sessionStore = sessionStore;
     this.preKeyStore = preKeyStore;
     this.signedPreKeyStore = signedPreKeyStore;
     this.identityKeyStore = identityKeyStore;
     this.remoteAddress = remoteAddress;
 }
Example #6
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--
        /// <summary>
        /// Basic Constructor
        /// </summary>
        /// <history>
        /// 06/08/2018 Created [Fabian Sauter]
        /// </history>
        public OmemoHelper(XMPPConnection2 connection)
        {
            this.CONNECTION = connection;

            this.OMEMO_SESSIONS       = new Dictionary <string, OmemoSession>();
            this.MESSAGE_CACHE        = new Dictionary <string, Tuple <List <OmemoMessageMessage>, OmemoSessionBuildHelper> >();
            this.SESSION_STORE        = new OmemoSessionStore(connection.account);
            this.PRE_KEY_STORE        = new OmemoPreKeyStore(connection.account);
            this.SIGNED_PRE_KEY_STORE = new OmemoSignedPreKeyStore(connection.account);
            this.IDENTITY_STORE       = new OmemoIdentityKeyStore(connection.account);

            reset();
        }
        public Models.Message[] GetMessages(ISharedPreferences sharedPref, User SelectedFriend, SessionStore sessionStore,
                                            PreKeyStore preKeyStore, SignedPreKeyStore signedPreKeyStore, IdentityKeyStore identityStore, SignalProtocolAddress SelectedFriendAddress)
        {
            // send the server the user name
            // server side does the selection and return the messages and store it in a message array.
            //Send the login username and password to the server and get response
            string apiUrl    = "https://ycandgap.me/api_server2.php";
            string apiMethod = "getMessage";

            //Login_Request has two properties:username and password
            Login_Request myLogin_Request = new Login_Request();

            Models.Message recieveMessage = new Models.Message();

            //get the login username from previow login page.
            recieveMessage.MessageReceiverRegisID = Convert.ToUInt32(sharedPref.GetString("RegistrationId", string.Empty));
            recieveMessage.MessageSenderRegisID   = SelectedFriend.RegisterationID;
            myLogin_Request.message = recieveMessage;
            UserID = myLogin_Request.RegistrationID;


            // make http post request
            string response = Http.Post(apiUrl, new NameValueCollection()
            {
                { "api_method", apiMethod },
                { "api_data", JsonConvert.SerializeObject(myLogin_Request) }
            });

            // decode json string to dto object
            API_Response2 r = JsonConvert.DeserializeObject <API_Response2>(response);

            // check response
            if (r != null)
            {
                if (!r.IsError && !string.IsNullOrEmpty(r.MessageText))
                {
                    SessionCipher sessionCipher = new SessionCipher(sessionStore, preKeyStore, signedPreKeyStore, identityStore, SelectedFriendAddress);
                    byte[]        decipherMessage;
                    if (!sessionStore.ContainsSession(SelectedFriendAddress))
                    {
                        decipherMessage = sessionCipher.decrypt(new PreKeySignalMessage((JsonConvert.DeserializeObject <byte[]>(r.MessageText))));
                    }
                    else
                    {
                        decipherMessage = sessionCipher.decrypt(new SignalMessage((JsonConvert.DeserializeObject <byte[]>(r.MessageText))));
                    }
                    string checkMessage = Encoding.UTF8.GetString(decipherMessage);

                    SelectedFriend.SelectedUserMessages.Add(new Models.Message
                    {
                        MessageID              = r.MessageID,
                        MessageSenderRegisID   = r.MessageSenderRegisID,
                        MessageReceiverRegisID = r.MessageReceiverRegisID,
                        MessageText            = checkMessage,
                        MessageTimestamp       = r.MessageTimestamp
                    });

                    return(SelectedFriend.SelectedUserMessages.ToArray());
                }
                else
                {
                    //if login fails, pop up an alert message. Wrong username or password or a new user
                    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
                    if (!string.IsNullOrEmpty(r.ErrorMessage))
                    {
                        dialogBuilder.SetMessage(r.ErrorMessage);
                    }
                    else
                    {
                        dialogBuilder.SetMessage("No new messages");
                    }
                    //dialogBuilder.SetPositiveButton("Ok", null);
                    dialogBuilder.Show();
                    return(null);
                }
            }
            else
            {
                if (!sessionStore.ContainsSession(SelectedFriendAddress))
                {
                    // Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
                    SessionBuilder sessionBuilder = new SessionBuilder(sessionStore, preKeyStore, signedPreKeyStore,
                                                                       identityStore, SelectedFriendAddress);
                    RetrievedPreKey preKeyPublic = RetrieveSelectedFriendPublicPreKey(SelectedFriend);
                    IdentityKey     SelectedFriendSignedPreKey = new IdentityKey(JsonConvert.DeserializeObject <byte[]>(SelectedFriend.SignedPreKey), 0);
                    PreKeyBundle    retrievedPreKey            = new PreKeyBundle(SelectedFriend.RegisterationID, 1, preKeyPublic.PrekeyID, preKeyPublic.PublicPreKey.getPublicKey()
                                                                                  , SelectedFriend.SignedPreKeyID, SelectedFriendSignedPreKey.getPublicKey(), JsonConvert.DeserializeObject <byte[]>(SelectedFriend.SignedPreKeySignature)
                                                                                  , new IdentityKey(JsonConvert.DeserializeObject <byte[]>(SelectedFriend.IdentityKey), 0));
                    // Build a session with a PreKey retrieved from the server.
                    sessionBuilder.process(retrievedPreKey);
                }
                return(null);
            }
        }