예제 #1
0
        public SignatureManager(DSASigner dsa_signer)
        {
            if (dsa_signer == null)
             throw new ArgumentException("SignatureManager: DSA signer object cannot be null");

            _dsa_signer = dsa_signer;

            _dsa_public_key_bytes_encoded = new byte[_dsa_signer.GetPublicKeyEncodedMpi().Length];
            Buffer.BlockCopy(_dsa_signer.GetPublicKeyEncodedMpi(), 0, _dsa_public_key_bytes_encoded, 0, _dsa_public_key_bytes_encoded.Length);
        }
예제 #2
0
        private static byte[] ComputeX(DSASigner dsa_signer, byte[] dsa_public_key_bytes_encoded, byte[] key_id_byte_array, byte[] hashed_m_byte_array_data)
        {
            if (key_id_byte_array == null || key_id_byte_array.Length < 1)
                throw new ArgumentException("ComputeX: The key id byte array should not be null/empty");

            if (hashed_m_byte_array_data == null || hashed_m_byte_array_data.Length < 1)
                throw new ArgumentException("ComputeX: The hashed m byte array should not be null/empty");

            if (dsa_signer == null)
                throw new ArgumentException("ComputeX: DSA signer object cannot be null");

            byte[] _signature_r_byte_array = null;
            byte[] _signature_s_byte_array = null;

            dsa_signer.GenerateSignature(hashed_m_byte_array_data, ref _signature_r_byte_array, ref _signature_s_byte_array);

            if (_signature_r_byte_array == null || _signature_r_byte_array.Length < 1)
                throw new InvalidDataException("ComputeX: The computed DSA signature parameter 'r' byte array cannot be null/empty");

            if (_signature_s_byte_array == null || _signature_s_byte_array.Length < 1)
                throw new InvalidDataException("ComputeX: The computed DSA signature parameter 's' byte array cannot be null/empty");

            byte[] _hashed_m_data_signature = null;
            byte[] _encoded_key_id_byte_array = null;

            try
            {

                byte[] _encoded_signature_r_byte_array = null;
                byte[] _encoded_signature_s_byte_array = null;

                /* This is unnecessary. It's just here to complement DecodeMacfromBytes used in IsEncryptedSignatureVerified().
                 * It should be removed if performance becomes an issue. */
                Utility.EncodeOTRMacBE(_signature_r_byte_array, ref _encoded_signature_r_byte_array);
                Utility.EncodeOTRMacBE(_signature_s_byte_array, ref _encoded_signature_s_byte_array);

                if (_encoded_signature_r_byte_array == null || _encoded_signature_r_byte_array.Length < 1)
                    throw new InvalidDataException("ComputeX: The encoded DSA signature parameter 'r' byte array cannot be null/empty");

                if (_encoded_signature_s_byte_array == null || _encoded_signature_s_byte_array.Length < 1)
                    throw new InvalidDataException("ComputeX: The encoded DSA signature parameter 's' byte array cannot be null/empty");

                _hashed_m_data_signature = new byte[_encoded_signature_r_byte_array.Length + _encoded_signature_s_byte_array.Length];

                Buffer.BlockCopy(_encoded_signature_r_byte_array, 0, _hashed_m_data_signature, 0, _encoded_signature_r_byte_array.Length);
                Buffer.BlockCopy(_encoded_signature_s_byte_array, 0, _hashed_m_data_signature, _encoded_signature_r_byte_array.Length, _encoded_signature_s_byte_array.Length);

                Utility.EncodeOTRInt(key_id_byte_array, ref _encoded_key_id_byte_array);

            }
            catch (Exception ex)
            {

                throw new InvalidDataException("ComputeX:" + ex.ToString());

            }

            if (_encoded_key_id_byte_array == null || _encoded_key_id_byte_array.Length < 1)
                throw new InvalidDataException("ComputeX: The encoded key id byte array should not be null/empty");

            int _x_data_array_length = _encoded_key_id_byte_array.Length + dsa_public_key_bytes_encoded.Length + _hashed_m_data_signature.Length;

            byte[] _x_data_array = new byte[_x_data_array_length];

            Buffer.BlockCopy(dsa_public_key_bytes_encoded, 0, _x_data_array, 0, dsa_public_key_bytes_encoded.Length);
            Buffer.BlockCopy(_encoded_key_id_byte_array, 0, _x_data_array, dsa_public_key_bytes_encoded.Length, _encoded_key_id_byte_array.Length);
            Buffer.BlockCopy(_hashed_m_data_signature, 0, _x_data_array, dsa_public_key_bytes_encoded.Length + _encoded_key_id_byte_array.Length, _hashed_m_data_signature.Length);

            return _x_data_array;
        }
예제 #3
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        public OTRSession(string my_unique_id, string my_buddy_unique_id)
        {
            if (string.IsNullOrEmpty(my_unique_id))
                throw new ArgumentException("OTRSession:My uique ID cannot be null/empty");

            if (string.IsNullOrEmpty(my_buddy_unique_id))
                throw new ArgumentException("OTRSession:My buddy's unique ID cannot be null/empty");

            if (my_buddy_unique_id.Equals(my_unique_id))
                throw new ArgumentException("OTRSession:My uique ID and My buddy's unique ID cannot be the same value");

            _my_unique_id = my_unique_id;
            _my_buddy_unique_id = my_buddy_unique_id;

            _ake_keys_manager = new AKEKeysManager();
            _otr_session_object = new OTRSessionObjects();

            _dsa_signer = new DSASigner();
            _signature_manager = new SignatureManager(_dsa_signer);
        }
예제 #4
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        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();
        }
예제 #5
0
파일: OTRSession.cs 프로젝트: zamud/OTRLib
        public OTRSession(string my_unique_id, string my_buddy_unique_id, DSAKeyParams dsa_key_hex_strings, bool debug_mode)
        {
            if (dsa_key_hex_strings == null)
                throw new ArgumentException("OTRSession: The DSA key hex string object cannot be null");

            if (string.IsNullOrEmpty(my_unique_id))
                throw new ArgumentException("OTRSession:My uique ID cannot be null/empty");

            if (string.IsNullOrEmpty(my_buddy_unique_id))
                throw new ArgumentException("OTRSession:My buddy's unique ID cannot be null/empty");

            if (my_buddy_unique_id.Equals(my_unique_id))
                throw new ArgumentException("OTRSession:My uique ID and My buddy's unique ID cannot be the same value");

            _my_unique_id = my_unique_id;
            _my_buddy_unique_id = my_buddy_unique_id;

            _ake_keys_manager = new AKEKeysManager();
            _otr_session_object = new OTRSessionObjects();

            _dsa_signer = new DSASigner(dsa_key_hex_strings);
            _signature_manager = new SignatureManager(_dsa_signer);

            _debug_mode = debug_mode;
        }