42 {
43 Socket newSocket = listener.Accept();
44 SslStream sslStream = new(new NetworkStream(newSocket), true);
45
46 try
47 {
48 sslStream.AuthenticateAsServer(
49 Certificate,
50 false,
51 System.Security.Authentication.SslProtocols.Tls13 | System.Security.Authentication.SslProtocols.Tls12,
52 false
53 );
54
55
56 Console.WriteLine("SSL Protocol: {0}", sslStream.SslProtocol);
57 Console.WriteLine("Cipher: {0} {1} bits", sslStream.CipherAlgorithm, sslStream.CipherStrength);
58 Console.WriteLine("Hash: {0} {1} bits", sslStream.HashAlgorithm, sslStream.HashStrength);
59 Console.WriteLine("Key exchange: {0} {1} bits", sslStream.KeyExchangeAlgorithm, sslStream.KeyExchangeStrength);
60 Console.WriteLine("\n");
61
62 int received = sslStream.Read(buffer);
63
64 if (received > 0)
65 {
66 Console.WriteLine("Received {0} bytes", received);
67 string req = Encoding.UTF8.GetString(buffer[..received]);
68 Console.WriteLine("Req: {0}\nFine stampa", req);
69
70 var lines = req.Split("\r\n");
71 var method = lines[0].Split(" ")[0];
72 var path = lines[0].Split(" ")[1];
73
74 string reply;
75 if (path == "/")
76 reply = "HTTP/1.1 200 OK\r\n" +
77 "Content-Type: text/html\r\n" +
78 "Content-Length: 20\r\n" +
79 "Connection: close\r\n" +
80 "\r\n" +
81 "Hello from HSB (TLS)";
82 else
83
84 reply = "HTTP/1.1 404 Not Found\r\n" +
85 "Content-Type: text/html\r\n" +
86 "Content-Length: 0\r\n" +
87 "Connection: close\r\n" +
88 "\r\n";
89
90 Console.WriteLine("Reply: {0}", reply);
91 var bytes = Encoding.UTF8.GetBytes(reply);
92 sslStream.Write(bytes);
93
94 sslStream.Close();
95
96 }
97 }
98 catch (Exception e)
99 {
100 Console.WriteLine(e.ToString());
101 return;
102 }
103
104 }