| | | 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.ComponentModel; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Security |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// An enumeration that lists the ways of validating a certificate. |
| | | 10 | | /// </summary> |
| | | 11 | | public enum X509CertificateValidationMode |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// No validation of the certificate is performed. |
| | | 15 | | /// </summary> |
| | | 16 | | None, |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// The certificate is valid if it is in the trusted people store. |
| | | 20 | | /// </summary> |
| | | 21 | | PeerTrust, |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// The certificate is valid if the chain builds to a certification authority in the trusted root store. |
| | | 25 | | /// </summary> |
| | | 26 | | ChainTrust, |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// The certificate is valid if it is in the trusted people store, or if the chain builds to a certification aut |
| | | 30 | | /// </summary> |
| | | 31 | | PeerOrChainTrust, |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// The user must plug in a custom <c>X509CertificateValidator</c> to validate the certificate. |
| | | 35 | | /// </summary> |
| | | 36 | | Custom |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | internal static class X509CertificateValidationModeHelper |
| | | 40 | | { |
| | | 41 | | public static bool IsDefined(X509CertificateValidationMode validationMode) |
| | | 42 | | { |
| | 10 | 43 | | return validationMode == X509CertificateValidationMode.None |
| | 10 | 44 | | || validationMode == X509CertificateValidationMode.PeerTrust |
| | 10 | 45 | | || validationMode == X509CertificateValidationMode.ChainTrust |
| | 10 | 46 | | || validationMode == X509CertificateValidationMode.PeerOrChainTrust |
| | 10 | 47 | | || validationMode == X509CertificateValidationMode.Custom; |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | internal static void Validate(X509CertificateValidationMode value) |
| | | 51 | | { |
| | 10 | 52 | | if (!IsDefined(value)) |
| | | 53 | | { |
| | 0 | 54 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException(nameof(value) |
| | 0 | 55 | | typeof(X509CertificateValidationMode))); |
| | | 56 | | } |
| | 10 | 57 | | } |
| | | 58 | | } |
| | | 59 | | } |