Beispiel #1
0
        /// <inheritdoc/>
        public AcmeResponse GetCertificate(AcmeRequest request, string thumbprint)
        {
            return(WrapAction((response) =>
            {
                var account = GetAccount(request);
                var certs = OrderService.GetCertificate(account.Id, thumbprint);

                switch (Options.DownloadCertificateFormat)
                {
                case DownloadCertificateFormat.PemCertificateChain:
                    {
                        var pem = PemConverter.Encode(certs.Select(o => o.RawData).ToArray(), "certificate");
                        response.Content = new MediaTypeContent("application/pem-certificate-chain", pem);
                    }
                    break;

                case DownloadCertificateFormat.PkixCert:
                    {
                        var cert = new X509Certificate2(certs[0].RawData);
                        response.Content = new MediaTypeContent("application/pkix-cert", cert.RawData);
                    }
                    break;

                case DownloadCertificateFormat.Pkcs7Mime:
                    {
                        var x509Certs = certs.Select(o => new X509Certificate2(o.RawData)).ToArray();
                        var x509Collection = new X509Certificate2Collection(x509Certs);
                        response.Content = new MediaTypeContent("application/pkcs7-mime", x509Collection.Export(X509ContentType.Pkcs7));
                    }
                    break;
                }
            }, request));
        }
        public void Encode()
        {
            var rawData  = Convert.FromBase64String("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1");
            var expected = "-----BEGIN CERTIFICATE-----\n" +
                           "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1\n" +
                           "-----END CERTIFICATE-----";
            var res = PemConverter.Encode(rawData, "certificate");

            Assert.Equal(expected, res);
        }
        public void Encode_Array()
        {
            var rawData      = Convert.FromBase64String(DATA);
            var rawDataArray = new byte[][]
            {
                rawData,
                rawData,
                rawData
            };
            var res = PemConverter.Encode(rawDataArray, "certificate");

            Assert.Equal(PEM, res);
        }