|
| 1 | +using Keyfactor.Extensions.CAPlugin.DigiCert.Models; |
| 2 | +using Microsoft.VisualBasic; |
| 3 | +using Newtonsoft.Json; |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.ComponentModel; |
| 8 | +using System.Linq; |
| 9 | +using System.Security.Cryptography.X509Certificates; |
| 10 | +using System.Text; |
| 11 | +using System.Threading.Tasks; |
| 12 | + |
| 13 | +namespace Keyfactor.Extensions.CAPlugin.DigiCert.API |
| 14 | +{ |
| 15 | + public class OrderSmimeRequest : CertCentralBaseRequest |
| 16 | + { |
| 17 | + public OrderSmimeRequest(CertCentralCertType certType) |
| 18 | + { |
| 19 | + Resource = "services/v2/order/certificate/" + certType.ProductCode; |
| 20 | + Method = "POST"; |
| 21 | + CertType = certType; |
| 22 | + Certificate = new SmimeCertificateRequest(); |
| 23 | + Certificate.Individual = new SmimeIndividual(); |
| 24 | + Certificate.UsageDesignation = new SmimeUsage(); |
| 25 | + Subject = new SmimeSubject(); |
| 26 | + CustomExpirationDate = null; |
| 27 | + } |
| 28 | + |
| 29 | + [JsonIgnore] |
| 30 | + public CertCentralCertType CertType { get; set; } |
| 31 | + |
| 32 | + [JsonProperty("certificate")] |
| 33 | + public SmimeCertificateRequest Certificate { get; set; } |
| 34 | + |
| 35 | + [JsonProperty("organization")] |
| 36 | + private IdInformation Organization { get; set; } // Set via SetOrganization method |
| 37 | + |
| 38 | + [JsonProperty("validity_years")] |
| 39 | + public int ValidityYears { get; set; } |
| 40 | + |
| 41 | + [JsonProperty("custom_expiration_date")] //YYYY-MM-DD |
| 42 | + public DateTime? CustomExpirationDate { get; set; } |
| 43 | + |
| 44 | + [JsonProperty("comments")] |
| 45 | + public string Comments { get; set; } |
| 46 | + |
| 47 | + [JsonProperty("disable_renewal_notifications")] |
| 48 | + public bool DisableRenewalNotifications { get; set; } |
| 49 | + |
| 50 | + [DefaultValue(0)] |
| 51 | + [JsonProperty("renewal_of_order_id")] |
| 52 | + public int RenewalOfOrderId { get; set; } |
| 53 | + |
| 54 | + [JsonProperty("dcv_method")] |
| 55 | + public string DCVMethod { get; set; } |
| 56 | + |
| 57 | + [JsonProperty("container")] |
| 58 | + public CertificateOrderContainer Container { get; set; } |
| 59 | + |
| 60 | + [JsonProperty("custom_fields")] |
| 61 | + public List<MetadataField> CustomFields { get; set; } |
| 62 | + |
| 63 | + [JsonProperty("skip_approval")] |
| 64 | + public bool SkipApproval { get; set; } |
| 65 | + |
| 66 | + [JsonProperty("subject")] |
| 67 | + public SmimeSubject Subject { get; set; } |
| 68 | + |
| 69 | + public void SetOrganization(int? organizationId) |
| 70 | + { |
| 71 | + if (organizationId.HasValue) |
| 72 | + { |
| 73 | + Organization = new IdInformation() |
| 74 | + { |
| 75 | + Id = organizationId.Value.ToString() |
| 76 | + }; |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + Organization = null; |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public class SmimeSubject |
| 86 | + { |
| 87 | + [JsonProperty("include_pseudonym")] |
| 88 | + public bool IncludePseudonym { get; set; } |
| 89 | + |
| 90 | + [JsonProperty("include_email")] |
| 91 | + public bool IncludeEmail { get; set; } |
| 92 | + |
| 93 | + [JsonProperty("include_given_name_surname")] |
| 94 | + public bool IncludeGivenName { get; set; } |
| 95 | + |
| 96 | + } |
| 97 | + |
| 98 | + public class SmimeCertificateRequest |
| 99 | + { |
| 100 | + [JsonProperty("emails")] |
| 101 | + public List<String> Emails { get; set; } |
| 102 | + |
| 103 | + [JsonProperty("csr")] |
| 104 | + public string CSR { get; set; } |
| 105 | + |
| 106 | + [JsonProperty("signature_hash")] |
| 107 | + public string SignatureHash { get; set; } |
| 108 | + |
| 109 | + [JsonProperty("ca_cert_id")] |
| 110 | + public string CACertID { get; set; } |
| 111 | + |
| 112 | + [JsonProperty("common_name_indicator")] |
| 113 | + public string CommonNameIndicator { get; set; } |
| 114 | + |
| 115 | + [JsonProperty("individual")] |
| 116 | + public SmimeIndividual Individual { get; set; } |
| 117 | + |
| 118 | + [JsonProperty("usage_designation")] |
| 119 | + public SmimeUsage UsageDesignation { get; set; } |
| 120 | + |
| 121 | + [JsonProperty("profile_type")] |
| 122 | + public string ProfileType { get; set; } |
| 123 | + } |
| 124 | + |
| 125 | + public class SmimeIndividual |
| 126 | + { |
| 127 | + [JsonProperty("first_name")] |
| 128 | + public string FirstName { get; set; } |
| 129 | + |
| 130 | + [JsonProperty("last_name")] |
| 131 | + public string LastName { get; set; } |
| 132 | + |
| 133 | + [JsonProperty("pseudonym")] |
| 134 | + public string Pseudonym { get; set; } |
| 135 | + } |
| 136 | + |
| 137 | + public class SmimeUsage |
| 138 | + { |
| 139 | + [JsonProperty("primary_usage")] |
| 140 | + public string PrimaryUsage { get; set; } |
| 141 | + } |
| 142 | +} |
0 commit comments