Esempio n. 1
0
        private void ReceiveApplicationData(INetState ns, byte[] buffer, int length)
        {
            string      request = Encoding.UTF8.GetString(buffer, 0, length);
            HttpRequest http    = new HttpRequest(ns, request);

            try {
                byte[] response = _OnHttpReceive?.Invoke(http);
                HttpsSmsgApplicationData packet = new HttpsSmsgApplicationData(ns.Https, response);
                ns.Send(packet);
                if (Config.DebugShowHttpRequests)
                {
                    Kernel.WriteLine(TypeName, $"{ns} req({http.RequestHost}{http.RequestPage}) => {packet.Length} encrypted bytes");
                    if (Config.DebugShowHttpResponses)
                    {
                        Console.WriteLine(response);
                    }
                }
                // string decrypted = packet.DebugDecryptSentPacket(ns, ns.Https.SequenceNumberSent - 1);
            }
            catch (Exception e) {
                Console.WriteLine($"{TypeName}: {ns} failed to receive ({e.Message})");
                Console.WriteLine(request);
            }
            if (!http.ParamConnectionKeepAlive)
            {
                ns.DisposeAfterNextFlush();
            }
        }
Esempio n. 2
0
        // === Http ===================================================================================================
        // ============================================================================================================

        public void ReceiveHttp(INetState ns, byte[] buffer, int length)
        {
            string      request = Encoding.UTF8.GetString(buffer, 0, length);
            HttpRequest http    = new HttpRequest(ns, request);

            try {
                byte[] response = HandleHttpRequest(http);
                ns.Send(response, response.Length);
                if (Config.DebugShowHttpRequests)
                {
                    Kernel.WriteLine(TypeName, $"{ns} req({http.RequestHost}{http.RequestPage}) => {response.Length} bytes");
                    if (Config.DebugShowHttpResponses)
                    {
                        Console.WriteLine(response);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine($"{TypeName}: {ns} failed to receive ({e.Message})");
                Console.WriteLine(request);
            }
            if (!http.ParamConnectionKeepAlive)
            {
                ns.DisposeAfterNextFlush();
            }
        }
Esempio n. 3
0
        internal void Receive(ICertificateProvider certProvider, INetState ns, HttpsReader reader)
        {
            RecordHandshake(reader.Buffer, reader.Length, !reader.IsDecrypted);
            EHandshake handshakeType      = (EHandshake)reader.ReadByte();
            int        handshakeMsgLength = reader.Read24BitInt();

            HttpsReader.VerifyLengthRemaining(reader, handshakeMsgLength, "Ssl handshake");
            switch (handshakeType)
            {
            case EHandshake.ClientHello:
                ReceiveClientHello(certProvider, ns, reader);
                break;

            case EHandshake.ClientKeyExchange:
                ReceiveClientKeyExchange(certProvider, ns, reader);
                break;

            case EHandshake.Finished:
                ReceiveClientFinished(ns, reader);
                break;

            default:
                ns.Send(new HttpsSmsgAlert(ns.Https, 2, 10));
                throw new HttpsException($"sent unknown handshake 0x{handshakeType:X}", reader);
            }
        }
Esempio n. 4
0
 internal void SendChangeCipherSpec(INetState ns, byte payload)
 {
     ns.Send(new HttpsSmsgChangeCipher(ns.Https, payload));
     IsServerEncrypting = true;
 }
Esempio n. 5
0
 private void Send(INetState ns, HttpsWriter packet)
 {
     ns.Send(packet, RecordHandshake);
 }