示例#1
0
        public override CAConnectorCertificate GetSingleRecord(string caRequestID)
        {
            Logger.MethodEntry(ILogExtensions.MethodLogLevel.Debug);

            CertificateStatusEnum certStatus = CertificateStatusEnum.PENDING_ISSUANCE;

            GETCertificateDetailsResponse certResponse = JsonConvert.DeserializeObject <GETCertificateDetailsResponse>(_api.GetCertificate(caRequestID));

            Enum.TryParse(certResponse.status, out certStatus);

            string issuedCert = string.Empty;

            if (certStatus == CertificateStatusEnum.ISSUED || certStatus == CertificateStatusEnum.REVOKED || certStatus == CertificateStatusEnum.EXPIRED)
            {
                issuedCert = RemovePEMHeader(JsonConvert.DeserializeObject <GETCertificateResponse>(_api.DownloadCertificate(caRequestID)).pems.certificate);
            }


            Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);

            return(new CAConnectorCertificate()
            {
                CARequestID = caRequestID,
                Certificate = issuedCert,
                CSR = certResponse.csr,
                ResolutionDate = certResponse.createdAt,
                RevocationDate = certResponse.revokedAt,
                RevocationReason = null,
                Status = APIProcessor.MapReturnStatus(certStatus),
                SubmissionDate = certResponse.createdAt
            });
        }
示例#2
0
        public override void Synchronize(ICertificateDataReader certificateDataReader, BlockingCollection <CAConnectorCertificate> blockingBuffer, CertificateAuthoritySyncInfo certificateAuthoritySyncInfo, CancellationToken cancelToken)
        {
            Logger.MethodEntry(ILogExtensions.MethodLogLevel.Debug);

            string customerId = JsonConvert.DeserializeObject <GETShopperResponse>(_api.GetCustomerId()).customerId;

            int  pageNumber  = 1;
            bool wasLastPage = false;

            do
            {
                GETCertificatesDetailsResponse certificates = JsonConvert.DeserializeObject <GETCertificatesDetailsResponse>(_api.GetCertificates(customerId, pageNumber, _syncPageSize));

                foreach (CertificateDetails certificate in certificates.certificates)
                {
                    Thread.Sleep(1000);
                    try
                    {
                        string issuedCert = RemovePEMHeader(JsonConvert.DeserializeObject <GETCertificateResponse>(_api.DownloadCertificate(certificate.certificateId)).pems.certificate);
                        CertificateStatusEnum certStatus = CertificateStatusEnum.ISSUED;
                        if (!Enum.TryParse(certificate.status, out certStatus))
                        {
                            certStatus = CertificateStatusEnum.CANCELED;
                        }

                        blockingBuffer.Add(new CAConnectorCertificate
                        {
                            CARequestID      = certificate.certificateId,
                            Certificate      = issuedCert,
                            CSR              = string.Empty,
                            ResolutionDate   = certificate.completedAt,
                            RevocationDate   = certificate.revokedAt,
                            RevocationReason = null,
                            Status           = APIProcessor.MapReturnStatus(certStatus),
                            SubmissionDate   = certificate.createdAt,
                            ProductID        = certificate.type
                        });
                    }
                    catch (GoDaddyException) { }
                }

                wasLastPage = certificates.pagination.previous == certificates.pagination.last;
                pageNumber++;
            } while (!wasLastPage);

            blockingBuffer.CompleteAdding();

            Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
        }
示例#3
0
        public override EnrollmentResult Enroll(ICertificateDataReader certificateDataReader, string csr, string subject, Dictionary <string, string[]> san, EnrollmentProductInfo productInfo, CSS.PKI.PKIConstants.X509.RequestFormat requestFormat, RequestUtilities.EnrollmentType enrollmentType)
        {
            Logger.MethodEntry(ILogExtensions.MethodLogLevel.Debug);

            foreach (KeyValuePair <string, string> configEntry in productInfo.ProductParameters)
            {
                Logger.Trace($"{configEntry.Key}: {configEntry.Value}");
            }

            string[][] parameterKeys = new string[][] { };
            if (enrollmentType == RequestUtilities.EnrollmentType.New)
            {
                parameterKeys = new string[][] { new string[] { "Email", "string" },
                                                 new string[] { "FirstName", "string" },
                                                 new string[] { "LastName", "string" },
                                                 new string[] { "Phone", "string" },
                                                 new string[] { "CertificatePeriodInYears", "int" } }
            }
            ;
            else
            {
                parameterKeys = new string[][] { new string[] { "PriorCertSN", "string" } }
            };

            ValidateParameters <string>(productInfo.ProductParameters, parameterKeys);

            POSTCertificateEnrollmentResponse enrollmentResponse = new POSTCertificateEnrollmentResponse();

            try
            {
                switch (enrollmentType)
                {
                case RequestUtilities.EnrollmentType.New:
                    switch (productInfo.ProductID)
                    {
                    case "DV_SSL":
                    case "DV_WILDCARD_SSL":
                    case "UCC_DV_SSL":
                        enrollmentResponse = EnrollDV(productInfo, csr, san);
                        break;

                    case "OV_SSL":
                    case "OV_CS":
                    case "OV_DS":
                    case "OV_WILDCARD_SSL":
                    case "UCC_OV_SSL":
                        enrollmentResponse = EnrollOV(productInfo, csr, san);
                        break;

                    case "EV_SSL":
                    case "UCC_EV_SSL":
                        enrollmentResponse = EnrollEV(productInfo, csr, san);
                        break;

                    default:
                        return(new EnrollmentResult {
                            Status = 30, StatusMessage = $"Error attempting to enroll certificate {subject}: Invalid Product ID - {productInfo.ProductID}."
                        });
                    }

                    break;

                case RequestUtilities.EnrollmentType.Renew:
                case RequestUtilities.EnrollmentType.Reissue:
                    CAConnectorCertificate certificate = certificateDataReader.GetCertificateRecord(DataConversion.HexToBytes(productInfo.ProductParameters["PriorCertSN"]));
                    enrollmentResponse = RenewReissue(certificate.CARequestID, productInfo, csr, san, enrollmentType == RequestUtilities.EnrollmentType.Renew);
                    break;

                default:
                    return(new EnrollmentResult {
                        Status = 30, StatusMessage = $"Unsupported EnrollmentType: {enrollmentType}"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new EnrollmentResult {
                    Status = 30, StatusMessage = $"Error attempting to enroll certificate {subject}: {ex.Message}."
                });
            }

            EnrollmentResult result = new EnrollmentResult();

            CertificateStatusEnum certStatus = CertificateStatusEnum.PENDING_ISSUANCE;

            for (int i = 0; i < _enrollmentRetries; i++)
            {
                try
                {
                    GETCertificateDetailsResponse certResponse = JsonConvert.DeserializeObject <GETCertificateDetailsResponse>(_api.GetCertificate(enrollmentResponse.certificateId));
                    Enum.TryParse(certResponse.status, out certStatus);
                    if (certStatus == CertificateStatusEnum.ISSUED)
                    {
                        break;
                    }
                }
                catch (Exception) { }

                Thread.Sleep(_secondsBetweenEnrollmentRetries * 1000);
            }

            string pemCertificate = certStatus == CertificateStatusEnum.ISSUED ? RemovePEMHeader(JsonConvert.DeserializeObject <GETCertificateResponse>(_api.DownloadCertificate(enrollmentResponse.certificateId)).pems.certificate) : string.Empty;

            Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);

            return(new EnrollmentResult {
                CARequestID = enrollmentResponse.certificateId,
                Certificate = pemCertificate,
                Status = APIProcessor.MapReturnStatus(certStatus),
                StatusMessage = $"GoDaddy Status = {certStatus.ToString()}"
            });
        }