Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ VerifyRemoteCertificate()

bool System.Net.Security.SecureChannel.VerifyRemoteCertificate ( RemoteCertificateValidationCallback remoteCertValidationCallback,
SslCertificateTrust trust,
ref ProtocolToken alertToken,
out SslPolicyErrors sslPolicyErrors,
out X509ChainStatusFlags chainStatus )
inlinepackage

Definition at line 650 of file SecureChannel.cs.

651 {
654 bool flag = false;
655 X509Chain x509Chain = null;
657 try
658 {
659 X509Certificate2 remoteCertificate = CertificateValidationPal.GetRemoteCertificate(_securityContext, out remoteCertificateCollection);
660 if (_remoteCertificate != null && remoteCertificate != null && remoteCertificate.RawData.AsSpan().SequenceEqual(_remoteCertificate.RawData))
661 {
662 return true;
663 }
665 if (_remoteCertificate == null)
666 {
668 {
669 System.Net.NetEventSource.Error(this, $"Remote certificate required, but no remote certificate received", "VerifyRemoteCertificate");
670 }
671 sslPolicyErrors |= SslPolicyErrors.RemoteCertificateNotAvailable;
672 }
673 else
674 {
675 x509Chain = new X509Chain();
676 x509Chain.ChainPolicy.RevocationMode = _sslAuthenticationOptions.CertificateRevocationCheckMode;
677 x509Chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
679 if (remoteCertificateCollection != null)
680 {
681 x509Chain.ChainPolicy.ExtraStore.AddRange(remoteCertificateCollection);
682 }
683 if (trust != null)
684 {
685 x509Chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
686 if (trust._store != null)
687 {
688 x509Chain.ChainPolicy.CustomTrustStore.AddRange(trust._store.Certificates);
689 }
690 if (trust._trustList != null)
691 {
692 x509Chain.ChainPolicy.CustomTrustStore.AddRange(trust._trustList);
693 }
694 }
696 }
698 {
699 object ssl = _ssl;
700 if (ssl == null)
701 {
702 throw new ObjectDisposedException("SslStream");
703 }
705 }
706 else
707 {
709 {
710 sslPolicyErrors &= ~SslPolicyErrors.RemoteCertificateNotAvailable;
711 }
712 flag = sslPolicyErrors == SslPolicyErrors.None;
713 }
714 if (System.Net.NetEventSource.Log.IsEnabled())
715 {
717 System.Net.NetEventSource.Info(this, $"Cert validation, remote cert = {_remoteCertificate}", "VerifyRemoteCertificate");
718 }
719 if (!flag)
720 {
722 if (x509Chain != null)
723 {
724 X509ChainStatus[] chainStatus2 = x509Chain.ChainStatus;
726 {
728 }
729 }
730 }
731 }
732 finally
733 {
734 if (x509Chain != null)
735 {
736 int count = x509Chain.ChainElements.Count;
737 for (int j = 0; j < count; j++)
738 {
739 x509Chain.ChainElements[j].Certificate.Dispose();
740 }
741 x509Chain.Dispose();
742 }
743 if (remoteCertificateCollection != null)
744 {
746 for (int k = 0; k < count2; k++)
747 {
749 }
750 }
751 }
752 return flag;
753 }
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
void Add(TKey key, TValue value)
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)
void LogCertificateValidation(RemoteCertificateValidationCallback remoteCertValidationCallback, SslPolicyErrors sslPolicyErrors, bool success, X509Chain chain)
static readonly Oid s_clientAuthOid
SafeDeleteSslContext _securityContext
ProtocolToken CreateFatalHandshakeAlertToken(SslPolicyErrors sslPolicyErrors, X509Chain chain)
readonly SslAuthenticationOptions _sslAuthenticationOptions
static readonly Oid s_serverAuthOid

References System.Net.Security.SecureChannel._remoteCertificate, System.Net.Security.SecureChannel._securityContext, System.Net.Security.SecureChannel._ssl, System.Net.Security.SecureChannel._sslAuthenticationOptions, System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Collections.Generic.Dictionary< TKey, TValue >.AddRange(), System.Net.Security.SslAuthenticationOptions.CertificateRevocationCheckMode, System.Net.Security.SslAuthenticationOptions.CheckCertName, System.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Net.Security.SecureChannel.CreateFatalHandshakeAlertToken(), System.Net.NetEventSource.Error(), System.Net.CertificateValidationPal.GetRemoteCertificate(), System.Net.NetEventSource.Info(), System.Net.Security.SslAuthenticationOptions.IsServer, System.Net.NetEventSource.Log, System.Net.Security.SecureChannel.LogCertificateValidation(), System.Security.Cryptography.X509Certificates.X509Certificate2.RawData, System.Net.Security.SecureChannel.RemoteCertRequired, System.Net.Security.SecureChannel.s_clientAuthOid, System.Net.Security.SecureChannel.s_serverAuthOid, System.Net.Security.SslAuthenticationOptions.TargetHost, and System.Net.CertificateValidationPal.VerifyCertificateProperties().

Referenced by System.Net.Security.SslStream.CompleteHandshake().