예제 #1
0
        private byte[] EncryptPackage(byte[] data)
        {
            int pkgLength = data.Length;

            serializer.ResetBytePos();
            serializer.Write(pkgLength);
            serializer.Write(data);
            return(serializer.ToArray());
        }
        private byte[] EncryptPackage(byte[] data)
        {
            NetworkSerializer serializer = new NetworkSerializer(8192);
            int pkgLength = data.Length;

            serializer.Clear();
            serializer.Write(pkgLength);
            serializer.Write(data);
            return(serializer.ToArray());
        }
예제 #3
0
 public void PadTo32Bits(int len, NetworkSerializer serializer)
 {
     while (((len++) % 4) != 0)
     {
         serializer.Write((byte)0);
     }
 }
예제 #4
0
        public void AddMessageIntegrity(NetworkSerializer packet)
        {
            string saslPassword = new SASLprep().Prepare(password);

            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string valueToHashMD5        = string.Format("{0}:{1}:{2}", username, realm, saslPassword);

            byte[] hmacSha1Key = md5.ComputeHash(Encoding.UTF8.GetBytes(valueToHashMD5));

            HMACSHA1 hmacSha1 = new HMACSHA1(hmacSha1Key);

            byte[] hmacBytes = hmacSha1.ComputeHash(packet.ByteBuffer, 0, packet.byteLength);

            packet.Write((ushort)STUNAttribute.MessageIntegrity);
            packet.Write((ushort)hmacBytes.Length);
            packet.Write(hmacBytes);
        }
예제 #5
0
        public byte[] WriteRequest()
        {
            serializer.SetBufferLength(0);

            serializer.Write((byte)0x38);

            //method id
            serializer.Write((byte)methodType);

            //attributes
            for (int i = 0; i < attributeBytes.Count; i++)
            {
                serializer.Write(attributeBytes[i]);
            }

            byte[] ret = serializer.ToArray();
            //cleanup
            attributeBytes.Clear();
            serializer.SetBufferLength(0);
            return(ret);
        }
예제 #6
0
        public byte[] WriteRequest()
        {
            Console.WriteLine("\nRequest Method= " + Enum.GetName(typeof(SignalingMethod), methodType));
            serializer.SetBufferLength(0);

            serializer.Write((byte)0x38);

            //method id
            serializer.Write((byte)methodType);

            //attributes
            for (int i = 0; i < attributeBytes.Count; i++)
            {
                //LogAttribute(i);
                serializer.Write(attributeBytes[i]);
            }

            byte[] ret = serializer.ToArray();
            //cleanup
            attributeBytes.Clear();
            serializer.SetBufferLength(0);
            return(ret);
        }
예제 #7
0
        public byte[] WriteRequest()
        {
            Console.WriteLine("\nRequest Method= " + Enum.GetName(typeof(STUNMethod), method));
            serializer.SetBufferLength(0);
            //method id
            serializer.Write((ushort)method);

            //method length
            serializer.Write((ushort)0);

            //transaction id
            serializer.Write(transactionID);

            //attributes
            for (int i = 0; i < attributeBytes.Count; i++)
            {
                LogAttribute(i);
                serializer.Write(attributeBytes[i]);
            }

            //update message length
            int totalLength = serializer.byteLength - 20;
            int lastPos     = serializer.byteLength;

            if (integrity)
            {
                totalLength += 24;
            }
            serializer.byteLength = 2;
            serializer.Write((ushort)totalLength);
            serializer.byteLength = lastPos;

            //method integrity goes here
            if (integrity)
            {
                //GenerateMessageIntegrity(packet);
                AddMessageIntegrity(serializer);
            }

            Console.WriteLine("Message Length = " + totalLength);
            Console.WriteLine("Total Bytes: \n\n" + serializer.byteLength);
            byte[] ret = serializer.ToArray();
            //cleanup
            attributeBytes.Clear();
            serializer.SetBufferLength(0);
            return(ret);
        }