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

◆ SslStreamCertificateContext()

System.Net.Security.SslStreamCertificateContext.SslStreamCertificateContext ( X509Certificate2 target,
X509Certificate2[] intermediates,
SslCertificateTrust trust )
inlineprivate

Definition at line 69 of file SslStreamCertificateContext.cs.

70 {
71 if (intermediates.Length != 0)
72 {
73 using X509Chain x509Chain = new X509Chain();
74 x509Chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
75 x509Chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
76 x509Chain.ChainPolicy.DisableCertificateDownloads = true;
77 bool flag = x509Chain.Build(target);
78 int num = 0;
79 X509ChainStatus[] chainStatus = x509Chain.ChainStatus;
80 for (int i = 0; i < chainStatus.Length; i++)
81 {
82 X509ChainStatus x509ChainStatus = chainStatus[i];
83 if (x509ChainStatus.Status.HasFlag(X509ChainStatusFlags.PartialChain) || x509ChainStatus.Status.HasFlag(X509ChainStatusFlags.NotSignatureValid))
84 {
85 flag = false;
86 break;
87 }
88 num++;
89 }
90 if (!flag)
91 {
92 X509Store x509Store = new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);
93 try
94 {
95 x509Store.Open(OpenFlags.ReadWrite);
96 }
97 catch
98 {
99 x509Store.Dispose();
100 x509Store = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser);
101 try
102 {
103 x509Store.Open(OpenFlags.ReadWrite);
104 }
105 catch
106 {
107 x509Store.Dispose();
108 x509Store = null;
109 if (System.Net.NetEventSource.Log.IsEnabled())
110 {
111 System.Net.NetEventSource.Error(this, $"Failed to open certificate store for intermediates.", ".ctor");
112 }
113 }
114 }
115 if (x509Store != null)
116 {
117 using (x509Store)
118 {
119 for (int j = num; j < intermediates.Length - 1; j++)
120 {
121 x509Store.Add(intermediates[j]);
122 }
123 flag = x509Chain.Build(target);
124 X509ChainStatus[] chainStatus2 = x509Chain.ChainStatus;
125 for (int k = 0; k < chainStatus2.Length; k++)
126 {
127 X509ChainStatus x509ChainStatus2 = chainStatus2[k];
128 if (x509ChainStatus2.Status.HasFlag(X509ChainStatusFlags.PartialChain) || x509ChainStatus2.Status.HasFlag(X509ChainStatusFlags.NotSignatureValid))
129 {
130 flag = false;
131 break;
132 }
133 }
134 if (!flag)
135 {
136 x509Store.Add(intermediates[^1]);
137 }
138 }
139 }
140 }
141 }
142 Certificate = target;
143 IntermediateCertificates = intermediates;
144 Trust = trust;
145 }
static readonly System.Net.NetEventSource Log
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)

References System.Security.Cryptography.X509Certificates.X509Store.Add(), System.Net.Security.SslStreamCertificateContext.Certificate, System.Security.Cryptography.X509Certificates.X509Store.Dispose(), System.Net.NetEventSource.Error(), System.Net.Security.SslStreamCertificateContext.IntermediateCertificates, System.Net.NetEventSource.Log, System.Security.Cryptography.X509Certificates.X509Store.Open(), System.Security.Cryptography.X509Certificates.X509ChainStatus.Status, and System.Net.Security.SslStreamCertificateContext.Trust.

Referenced by System.Net.Security.SslStreamCertificateContext.Create(), and System.Net.Security.SslStreamCertificateContext.Create().