50 return $
"{Header.Version}:{HandshakeType}[{Header.Length}] SupportedVersion='{SupportedVersions}'";
52 return $
"{Header.Version}:{HandshakeType}[{Header.Length}] SupportedVersion='{SupportedVersions}' ApplicationProtocols='{ApplicationProtocols}'";
54 return $
"{Header.Version}:{HandshakeType}[{Header.Length}] TargetName='{TargetName}' SupportedVersion='{SupportedVersions}' ApplicationProtocols='{ApplicationProtocols}'";
56 return $
"{Header.Version}:{Header.Type}[{Header.Length}]";
79 AllowUnassigned =
true
86 bool result = frame.Length > 4;
96 header.Length = (frame[3] << 8) | frame[4];
117 info.SupportedVersions =
info.Header.Version;
124 info.AlertDescription = description;
134 bool result = frame.Length >= 5 +
info.Header.
Length;
144 if (frame.
Length < 7 || frame[0] != 21)
155 return version
switch
162 _ =>
Array.Empty<
byte>(),
174 byte[]
obj =
new byte[7] { 21, 3, 3, 0, 2, 2, 0 };
175 obj[6] = (byte)reason;
191 return Array.Empty<
byte>();
196 if (sslHandshake.
Length < 4 || (sslHandshake[0] != 1 && sslHandshake[0] != 2))
202 if (readOnlySpan.
Length < num)
206 if (readOnlySpan[0] == 3)
210 if (sslHandshake[0] != 1)
229 if (num !=
bytes.Length)
247 if (num !=
bytes.Length)
257 while (extensions.
Length >= 4)
263 if (extensions.
Length < num)
275 info.TargetName = sni;
283 info.SupportedVersions |= protocols;
291 info.ApplicationProtocols |= alpn;
293 callback?.Invoke(ref
info, extensionType, readOnlySpan);
294 extensions = extensions.
Slice(num);
302 if (serverNameListExtension.
Length < 2)
308 if (num != readOnlySpan.
Length)
319 if (serverName.
Length < 1)
338 if (num !=
bytes.Length)
350 byte b = extensionData[0];
351 extensionData = extensionData.
Slice(1);
352 if (extensionData.
Length != b)
356 while (extensionData.
Length >= 2)
358 if (extensionData[0] == 3)
362 extensionData = extensionData.
Slice(2);
370 if (extensionData.
Length < 2)
376 if (num != readOnlySpan.
Length)
382 byte b = readOnlySpan[0];
383 if (readOnlySpan.
Length < b + 1)
407 readOnlySpan = readOnlySpan.
Slice(b + 1);
453 if (numberOfBytesToSkip >=
bytes.Length)
457 return bytes.Slice(numberOfBytesToSkip);
462 if (
bytes.Length < 1)
467 int numberOfBytesToSkip = 1 + b;
473 if (
bytes.Length < 2)
478 int numberOfBytesToSkip = 2 + num;
static ushort ReadUInt16BigEndian(ReadOnlySpan< byte > source)
static ReadOnlySpan< byte > SkipOpaqueType1(ReadOnlySpan< byte > bytes)
static int ReadUInt24BigEndian(ReadOnlySpan< byte > bytes)
static string DecodeString(ReadOnlySpan< byte > bytes)
static byte[] s_protocolMismatch12
static bool TryGetAlertInfo(ReadOnlySpan< byte > frame, ref TlsAlertLevel level, ref TlsAlertDescription description)
static byte[] s_protocolMismatch13
static readonly Encoding s_encoding
static byte[] s_protocolMismatch10
static bool TryGetSniFromServerNameList(ReadOnlySpan< byte > serverNameListExtension, out string sni)
delegate bool HelloExtensionCallback(ref TlsFrameInfo info, ExtensionType type, ReadOnlySpan< byte > extensionsData)
static bool TryGetApplicationProtocolsFromExtension(ReadOnlySpan< byte > extensionData, out ApplicationProtocolInfo alpn)
static string GetSniFromServerName(ReadOnlySpan< byte > serverName, out bool invalid)
static string GetSniFromHostNameStruct(ReadOnlySpan< byte > hostNameStruct, out bool invalid)
static ReadOnlySpan< byte > SkipOpaqueType2(ReadOnlySpan< byte > bytes)
static byte[] CreateAlertFrame(SslProtocols version, TlsAlertDescription reason)
static bool TryParseHelloFrame(ReadOnlySpan< byte > sslHandshake, ref TlsFrameInfo info, ProcessingOptions options, HelloExtensionCallback callback)
static readonly IdnMapping s_idnMapping
static bool TryGetFrameInfo(ReadOnlySpan< byte > frame, ref TlsFrameInfo info, ProcessingOptions options=ProcessingOptions.All, HelloExtensionCallback callback=null)
static byte[] s_protocolMismatch11
static bool TryGetFrameHeader(ReadOnlySpan< byte > frame, ref TlsFrameHeader header)
static bool TryParseClientHello(ReadOnlySpan< byte > clientHello, ref TlsFrameInfo info, ProcessingOptions options, HelloExtensionCallback callback)
static byte[] s_protocolMismatch30
static bool TryParseServerHello(ReadOnlySpan< byte > serverHello, ref TlsFrameInfo info, ProcessingOptions options, HelloExtensionCallback callback)
static bool TryGetSupportedVersionsFromExtension(ReadOnlySpan< byte > extensionData, out SslProtocols protocols)
static SslProtocols TlsMinorVersionToProtocol(byte value)
static ReadOnlySpan< byte > SkipBytes(ReadOnlySpan< byte > bytes, int numberOfBytesToSkip)
static byte[] CreateProtocolVersionAlert(SslProtocols version)
static bool TryParseHelloExtensions(ReadOnlySpan< byte > extensions, ref TlsFrameInfo info, ProcessingOptions options, HelloExtensionCallback callback)
static Encoding GetEncoding(int codepage)
static readonly SslApplicationProtocol Http2
static readonly SslApplicationProtocol Http11
TlsAlertDescription AlertDescription
ApplicationProtocolInfo ApplicationProtocols
TlsHandshakeType HandshakeType
override string ToString()
SslProtocols SupportedVersions
static ReadOnlySpan< T > Empty
ReadOnlySpan< T > Slice(int start)