示例#1
0
        private bool TryGetReader(HttpsSession https, ref byte[] buffer, ref int length, out HttpsReader reader)
        {
            reader = null;
            if (length < 5)
            {
                return(false);
            }
            int fragmentLength = (buffer[3] << 8) + buffer[4] + 5;

            if (length < fragmentLength)
            {
                return(false);
            }
            else if (length == fragmentLength)
            {
                reader = new HttpsReader(https, buffer, length);
                length = 0;
            }
            else
            {
                // todo: this is so inefficient!
                byte[] fragmentBuffer = new byte[fragmentLength];
                Array.Copy(buffer, fragmentBuffer, fragmentLength);
                reader = new HttpsReader(https, fragmentBuffer, fragmentLength);
                Array.Copy(buffer, fragmentLength, buffer, 0, length - fragmentLength);
                length -= fragmentLength;
            }
            return(true);
        }
示例#2
0
 public HttpsWriter(HttpsSession session, ERecordType recordType)
 {
     IsEncrypted = false;
     RecordType  = recordType;
     Write((byte)recordType);
     Write((ushort)session.Protocol);
     Write((ushort)0x0000); // length, must fixup on compile.
 }
示例#3
0
 public HttpSmsgFinished(HttpsSession session, byte[] hash)
     : base(session, ERecordType.Handshake)
 {
     Write((byte)EHandshake.Finished);
     Write24BitInt(0x000000); // position = 6, length, must be fixed up before send.
     Write(hash);
     FixupLength24Bit(6, (int)Length - 9);
 }
示例#4
0
 public HttpsReader(HttpsSession session, byte[] buffer, int length)
     : base(buffer, length)
 {
     IsDecrypted   = false;
     Session       = session;
     RecordType    = (ERecordType)ReadByte();
     RecordVersion = (EProtocol)ReadUShort();
     RecordLength  = ReadUShort();
     VerifyLengthRemaining(this, LengthRemaining, "SSL record header");
     if (Session?.IsClientEncrypting ?? false)
     {
         Decrypt();
     }
 }
示例#5
0
        public HttpsSmsgCertificate(HttpsSession session, IEnumerable <X509Certificate2> certificates)
            : base(session, ERecordType.Handshake)
        {
            Write((byte)EHandshake.ServerCertificate);
            Write24BitInt(0x000000); // position = 6, length, must be fixed up before send.
            Write24BitInt(0x000000); // position = 9, cert chain length, must be fixed up before send.
            int certChainLength = 0;

            foreach (X509Certificate2 certificate in certificates)
            {
                byte[] certData = certificate.GetRawCertData();
                Write24BitInt(certData.Length);
                Write(certData);
                certChainLength += certData.Length + 3;
            }
            FixupLength24Bit(6, (int)Length - 9);
            FixupLength24Bit(9, (int)Length - 12);
        }
示例#6
0
 public HttpsSmsgHello(HttpsSession session, ECipherSuite cipherSuite, byte[] sessionID, byte[] serverRandom)
     : base(session, ERecordType.Handshake)
 {
     Write((byte)EHandshake.ServerHello);
     Write24BitInt(0x000000); // position = 6, length, must be fixed up on compile.
     Write((ushort)session.Protocol);
     Write(serverRandom);     // 32 bytes server random data
     if (sessionID == null)
     {
         Write((byte)0x00); // session id = null
     }
     else
     {
         Write((byte)sessionID.Length);
         Write(sessionID);
     }
     Write((ushort)cipherSuite); // cipher suite used
     Write((byte)0x00);          // compression method used = null
     FixupLength24Bit(6, (int)Length - 9);
 }
示例#7
0
 public HttpsSmsgHelloDone(HttpsSession session)
     : base(session, ERecordType.Handshake)
 {
     Write((byte)EHandshake.ServerHelloDone);
     Write24BitInt(0x000000); // length, always zero
 }
示例#8
0
 public HttpsSmsgAlert(HttpsSession session, int alertLevel, int alertType)
     : base(session, ERecordType.Alert)
 {
     Write((byte)alertLevel);
     Write((byte)alertType);
 }
示例#9
0
 public HttpsSmsgChangeCipher(HttpsSession session, byte payload)
     : base(session, ERecordType.ChangeCipherSpec)
 {
     Write((byte)payload);
 }
 public HttpsSmsgApplicationData(HttpsSession session, byte[] data)
     : base(session, ERecordType.ApplicationData)
 {
     Write(data);
 }