Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Set options in Program.cs
Browse files Browse the repository at this point in the history
(Of note, current .NET 6 won't do TLS 1.3 on macOS. Like, at all. See
dotnet/runtime#1979)

Minor other changes
fixed an error in ExtensionType enum
  • Loading branch information
therealchjones committed May 19, 2022
1 parent 9637e3c commit 5bf34ad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
16 changes: 15 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
using TlsPrinter;

string url = "https://httpbin.org/post";
url = "https://android.clients.google.com/auth";

Uri uri = new(url);

Socket tcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
tcpSocket.Connect(uri.IdnHost, uri.Port);
NetworkStream tcpStream = new(tcpSocket, true);
SslClientAuthenticationOptions sslOptions = new() { TargetHost = uri.IdnHost };
CipherSuitesPolicy ciphers = new CipherSuitesPolicy(new List<TlsCipherSuite>(){
TlsCipherSuite.TLS_AES_256_GCM_SHA384,
TlsCipherSuite.TLS_AES_128_GCM_SHA256,
TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256,
TlsCipherSuite.TLS_AES_128_CCM_SHA256,
TlsCipherSuite.TLS_AES_128_CCM_8_SHA256,
});

SslClientAuthenticationOptions sslOptions = new()
{
TargetHost = uri.IdnHost,
//CipherSuitesPolicy = ciphers,
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls13
};
TlsPrinterSettings tlsSettings = new(sslOptions);
TlsPrinterStream tlsStream = new(tcpStream, tlsSettings);
SslStream sslStream = new(tlsStream);
Expand Down
3 changes: 3 additions & 0 deletions classes/TlsObjectModel/ClientHello.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public override void AddBytes(byte[] bytes)
Extension newExtension;
switch (extensionType)
{
//case ExtensionType.server_name:
//newExtension = new ServerNameExtension(extensionBytes);
//break;
default:
newExtension = new UnknownExtension(extensionBytes);
break;
Expand Down
4 changes: 2 additions & 2 deletions classes/TlsObjectModel/ExtensionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace TlsObjectModel
{
public enum ExtensionType : ushort
{
server_name = 1,
max_fragment_length = 2,
server_name = 0,
max_fragment_length = 1,
status_request = 5,
supported_groups = 10,
signature_algorithms = 13,
Expand Down
4 changes: 2 additions & 2 deletions classes/TlsObjectModel/UnknownExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace TlsObjectModel
{
public class UnknownExtension : Extension
{
ushort ExtensionType;
ExtensionType ExtensionType;
byte[] ExtensionData = new byte[0];
public UnknownExtension(byte[] bytes)
{
Expand All @@ -29,7 +29,7 @@ public override void AddBytes(byte[] bytes)
case 1:
BackingBytes = BackingBytes.Append(bytes[0]).ToArray();
bytes = bytes.Remove(1);
ExtensionType = (ushort)TlsUtils.BytesToUInt64(BackingBytes[0..2]);
ExtensionType = (ExtensionType)TlsUtils.BytesToUInt64(BackingBytes[0..2]);
break;
case 2:
BackingBytes = BackingBytes.Append(bytes[0]).ToArray();
Expand Down

0 comments on commit 5bf34ad

Please sign in to comment.