Skip to content

Commit

Permalink
improve TLS frame parser (dotnet#36201)
Browse files Browse the repository at this point in the history
* improve TLS frame parser

* retire SniHelper.cs

* feedback from review

* feedback from review

* feedback from review

Co-authored-by: Tomas Weinfurt <[email protected]>
  • Loading branch information
wfurt and Tomas Weinfurt authored Jun 10, 2020
1 parent b517c9d commit 180f9d9
Show file tree
Hide file tree
Showing 7 changed files with 945 additions and 438 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<Compile Include="System\Net\Security\NetEventSource.Security.cs" />
<Compile Include="System\Net\Security\ReadWriteAdapter.cs" />
<Compile Include="System\Net\Security\ProtectionLevel.cs" />
<Compile Include="System\Net\Security\SniHelper.cs" />
<Compile Include="System\Net\Security\SslApplicationProtocol.cs" />
<Compile Include="System\Net\Security\SslAuthenticationOptions.cs" />
<Compile Include="System\Net\Security\SslClientAuthenticationOptions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal sealed partial class NetEventSource
private const int RemoteVertificateValidId = RemoteCertificateErrorId + 1;
private const int RemoteCertificateSuccesId = RemoteVertificateValidId + 1;
private const int RemoteCertificateInvalidId = RemoteCertificateSuccesId + 1;
private const int SentFrameId = RemoteCertificateInvalidId + 1;
private const int ReceivedFrameId = SentFrameId + 1;

[Event(EnumerateSecurityPackagesId, Keywords = Keywords.Default, Level = EventLevel.Informational)]
public void EnumerateSecurityPackages(string? securityPackage)
Expand Down Expand Up @@ -312,6 +314,42 @@ public void RemoteCertUserDeclaredInvalid(SecureChannel secureChannel)
private void RemoteCertUserDeclaredInvalid(int secureChannelHash) =>
WriteEvent(RemoteCertificateInvalidId, secureChannelHash);

[NonEvent]
public void SentFrame(SslStream sslStream, ReadOnlySpan<byte> frame)
{
if (IsEnabled())
{
TlsFrameHelper.TlsFrameInfo info = default;
bool isComplete = TlsFrameHelper.TryGetFrameInfo(frame, ref info);
SentFrame(IdOf(sslStream), info.ToString(), isComplete ? 1 : 0);
}
}
[Event(SentFrameId, Keywords = Keywords.Default, Level = EventLevel.Verbose)]
private void SentFrame(string sslStream, string tlsFrame, int isComplete) =>
WriteEvent(SentFrameId, sslStream, tlsFrame, isComplete);

[NonEvent]
public void ReceivedFrame(SslStream sslStream, TlsFrameHelper.TlsFrameInfo frameInfo)
{
if (IsEnabled())
{
ReceivedFrame(IdOf(sslStream), frameInfo.ToString(), 1);
}
}
[NonEvent]
public void ReceivedFrame(SslStream sslStream, ReadOnlySpan<byte> frame)
{
if (IsEnabled())
{
TlsFrameHelper.TlsFrameInfo info = default;
bool isComplete = TlsFrameHelper.TryGetFrameInfo(frame, ref info);
ReceivedFrame(IdOf(sslStream), info.ToString(), isComplete ? 1 : 0);
}
}
[Event(ReceivedFrameId, Keywords = Keywords.Default, Level = EventLevel.Verbose)]
private void ReceivedFrame(string sslStream, string tlsFrame, int isComplete) =>
WriteEvent(ReceivedFrameId, sslStream, tlsFrame, isComplete);

static partial void AdditionalCustomizedToString<T>(T value, ref string? result)
{
X509Certificate? cert = value as X509Certificate;
Expand Down
Loading

0 comments on commit 180f9d9

Please sign in to comment.