}
}
}
+
+ [NonEvent]
+ private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8)
+ {
+ if (IsEnabled())
+ {
+ if (arg1 == null) arg1 = "";
+
+ fixed (char* arg1Ptr = arg1)
+ {
+ const int NumEventDatas = 8;
+ var descrs = stackalloc EventData[NumEventDatas];
+
+ descrs[0] = new EventData
+ {
+ DataPointer = (IntPtr)(arg1Ptr),
+ Size = (arg1.Length + 1) * sizeof(char)
+ };
+ descrs[1] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg2),
+ Size = sizeof(int)
+ };
+ descrs[2] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg3),
+ Size = sizeof(int)
+ };
+ descrs[3] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg4),
+ Size = sizeof(int)
+ };
+ descrs[4] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg5),
+ Size = sizeof(int)
+ };
+ descrs[5] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg6),
+ Size = sizeof(int)
+ };
+ descrs[6] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg7),
+ Size = sizeof(int)
+ };
+ descrs[7] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg8),
+ Size = sizeof(int)
+ };
+
+ WriteEventCore(eventId, NumEventDatas, descrs);
+ }
+ }
+ }
+
+ [NonEvent]
+ private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3, int arg4, int arg5)
+ {
+ if (IsEnabled())
+ {
+ if (arg1 == null) arg1 = "";
+ if (arg2 == null) arg2 = "";
+
+ fixed (char* arg1Ptr = arg1)
+ fixed (char* arg2Ptr = arg2)
+ {
+ const int NumEventDatas = 5;
+ var descrs = stackalloc EventData[NumEventDatas];
+
+ descrs[0] = new EventData
+ {
+ DataPointer = (IntPtr)(arg1Ptr),
+ Size = (arg1.Length + 1) * sizeof(char)
+ };
+ descrs[1] = new EventData
+ {
+ DataPointer = (IntPtr)(arg2Ptr),
+ Size = (arg2.Length + 1) * sizeof(char)
+ };
+ descrs[2] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg3),
+ Size = sizeof(int)
+ };
+ descrs[3] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg4),
+ Size = sizeof(int)
+ };
+ descrs[4] = new EventData
+ {
+ DataPointer = (IntPtr)(&arg5),
+ Size = sizeof(int)
+ };
+
+ WriteEventCore(eventId, NumEventDatas, descrs);
+ }
+ }
+ }
#endregion
}
}
<Reference Include="System.Linq" />
<Reference Include="System.Memory" />
<Reference Include="System.Net.Primitives" />
+ <Reference Include="System.Net.Sockets" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
using System.Diagnostics.Tracing;
using System.Globalization;
+using System.IO;
using System.Net.Security;
+using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
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 SslStreamCtorId = RemoteCertificateInvalidId + 1;
+ private const int SentFrameId = SslStreamCtorId + 1;
private const int ReceivedFrameId = SentFrameId + 1;
[Event(EnumerateSecurityPackagesId, Keywords = Keywords.Default, Level = EventLevel.Informational)]
}
[NonEvent]
- public void SecureChannelCtor(SecureChannel secureChannel, string hostname, X509CertificateCollection? clientCertificates, EncryptionPolicy encryptionPolicy)
+ public void SslStreamCtor(SslStream sslStream, Stream innerStream)
{
if (IsEnabled())
{
- SecureChannelCtor(hostname, GetHashCode(secureChannel), clientCertificates?.Count ?? 0, encryptionPolicy);
+ string? localId = null;
+ string? remoteId = null;
+
+ NetworkStream? ns = innerStream as NetworkStream;
+ if (ns != null)
+ {
+ try
+ {
+ localId = ns.Socket.LocalEndPoint?.ToString();
+ remoteId = ns.Socket.RemoteEndPoint?.ToString();
+
+ }
+ catch { };
+ }
+
+ if (localId == null)
+ {
+ localId = IdOf(innerStream);
+ }
+
+ SslStreamCtor(IdOf(sslStream), localId, remoteId);
}
}
+
+ [Event(SslStreamCtorId, Keywords = Keywords.Default, Level = EventLevel.Informational)]
+ private unsafe void SslStreamCtor(string thisOrContextObject, string? localId, string? remoteId) =>
+ WriteEvent(SslStreamCtorId, thisOrContextObject, localId, remoteId);
+
+ [NonEvent]
+ public void SecureChannelCtor(SecureChannel secureChannel, SslStream sslStream, string hostname, X509CertificateCollection? clientCertificates, EncryptionPolicy encryptionPolicy)
+ {
+ if (IsEnabled())
+ {
+ SecureChannelCtor(IdOf(secureChannel), hostname, GetHashCode(secureChannel), clientCertificates?.Count ?? 0, encryptionPolicy);
+ }
+ }
+
[Event(SecureChannelCtorId, Keywords = Keywords.Default, Level = EventLevel.Informational)]
- private unsafe void SecureChannelCtor(string hostname, int secureChannelHash, int clientCertificatesCount, EncryptionPolicy encryptionPolicy) =>
- WriteEvent(SecureChannelCtorId, hostname, secureChannelHash, clientCertificatesCount, (int)encryptionPolicy);
+ private unsafe void SecureChannelCtor(string sslStream, string hostname, int secureChannelHash, int clientCertificatesCount, EncryptionPolicy encryptionPolicy) =>
+ WriteEvent(SecureChannelCtorId, sslStream, hostname, secureChannelHash, clientCertificatesCount, (int)encryptionPolicy);
[NonEvent]
public void LocatingPrivateKey(X509Certificate x509Certificate, SecureChannel secureChannel)
result = cert.ToString(fVerbose: true);
}
}
-
- [NonEvent]
- private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8)
- {
- if (IsEnabled())
- {
- if (arg1 == null) arg1 = "";
-
- fixed (char* arg1Ptr = arg1)
- {
- const int NumEventDatas = 8;
- var descrs = stackalloc EventData[NumEventDatas];
-
- descrs[0] = new EventData
- {
- DataPointer = (IntPtr)(arg1Ptr),
- Size = (arg1.Length + 1) * sizeof(char)
- };
- descrs[1] = new EventData
- {
- DataPointer = (IntPtr)(&arg2),
- Size = sizeof(int)
- };
- descrs[2] = new EventData
- {
- DataPointer = (IntPtr)(&arg3),
- Size = sizeof(int)
- };
- descrs[3] = new EventData
- {
- DataPointer = (IntPtr)(&arg4),
- Size = sizeof(int)
- };
- descrs[4] = new EventData
- {
- DataPointer = (IntPtr)(&arg5),
- Size = sizeof(int)
- };
- descrs[5] = new EventData
- {
- DataPointer = (IntPtr)(&arg6),
- Size = sizeof(int)
- };
- descrs[6] = new EventData
- {
- DataPointer = (IntPtr)(&arg7),
- Size = sizeof(int)
- };
- descrs[7] = new EventData
- {
- DataPointer = (IntPtr)(&arg8),
- Size = sizeof(int)
- };
-
- WriteEventCore(eventId, NumEventDatas, descrs);
- }
- }
- }
}
}
private static readonly Oid s_serverAuthOid = new Oid("1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.1");
private static readonly Oid s_clientAuthOid = new Oid("1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.2");
- internal SecureChannel(SslAuthenticationOptions sslAuthenticationOptions)
+ internal SecureChannel(SslAuthenticationOptions sslAuthenticationOptions, SslStream sslStream)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(this, sslAuthenticationOptions.TargetHost, sslAuthenticationOptions.ClientCertificates);
- NetEventSource.Log.SecureChannelCtor(this, sslAuthenticationOptions.TargetHost!, sslAuthenticationOptions.ClientCertificates, sslAuthenticationOptions.EncryptionPolicy);
+ NetEventSource.Log.SecureChannelCtor(this, sslStream, sslAuthenticationOptions.TargetHost!, sslAuthenticationOptions.ClientCertificates, sslAuthenticationOptions.EncryptionPolicy);
}
SslStreamPal.VerifyPackageInfo();
{
_sslAuthenticationOptions.TargetHost = "?" + Interlocked.Increment(ref s_uniqueNameInteger).ToString(NumberFormatInfo.InvariantInfo);
}
- _context = new SecureChannel(_sslAuthenticationOptions);
+ _context = new SecureChannel(_sslAuthenticationOptions, this);
}
catch (Win32Exception e)
{
try
{
- _context = new SecureChannel(_sslAuthenticationOptions);
+ _context = new SecureChannel(_sslAuthenticationOptions, this);
}
catch (Win32Exception e)
{
//
private void CloseInternal()
{
+ if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
+
_exception = s_disposedSentinel;
_context?.Close();
// Suppress finalizer if the read buffer was returned.
GC.SuppressFinalize(this);
}
+
+ if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}
private SecurityStatusPal EncryptData(ReadOnlyMemory<byte> buffer, ref byte[] outBuffer, out int outSize)
_certSelectionDelegate = userCertificateSelectionCallback == null ? null : new LocalCertSelectionCallback(UserCertSelectionCallbackWrapper);
_innerStream = innerStream;
+
+ if (NetEventSource.IsEnabled) NetEventSource.Log.SslStreamCtor(this, innerStream);
}
public SslApplicationProtocol NegotiatedApplicationProtocol
</ItemGroup>
<ItemGroup>
<!-- Production code references -->
+ <Compile Include="..\..\src\System\Net\Security\NetEventSource.Security.cs"
+ Link="ProductionCode\System\Net\Security\NetEventSource.Security.cs" />
<Compile Include="..\..\src\System\Net\Security\SslStream.cs"
Link="ProductionCode\System\Net\Security\SslStream.cs" />
<Compile Include="..\..\src\System\Net\Security\SslClientAuthenticationOptions.cs"
Link="ProductionCode\Common\System\Net\TlsAlertType.cs" />
<Compile Include="..\..\src\System\Net\Security\TlsAlertMessage.cs"
Link="ProductionCode\Common\System\Net\TlsAlertMessage.cs" />
+ <Compile Include="..\..\src\System\Net\Security\TlsFrameHelper.cs"
+ Link="ProductionCode\Common\System\Net\TlsFrameHelper.cs" />
<Compile Include="$(CommonPath)Interop\Windows\SChannel\Interop.Alerts.cs"
Link="Common\Interop\Windows\SChannel\Interop.Alerts.cs" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs"
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Threading" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>