| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Security.Cryptography.X509Certificates; |
| | | 5 | | |
| | | 6 | | namespace System.Net.Security |
| | | 7 | | { |
| | | 8 | | public sealed class SslCertificateTrust |
| | | 9 | | { |
| | | 10 | | internal X509Store? _store; |
| | | 11 | | internal X509Certificate2Collection? _trustList; |
| | | 12 | | internal bool _sendTrustInHandshake; |
| | | 13 | | |
| | | 14 | | public static SslCertificateTrust CreateForX509Store(X509Store store, bool sendTrustInHandshake = false) |
| | 0 | 15 | | { |
| | | 16 | | |
| | | 17 | | #if TARGET_WINDOWS |
| | 0 | 18 | | if (sendTrustInHandshake && store.Location != StoreLocation.LocalMachine) |
| | 0 | 19 | | { |
| | 0 | 20 | | throw new PlatformNotSupportedException(SR.net_ssl_trust_store); |
| | | 21 | | } |
| | | 22 | | #endif |
| | 0 | 23 | | if (sendTrustInHandshake && !System.OperatingSystem.IsLinux() && !System.OperatingSystem.IsMacOS() && |
| | 0 | 24 | | !System.OperatingSystem.IsWindows()) |
| | 0 | 25 | | { |
| | 0 | 26 | | throw new PlatformNotSupportedException(SR.net_ssl_trust_handshake); |
| | | 27 | | } |
| | 0 | 28 | | if (!store.IsOpen) |
| | 0 | 29 | | { |
| | 0 | 30 | | store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); |
| | 0 | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | var trust = new SslCertificateTrust(); |
| | 0 | 34 | | trust._store = store; |
| | 0 | 35 | | trust._sendTrustInHandshake = sendTrustInHandshake; |
| | 0 | 36 | | return trust; |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | public static SslCertificateTrust CreateForX509Collection(X509Certificate2Collection trustList, bool sendTrustIn |
| | 0 | 40 | | { |
| | | 41 | | |
| | | 42 | | #if TARGET_WINDOWS |
| | 0 | 43 | | if (sendTrustInHandshake) |
| | 0 | 44 | | { |
| | 0 | 45 | | throw new PlatformNotSupportedException(SR.net_ssl_trust_collection); |
| | | 46 | | } |
| | | 47 | | #else |
| | | 48 | | if (sendTrustInHandshake && !System.OperatingSystem.IsLinux() && !System.OperatingSystem.IsMacOS()) |
| | | 49 | | { |
| | | 50 | | throw new PlatformNotSupportedException(SR.net_ssl_trust_handshake); |
| | | 51 | | } |
| | | 52 | | #endif |
| | | 53 | | |
| | 0 | 54 | | var trust = new SslCertificateTrust(); |
| | 0 | 55 | | trust._trustList = trustList; |
| | 0 | 56 | | trust._sendTrustInHandshake = sendTrustInHandshake; |
| | 0 | 57 | | return trust; |
| | 0 | 58 | | } |
| | | 59 | | |
| | 0 | 60 | | private SslCertificateTrust() { } |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | |