Welcome to mirror list, hosted at ThFree Co, Russian Federation.

X509FilesystemTests.Unix.cs « tests « System.Security.Cryptography.X509Certificates « src - github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e27cfa9ac5d36190b490adace8ad3acebce0a45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.IO;
using System.Linq;
using System.Text;
using Xunit;

namespace System.Security.Cryptography.X509Certificates.Tests
{
    /// <summary>
    /// Tests that apply to the filesystem/cache portions of the X509 infrastructure on Unix implementations.
    /// </summary>
    [Collection("X509Filesystem")]
    public static class X509FilesystemTests
    {
        // #9293: Our Fedora23 CI machines use NTFS for "tmphome", which causes our filesystem permissions checks to fail.
        private static bool IsReliableInCI { get; } = !PlatformDetection.IsFedora23;

        [Fact]
        [OuterLoop]
        public static void VerifyCrlCache()
        {
            string crlDirectory = PersistedFiles.GetUserFeatureDirectory("cryptography", "crls");
            string crlFile = Path.Combine(crlDirectory,MicrosoftDotComRootCrlFilename);

            Directory.CreateDirectory(crlDirectory);
            File.Delete(crlFile);

            using (var microsoftDotComIssuer = new X509Certificate2(TestData.MicrosoftDotComIssuerBytes))
            using (var microsoftDotComRoot = new X509Certificate2(TestData.MicrosoftDotComRootBytes))
            using (var unrelated = new X509Certificate2(TestData.DssCer))
            using (var chainHolder = new ChainHolder())
            {
                X509Chain chain = chainHolder.Chain;

                chain.ChainPolicy.ExtraStore.Add(unrelated);
                chain.ChainPolicy.ExtraStore.Add(microsoftDotComRoot);
                
                // The very start of the CRL period.
                chain.ChainPolicy.VerificationTime = new DateTime(2015, 6, 17, 0, 0, 0, DateTimeKind.Utc);
                chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
                chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EndCertificateOnly;
                chain.ChainPolicy.VerificationFlags |= X509VerificationFlags.AllowUnknownCertificateAuthority;

                bool valid = chain.Build(microsoftDotComIssuer);
                Assert.True(valid, "Precondition: Chain builds with no revocation checks");

                int initialErrorCount = chain.ChainStatus.Length;
                Assert.InRange(initialErrorCount, 0, 1);

                if (initialErrorCount > 0)
                {
                    Assert.Equal(X509ChainStatusFlags.UntrustedRoot, chain.ChainStatus[0].Status);
                }

                chainHolder.DisposeChainElements();

                chain.ChainPolicy.RevocationMode = X509RevocationMode.Offline;

                valid = chain.Build(microsoftDotComIssuer);
                Assert.False(valid, "Chain should not build validly");

                Assert.Equal(initialErrorCount + 1, chain.ChainStatus.Length);
                Assert.Equal(X509ChainStatusFlags.RevocationStatusUnknown, chain.ChainStatus[0].Status);

                File.WriteAllText(crlFile, MicrosoftDotComRootCrlPem, Encoding.ASCII);

                chainHolder.DisposeChainElements();

                valid = chain.Build(microsoftDotComIssuer);
                Assert.True(valid, "Chain should build validly now");
                Assert.Equal(initialErrorCount, chain.ChainStatus.Length);
            }
        }

        [Fact]
        public static void X509Store_OpenExisting_Fails()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    // Since the directory was explicitly deleted already, this should fail.
                    Assert.Throws<CryptographicException>(
                        () => store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly));
                });
        }

        [Fact]
        private static void X509Store_AddReadOnly()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var cert = new X509Certificate2(TestData.MsCertificate))
                    {
                        store.Open(OpenFlags.ReadOnly);

                        // Adding a certificate when the store is ReadOnly should fail:
                        Assert.Throws<CryptographicException>(() => store.Add(cert));

                        // Since we haven't done anything yet, we shouldn't have polluted the hard drive.
                        Assert.False(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                    }
                });
        }

        [Fact]
        private static void X509Store_AddClosed()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var cert = new X509Certificate2(TestData.MsCertificate))
                    {
                        // Adding a certificate when the store is closed should fail:
                        Assert.Throws<CryptographicException>(() => store.Add(cert));

                        // Since we haven't done anything yet, we shouldn't have polluted the hard drive.
                        Assert.False(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddOne()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var cert = new X509Certificate2(TestData.MsCertificate))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(cert);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(1, Directory.GetFiles(storeDirectory).Length);

                        X509Certificate2Collection storeCerts = store.Certificates;

                        Assert.Equal(1, storeCerts.Count);

                        using (X509Certificate2 storeCert = storeCerts[0])
                        {
                            Assert.Equal(cert, storeCert);
                            Assert.NotSame(cert, storeCert);
                        }
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddOneAfterUpgrade()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var cert = new X509Certificate2(TestData.MsCertificate))
                    {
                        store.Open(OpenFlags.ReadOnly);

                        // Adding a certificate when the store is ReadOnly should fail:
                        Assert.Throws<CryptographicException>(() => store.Add(cert));

                        // Since we haven't done anything yet, we shouldn't have polluted the hard drive.
                        Assert.False(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");

                        // Calling Open on an open store changes the access rights:
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(cert);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(1, Directory.GetFiles(storeDirectory).Length);

                        X509Certificate2Collection storeCerts = store.Certificates;

                        Assert.Equal(1, storeCerts.Count);

                        using (X509Certificate2 storeCert = storeCerts[0])
                        {
                            Assert.Equal(cert, storeCert);
                            Assert.NotSame(cert, storeCert);
                        }
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_DowngradePermissions()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certA = new X509Certificate2(TestData.MsCertificate))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    {
                        store.Open(OpenFlags.ReadWrite);
                        
                        // Ensure that ReadWrite took effect.
                        store.Add(certA);

                        store.Open(OpenFlags.ReadOnly);

                        // Adding a certificate when the store is ReadOnly should fail:
                        Assert.Throws<CryptographicException>(() => store.Add(certB));
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddAfterDispose()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certA = new X509Certificate2(TestData.MsCertificate))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(certA);

                        // Dispose returns the store to the pre-opened state.
                        store.Dispose();

                        // Adding a certificate when the store is closed should fail:
                        Assert.Throws<CryptographicException>(() => store.Add(certB));
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddAndClear()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var cert = new X509Certificate2(TestData.MsCertificate))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(cert);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(1, Directory.GetFiles(storeDirectory).Length);

                        store.Remove(cert);

                        // The directory should still exist.
                        Assert.True(Directory.Exists(storeDirectory), "Store Directory Still Exists");
                        Assert.Equal(0, Directory.GetFiles(storeDirectory).Length);
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddDuplicate()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var cert = new X509Certificate2(TestData.MsCertificate))
                    using (var certClone = new X509Certificate2(cert.RawData))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(cert);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(1, Directory.GetFiles(storeDirectory).Length);

                        store.Add(certClone);
                        Assert.Equal(1, Directory.GetFiles(storeDirectory).Length);
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddTwo()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certA = new X509Certificate2(TestData.MsCertificate))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(certA);
                        store.Add(certB);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(2, Directory.GetFiles(storeDirectory).Length);

                        X509Certificate2Collection storeCerts = store.Certificates;
                        Assert.Equal(2, storeCerts.Count);

                        X509Certificate2[] expectedCerts = { certA, certB };

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            Assert.Contains(storeCert, expectedCerts);
                            storeCert.Dispose();
                        }
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddTwo_UpgradePrivateKey()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certAPrivate = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
                    using (var certAPublic = new X509Certificate2(certAPrivate.RawData))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(certAPublic);
                        store.Add(certB);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");

                        string[] storeFiles = Directory.GetFiles(storeDirectory);
                        Assert.Equal(2, storeFiles.Length);

                        X509Certificate2Collection storeCerts = store.Certificates;
                        Assert.Equal(2, storeCerts.Count);

                        X509Certificate2[] expectedCerts = { certAPublic, certB };

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            Assert.False(storeCert.HasPrivateKey, "storeCert.HasPrivateKey (before)");
                            storeCert.Dispose();
                        }

                        store.Add(certAPrivate);
                        // It replaces the existing file, the names should be unaffected.
                        Assert.Equal(storeFiles, Directory.GetFiles(storeDirectory));

                        storeCerts = store.Certificates;
                        Assert.Equal(2, storeCerts.Count);

                        bool foundCertA = false;

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            // The public instance and private instance are .Equal
                            if (storeCert.Equals(certAPublic))
                            {
                                Assert.True(storeCert.HasPrivateKey, "storeCert.HasPrivateKey (affected cert)");
                                foundCertA = true;
                            }
                            else
                            {
                                Assert.False(storeCert.HasPrivateKey, "storeCert.HasPrivateKey (other cert)");
                            }

                            Assert.Contains(storeCert, expectedCerts);
                            storeCert.Dispose();
                        }

                        Assert.True(foundCertA, "foundCertA");
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_AddTwo_UpgradePrivateKey_NoDowngrade()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certAPrivate = new X509Certificate2(TestData.PfxData, TestData.PfxDataPassword))
                    using (var certAPublic = new X509Certificate2(certAPrivate.RawData))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(certAPublic);
                        store.Add(certB);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");

                        X509Certificate2Collection storeCerts = store.Certificates;
                        Assert.Equal(2, storeCerts.Count);

                        X509Certificate2[] expectedCerts = { certAPublic, certB };

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            Assert.False(storeCert.HasPrivateKey, "storeCert.HasPrivateKey (before)");
                            Assert.Contains(storeCert, expectedCerts);
                            storeCert.Dispose();
                        }

                        // Add the private (checked in X509Store_AddTwo_UpgradePrivateKey)
                        store.Add(certAPrivate);
                        // Then add the public again, which shouldn't do anything.
                        store.Add(certAPublic);

                        storeCerts = store.Certificates;
                        Assert.Equal(2, storeCerts.Count);

                        bool foundCertA = false;

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            if (storeCert.Equals(certAPublic))
                            {
                                Assert.True(storeCert.HasPrivateKey, "storeCert.HasPrivateKey (affected cert)");
                                foundCertA = true;
                            }
                            else
                            {
                                Assert.False(storeCert.HasPrivateKey, "storeCert.HasPrivateKey (other cert)");
                            }

                            Assert.Contains(storeCert, expectedCerts);
                            storeCert.Dispose();
                        }
                        
                        Assert.True(foundCertA, "foundCertA");
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_DistinctCollections()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certA = new X509Certificate2(TestData.MsCertificate))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(certA);
                        store.Add(certB);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(2, Directory.GetFiles(storeDirectory).Length);

                        X509Certificate2Collection storeCertsA = store.Certificates;
                        X509Certificate2Collection storeCertsB = store.Certificates;

                        Assert.NotSame(storeCertsA, storeCertsB);
                        Assert.Equal(storeCertsA.Count, storeCertsB.Count);

                        foreach (X509Certificate2 collACert in storeCertsA)
                        {
                            int bIndex = storeCertsB.IndexOf(collACert);
                            Assert.InRange(bIndex, 0, storeCertsB.Count);

                            X509Certificate2 collBCert = storeCertsB[bIndex];
                            // Equal is implied by IndexOf working.
                            Assert.NotSame(collACert, collBCert);

                            storeCertsB.RemoveAt(bIndex);

                            collACert.Dispose();
                            collBCert.Dispose();
                        }
                    }
                });
        }

        [ConditionalFact(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        private static void X509Store_Add4_Remove1()
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certA = new X509Certificate2(TestData.MsCertificate))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    using (var certBClone = new X509Certificate2(certB.RawData))
                    using (var certC = new X509Certificate2(TestData.ECDsa256Certificate))
                    using (var certD = new X509Certificate2(TestData.MicrosoftDotComRootBytes))
                    {
                        store.Open(OpenFlags.ReadWrite);
                        
                        store.Add(certA);
                        store.Add(certB);
                        store.Add(certC);
                        store.Add(certD);

                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");
                        Assert.Equal(4, Directory.GetFiles(storeDirectory).Length);

                        X509Certificate2[] expectedCerts = { certA, certB, certC, certD };
                        X509Certificate2Collection storeCerts = store.Certificates;
                        Assert.Equal(4, storeCerts.Count);

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            Assert.Contains(storeCert, expectedCerts);
                            storeCert.Dispose();
                        }

                        store.Remove(certBClone);
                        Assert.Equal(3, Directory.GetFiles(storeDirectory).Length);

                        expectedCerts = new[] { certA, certC, certD };
                        storeCerts = store.Certificates;
                        Assert.Equal(3, storeCerts.Count);

                        foreach (X509Certificate2 storeCert in storeCerts)
                        {
                            Assert.Contains(storeCert, expectedCerts);
                            storeCert.Dispose();
                        }
                    }
                });
        }

        [ConditionalTheory(nameof(IsReliableInCI))]
        [OuterLoop(/* Alters user/machine state */)]
        [InlineData(false)]
        [InlineData(true)]
        private static void X509Store_MultipleObjects(bool matchCase)
        {
            RunX509StoreTest(
                (store, storeDirectory) =>
                {
                    using (var certA = new X509Certificate2(TestData.MsCertificate))
                    using (var certB = new X509Certificate2(TestData.DssCer))
                    using (var certC = new X509Certificate2(TestData.ECDsa256Certificate))
                    using (var certD = new X509Certificate2(TestData.MicrosoftDotComRootBytes))
                    {
                        store.Open(OpenFlags.ReadWrite);

                        store.Add(certA);
                        store.Add(certB);
                        Assert.True(Directory.Exists(storeDirectory), "Directory.Exists(storeDirectory)");

                        string newName = store.Name;

                        if (!matchCase)
                        {
                            newName = newName.ToUpperInvariant();
                            Assert.NotEqual(store.Name, newName);
                        }

                        using (X509Store storeClone = new X509Store(newName, store.Location))
                        {
                            storeClone.Open(OpenFlags.ReadWrite);
                            AssertEqualContents(store, storeClone);

                            store.Add(certC);

                            // The object was added to store, but should show up in both objects
                            // after re-reading the Certificates property
                            AssertEqualContents(store, storeClone);

                            // Now add one to storeClone to prove bidirectionality.
                            storeClone.Add(certD);
                            AssertEqualContents(store, storeClone);
                        }
                    }
                });
        }

        private static void AssertEqualContents(X509Store storeA, X509Store storeB)
        {
            Assert.NotSame(storeA, storeB);

            using (var storeATracker = new ImportedCollection(storeA.Certificates))
            using (var storeBTracker = new ImportedCollection(storeB.Certificates))
            {
                X509Certificate2Collection storeACerts = storeATracker.Collection;
                X509Certificate2Collection storeBCerts = storeBTracker.Collection;

                Assert.Equal(storeACerts.OfType<X509Certificate2>(), storeBCerts.OfType<X509Certificate2>());
            }
        }

        private static void RunX509StoreTest(Action<X509Store, string> testAction)
        {
            string certStoresFeaturePath = PersistedFiles.GetUserFeatureDirectory("cryptography", "x509stores");
            string storeName = "TestStore" + Guid.NewGuid().ToString("N");
            string storeDirectory = Path.Combine(certStoresFeaturePath, storeName.ToLowerInvariant());

            if (Directory.Exists(storeDirectory))
            {
                Directory.Delete(storeDirectory, true);
            }

            try
            {
                using (X509Store store = new X509Store(storeName, StoreLocation.CurrentUser))
                {
                    testAction(store, storeDirectory);
                }
            }
            finally
            {
                try
                {
                    if (Directory.Exists(storeDirectory))
                    {
                        Directory.Delete(storeDirectory, true);
                    }
                }
                catch
                {
                    // Don't allow any (additional?) I/O errors to propagate.
                }
            }
        }

        // `openssl crl -in [MicrosoftDotComRootCrlPem] -noout -hash`.crl
        private const string MicrosoftDotComRootCrlFilename = "b204d74a.crl";

        // This CRL was downloaded 2015-08-31 20:31 PDT
        // It is valid from Jun 17 00:00:00 2015 GMT to Sep 30 23:59:59 2015 GMT
        private const string MicrosoftDotComRootCrlPem =
            @"-----BEGIN X509 CRL-----
MIICETCB+jANBgkqhkiG9w0BAQUFADCByjELMAkGA1UEBhMCVVMxFzAVBgNVBAoT
DlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3b3Jr
MTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3Jp
emVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQ
cmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0gRzUXDTE1MDYxNzAwMDAw
MFoXDTE1MDkzMDIzNTk1OVowDQYJKoZIhvcNAQEFBQADggEBAFxqobObEqKNSAe+
A9cHCYI7sw+Vc8HuE7E+VZc6ni3a2UHiprYuXDsvD18+cyv/nFSLpLqLmExZrsf/
dzH8GH2HgBTt5aO/nX08EBrDgcjHo9b0VI6ZuOOaEeS0NsRh28Jupfn1Xwcsbdw9
nVh1OaExpHwxgg7pJr4pXzaAjbl3b4QfCPyTd5aaOQOEmqvJtRrMwCna4qQ3p4r6
QYe19/pXqK9my7lSmH1vZ0CmNvQeNPmnx+YmFXYTBgap+Xi2cs6GX/qI04CDzjWi
sm6L0+S1Zx2wMhiYOi0JvrRizf+rIyKkDbPMoYEyXZqcCwSnv6mJQY81vmKRKU5N
WKo2mLw=
-----END X509 CRL-----";
    }
}