Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private void CloseOTRSession(string session_closed_message)
        {
            DebugPrint("Ending OTR session");

            _otr_event_args = new OTREventArgs();
            _otr_event_args.SetMessage(session_closed_message);
            _otr_event_args.SetOTREvent(OTR_EVENT.CLOSED);
            DoOTREvent(_otr_event_args);

            _message_state = OTR_MESSAGE_STATE.MSG_STATE_PLAINTEXT;
            _message_manager = null;
            _ake_keys_manager = null;
            _dsa_signer = null;
            _signature_manager = null;
            _smp_manager = null;
            _ake_keys = null;
            _my_unique_id = string.Empty;
            _my_buddy_unique_id = string.Empty;
            _otr_fragment_object = null;
            EndSMPSession();
        }
Esempio n. 3
0
        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);
        }