Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SslStream.cs
Go to the documentation of this file.
3using System.IO;
12
13namespace System.Net.Security;
14
16{
17 private enum Framing
18 {
19 Unknown,
22 Unified,
24 }
25
26 private static readonly ExceptionDispatchInfo s_disposedSentinel = ExceptionDispatchInfo.Capture(new ObjectDisposedException("SslStream", (string?)null));
27
28 internal RemoteCertificateValidationCallback _userCertificateValidationCallback;
29
30 internal LocalCertificateSelectionCallback _userCertificateSelectionCallback;
31
32 internal ServerCertificateSelectionCallback _userServerCertificateSelectionCallback;
33
34 internal LocalCertSelectionCallback _certSelectionDelegate;
35
37
38 private readonly Stream _innerStream;
39
41
43
44 private bool _shutdown;
45
46 private bool _handshakeCompleted;
47
48 internal byte[] _internalBuffer;
49
50 internal int _internalOffset;
51
53
55
57
58 private int _nestedWrite;
59
60 private int _nestedRead;
61
63
64 private int _nestedAuth;
65
66 private bool _isRenego;
67
69
71
73
75
76 private bool _receivedEOF;
77
79
81 {
82 get
83 {
84 if (_context == null)
85 {
86 return default(SslApplicationProtocol);
87 }
89 }
90 }
91
93
94 public override bool IsAuthenticated
95 {
96 get
97 {
98 if (_context != null && _context.IsValidContext && _exception == null)
99 {
100 return _handshakeCompleted;
101 }
102 return false;
103 }
104 }
105
106 public override bool IsMutuallyAuthenticated
107 {
108 get
109 {
111 {
113 }
114 return false;
115 }
116 }
117
118 public override bool IsEncrypted => IsAuthenticated;
119
120 public override bool IsSigned => IsAuthenticated;
121
122 public override bool IsServer
123 {
124 get
125 {
126 if (_context != null)
127 {
128 return _context.IsServer;
129 }
130 return false;
131 }
132 }
133
135 {
136 get
137 {
139 return GetSslProtocolInternal();
140 }
141 }
142
143 public virtual bool CheckCertRevocationStatus
144 {
145 get
146 {
147 if (_context != null)
148 {
149 return _context.CheckCertRevocationStatus != X509RevocationMode.NoCheck;
150 }
151 return false;
152 }
153 }
154
156 {
157 get
158 {
160 if (!_context.IsServer)
161 {
163 }
165 }
166 }
167
169 {
170 get
171 {
174 }
175 }
176
177 [CLSCompliant(false)]
179 {
180 get
181 {
183 return _context.ConnectionInfo?.TlsCipherSuite ?? TlsCipherSuite.TLS_NULL_WITH_NULL_NULL;
184 }
185 }
186
188 {
189 get
190 {
193 }
194 }
195
196 public virtual int CipherStrength
197 {
198 get
199 {
202 }
203 }
204
206 {
207 get
208 {
211 }
212 }
213
214 public virtual int HashStrength
215 {
216 get
217 {
220 }
221 }
222
231
232 public virtual int KeyExchangeStrength
233 {
234 get
235 {
238 }
239 }
240
241 public string TargetHostName
242 {
243 get
244 {
245 if (_sslAuthenticationOptions == null)
246 {
247 return string.Empty;
248 }
250 }
251 }
252
253 public override bool CanSeek => false;
254
255 public override bool CanRead
256 {
257 get
258 {
259 if (IsAuthenticated)
260 {
261 return base.InnerStream.CanRead;
262 }
263 return false;
264 }
265 }
266
267 public override bool CanTimeout => base.InnerStream.CanTimeout;
268
269 public override bool CanWrite
270 {
271 get
272 {
273 if (IsAuthenticated && base.InnerStream.CanWrite)
274 {
275 return !_shutdown;
276 }
277 return false;
278 }
279 }
280
281 public override int ReadTimeout
282 {
283 get
284 {
285 return base.InnerStream.ReadTimeout;
286 }
287 set
288 {
289 base.InnerStream.ReadTimeout = value;
290 }
291 }
292
293 public override int WriteTimeout
294 {
295 get
296 {
297 return base.InnerStream.WriteTimeout;
298 }
299 set
300 {
301 base.InnerStream.WriteTimeout = value;
302 }
303 }
304
305 public override long Length => base.InnerStream.Length;
306
307 public override long Position
308 {
309 get
310 {
311 return base.InnerStream.Position;
312 }
313 set
314 {
316 }
317 }
318
320
322
323 public SslStream(Stream innerStream)
324 : this(innerStream, leaveInnerStreamOpen: false, null, null)
325 {
326 }
327
328 public SslStream(Stream innerStream, bool leaveInnerStreamOpen)
329 : this(innerStream, leaveInnerStreamOpen, null, null, EncryptionPolicy.RequireEncryption)
330 {
331 }
332
333 public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback)
334 : this(innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, null, EncryptionPolicy.RequireEncryption)
335 {
336 }
337
338 public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback, LocalCertificateSelectionCallback? userCertificateSelectionCallback)
339 : this(innerStream, leaveInnerStreamOpen, userCertificateValidationCallback, userCertificateSelectionCallback, EncryptionPolicy.RequireEncryption)
340 {
341 }
342
343 public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback, LocalCertificateSelectionCallback? userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
344 : base(innerStream, leaveInnerStreamOpen)
345 {
346 if (encryptionPolicy != 0 && encryptionPolicy != EncryptionPolicy.AllowNoEncryption && encryptionPolicy != EncryptionPolicy.NoEncryption)
347 {
348 throw new ArgumentException(System.SR.Format(System.SR.net_invalid_enum, "EncryptionPolicy"), "encryptionPolicy");
349 }
350 _userCertificateValidationCallback = userCertificateValidationCallback;
351 _userCertificateSelectionCallback = userCertificateSelectionCallback;
352 _encryptionPolicy = encryptionPolicy;
353 _certSelectionDelegate = ((userCertificateSelectionCallback == null) ? null : new LocalCertSelectionCallback(UserCertSelectionCallbackWrapper));
354 _innerStream = innerStream;
355 if (System.Net.NetEventSource.Log.IsEnabled())
356 {
357 System.Net.NetEventSource.Log.SslStreamCtor(this, innerStream);
358 }
359 }
360
361 private void SetAndVerifyValidationCallback(RemoteCertificateValidationCallback callback)
362 {
364 {
366 }
367 else if (callback != null && _userCertificateValidationCallback != callback)
368 {
369 throw new InvalidOperationException(System.SR.Format(System.SR.net_conflicting_options, "RemoteCertificateValidationCallback"));
370 }
371 }
372
373 private void SetAndVerifySelectionCallback(LocalCertificateSelectionCallback callback)
374 {
376 {
379 }
380 else if (callback != null && _userCertificateSelectionCallback != callback)
381 {
382 throw new InvalidOperationException(System.SR.Format(System.SR.net_conflicting_options, "LocalCertificateSelectionCallback"));
383 }
384 }
385
386 private X509Certificate UserCertSelectionCallbackWrapper(string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers)
387 {
388 return _userCertificateSelectionCallback(this, targetHost, localCertificates, remoteCertificate, acceptableIssuers);
389 }
390
392 {
393 return _userServerCertificateSelectionCallback(this, targetHost);
394 }
395
397 {
398 if (sslServerAuthenticationOptions.ServerCertificate == null && sslServerAuthenticationOptions.ServerCertificateContext == null && sslServerAuthenticationOptions.ServerCertificateSelectionCallback == null && _certSelectionDelegate == null)
399 {
400 throw new ArgumentNullException("ServerCertificate");
401 }
402 if ((sslServerAuthenticationOptions.ServerCertificate != null || sslServerAuthenticationOptions.ServerCertificateContext != null || _certSelectionDelegate != null) && sslServerAuthenticationOptions.ServerCertificateSelectionCallback != null)
403 {
404 throw new InvalidOperationException(System.SR.Format(System.SR.net_conflicting_options, "ServerCertificateSelectionCallback"));
405 }
406 SslAuthenticationOptions sslAuthenticationOptions = new SslAuthenticationOptions(sslServerAuthenticationOptions);
408 sslAuthenticationOptions.ServerCertSelectionDelegate = ((_userServerCertificateSelectionCallback == null) ? null : new ServerCertSelectionCallback(ServerCertSelectionCallbackWrapper));
409 sslAuthenticationOptions.CertValidationDelegate = _userCertificateValidationCallback;
410 sslAuthenticationOptions.CertSelectionDelegate = _certSelectionDelegate;
411 return sslAuthenticationOptions;
412 }
413
414 public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, AsyncCallback? asyncCallback, object? asyncState)
415 {
416 return BeginAuthenticateAsClient(targetHost, null, SslProtocols.None, checkCertificateRevocation: false, asyncCallback, asyncState);
417 }
418
419 public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
420 {
421 return BeginAuthenticateAsClient(targetHost, clientCertificates, SslProtocols.None, checkCertificateRevocation, asyncCallback, asyncState);
422 }
423
424 public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
425 {
426 SslClientAuthenticationOptions sslClientAuthenticationOptions = new SslClientAuthenticationOptions
427 {
428 TargetHost = targetHost,
429 ClientCertificates = clientCertificates,
430 EnabledSslProtocols = enabledSslProtocols,
431 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
433 };
434 return BeginAuthenticateAsClient(sslClientAuthenticationOptions, CancellationToken.None, asyncCallback, asyncState);
435 }
436
437 internal IAsyncResult BeginAuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, object asyncState)
438 {
439 return System.Threading.Tasks.TaskToApm.Begin(AuthenticateAsClientApm(sslClientAuthenticationOptions, cancellationToken), asyncCallback, asyncState);
440 }
441
446
447 public virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, AsyncCallback? asyncCallback, object? asyncState)
448 {
449 return BeginAuthenticateAsServer(serverCertificate, clientCertificateRequired: false, SslProtocols.None, checkCertificateRevocation: false, asyncCallback, asyncState);
450 }
451
452 public virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
453 {
454 return BeginAuthenticateAsServer(serverCertificate, clientCertificateRequired, SslProtocols.None, checkCertificateRevocation, asyncCallback, asyncState);
455 }
456
457 public virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
458 {
459 SslServerAuthenticationOptions sslServerAuthenticationOptions = new SslServerAuthenticationOptions
460 {
461 ServerCertificate = serverCertificate,
462 ClientCertificateRequired = clientCertificateRequired,
463 EnabledSslProtocols = enabledSslProtocols,
464 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
466 };
467 return BeginAuthenticateAsServer(sslServerAuthenticationOptions, CancellationToken.None, asyncCallback, asyncState);
468 }
469
470 private IAsyncResult BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, object asyncState)
471 {
472 return System.Threading.Tasks.TaskToApm.Begin(AuthenticateAsServerApm(sslServerAuthenticationOptions, cancellationToken), asyncCallback, asyncState);
473 }
474
479
481 {
482 return _context?.GetChannelBinding(kind);
483 }
484
485 public virtual void AuthenticateAsClient(string targetHost)
486 {
487 AuthenticateAsClient(targetHost, null, SslProtocols.None, checkCertificateRevocation: false);
488 }
489
490 public virtual void AuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation)
491 {
492 AuthenticateAsClient(targetHost, clientCertificates, SslProtocols.None, checkCertificateRevocation);
493 }
494
495 public virtual void AuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
496 {
497 SslClientAuthenticationOptions sslClientAuthenticationOptions = new SslClientAuthenticationOptions
498 {
499 TargetHost = targetHost,
500 ClientCertificates = clientCertificates,
501 EnabledSslProtocols = enabledSslProtocols,
502 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
504 };
505 AuthenticateAsClient(sslClientAuthenticationOptions);
506 }
507
508 public void AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
509 {
510 if (sslClientAuthenticationOptions == null)
511 {
512 throw new ArgumentNullException("sslClientAuthenticationOptions");
513 }
518 }
519
520 public virtual void AuthenticateAsServer(X509Certificate serverCertificate)
521 {
522 AuthenticateAsServer(serverCertificate, clientCertificateRequired: false, SslProtocols.None, checkCertificateRevocation: false);
523 }
524
525 public virtual void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
526 {
527 AuthenticateAsServer(serverCertificate, clientCertificateRequired, SslProtocols.None, checkCertificateRevocation);
528 }
529
530 public virtual void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
531 {
532 SslServerAuthenticationOptions sslServerAuthenticationOptions = new SslServerAuthenticationOptions
533 {
534 ServerCertificate = serverCertificate,
535 ClientCertificateRequired = clientCertificateRequired,
536 EnabledSslProtocols = enabledSslProtocols,
537 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
539 };
540 AuthenticateAsServer(sslServerAuthenticationOptions);
541 }
542
543 public void AuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions)
544 {
545 if (sslServerAuthenticationOptions == null)
546 {
547 throw new ArgumentNullException("sslServerAuthenticationOptions");
548 }
550 ValidateCreateContext(CreateAuthenticationOptions(sslServerAuthenticationOptions));
552 }
553
554 public virtual Task AuthenticateAsClientAsync(string targetHost)
555 {
556 return AuthenticateAsClientAsync(targetHost, null, checkCertificateRevocation: false);
557 }
558
559 public virtual Task AuthenticateAsClientAsync(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation)
560 {
561 return AuthenticateAsClientAsync(targetHost, clientCertificates, SslProtocols.None, checkCertificateRevocation);
562 }
563
564 public virtual Task AuthenticateAsClientAsync(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
565 {
566 SslClientAuthenticationOptions sslClientAuthenticationOptions = new SslClientAuthenticationOptions
567 {
568 TargetHost = targetHost,
569 ClientCertificates = clientCertificates,
570 EnabledSslProtocols = enabledSslProtocols,
571 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
573 };
574 return AuthenticateAsClientAsync(sslClientAuthenticationOptions);
575 }
576
578 {
579 if (sslClientAuthenticationOptions == null)
580 {
581 throw new ArgumentNullException("sslClientAuthenticationOptions");
582 }
586 return ProcessAuthenticationAsync(isAsync: true, isApm: false, cancellationToken);
587 }
588
596
597 public virtual Task AuthenticateAsServerAsync(X509Certificate serverCertificate)
598 {
599 return AuthenticateAsServerAsync(serverCertificate, clientCertificateRequired: false, SslProtocols.None, checkCertificateRevocation: false);
600 }
601
602 public virtual Task AuthenticateAsServerAsync(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
603 {
604 SslServerAuthenticationOptions sslServerAuthenticationOptions = new SslServerAuthenticationOptions
605 {
606 ServerCertificate = serverCertificate,
607 ClientCertificateRequired = clientCertificateRequired,
608 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
610 };
611 return AuthenticateAsServerAsync(sslServerAuthenticationOptions);
612 }
613
614 public virtual Task AuthenticateAsServerAsync(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
615 {
616 SslServerAuthenticationOptions sslServerAuthenticationOptions = new SslServerAuthenticationOptions
617 {
618 ServerCertificate = serverCertificate,
619 ClientCertificateRequired = clientCertificateRequired,
620 EnabledSslProtocols = enabledSslProtocols,
621 CertificateRevocationCheckMode = (checkCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck),
623 };
624 return AuthenticateAsServerAsync(sslServerAuthenticationOptions);
625 }
626
628 {
629 if (sslServerAuthenticationOptions == null)
630 {
631 throw new ArgumentNullException("sslServerAuthenticationOptions");
632 }
634 ValidateCreateContext(CreateAuthenticationOptions(sslServerAuthenticationOptions));
635 return ProcessAuthenticationAsync(isAsync: true, isApm: false, cancellationToken);
636 }
637
639 {
641 ValidateCreateContext(CreateAuthenticationOptions(sslServerAuthenticationOptions));
642 return ProcessAuthenticationAsync(isAsync: true, isApm: true, cancellationToken);
643 }
644
650
651 public virtual Task ShutdownAsync()
652 {
655 _shutdown = true;
656 return base.InnerStream.WriteAsync(protocolToken.Payload).AsTask();
657 }
658
660 {
662 if (connectionInfo == null)
663 {
664 return SslProtocols.None;
665 }
666 SslProtocols protocol = (SslProtocols)connectionInfo.Protocol;
667 SslProtocols sslProtocols = SslProtocols.None;
668 if ((protocol & SslProtocols.Ssl2) != 0)
669 {
670 sslProtocols |= SslProtocols.Ssl2;
671 }
672 if ((protocol & SslProtocols.Ssl3) != 0)
673 {
674 sslProtocols |= SslProtocols.Ssl3;
675 }
676 if ((protocol & SslProtocols.Tls) != 0)
677 {
678 sslProtocols |= SslProtocols.Tls;
679 }
680 if ((protocol & SslProtocols.Tls11) != 0)
681 {
682 sslProtocols |= SslProtocols.Tls11;
683 }
684 if ((protocol & SslProtocols.Tls12) != 0)
685 {
686 sslProtocols |= SslProtocols.Tls12;
687 }
688 if ((protocol & SslProtocols.Tls13) != 0)
689 {
690 sslProtocols |= SslProtocols.Tls13;
691 }
692 return sslProtocols;
693 }
694
695 public override void SetLength(long value)
696 {
697 base.InnerStream.SetLength(value);
698 }
699
700 public override long Seek(long offset, SeekOrigin origin)
701 {
703 }
704
705 public override void Flush()
706 {
707 base.InnerStream.Flush();
708 }
709
711 {
712 return base.InnerStream.FlushAsync(cancellationToken);
713 }
714
724
725 protected override void Dispose(bool disposing)
726 {
727 try
728 {
730 }
731 finally
732 {
733 base.Dispose(disposing);
734 }
735 }
736
737 public override async ValueTask DisposeAsync()
738 {
739 try
740 {
742 }
743 finally
744 {
745 await base.DisposeAsync().ConfigureAwait(continueOnCapturedContext: false);
746 }
747 }
748
749 public override int ReadByte()
750 {
752 if (Interlocked.Exchange(ref _nestedRead, 1) == 1)
753 {
755 }
756 try
757 {
758 if (_decryptedBytesCount > 0)
759 {
763 return result;
764 }
765 }
766 finally
767 {
768 _nestedRead = 0;
769 }
770 byte[] array = new byte[1];
771 int num = Read(array, 0, 1);
772 if (num != 1)
773 {
774 return -1;
775 }
776 return array[0];
777 }
778
779 public override int Read(byte[] buffer, int offset, int count)
780 {
783 return ReadAsyncInternal(new SyncReadWriteAdapter(base.InnerStream), new Memory<byte>(buffer, offset, count)).GetAwaiter().GetResult();
784 }
785
786 public void Write(byte[] buffer)
787 {
788 Write(buffer, 0, buffer.Length);
789 }
790
791 public override void Write(byte[] buffer, int offset, int count)
792 {
795 WriteAsyncInternal(new SyncReadWriteAdapter(base.InnerStream), new ReadOnlyMemory<byte>(buffer, offset, count)).GetAwaiter().GetResult();
796 }
797
798 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
799 {
801 return System.Threading.Tasks.TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
802 }
803
809
810 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
811 {
813 return System.Threading.Tasks.TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
814 }
815
821
828
834
836 {
839 return ReadAsyncInternal(new AsyncReadWriteAdapter(base.InnerStream, cancellationToken), new Memory<byte>(buffer, offset, count)).AsTask();
840 }
841
847
848 private void ThrowIfExceptional()
849 {
851 if (exception != null)
852 {
853 ThrowExceptional(exception);
854 }
855 static void ThrowExceptional(ExceptionDispatchInfo e)
856 {
857 if (e == s_disposedSentinel)
858 {
859 throw new ObjectDisposedException("SslStream");
860 }
861 e.Throw();
862 }
863 }
864
865 [MethodImpl(MethodImplOptions.AggressiveInlining)]
867 {
869 if (!IsAuthenticated)
870 {
872 }
873 }
874
875 [MethodImpl(MethodImplOptions.AggressiveInlining)]
877 {
879 if (!IsAuthenticated && _context?.ConnectionInfo == null)
880 {
882 }
883 }
884
885 [MethodImpl(MethodImplOptions.AggressiveInlining)]
887 {
889 if (!IsAuthenticated)
890 {
892 }
893 if (_shutdown)
894 {
895 ThrowAlreadyShutdown();
896 }
897 static void ThrowAlreadyShutdown()
898 {
900 }
901 }
902
903 private static void ThrowNotAuthenticated()
904 {
906 }
907
908 private void ValidateCreateContext(SslClientAuthenticationOptions sslClientAuthenticationOptions, RemoteCertificateValidationCallback remoteCallback, LocalCertSelectionCallback localCallback)
909 {
911 if (_context != null && _context.IsValidContext)
912 {
914 }
915 if (_context != null && IsServer)
916 {
918 }
919 if (sslClientAuthenticationOptions.TargetHost == null)
920 {
921 throw new ArgumentNullException("TargetHost");
922 }
923 _exception = null;
924 try
925 {
926 _sslAuthenticationOptions = new SslAuthenticationOptions(sslClientAuthenticationOptions, remoteCallback, localCallback);
928 }
929 catch (Win32Exception innerException)
930 {
931 throw new AuthenticationException(System.SR.net_auth_SSPI, innerException);
932 }
933 }
934
935 private void ValidateCreateContext(SslAuthenticationOptions sslAuthenticationOptions)
936 {
938 if (_context != null && _context.IsValidContext)
939 {
941 }
942 if (_context != null && !IsServer)
943 {
945 }
946 _exception = null;
947 _sslAuthenticationOptions = sslAuthenticationOptions;
948 try
949 {
951 }
952 catch (Win32Exception innerException)
953 {
954 throw new AuthenticationException(System.SR.net_auth_SSPI, innerException);
955 }
956 }
957
958 private void SetException(Exception e)
959 {
960 if (_exception == null)
961 {
963 }
964 _context?.Close();
965 }
966
967 private void CloseInternal()
968 {
970 _context?.Close();
971 if (Interlocked.CompareExchange(ref _nestedRead, 1, 0) == 0)
972 {
973 byte[] internalBuffer = _internalBuffer;
974 if (internalBuffer != null)
975 {
976 _internalBuffer = null;
978 _internalOffset = 0;
979 ArrayPool<byte>.Shared.Return(internalBuffer);
980 }
981 }
982 if (_internalBuffer == null)
983 {
984 GC.SuppressFinalize(this);
985 }
987 {
989 }
990 }
991
992 private SecurityStatusPal EncryptData(ReadOnlyMemory<byte> buffer, ref byte[] outBuffer, out int outSize)
993 {
995 lock (_handshakeLock)
996 {
997 if (_handshakeWaiter != null)
998 {
999 outSize = 0;
1000 return new SecurityStatusPal(SecurityStatusPalErrorCode.TryAgain);
1001 }
1002 return _context.Encrypt(buffer, ref outBuffer, out outSize);
1003 }
1004 }
1005
1006 private Task ProcessAuthenticationAsync(bool isAsync = false, bool isApm = false, CancellationToken cancellationToken = default(CancellationToken))
1007 {
1009 if (NetSecurityTelemetry.Log.IsEnabled())
1010 {
1012 }
1013 if (!isAsync)
1014 {
1015 return ForceAuthenticationAsync(new SyncReadWriteAdapter(base.InnerStream), _context.IsServer, null);
1016 }
1017 return ForceAuthenticationAsync(new AsyncReadWriteAdapter(base.InnerStream, cancellationToken), _context.IsServer, null, isApm);
1018 }
1019
1021 {
1024 try
1025 {
1026 Task task = (isAsync ? ForceAuthenticationAsync(new AsyncReadWriteAdapter(base.InnerStream, cancellationToken), _context.IsServer, null, isApm) : ForceAuthenticationAsync(new SyncReadWriteAdapter(base.InnerStream), _context.IsServer, null));
1027 await task.ConfigureAwait(continueOnCapturedContext: false);
1028 bool connectionOpen = Interlocked.CompareExchange(ref _connectionOpenedStatus, 1, 0) == 0;
1029 NetSecurityTelemetry.Log.HandshakeCompleted(GetSslProtocolInternal(), stopwatch, connectionOpen);
1030 }
1031 catch (Exception ex)
1032 {
1033 NetSecurityTelemetry.Log.HandshakeFailed(_context.IsServer, stopwatch, ex.Message);
1034 throw;
1035 }
1036 }
1037
1038 private async Task ReplyOnReAuthenticationAsync<TIOAdapter>(TIOAdapter adapter, byte[] buffer) where TIOAdapter : IReadWriteAdapter
1039 {
1040 try
1041 {
1042 await ForceAuthenticationAsync(adapter, receiveFirst: false, buffer).ConfigureAwait(continueOnCapturedContext: false);
1043 }
1044 finally
1045 {
1046 _handshakeWaiter.SetResult(result: true);
1047 _handshakeWaiter = null;
1048 }
1049 }
1050
1051 private async Task RenegotiateAsync<TIOAdapter>(TIOAdapter adapter) where TIOAdapter : IReadWriteAdapter
1052 {
1053 if (Interlocked.Exchange(ref _nestedAuth, 1) == 1)
1054 {
1055 throw new InvalidOperationException(System.SR.Format(System.SR.net_io_invalidnestedcall, "NegotiateClientCertificateAsync", "renegotiate"));
1056 }
1057 if (Interlocked.Exchange(ref _nestedRead, 1) == 1)
1058 {
1059 throw new NotSupportedException(System.SR.Format(System.SR.net_io_invalidnestedcall, "ReadAsync", "read"));
1060 }
1061 if (Interlocked.Exchange(ref _nestedWrite, 1) == 1)
1062 {
1063 _nestedRead = 0;
1064 throw new NotSupportedException(System.SR.Format(System.SR.net_io_invalidnestedcall, "WriteAsync", "write"));
1065 }
1066 try
1067 {
1068 if (_decryptedBytesCount != 0)
1069 {
1071 }
1072 _sslAuthenticationOptions.RemoteCertRequired = true;
1073 _isRenego = true;
1074 byte[] output;
1075 SecurityStatusPal status = _context.Renegotiate(out output);
1076 if (output != null && output.Length != 0)
1077 {
1078 await adapter.WriteAsync(output, 0, output.Length).ConfigureAwait(continueOnCapturedContext: false);
1079 await adapter.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);
1080 }
1081 if (status.ErrorCode != SecurityStatusPalErrorCode.OK)
1082 {
1083 if (status.ErrorCode != SecurityStatusPalErrorCode.NoRenegotiation)
1084 {
1085 throw SslStreamPal.GetException(status);
1086 }
1087 return;
1088 }
1089 _handshakeBuffer = new ArrayBuffer(4160);
1090 ProtocolToken message;
1091 do
1092 {
1093 message = await ReceiveBlobAsync(adapter).ConfigureAwait(continueOnCapturedContext: false);
1094 if (message.Size > 0)
1095 {
1096 await adapter.WriteAsync(message.Payload, 0, message.Size).ConfigureAwait(continueOnCapturedContext: false);
1097 await adapter.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);
1098 }
1099 }
1100 while (message.Status.ErrorCode == SecurityStatusPalErrorCode.ContinueNeeded);
1102 {
1106 }
1108 }
1109 finally
1110 {
1111 _nestedRead = 0;
1112 _nestedWrite = 0;
1113 _isRenego = false;
1114 }
1115 }
1116
1117 private async Task ForceAuthenticationAsync<TIOAdapter>(TIOAdapter adapter, bool receiveFirst, byte[] reAuthenticationData, bool isApm = false) where TIOAdapter : IReadWriteAdapter
1118 {
1119 bool handshakeCompleted = false;
1120 if (reAuthenticationData == null && Interlocked.Exchange(ref _nestedAuth, 1) == 1)
1121 {
1122 throw new InvalidOperationException(System.SR.Format(System.SR.net_io_invalidnestedcall, isApm ? "BeginAuthenticate" : "Authenticate", "authenticate"));
1123 }
1124 try
1125 {
1126 if (!receiveFirst)
1127 {
1128 ProtocolToken message = _context.NextMessage(reAuthenticationData);
1129 if (message.Size > 0)
1130 {
1131 await adapter.WriteAsync(message.Payload, 0, message.Size).ConfigureAwait(continueOnCapturedContext: false);
1132 await adapter.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);
1133 if (System.Net.NetEventSource.Log.IsEnabled())
1134 {
1135 System.Net.NetEventSource.Log.SentFrame(this, message.Payload);
1136 }
1137 }
1138 if (message.Failed)
1139 {
1141 }
1143 {
1144 handshakeCompleted = true;
1145 }
1146 }
1147 if (!handshakeCompleted)
1148 {
1149 _handshakeBuffer = new ArrayBuffer(4160);
1150 }
1151 while (!handshakeCompleted)
1152 {
1153 ProtocolToken message = await ReceiveBlobAsync(adapter).ConfigureAwait(continueOnCapturedContext: false);
1154 byte[] payload = null;
1155 int num = 0;
1156 if (message.Size > 0)
1157 {
1158 payload = message.Payload;
1159 num = message.Size;
1160 }
1161 else if (message.Failed && (_lastFrame.Header.Type == TlsContentType.Handshake || _lastFrame.Header.Type == TlsContentType.ChangeCipherSpec))
1162 {
1163 payload = TlsFrameHelper.CreateAlertFrame(_lastFrame.Header.Version, TlsAlertDescription.ProtocolVersion);
1164 num = payload.Length;
1165 }
1166 if (payload != null && num > 0)
1167 {
1168 await adapter.WriteAsync(payload, 0, num).ConfigureAwait(continueOnCapturedContext: false);
1169 await adapter.FlushAsync().ConfigureAwait(continueOnCapturedContext: false);
1170 if (System.Net.NetEventSource.Log.IsEnabled())
1171 {
1172 System.Net.NetEventSource.Log.SentFrame(this, payload);
1173 }
1174 }
1175 if (message.Failed)
1176 {
1177 if (System.Net.NetEventSource.Log.IsEnabled())
1178 {
1179 System.Net.NetEventSource.Error(this, message.Status, "ForceAuthenticationAsync");
1180 }
1181 if (_lastFrame.Header.Type == TlsContentType.Alert && _lastFrame.AlertDescription != 0 && message.Status.ErrorCode == SecurityStatusPalErrorCode.IllegalMessage)
1182 {
1183 throw new AuthenticationException(System.SR.Format(System.SR.net_auth_tls_alert, _lastFrame.AlertDescription.ToString()), message.GetException());
1184 }
1186 }
1188 {
1189 handshakeCompleted = true;
1190 }
1191 }
1193 {
1197 }
1199 }
1200 finally
1201 {
1203 if (reAuthenticationData == null)
1204 {
1205 _nestedAuth = 0;
1206 _isRenego = false;
1207 }
1208 }
1209 if (System.Net.NetEventSource.Log.IsEnabled())
1210 {
1212 }
1213 }
1214
1215 private async ValueTask<ProtocolToken> ReceiveBlobAsync<TIOAdapter>(TIOAdapter adapter) where TIOAdapter : IReadWriteAdapter
1216 {
1217 if (await FillHandshakeBufferAsync(adapter, 5).ConfigureAwait(continueOnCapturedContext: false) == 0)
1218 {
1219 throw new IOException(System.SR.net_io_eof);
1220 }
1221 if (_framing == Framing.Unified || _framing == Framing.Unknown)
1222 {
1224 }
1225 if (_framing != Framing.SinceSSL3)
1226 {
1227 _lastFrame.Header.Version = SslProtocols.Ssl2;
1228 _lastFrame.Header.Length = GetFrameSize(_handshakeBuffer.ActiveReadOnlySpan) - 5;
1229 }
1230 else
1231 {
1233 }
1234 if (_lastFrame.Header.Length < 0)
1235 {
1236 if (System.Net.NetEventSource.Log.IsEnabled())
1237 {
1238 System.Net.NetEventSource.Error(this, "invalid TLS frame size", "ReceiveBlobAsync");
1239 }
1241 }
1242 int frameSize = _lastFrame.Header.Length + 5;
1243 if (_handshakeBuffer.ActiveLength < frameSize)
1244 {
1245 await FillHandshakeBufferAsync(adapter, frameSize).ConfigureAwait(continueOnCapturedContext: false);
1246 }
1247 switch (_lastFrame.Header.Type)
1248 {
1249 case TlsContentType.Alert:
1250 if (TlsFrameHelper.TryGetFrameInfo(_handshakeBuffer.ActiveReadOnlySpan, ref _lastFrame) && System.Net.NetEventSource.Log.IsEnabled() && _lastFrame.AlertDescription != 0)
1251 {
1252 System.Net.NetEventSource.Error(this, $"Received TLS alert {_lastFrame.AlertDescription}", "ReceiveBlobAsync");
1253 }
1254 break;
1255 case TlsContentType.Handshake:
1256 {
1258 {
1259 break;
1260 }
1263 {
1264 System.Net.NetEventSource.Error(this, $"Failed to parse TLS hello.", "ReceiveBlobAsync");
1265 }
1266 if (_lastFrame.HandshakeType == TlsHandshakeType.ClientHello)
1267 {
1268 if (_lastFrame.TargetName != null)
1269 {
1270 _sslAuthenticationOptions.TargetHost = _lastFrame.TargetName;
1271 }
1273 {
1274 SslServerAuthenticationOptions sslServerAuthenticationOptions = await _sslAuthenticationOptions.ServerOptionDelegate(this, new SslClientHelloInfo(_sslAuthenticationOptions.TargetHost, _lastFrame.SupportedVersions), _sslAuthenticationOptions.UserState, adapter.CancellationToken).ConfigureAwait(continueOnCapturedContext: false);
1275 _sslAuthenticationOptions.UpdateOptions(sslServerAuthenticationOptions);
1276 }
1277 }
1278 if (System.Net.NetEventSource.Log.IsEnabled())
1279 {
1280 System.Net.NetEventSource.Log.ReceivedFrame(this, _lastFrame);
1281 }
1282 break;
1283 }
1284 case TlsContentType.AppData:
1285 if (_isRenego && SslProtocol != SslProtocols.Tls13)
1286 {
1288 }
1289 break;
1290 }
1291 return ProcessBlob(frameSize);
1292 }
1293
1294 private ProtocolToken ProcessBlob(int frameSize)
1295 {
1296 int num = frameSize;
1298 _handshakeBuffer.Discard(frameSize);
1299 if (_framing == Framing.SinceSSL3)
1300 {
1301 while (_handshakeBuffer.ActiveLength > 5)
1302 {
1303 TlsFrameHeader header = default(TlsFrameHeader);
1305 {
1306 break;
1307 }
1308 frameSize = header.Length + 5;
1309 if ((header.Type != TlsContentType.Handshake && header.Type != TlsContentType.ChangeCipherSpec) || frameSize > _handshakeBuffer.ActiveLength)
1310 {
1311 break;
1312 }
1313 num += frameSize;
1314 _handshakeBuffer.Discard(frameSize);
1315 }
1316 }
1317 return _context.NextMessage(activeReadOnlySpan.Slice(0, num));
1318 }
1319
1321 {
1322 SetException(exception.SourceException);
1323 if (message == null || message.Size == 0)
1324 {
1325 exception.Throw();
1326 }
1327 base.InnerStream.Write(message.Payload, 0, message.Size);
1328 exception.Throw();
1329 }
1330
1331 private bool CompleteHandshake(ref ProtocolToken alertToken, out SslPolicyErrors sslPolicyErrors, out X509ChainStatusFlags chainStatus)
1332 {
1334 if (_nestedAuth != 1)
1335 {
1336 if (System.Net.NetEventSource.Log.IsEnabled())
1337 {
1338 System.Net.NetEventSource.Error(this, $"Ignoring unsolicited renegotiated certificate.", "CompleteHandshake");
1339 }
1340 sslPolicyErrors = SslPolicyErrors.None;
1341 chainStatus = X509ChainStatusFlags.NoError;
1342 return true;
1343 }
1345 {
1346 _handshakeCompleted = false;
1347 return false;
1348 }
1349 _handshakeCompleted = true;
1350 return true;
1351 }
1352
1353 private void CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)
1354 {
1355 ProtocolToken alertToken = null;
1356 if (!CompleteHandshake(ref alertToken, out var sslPolicyErrors, out var chainStatus))
1357 {
1358 if (sslAuthenticationOptions.CertValidationDelegate != null)
1359 {
1361 }
1362 else if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors && chainStatus != 0)
1363 {
1365 }
1366 else
1367 {
1369 }
1370 }
1371 }
1372
1373 private async ValueTask WriteAsyncChunked<TIOAdapter>(TIOAdapter writeAdapter, ReadOnlyMemory<byte> buffer) where TIOAdapter : struct, IReadWriteAdapter
1374 {
1375 do
1376 {
1377 int chunkBytes = Math.Min(buffer.Length, MaxDataSize);
1378 await WriteSingleChunk(writeAdapter, buffer.Slice(0, chunkBytes)).ConfigureAwait(continueOnCapturedContext: false);
1379 buffer = buffer.Slice(chunkBytes);
1380 }
1381 while (buffer.Length != 0);
1382 }
1383
1384 private ValueTask WriteSingleChunk<TIOAdapter>(TIOAdapter writeAdapter, ReadOnlyMemory<byte> buffer) where TIOAdapter : struct, IReadWriteAdapter
1385 {
1386 byte[] array = ArrayPool<byte>.Shared.Rent(buffer.Length + 64);
1387 byte[] outBuffer = array;
1388 SecurityStatusPal status;
1389 int outSize;
1390 while (true)
1391 {
1392 status = EncryptData(buffer, ref outBuffer, out outSize);
1393 if (status.ErrorCode != SecurityStatusPalErrorCode.TryAgain)
1394 {
1395 break;
1396 }
1398 if (handshakeWaiter != null)
1399 {
1400 Task task = writeAdapter.WaitAsync(handshakeWaiter);
1401 if (!task.IsCompletedSuccessfully)
1402 {
1403 return WaitAndWriteAsync(writeAdapter, buffer, task, array);
1404 }
1405 }
1406 }
1407 if (status.ErrorCode != SecurityStatusPalErrorCode.OK)
1408 {
1411 }
1412 ValueTask valueTask = writeAdapter.WriteAsync(outBuffer, 0, outSize);
1413 if (valueTask.IsCompletedSuccessfully)
1414 {
1416 return valueTask;
1417 }
1418 return CompleteWriteAsync(valueTask, array);
1419 static async ValueTask CompleteWriteAsync(ValueTask writeTask, byte[] bufferToReturn)
1420 {
1421 try
1422 {
1423 await writeTask.ConfigureAwait(continueOnCapturedContext: false);
1424 }
1425 finally
1426 {
1427 ArrayPool<byte>.Shared.Return(bufferToReturn);
1428 }
1429 }
1430 async ValueTask WaitAndWriteAsync(TIOAdapter writeAdapter, ReadOnlyMemory<byte> buffer, Task waitTask, byte[] rentedBuffer)
1431 {
1432 byte[] bufferToReturn2 = rentedBuffer;
1433 byte[] outBuffer2 = rentedBuffer;
1434 try
1435 {
1436 await waitTask.ConfigureAwait(continueOnCapturedContext: false);
1437 int outSize2;
1438 SecurityStatusPal status2 = EncryptData(buffer, ref outBuffer2, out outSize2);
1439 if (status2.ErrorCode == SecurityStatusPalErrorCode.TryAgain)
1440 {
1441 byte[] array2 = bufferToReturn2;
1442 bufferToReturn2 = null;
1443 ArrayPool<byte>.Shared.Return(array2);
1444 await WriteSingleChunk(writeAdapter, buffer).ConfigureAwait(continueOnCapturedContext: false);
1445 }
1446 else
1447 {
1448 if (status2.ErrorCode != SecurityStatusPalErrorCode.OK)
1449 {
1451 }
1452 await writeAdapter.WriteAsync(outBuffer2, 0, outSize2).ConfigureAwait(continueOnCapturedContext: false);
1453 }
1454 }
1455 finally
1456 {
1457 if (bufferToReturn2 != null)
1458 {
1459 ArrayPool<byte>.Shared.Return(bufferToReturn2);
1460 }
1461 }
1462 }
1463 }
1464
1466 {
1467 Dispose(disposing: false);
1468 }
1469
1471 {
1472 byte[] internalBuffer = _internalBuffer;
1473 if (internalBuffer != null && _decryptedBytesCount == 0 && _internalBufferCount == 0)
1474 {
1475 _internalBuffer = null;
1476 _internalOffset = 0;
1478 ArrayPool<byte>.Shared.Return(internalBuffer);
1479 }
1480 else if (_decryptedBytesCount == 0)
1481 {
1483 }
1484 }
1485
1486 private bool HaveFullTlsFrame(out int frameSize)
1487 {
1488 if (_internalBufferCount < 5)
1489 {
1490 frameSize = int.MaxValue;
1491 return false;
1492 }
1493 frameSize = GetFrameSize(_internalBuffer.AsSpan(_internalOffset));
1494 return _internalBufferCount >= frameSize;
1495 }
1496
1497 private async ValueTask<int> EnsureFullTlsFrameAsync<TIOAdapter>(TIOAdapter adapter) where TIOAdapter : IReadWriteAdapter
1498 {
1499 if (HaveFullTlsFrame(out var frameSize))
1500 {
1501 return frameSize;
1502 }
1504 while (_internalBufferCount < frameSize)
1505 {
1506 int num = await adapter.ReadAsync(_internalBuffer.AsMemory(_internalBufferCount)).ConfigureAwait(continueOnCapturedContext: false);
1507 if (num == 0)
1508 {
1509 if (_internalBufferCount != 0)
1510 {
1511 throw new IOException(System.SR.net_io_eof);
1512 }
1513 return 0;
1514 }
1515 _internalBufferCount += num;
1516 if (frameSize == int.MaxValue && _internalBufferCount > 5)
1517 {
1518 frameSize = GetFrameSize(_internalBuffer.AsSpan(_internalOffset));
1519 }
1520 }
1521 return frameSize;
1522 }
1523
1524 private SecurityStatusPal DecryptData(int frameSize)
1525 {
1527 _decryptedBytesCount = frameSize;
1528 SecurityStatusPal result;
1529 lock (_handshakeLock)
1530 {
1532 result = _context.Decrypt(new Span<byte>(_internalBuffer, _internalOffset, frameSize), out var outputOffset, out var outputCount);
1533 _decryptedBytesCount = outputCount;
1534 if (outputCount > 0)
1535 {
1536 _decryptedBytesOffset = _internalOffset + outputOffset;
1537 }
1539 {
1540 _handshakeWaiter = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
1541 }
1542 }
1543 ConsumeBufferedBytes(frameSize);
1544 return result;
1545 }
1546
1547 private async ValueTask<int> ReadAsyncInternal<TIOAdapter>(TIOAdapter adapter, Memory<byte> buffer) where TIOAdapter : IReadWriteAdapter
1548 {
1549 if (Interlocked.Exchange(ref _nestedRead, 1) == 1)
1550 {
1551 throw new NotSupportedException(System.SR.Format(System.SR.net_io_invalidnestedcall, "ReadAsync", "read"));
1552 }
1554 int processedLength = 0;
1555 int frameSize = 0;
1556 try
1557 {
1558 if (_decryptedBytesCount != 0)
1559 {
1560 processedLength = CopyDecryptedData(buffer);
1561 if (processedLength == buffer.Length || !HaveFullTlsFrame(out frameSize))
1562 {
1563 return processedLength;
1564 }
1565 buffer = buffer.Slice(processedLength);
1566 }
1567 if (_receivedEOF)
1568 {
1569 return 0;
1570 }
1571 if (buffer.Length == 0 && _internalBuffer == null)
1572 {
1573 await adapter.ReadAsync(Memory<byte>.Empty).ConfigureAwait(continueOnCapturedContext: false);
1574 }
1575 while (true)
1576 {
1577 frameSize = await EnsureFullTlsFrameAsync(adapter).ConfigureAwait(continueOnCapturedContext: false);
1578 if (frameSize == 0)
1579 {
1580 _receivedEOF = true;
1581 break;
1582 }
1583 SecurityStatusPal securityStatusPal = DecryptData(frameSize);
1584 if (securityStatusPal.ErrorCode != SecurityStatusPalErrorCode.OK)
1585 {
1586 byte[] array = null;
1587 if (_decryptedBytesCount != 0)
1588 {
1589 array = new byte[_decryptedBytesCount];
1592 }
1593 if (System.Net.NetEventSource.Log.IsEnabled())
1594 {
1595 System.Net.NetEventSource.Info(null, $"***Processing an error Status = {securityStatusPal}", "ReadAsyncInternal");
1596 }
1597 if (securityStatusPal.ErrorCode == SecurityStatusPalErrorCode.Renegotiate)
1598 {
1599 if (_handshakeWaiter == null)
1600 {
1602 }
1603 await ReplyOnReAuthenticationAsync(adapter, array).ConfigureAwait(continueOnCapturedContext: false);
1604 continue;
1605 }
1606 if (securityStatusPal.ErrorCode == SecurityStatusPalErrorCode.ContextExpired)
1607 {
1608 _receivedEOF = true;
1609 break;
1610 }
1611 throw new IOException(System.SR.net_io_decrypt, SslStreamPal.GetException(securityStatusPal));
1612 }
1613 if (_decryptedBytesCount > 0)
1614 {
1615 int num = CopyDecryptedData(buffer);
1616 processedLength += num;
1617 if (num == buffer.Length)
1618 {
1619 break;
1620 }
1621 buffer = buffer.Slice(num);
1622 }
1623 if (processedLength != 0)
1624 {
1625 if (!HaveFullTlsFrame(out frameSize))
1626 {
1627 break;
1628 }
1630 if (_lastFrame.Header.Type != TlsContentType.AppData)
1631 {
1632 break;
1633 }
1634 }
1635 }
1636 return processedLength;
1637 }
1638 catch (Exception ex)
1639 {
1641 {
1642 throw;
1643 }
1644 throw new IOException(System.SR.net_io_read, ex);
1645 }
1646 finally
1647 {
1649 _nestedRead = 0;
1650 }
1651 }
1652
1653 private ValueTask<int> FillHandshakeBufferAsync<TIOAdapter>(TIOAdapter adapter, int minSize) where TIOAdapter : IReadWriteAdapter
1654 {
1655 if (_handshakeBuffer.ActiveLength >= minSize)
1656 {
1657 return new ValueTask<int>(minSize);
1658 }
1659 int byteCount = minSize - _handshakeBuffer.ActiveLength;
1661 while (_handshakeBuffer.ActiveLength < minSize)
1662 {
1663 ValueTask<int> task2 = adapter.ReadAsync(_handshakeBuffer.AvailableMemory);
1664 if (!task2.IsCompletedSuccessfully)
1665 {
1666 return InternalFillHandshakeBufferAsync(adapter, task2, minSize);
1667 }
1668 int result = task2.Result;
1669 if (result == 0)
1670 {
1671 return new ValueTask<int>(0);
1672 }
1673 _handshakeBuffer.Commit(result);
1674 }
1675 return new ValueTask<int>(minSize);
1676 async ValueTask<int> InternalFillHandshakeBufferAsync(TIOAdapter adap, ValueTask<int> task, int minSize)
1677 {
1678 while (true)
1679 {
1680 int num = await task.ConfigureAwait(continueOnCapturedContext: false);
1681 if (num == 0)
1682 {
1683 throw new IOException(System.SR.net_io_eof);
1684 }
1686 if (_handshakeBuffer.ActiveLength >= minSize)
1687 {
1688 break;
1689 }
1690 task = adap.ReadAsync(_handshakeBuffer.AvailableMemory);
1691 }
1692 return minSize;
1693 }
1694 }
1695
1696 private async ValueTask WriteAsyncInternal<TIOAdapter>(TIOAdapter writeAdapter, ReadOnlyMemory<byte> buffer) where TIOAdapter : struct, IReadWriteAdapter
1697 {
1699 _ = buffer.Length;
1700 if (Interlocked.Exchange(ref _nestedWrite, 1) == 1)
1701 {
1702 throw new NotSupportedException(System.SR.Format(System.SR.net_io_invalidnestedcall, "WriteAsync", "write"));
1703 }
1704 try
1705 {
1706 await ((buffer.Length < MaxDataSize) ? WriteSingleChunk(writeAdapter, buffer) : WriteAsyncChunked(writeAdapter, buffer)).ConfigureAwait(continueOnCapturedContext: false);
1707 }
1708 catch (Exception ex)
1709 {
1711 {
1712 throw;
1713 }
1714 throw new IOException(System.SR.net_io_write, ex);
1715 }
1716 finally
1717 {
1718 _nestedWrite = 0;
1719 }
1720 }
1721
1723 {
1726 if (_internalBufferCount == 0)
1727 {
1728 _internalOffset = 0;
1729 }
1730 }
1731
1733 {
1734 int num = Math.Min(_decryptedBytesCount, buffer.Length);
1735 if (num != 0)
1736 {
1738 _decryptedBytesOffset += num;
1739 _decryptedBytesCount -= num;
1740 }
1741 if (_decryptedBytesCount == 0)
1742 {
1744 }
1745 return num;
1746 }
1747
1748 private void ResetReadBuffer()
1749 {
1750 if (_internalBuffer == null)
1751 {
1753 }
1754 else if (_internalOffset > 0)
1755 {
1757 _internalOffset = 0;
1758 }
1759 }
1760
1762 {
1763 int num = -1;
1764 if (bytes[0] == 22 || bytes[0] == 23 || bytes[0] == 21)
1765 {
1766 if (bytes.Length < 3)
1767 {
1768 return Framing.Invalid;
1769 }
1770 num = (bytes[1] << 8) | bytes[2];
1771 if (num < 768 || num >= 1280)
1772 {
1773 return Framing.Invalid;
1774 }
1775 return Framing.SinceSSL3;
1776 }
1777 if (bytes.Length < 3)
1778 {
1779 return Framing.Invalid;
1780 }
1781 if (bytes[2] > 8)
1782 {
1783 return Framing.Invalid;
1784 }
1785 if (bytes[2] == 1)
1786 {
1787 if (bytes.Length >= 5)
1788 {
1789 num = (bytes[3] << 8) | bytes[4];
1790 }
1791 }
1792 else if (bytes[2] == 4 && bytes.Length >= 7)
1793 {
1794 num = (bytes[5] << 8) | bytes[6];
1795 }
1796 if (num != -1)
1797 {
1798 if (_framing == Framing.Unknown)
1799 {
1800 if (num != 2 && (num < 512 || num >= 1280))
1801 {
1802 return Framing.Invalid;
1803 }
1804 }
1805 else if (num != 2)
1806 {
1807 return Framing.Invalid;
1808 }
1809 }
1810 if (!_context.IsServer || _framing == Framing.Unified)
1811 {
1812 return Framing.BeforeSSL3;
1813 }
1814 return Framing.Unified;
1815 }
1816
1818 {
1819 int num = -1;
1820 switch (_framing)
1821 {
1822 case Framing.BeforeSSL3:
1823 case Framing.Unified:
1824 if (buffer.Length < 2)
1825 {
1827 }
1828 if ((buffer[0] & 0x80u) != 0)
1829 {
1830 return (((buffer[0] & 0x7F) << 8) | buffer[1]) + 2;
1831 }
1832 return (((buffer[0] & 0x3F) << 8) | buffer[1]) + 3;
1833 case Framing.SinceSSL3:
1834 if (buffer.Length < 5)
1835 {
1837 }
1838 return ((buffer[3] << 8) | buffer[4]) + 5;
1839 default:
1841 }
1842 }
1843}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
virtual string Message
Definition Exception.cs:100
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
Definition Stream.cs:1044
void Dispose()
Definition Stream.cs:639
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static readonly NetSecurityTelemetry Log
ChannelBinding GetChannelBinding(ChannelBindingKind kind)
SecurityStatusPal Decrypt(Span< byte > buffer, out int outputOffset, out int outputCount)
SecurityStatusPal Encrypt(ReadOnlyMemory< byte > buffer, ref byte[] output, out int resultSize)
SecurityStatusPal Renegotiate(out byte[] output)
SslApplicationProtocol NegotiatedApplicationProtocol
bool VerifyRemoteCertificate(RemoteCertificateValidationCallback remoteCertValidationCallback, SslCertificateTrust trust, ref ProtocolToken alertToken, out SslPolicyErrors sslPolicyErrors, out X509ChainStatusFlags chainStatus)
ProtocolToken NextMessage(ReadOnlySpan< byte > incomingBuffer)
RemoteCertificateValidationCallback CertValidationDelegate
void UpdateOptions(SslServerAuthenticationOptions sslServerAuthenticationOptions)
RemoteCertificateValidationCallback? RemoteCertificateValidationCallback
RemoteCertificateValidationCallback? RemoteCertificateValidationCallback
ServerCertificateSelectionCallback? ServerCertificateSelectionCallback
static Exception GetException(SecurityStatusPal status)
override int EndRead(IAsyncResult asyncResult)
Definition SslStream.cs:804
async ValueTask< int > ReadAsyncInternal< TIOAdapter >(TIOAdapter adapter, Memory< byte > buffer)
async Task ForceAuthenticationAsync< TIOAdapter >(TIOAdapter adapter, bool receiveFirst, byte[] reAuthenticationData, bool isApm=false)
SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback, LocalCertificateSelectionCallback? userCertificateSelectionCallback, EncryptionPolicy encryptionPolicy)
Definition SslStream.cs:343
ValueTask< int > FillHandshakeBufferAsync< TIOAdapter >(TIOAdapter adapter, int minSize)
SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback)
Definition SslStream.cs:333
SslApplicationProtocol NegotiatedApplicationProtocol
Definition SslStream.cs:81
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:829
SslAuthenticationOptions CreateAuthenticationOptions(SslServerAuthenticationOptions sslServerAuthenticationOptions)
Definition SslStream.cs:396
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:842
IAsyncResult BeginAuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, object asyncState)
Definition SslStream.cs:437
virtual bool CheckCertRevocationStatus
Definition SslStream.cs:144
override void Dispose(bool disposing)
Definition SslStream.cs:725
SecurityStatusPal DecryptData(int frameSize)
EncryptionPolicy _encryptionPolicy
Definition SslStream.cs:36
ValueTask WriteSingleChunk< TIOAdapter >(TIOAdapter writeAdapter, ReadOnlyMemory< byte > buffer)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Definition SslStream.cs:822
override Task FlushAsync(CancellationToken cancellationToken)
Definition SslStream.cs:710
virtual ExchangeAlgorithmType KeyExchangeAlgorithm
Definition SslStream.cs:224
virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:424
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Definition SslStream.cs:835
virtual void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Definition SslStream.cs:530
X509Certificate UserCertSelectionCallbackWrapper(string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssuers)
Definition SslStream.cs:386
virtual Task AuthenticateAsClientAsync(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation)
Definition SslStream.cs:559
virtual Task NegotiateClientCertificateAsync(CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:715
override bool IsMutuallyAuthenticated
Definition SslStream.cs:107
TlsFrameHelper.TlsFrameInfo _lastFrame
Definition SslStream.cs:70
int GetFrameSize(ReadOnlySpan< byte > buffer)
static readonly ExceptionDispatchInfo s_disposedSentinel
Definition SslStream.cs:26
virtual void AuthenticateAsServer(X509Certificate serverCertificate)
Definition SslStream.cs:520
void SetAndVerifySelectionCallback(LocalCertificateSelectionCallback callback)
Definition SslStream.cs:373
Task AuthenticateAsServerAsync(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:627
static void ThrowNotAuthenticated()
Definition SslStream.cs:903
virtual ? X509Certificate LocalCertificate
Definition SslStream.cs:156
virtual Task AuthenticateAsServerAsync(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Definition SslStream.cs:614
async Task ReplyOnReAuthenticationAsync< TIOAdapter >(TIOAdapter adapter, byte[] buffer)
void CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)
ChannelBinding GetChannelBinding(ChannelBindingKind kind)
Definition SslStream.cs:480
ExceptionDispatchInfo _exception
Definition SslStream.cs:42
SslStream(Stream innerStream, bool leaveInnerStreamOpen)
Definition SslStream.cs:328
virtual void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
Definition SslStream.cs:525
void AuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions)
Definition SslStream.cs:543
LocalCertSelectionCallback _certSelectionDelegate
Definition SslStream.cs:34
virtual CipherAlgorithmType CipherAlgorithm
Definition SslStream.cs:188
Task AuthenticateAsClientApm(SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:589
virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:452
void ValidateCreateContext(SslClientAuthenticationOptions sslClientAuthenticationOptions, RemoteCertificateValidationCallback remoteCallback, LocalCertSelectionCallback localCallback)
Definition SslStream.cs:908
virtual Task AuthenticateAsClientAsync(string targetHost)
Definition SslStream.cs:554
void ThrowIfExceptionalOrNotAuthenticatedOrShutdown()
Definition SslStream.cs:886
SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback? userCertificateValidationCallback, LocalCertificateSelectionCallback? userCertificateSelectionCallback)
Definition SslStream.cs:338
void ConsumeBufferedBytes(int byteCount)
IAsyncResult BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, object asyncState)
Definition SslStream.cs:470
Task AuthenticateAsServerAsync(ServerOptionsSelectionCallback optionsCallback, object? state, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:645
SecurityStatusPal EncryptData(ReadOnlyMemory< byte > buffer, ref byte[] outBuffer, out int outSize)
Definition SslStream.cs:992
ProtocolToken ProcessBlob(int frameSize)
virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:447
override async ValueTask DisposeAsync()
Definition SslStream.cs:737
volatile TaskCompletionSource< bool > _handshakeWaiter
Definition SslStream.cs:72
Framing DetectFraming(ReadOnlySpan< byte > bytes)
void SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)
async Task RenegotiateAsync< TIOAdapter >(TIOAdapter adapter)
virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:414
override void EndWrite(IAsyncResult asyncResult)
Definition SslStream.cs:816
virtual TlsCipherSuite NegotiatedCipherSuite
Definition SslStream.cs:179
override long Seek(long offset, SeekOrigin origin)
Definition SslStream.cs:700
async ValueTask< ProtocolToken > ReceiveBlobAsync< TIOAdapter >(TIOAdapter adapter)
async Task ProcessAuthenticationWithTelemetryAsync(bool isAsync, bool isApm, CancellationToken cancellationToken)
void ValidateCreateContext(SslAuthenticationOptions sslAuthenticationOptions)
Definition SslStream.cs:935
ServerCertificateSelectionCallback _userServerCertificateSelectionCallback
Definition SslStream.cs:32
SslProtocols GetSslProtocolInternal()
Definition SslStream.cs:659
RemoteCertificateValidationCallback _userCertificateValidationCallback
Definition SslStream.cs:28
virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:419
virtual void EndAuthenticateAsServer(IAsyncResult asyncResult)
Definition SslStream.cs:475
SslStream(Stream innerStream)
Definition SslStream.cs:323
void SetException(Exception e)
Definition SslStream.cs:958
async ValueTask WriteAsyncChunked< TIOAdapter >(TIOAdapter writeAdapter, ReadOnlyMemory< byte > buffer)
async ValueTask< int > EnsureFullTlsFrameAsync< TIOAdapter >(TIOAdapter adapter)
SslAuthenticationOptions _sslAuthenticationOptions
Definition SslStream.cs:62
virtual ? X509Certificate RemoteCertificate
Definition SslStream.cs:169
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:810
virtual Task AuthenticateAsClientAsync(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Definition SslStream.cs:564
Task ProcessAuthenticationAsync(bool isAsync=false, bool isApm=false, CancellationToken cancellationToken=default(CancellationToken))
Task AuthenticateAsClientAsync(SslClientAuthenticationOptions sslClientAuthenticationOptions, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:577
void AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
Definition SslStream.cs:508
virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:457
bool HaveFullTlsFrame(out int frameSize)
virtual void AuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, bool checkCertificateRevocation)
Definition SslStream.cs:490
virtual Task AuthenticateAsServerAsync(X509Certificate serverCertificate, bool clientCertificateRequired, bool checkCertificateRevocation)
Definition SslStream.cs:602
virtual void EndAuthenticateAsClient(IAsyncResult asyncResult)
Definition SslStream.cs:442
override int Read(byte[] buffer, int offset, int count)
Definition SslStream.cs:779
override bool IsAuthenticated
Definition SslStream.cs:95
void Write(byte[] buffer)
Definition SslStream.cs:786
async ValueTask WriteAsyncInternal< TIOAdapter >(TIOAdapter writeAdapter, ReadOnlyMemory< byte > buffer)
override void SetLength(long value)
Definition SslStream.cs:695
void SetAndVerifyValidationCallback(RemoteCertificateValidationCallback callback)
Definition SslStream.cs:361
virtual void AuthenticateAsClient(string targetHost)
Definition SslStream.cs:485
readonly Stream _innerStream
Definition SslStream.cs:38
bool CompleteHandshake(ref ProtocolToken alertToken, out SslPolicyErrors sslPolicyErrors, out X509ChainStatusFlags chainStatus)
virtual Task AuthenticateAsServerAsync(X509Certificate serverCertificate)
Definition SslStream.cs:597
LocalCertificateSelectionCallback _userCertificateSelectionCallback
Definition SslStream.cs:30
virtual SslProtocols SslProtocol
Definition SslStream.cs:135
virtual void AuthenticateAsClient(string targetHost, X509CertificateCollection? clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation)
Definition SslStream.cs:495
Task AuthenticateAsServerApm(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken=default(CancellationToken))
Definition SslStream.cs:638
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? asyncCallback, object? asyncState)
Definition SslStream.cs:798
X509Certificate ServerCertSelectionCallbackWrapper(string targetHost)
Definition SslStream.cs:391
override void Write(byte[] buffer, int offset, int count)
Definition SslStream.cs:791
int CopyDecryptedData(Memory< byte > buffer)
static byte[] CreateAlertFrame(SslProtocols version, TlsAlertDescription reason)
static bool TryGetFrameInfo(ReadOnlySpan< byte > frame, ref TlsFrameInfo info, ProcessingOptions options=ProcessingOptions.All, HelloExtensionCallback callback=null)
static bool TryGetFrameHeader(ReadOnlySpan< byte > frame, ref TlsFrameHeader header)
static ExceptionDispatchInfo Capture(Exception source)
static string net_ssl_io_cert_validation
Definition SR.cs:46
static string net_frame_read_size
Definition SR.cs:86
static string net_ssl_renegotiate_buffer
Definition SR.cs:124
static string net_io_invalidnestedcall
Definition SR.cs:24
static string net_auth_client_server
Definition SR.cs:70
static string net_invalid_enum
Definition SR.cs:40
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_io_encrypt
Definition SR.cs:32
static string net_auth_tls_alert
Definition SR.cs:76
static string net_ssl_io_frame
Definition SR.cs:42
static string net_auth_noauth
Definition SR.cs:68
static string net_ssl_io_cert_custom_validation
Definition SR.cs:50
static string net_auth_reauth
Definition SR.cs:66
static string net_io_eof
Definition SR.cs:40
static string net_conflicting_options
Definition SR.cs:116
static string net_ssl_io_cert_chain_validation
Definition SR.cs:48
static string net_auth_SSPI
Definition SR.cs:72
static string net_ssl_renegotiate_data
Definition SR.cs:122
static string net_io_read
Definition SR.cs:36
static string net_io_write
Definition SR.cs:38
static string net_noseek
Definition SR.cs:114
static string net_io_decrypt
Definition SR.cs:34
static string net_ssl_io_renego
Definition SR.cs:44
static string net_ssl_io_already_shutdown
Definition SR.cs:54
static string net_ssl_certificate_exist
Definition SR.cs:120
Definition SR.cs:7
static int CompareExchange(ref int location1, int value, int comparand)
static int Exchange(ref int location1, int value)
static IAsyncResult Begin(Task task, AsyncCallback callback, object state)
Definition TaskToApm.cs:43
static void End(IAsyncResult asyncResult)
Definition TaskToApm.cs:48
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
new Task< TResult > WaitAsync(CancellationToken cancellationToken)
Definition Task.cs:231
new TaskAwaiter< TResult > GetAwaiter()
Definition Task.cs:221
delegate ValueTask< SslServerAuthenticationOptions > ServerOptionsSelectionCallback(SslStream stream, SslClientHelloInfo clientHelloInfo, object? state, CancellationToken cancellationToken)
delegate X509Certificate ServerCertSelectionCallback(string hostName)
delegate X509Certificate LocalCertSelectionCallback(string targetHost, X509CertificateCollection localCertificates, X509Certificate2 remoteCertificate, string[] acceptableIssuers)
static Microsoft.Extensions.Internal.ValueStopwatch StartNew()
Memory< byte > AvailableMemory
Span< byte > ActiveSpan
ReadOnlySpan< byte > ActiveReadOnlySpan
void Commit(int byteCount)
void Discard(int byteCount)
void EnsureAvailableSpace(int byteCount)
readonly System.Net.SecurityStatusPalErrorCode ErrorCode
void CopyTo(Span< T > destination)
ReadOnlySpan< T > Slice(int start)
void CopyTo(Span< T > destination)
Definition Span.cs:224
ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
Definition ValueTask.cs:312
static ValueTask FromException(Exception exception)
Definition ValueTask.cs:190