Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CertificatePolicy"/> class.
        /// </summary>
        /// <param name="issuerName">The name of an issuer for the certificate, including values from <see cref="WellKnownIssuerNames"/>.</param>
        /// <param name="subjectAlternativeNames">The subject alternative names (SANs) of the certificate.</param>
        /// <exception cref="ArgumentException"><paramref name="issuerName"/> is empty or <paramref name="subjectAlternativeNames"/> contains empty collection properties.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="subjectAlternativeNames"/> or <paramref name="issuerName"/> is null.</exception>
        public CertificatePolicy(string issuerName, SubjectAlternativeNames subjectAlternativeNames)
        {
            Argument.AssertNotNullOrEmpty(issuerName, nameof(issuerName));
            Argument.AssertNotNull(subjectAlternativeNames, nameof(subjectAlternativeNames));
            if (subjectAlternativeNames.IsEmpty)
            {
                throw new ArgumentException("Value cannot contain empty collection properties.", nameof(subjectAlternativeNames));
            }

            SubjectAlternativeNames = subjectAlternativeNames;
            IssuerName = issuerName;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Certificates.CertificatePolicy"/> for mocking purposes.
 /// </summary>
 /// <param name="subject">Sets the <see cref="Certificates.CertificatePolicy.Subject"/> property.</param>
 /// <param name="subjectAlternativeNames">Sets the <see cref="Certificates.CertificatePolicy.SubjectAlternativeNames"/> property.</param>
 /// <param name="issuerName">Sets the <see cref="Certificates.CertificatePolicy.IssuerName"/> property.</param>
 /// <param name="createdOn">Sets the <see cref="Certificates.CertificatePolicy.CreatedOn"/> property.</param>
 /// <param name="updatedOn">Sets the <see cref="Certificates.CertificatePolicy.UpdatedOn"/> property.</param>
 /// <returns>A new instance of the <see cref="Certificates.CertificatePolicy"/> for mocking purposes.</returns>
 public static CertificatePolicy CertificatePolicy(
     string subject = default,
     SubjectAlternativeNames subjectAlternativeNames = default,
     string issuerName        = default,
     DateTimeOffset?createdOn = default,
     DateTimeOffset?updatedOn = default) => new CertificatePolicy
 {
     Subject = subject,
     SubjectAlternativeNames = subjectAlternativeNames,
     IssuerName = issuerName,
     CreatedOn  = createdOn,
     UpdatedOn  = updatedOn,
 };
        private void ReadX509CertificateProperties(JsonElement json)
        {
            foreach (JsonProperty prop in json.EnumerateObject())
            {
                switch (prop.Name)
                {
                case SubjectPropertyName:
                    Subject = prop.Value.GetString();
                    break;

                case SansPropertyName:
                    SubjectAlternativeNames = new SubjectAlternativeNames();
                    ((IJsonDeserializable)SubjectAlternativeNames).ReadProperties(prop.Value);
                    break;

                case KeyUsagePropertyName:
                    KeyUsage = new List <CertificateKeyUsage>();
                    foreach (JsonElement usageElem in prop.Value.EnumerateArray())
                    {
                        KeyUsage.Add(usageElem.GetString());
                    }
                    break;

                case EkusPropertyName:
                    EnhancedKeyUsage = new List <string>();
                    foreach (JsonElement usageElem in prop.Value.EnumerateArray())
                    {
                        EnhancedKeyUsage.Add(usageElem.GetString());
                    }
                    break;

                case ValidityMonthsPropertyName:
                    ValidityInMonths = prop.Value.GetInt32();
                    break;
                }
            }
        }