예제 #1
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        public void StartOTRSession(string otr_version_string)
        {
            OTR_VERSION _otr_version = Utility.GetOTRVersion(otr_version_string);

            if (_otr_version == OTR_VERSION.INVALID)
            throw new ArgumentException("StartOTRSession:The OTR Version is unsupported or invalid");

            SetOTRVersion(_otr_version);

            _aes_key = Utility.GetRandomByteArray(OTRConstants.AES_KEY_LENGTH_BITS / 8);

            byte[] _dh_commit_message = _message_manager.FormatDHCommit(_otr_session_object.GetMyRecentDHKeyPair().GetDHPublicKeyData(_aes_key, _otr_session_object.GetCounter()));

            _authentication_state = OTR_AUTH_STATE.AUTH_STATE_AWAITING_DH_KEY;

            DebugPrint("Sending DH Commit Message");

            SendOTRMessage(_dh_commit_message);
        }
예제 #2
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        private void ProcessSignatureMessage(OTRMessage otr_message)
        {
            DebugPrint("Received Signature Message");

            _otr_event_args = new OTREventArgs();

            if (_authentication_state != OTR_AUTH_STATE.AUTH_STATE_AWAITING_SIG)
            {

                OTRError("ProcessSignatureMessage: OTR Engine is not in the AUTH_STATE_AWAITING_SIG state",
                  "ProcessSignatureMessage: OTR Engine is not in the AUTH_STATE_AWAITING_SIG state",
                 null);

                return;

            }

            if (otr_message.GetEncodedEncryptedSignature() == null || otr_message.GetEncodedEncryptedSignature().Length < 1)
            {
                OTRError("ProcessSignatureMessage: The encoded encrypted signature byte array cannot be null/empty", null,
                    "OTR Failed. Unexpected error");
                return;
            }

            if (otr_message.GetMacDSignature() == null || otr_message.GetMacDSignature().Length < 1)
              {
                    OTRError("ProcessSignatureMessage: The MAC'd signature byte array cannot be null/empty", null,
                        "OTR Failed. Unexpected error");
                    return;
                }

            _otr_event_args.SetOTREvent(OTR_EVENT.ERROR);

            byte[] dsa_public_key_byte_array_encoded = null;

            bool _is_sig_verified = SignatureManager.IsSignatureVerified(_ake_keys, _otr_session_object.GetMyRecentDHKeyPair(), _otr_session_object.GetBuddyRecentPublicKeyMpi(),
                otr_message.GetEncodedEncryptedSignature(), otr_message.GetMacDSignature(), false, ref _temp_int_32_val, ref dsa_public_key_byte_array_encoded);

            if (_otr_session_object.IsComputeBuddyFingerPrint(dsa_public_key_byte_array_encoded) == false)
            {

                OTRError("ProcessSignatureMessage:" + _my_buddy_unique_id + "'s DSA public key fingerprint computation failed",
                 "ProcessSignatureMessage:" + _my_buddy_unique_id + "'s DSA public key fingerprint computation failed",
                 null);
                _authentication_state = OTR_AUTH_STATE.AUTH_STATE_NONE;
                return;
            }

            if (_is_sig_verified != true)
            {

                OTRError("ProcessSignatureMessage:" + _my_buddy_unique_id + "'s signature verification failed",
                    "ProcessSignatureMessage:" + _my_buddy_unique_id + "'s signature verification failed",
                    null);
                _authentication_state = OTR_AUTH_STATE.AUTH_STATE_NONE;
                return;
            }

            /* Inform client of OTR readiness  */
            _otr_session_object.SetFirstBuddyPublicKeyID(_temp_int_32_val);
            _authentication_state = OTR_AUTH_STATE.AUTH_STATE_NONE;
            _message_state = OTR_MESSAGE_STATE.MSG_STATE_ENCRYPTED;
            _otr_event_args.SetOTREvent(OTR_EVENT.READY);
            _otr_event_args.SetMessage(_my_buddy_unique_id + "'s signature verification successful");

            DoOTREvent(_otr_event_args);
        }
예제 #3
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        private void ProcessDHKeyMessage(OTRMessage otr_message)
        {
            DebugPrint("Received DH Key Message");

            _otr_event_args = new OTREventArgs();

            if (_authentication_state != OTR_AUTH_STATE.AUTH_STATE_AWAITING_DH_KEY)
            {

                OTRError("ProcessDHKeyMessage: OTR Engine is not in the AUTH_STATE_AWAITING_DH_KEY state", "ProcessDHKeyMessage: OTR Engine is not in the AUTH_STATE_AWAITING_DH_KEY state",
                null);

                return;

            }

            if (otr_message.GetGxMpi() == null || otr_message.GetGxMpi().Length < 1)
            {
                OTRError("ProcessDHKeyMessage: The received MPI encoded public key byte array cannot be null/empty", null,
                    "OTR Failed. Unexpected error");
                return;
            }

            if (_otr_session_object.IsSetBuddyFirstPublicKey(otr_message.GetGxMpi()) == false)
            {

                OTRError("ProcessDHKeyMessage:" + _my_buddy_unique_id + "'s DH public key is invalid",
                    "ProcessDHKeyMessage:" + _my_buddy_unique_id + "'s DH public key is invalid",
               "OTR Failed. Unexpected error");

                return;
            }

               _ake_keys = _ake_keys_manager.ComputeKeys(_otr_session_object.GetMyRecentDHKeyPair(), _otr_session_object.GetBuddyRecentPublicKey());

            _signature_manager.ComputeSignature(_ake_keys, _otr_session_object.GetMyRecentDHKeyPair().GetPublicKeyMpiBytes(), _otr_session_object.GetMyRecentDHKeyPair().GetKeyIDBytes(),
                 otr_message.GetGxMpi(), _otr_session_object.GetCounter(), true);

            if (_aes_key == null || _aes_key.Length < 1)
            {
                OTRError("ProcessDHKeyMessage: The AES key byte array cannot be null/empty", null,
                    "OTR Failed. Unexpected error");
                return;
            }

            Utility.EncodeOTRDataBE(_aes_key, ref _temp_buffer);

            _temp_buffer_2 = new byte[_temp_buffer.Length + _signature_manager.GetSignatureDataLength()];

            Buffer.BlockCopy(_temp_buffer, 0, _temp_buffer_2, 0, _temp_buffer.Length);
            Buffer.BlockCopy(_signature_manager.GetSignatureDataBytes(), 0, _temp_buffer_2, _temp_buffer.Length, _signature_manager.GetSignatureDataLength());

            byte[] _dh_reveal_byte_array = _message_manager.FormatRevealSig(_temp_buffer_2);

            _authentication_state = OTR_AUTH_STATE.AUTH_STATE_AWAITING_SIG;

            DebugPrint("Sending Reveal Signature Message");
            SendOTRMessage(_dh_reveal_byte_array);
        }
예제 #4
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        private void ProcessRevealSigMessage(OTRMessage otr_message)
        {
            DebugPrint("Received Reveal Signature Message");

            _otr_event_args = new OTREventArgs();

            if (_authentication_state != OTR_AUTH_STATE.AUTH_STATE_AWAITING_REVEAL_SIG)
            {
                OTRError("ProcessRevealSigMessage: OTR Engine is not in the AUTH_STATE_AWAITING_REVEAL_SIG state",
                  "ProcessRevealSigMessage: OTR Engine is not in the AUTH_STATE_AWAITING_REVEAL_SIG state",
             null);

                return;

            }

            if (otr_message.GetRevealedKey() == null || otr_message.GetRevealedKey().Length < 1)
            {
                OTRError("ProcessRevealSigMessage: The AES revealed key byte array cannot be null/empty", null,
                    "OTR Failed. Unexpected error");
                 return;
            }

            if (otr_message.GetEncodedEncryptedSignature() == null || otr_message.GetEncodedEncryptedSignature().Length < 1)
            {
                OTRError("ProcessRevealSigMessage: The encoded encrypted signature byte array cannot be null/empty", null,
                    "OTR Failed. Unexpected error");
                return;
            }

            if (otr_message.GetMacDSignature() == null || otr_message.GetMacDSignature().Length < 1)
            {
                OTRError("ProcessRevealSigMessage: The MAC'd signature byte array cannot be null/empty", null,
                    "OTR Failed. Unexpected error");
                return;
            }

            _otr_event_args.SetOTREvent(OTR_EVENT.ERROR);

            if (_dh_commit_message == null || _dh_commit_message.GetEncryptedGxMpi() == null || _dh_commit_message.GetEncryptedGxMpi().Length < 1)
            {
                OTRError("ProcessRevealSigMessage: The MPI encoded encrypted public key (g^x mpi) should not be null/empty",
                  "ProcessRevealSigMessage: The MPI encoded encrypted public key (g^x mpi) should not be null/empty",
             "OTR Failed. Unexpected error");

                return;

            }

            if (_otr_session_object.IsSetMyBuddyFirstPublicKey(otr_message.GetRevealedKey(), _dh_commit_message.GetEncryptedGxMpi(),
                _dh_commit_message.GetHashedGxMpi()) == false)
            {

                OTRError("ProcessRevealSigMessage: The MPI encoded decrypted public key (g^x mpi) should not be null/empty",
                "ProcessRevealSigMessage: The MPI encoded decrypted public key (g^x mpi) should not be null/empty",
                "OTR Failed. Unexpected error");
                return;

            }

            _ake_keys = _ake_keys_manager.ComputeKeys(_otr_session_object.GetMyRecentDHKeyPair(), _otr_session_object.GetBuddyRecentPublicKey());

            byte[] dsa_public_key_byte_array_encoded = null;

            bool _is_sig_verified = SignatureManager.IsSignatureVerified(_ake_keys, _otr_session_object.GetMyRecentDHKeyPair(), _otr_session_object.GetBuddyRecentPublicKeyMpi(),
                otr_message.GetEncodedEncryptedSignature(), otr_message.GetMacDSignature(), true, ref _temp_int_32_val, ref dsa_public_key_byte_array_encoded);

            if (_otr_session_object.IsComputeBuddyFingerPrint(dsa_public_key_byte_array_encoded) == false)
            {

                OTRError("ProcessRevealSigMessage:" + _my_buddy_unique_id + "'s DSA public key fingerprint computation failed",
                 "ProcessRevealSigMessage:" + _my_buddy_unique_id + "'s DSA public key fingerprint computation failed",
                 null);
                _authentication_state = OTR_AUTH_STATE.AUTH_STATE_NONE;
                return;
            }

            if (_is_sig_verified != true)
            {

                OTRError("ProcessRevealSigMessage:" + _my_buddy_unique_id + "'s signature verification failed",
                   "ProcessRevealSigMessage:" + _my_buddy_unique_id + "'s signature verification failed",
                  "OTR Failed. Unexpected error");

                _authentication_state = OTR_AUTH_STATE.AUTH_STATE_NONE;

                return;
            }

            _signature_manager.ComputeSignature(_ake_keys, _otr_session_object.GetMyRecentDHKeyPair().GetPublicKeyMpiBytes(), _otr_session_object.GetMyRecentDHKeyPair().GetKeyIDBytes(),
               _otr_session_object.GetBuddyRecentPublicKeyMpi(), _otr_session_object.GetCounter(), false);

            //Send signature message
            byte[] _dh_signature_byte_array = _message_manager.FormatSignature(_signature_manager.GetSignatureDataBytes());

            DebugPrint("Sending Signature Message");
            SendOTRMessage(_dh_signature_byte_array);

            /* Inform client of OTR readiness  */
            _otr_session_object.SetFirstBuddyPublicKeyID(_temp_int_32_val);
            _authentication_state = OTR_AUTH_STATE.AUTH_STATE_NONE;
            _message_state = OTR_MESSAGE_STATE.MSG_STATE_ENCRYPTED;
            _otr_event_args.SetOTREvent(OTR_EVENT.READY);
            _otr_event_args.SetMessage(_my_buddy_unique_id + "'s signature verification successful");

            DoOTREvent(_otr_event_args);
        }
예제 #5
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        private void ProcessDHCommitMessage(OTRMessage otr_message)
        {
            DebugPrint("Received DH Commit Message");

            if (_authentication_state != OTR_AUTH_STATE.AUTH_STATE_NONE)
            {

                OTRError("ProcessDHCommitMessage: OTR Engine is not in the AUTH_STATE_NONE state", "ProcessDHCommitMessage: OTR Engine is not in the AUTH_STATE_NONE state",
                null);

                return;

            }

            _dh_commit_message = otr_message;

            byte[] _dh_key_message = _message_manager.FormatDHKey(_otr_session_object.GetMyRecentDHKeyPair().GetPublicKeyMpiBytes());

            _authentication_state = OTR_AUTH_STATE.AUTH_STATE_AWAITING_REVEAL_SIG;

            DebugPrint("Sending DH Key Message");
            SendOTRMessage(_dh_key_message);
        }