Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
X509Chain.cs
Go to the documentation of this file.
4
6
7public class X509Chain : IDisposable
8{
10
12
14
15 private IChainPal _pal;
16
17 private bool _useMachineContext;
18
19 private readonly object _syncRoot = new object();
20
22 {
23 get
24 {
25 if (_chainElements == null)
26 {
28 }
29 return _chainElements;
30 }
31 }
32
34 {
35 get
36 {
37 if (_chainPolicy == null)
38 {
40 }
41 return _chainPolicy;
42 }
43 set
44 {
45 if (value == null)
46 {
47 throw new ArgumentNullException("value");
48 }
50 }
51 }
52
54 {
55 get
56 {
58 if (array == null)
59 {
60 array = (_lazyChainStatus = ((_pal == null) ? Array.Empty<X509ChainStatus>() : _pal.ChainStatus));
61 }
62 return array;
63 }
64 }
65
66 public IntPtr ChainContext => SafeHandle?.DangerousGetHandle() ?? IntPtr.Zero;
67
69 {
70 get
71 {
72 if (_pal == null)
73 {
75 }
76 return _pal.SafeHandle;
77 }
78 }
79
80 public X509Chain()
81 {
82 }
83
84 public X509Chain(bool useMachineContext)
85 {
86 _useMachineContext = useMachineContext;
87 }
88
89 [SupportedOSPlatform("windows")]
90 public X509Chain(IntPtr chainContext)
91 {
92 _pal = ChainPal.FromHandle(chainContext);
94 }
95
96 public static X509Chain Create()
97 {
98 return new X509Chain();
99 }
100
101 public bool Build(X509Certificate2 certificate)
102 {
103 return Build(certificate, throwOnException: true);
104 }
105
106 internal bool Build(X509Certificate2 certificate, bool throwOnException)
107 {
108 lock (_syncRoot)
109 {
110 if (certificate == null || certificate.Pal == null)
111 {
113 }
114 if (_chainPolicy != null && _chainPolicy.CustomTrustStore != null)
115 {
117 {
119 }
121 {
122 if (item == null || item.Handle == IntPtr.Zero)
123 {
125 }
126 }
127 }
128 Reset();
129 X509ChainPolicy chainPolicy = ChainPolicy;
130 _pal = ChainPal.BuildChain(_useMachineContext, certificate.Pal, chainPolicy._extraStore, chainPolicy._applicationPolicy, chainPolicy._certificatePolicy, chainPolicy.RevocationMode, chainPolicy.RevocationFlag, chainPolicy.CustomTrustStore, chainPolicy.TrustMode, chainPolicy.VerificationTime, chainPolicy.UrlRetrievalTimeout, chainPolicy.DisableCertificateDownloads);
131 if (_pal == null)
132 {
133 return false;
134 }
137 bool? flag = _pal.Verify(chainPolicy.VerificationFlags, out exception);
138 if (!flag.HasValue)
139 {
140 if (throwOnException)
141 {
142 throw exception;
143 }
144 flag = false;
145 }
146 return flag.Value;
147 }
148 }
149
150 public void Dispose()
151 {
152 Dispose(disposing: true);
153 GC.SuppressFinalize(this);
154 }
155
156 protected virtual void Dispose(bool disposing)
157 {
158 if (disposing)
159 {
160 Reset();
161 }
162 }
163
164 public void Reset()
165 {
166 _lazyChainStatus = null;
167 _chainElements = null;
168 _useMachineContext = false;
169 IChainPal pal = _pal;
170 _pal = null;
171 pal?.Dispose();
172 }
173}
static unsafe ChainPal BuildChain(bool useMachineContext, ICertificatePal cert, X509Certificate2Collection extraStore, OidCollection applicationPolicy, OidCollection certificatePolicy, X509RevocationMode revocationMode, X509RevocationFlag revocationFlag, X509Certificate2Collection customTrustStore, X509ChainTrustMode trustMode, DateTime verificationTime, TimeSpan timeout, bool disableAia)
Definition ChainPal.cs:94
static IChainPal FromHandle(IntPtr chainContext)
Definition ChainPal.cs:175
static void SuppressFinalize(object obj)
Definition GC.cs:202
Definition GC.cs:8
static string Cryptography_InvalidTrustCertificate
Definition SR.cs:80
static string Cryptography_CustomTrustCertsInSystemMode
Definition SR.cs:78
static string Cryptography_InvalidContextHandle
Definition SR.cs:70
Definition SR.cs:7
bool Build(X509Certificate2 certificate, bool throwOnException)
Definition X509Chain.cs:106
SafeX509ChainHandle SafeHandle
Definition IChainPal.cs:13
bool? Verify(X509VerificationFlags flags, out Exception exception)
X509ChainElement[] ChainElements
Definition IChainPal.cs:9
static readonly IntPtr Zero
Definition IntPtr.cs:18