HttpServerBoxed 0.0.11 alpha
A simple http server for C# and .NET
Loading...
Searching...
No Matches
HSB.SystemTLS Class Reference

Public Member Functions

void Run ()
 

Detailed Description

Definition at line 10 of file SystemTLS.cs.

Constructor & Destructor Documentation

◆ SystemTLS()

HSB.SystemTLS.SystemTLS ( )

Definition at line 20 of file SystemTLS.cs.

21 {
22 Console.WriteLine("Hello from HSB (SystemTLS)");
23
24 c.SetTLSVersion(TLS.Constants.TLSVersion.TLS_1_2);
25 c.RunAsync(false, 700);
26
27
28 endPoint = new(address, 443);
29
30
31 listener = new(
32 address.AddressFamily,
33 SocketType.Stream,
34 ProtocolType.Tcp
35 );
36
37 listener.Bind(endPoint);
38 listener.Listen(100);
39 }

Member Function Documentation

◆ Run()

void HSB.SystemTLS.Run ( )

Definition at line 41 of file SystemTLS.cs.

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 //print ssl informations
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 //not found
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 }

The documentation for this class was generated from the following file: