Esempio n. 1
0
        public MessageManager(OTR_VERSION otr_version)
        {
            if (otr_version == OTR_VERSION.INVALID)
            {
                throw new ArgumentException("MessageManager: The OTR version is invalid");
            }

            _otr_version = otr_version;


            _temp_buffer = null;

            try
            {
                Utility.GetEncodedOtrVersion(otr_version, ref _encoded_otr_version_byte_array);
                _message_length_1 = _encoded_otr_version_byte_array.Length;


                if (_otr_version != OTR_VERSION.VERSION_2)
                {
                    _my_instance_tag = Utility.GetRandomInteger(OTRConstants.MIN_INSTANCE_VALUE);
                    _temp_buffer     = BitConverter.GetBytes(_my_instance_tag);

                    Utility.EncodeOTRInt(_temp_buffer, ref _encoded_my_instance_tag);
                    _message_length_1 += _encoded_my_instance_tag.Length * 2;
                }


                _temp_buffer = new byte[1];

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_DH_COMMIT;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_dh_commit_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_DH_KEY;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_dh_key_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_REVEAL_SIGNATURE;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_reveal_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_SIGNATURE;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_signature_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_DATA;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_data_message_type);

                _temp_buffer[0] = 0;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_flag);



                _message_length_1 += _encoded_data_message_type.Length;
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("MessageManager:" + ex.ToString());
            }
        }
Esempio n. 2
0
        public MessageManager(OTR_VERSION otr_version)
        {
            if (otr_version == OTR_VERSION.INVALID)
                throw new ArgumentException("MessageManager: The OTR version is invalid");

            _otr_version = otr_version;

            _temp_buffer = null;

            try
            {

                Utility.GetEncodedOtrVersion(otr_version, ref _encoded_otr_version_byte_array);
                _message_length_1 = _encoded_otr_version_byte_array.Length;

                if (_otr_version != OTR_VERSION.VERSION_2)
                {
                    _my_instance_tag = Utility.GetRandomInteger(OTRConstants.MIN_INSTANCE_VALUE);
                    _temp_buffer = BitConverter.GetBytes(_my_instance_tag);

                    Utility.EncodeOTRInt(_temp_buffer, ref _encoded_my_instance_tag);
                    _message_length_1 += _encoded_my_instance_tag.Length * 2;

                }

                _temp_buffer = new byte[1];

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_DH_COMMIT;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_dh_commit_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_DH_KEY;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_dh_key_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_REVEAL_SIGNATURE;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_reveal_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_SIGNATURE;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_signature_message_type);

                _temp_buffer[0] = OTRConstants.MESSAGE_TYPE_DATA;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_data_message_type);

                _temp_buffer[0] = 0;
                Utility.EncodeOTRByte(_temp_buffer, ref _encoded_flag);

                _message_length_1 += _encoded_data_message_type.Length;

            }
            catch (Exception ex)
            {
                throw new InvalidDataException("MessageManager:" + ex.ToString());
            }
        }
Esempio n. 3
0
        public void RequestOTRSession(string my_buddy_unique_id, string otr_version)
        {
            if (string.IsNullOrEmpty(otr_version) == true)
            {
                throw new ArgumentException("RequestOTRSession: The OTR version string cannot be null/empty");
            }


            if (IsSessionRegistered(my_buddy_unique_id) == false)
            {
                throw new ArgumentException("RequestOTRSession: my buddy unique id does not exist");
            }

            OTR_VERSION _otr_version = Utility.GetOTRVersion(otr_version);


            if (_otr_version == OTR_VERSION.INVALID)
            {
                throw new ArgumentException("RequestOTRSession: OTR version is invalid");
            }

            string _otr_version_string = string.Empty;

            if (_otr_version == OTR_VERSION.VERSION_2)
            {
                _otr_version_string = OTRConstants.OTR_VERSION_2;
            }
            else if (_otr_version == OTR_VERSION.VERSION_3)
            {
                _otr_version_string = OTRConstants.OTR_VERSION_3;
            }

            OTREventArgs _event_args = new OTREventArgs();

            _event_args.SetMessage(_otr_version_string);
            _event_args.SetOTREvent(OTR_EVENT.SEND);
            _event_args.SetSessionID(my_buddy_unique_id);

            OnOTREvent(this, _event_args);
        }
Esempio n. 4
0
 public void SetProtocolVersion(OTR_VERSION protocol_version)
 {
     _protocol_version = protocol_version;
 }
Esempio n. 5
0
 public void SetProtocolVersion(OTR_VERSION protocol_version)
 {
     _protocol_version = protocol_version;
 }
Esempio n. 6
0
        public static void GetEncodedOtrVersion(OTR_VERSION version, ref byte[] encoded_otr_version_byte_array)
        {
            if (version == OTR_VERSION.INVALID)
                return;

            byte [] _temp_buffer = null;
            byte [] _otr_version = new byte [2];

             if (version == OTR_VERSION.VERSION_2)
             {
             _temp_buffer = BitConverter.GetBytes(OTRConstants.iOTR_VERSION_2);
              Buffer.BlockCopy (_temp_buffer,0,_otr_version,0,_otr_version.Length);
             }
             else if (version == OTR_VERSION.VERSION_3)
             {
              _temp_buffer = BitConverter.GetBytes(OTRConstants.iOTR_VERSION_3);
              Buffer.BlockCopy (_temp_buffer,0,_otr_version,0,_otr_version.Length);
             }

            if (_otr_version == null || _otr_version.Length < 1)
            return;

            Utility.EncodeOTRShort(_otr_version, ref encoded_otr_version_byte_array);
        }
Esempio n. 7
0
        private void SetOTRVersion(OTR_VERSION otr_version)
        {
            _current_otr_version = otr_version;
            _message_manager = new MessageManager(otr_version);

            DebugPrint("Setting OTR Version:" + otr_version);
        }
Esempio n. 8
0
        public OTRMessage ExtractMessage(byte[] in_message_byte_array)
        {
            int _next_index = 0;

            _otr_message  = null;
            _temp_buffer  = null;
            _message_type = OTR_MESSAGE_TYPE.INVALID;


            //get protocol version


            _next_index = Utility.DecodeShortFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2);
            OTR_VERSION _otr_version = Utility.GetOTRVersion(_temp_buffer_2);

            if (_otr_version == OTR_VERSION.INVALID)
            {
                throw new ArgumentException("ExtractMessage:OTR version is invalid");
            }



            _otr_message = new OTRMessage();

            _otr_message.SetProtocolVersion(_otr_version);



            // get message type

            _temp_buffer_2 = _temp_buffer = null;
            _next_index    = Utility.DecodeByteFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2);
            _message_type  = GetMessageType(_temp_buffer_2[0]);


            if (_message_type == OTR_MESSAGE_TYPE.INVALID)
            {
                throw new ArgumentException("ExtractMessage:OTR message type is invalid");
            }



            _otr_message.SetMessageType(_message_type);


            //get instance tags
            if (_otr_version != OTR_VERSION.VERSION_2)
            {
                _temp_buffer_2 = _temp_buffer = null;
                _next_index    = Utility.DecodeIntFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2);
                _otr_message.SetSenderInstanceTag(_temp_buffer_2);


                if (_otr_message.GetSenderInstanceTag() < 4)
                {
                    throw new ArgumentException("ExtractMessage:The Sender's instance tag cannot be less than 4");
                }


                if (_buddy_instance_tag == 0)
                {
                    _buddy_instance_tag = _otr_message.GetSenderInstanceTag();
                }


                if (_buddy_instance_tag != 0 && _otr_message.GetSenderInstanceTag() != _buddy_instance_tag)
                {
                    throw new ArgumentException("ExtractMessage:The Sender's instance tag is invalid");
                }



                _temp_buffer_2 = _temp_buffer = null;
                _next_index    = Utility.DecodeIntFromBytes(in_message_byte_array, _next_index, ref _temp_buffer_2);

                _otr_message.SetReceiverInstanceTag(_temp_buffer_2);
            }



            if (_message_type == OTR_MESSAGE_TYPE.DATA)
            {
                return(ExtractData(in_message_byte_array, _next_index));
            }
            else if (_message_type == OTR_MESSAGE_TYPE.DH_COMMIT)
            {
                return(ExtractDHCommit(in_message_byte_array, _next_index));
            }
            else if (_message_type == OTR_MESSAGE_TYPE.DH_KEY)
            {
                return(ExtractDHKey(in_message_byte_array, _next_index));
            }
            else if (_message_type == OTR_MESSAGE_TYPE.REVEAL_SIGNATURE)
            {
                return(ExtractRevealSig(in_message_byte_array, _next_index));
            }
            else if (_message_type == OTR_MESSAGE_TYPE.SIGNATURE)
            {
                return(ExtractSignature(in_message_byte_array, _next_index));
            }



            return(null);
        }