Skip to content

Commit e43f883

Browse files
rzikmCopilot
andcommitted
Validate context and role before Apple PNSE in RequestClientCertificateBufferedCore
RequestClientCertificateBufferedCore dereferenced _context via _context!.IsServer without first ensuring a context was set, risking a NullReferenceException when callers invoke post-handshake client authentication before SetContext. It also performed the server-only role check only inside the non-Apple branch, so on Apple platforms client-session misuse threw PlatformNotSupportedException instead of the documented InvalidOperationException. Add ThrowIfContextNotSet() so the missing-context case surfaces the documented InvalidOperationException, and hoist the server-only role guard ahead of the TARGET_APPLE PlatformNotSupportedException so role misuse validates consistently across all platforms. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 89084543-7d70-4562-8776-d4ca1baa3c7c
1 parent 138a5a5 commit e43f883

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

  • src/libraries/System.Net.Security/src/System/Net/Security

‎src/libraries/System.Net.Security/src/System/Net/Security/TlsSession.cs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,22 +1439,26 @@ private TlsOperationStatus TryDrainBufferedPlaintext(Span<byte> plaintext, out i
14391439
private protected TlsOperationStatus RequestClientCertificateBufferedCore(Span<byte> ciphertext, out int bytesWritten)
14401440
{
14411441
ThrowIfDisposed();
1442+
ThrowIfContextNotSet();
14421443
// Like Read/Write, post-handshake client authentication is a top-level session
14431444
// operation: if the previous handshake surfaced NeedsCertificateValidation the
14441445
// caller must record the result (or observe the recorded fault) before starting it.
14451446
ThrowIfPendingExternalValidation();
14461447
bytesWritten = 0;
14471448

1448-
#if TARGET_APPLE
1449-
// SecureTransport does not expose a post-handshake client-authentication
1450-
// path, and Network.framework does not provide renegotiation primitives.
1451-
throw new PlatformNotSupportedException(SR.net_ssl_renegotiate_not_supported);
1452-
#else
1449+
// Post-handshake client authentication is a server-only operation. Enforce the role
1450+
// guard before the Apple platform check so client-session misuse consistently surfaces
1451+
// InvalidOperationException on every platform rather than PlatformNotSupportedException.
14531452
if (!_context!.IsServer)
14541453
{
14551454
throw new InvalidOperationException(SR.net_tlssession_request_client_cert_server_only);
14561455
}
14571456

1457+
#if TARGET_APPLE
1458+
// SecureTransport does not expose a post-handshake client-authentication
1459+
// path, and Network.framework does not provide renegotiation primitives.
1460+
throw new PlatformNotSupportedException(SR.net_ssl_renegotiate_not_supported);
1461+
#else
14581462
if (!_postHandshakeAuthActive)
14591463
{
14601464
if (!_isHandshakeComplete || _securityContext == null || _securityContext.IsInvalid)

0 commit comments

Comments
 (0)