Beispiel #1
0
        /// <summary>
        /// Downloads the certificate chain in PEM.
        /// <param name="preferredChain">The preferred Root Certificate</param>
        /// </summary>
        /// <returns>The certificate chain in PEM.</returns>
        public async Task <CertificateChain> Download(string preferredChain = null)
        {
            var order = await Resource();

            var resp = await Context.HttpClient.Post <string>(Context, order.Certificate, null, false);

            var defaultChain = new CertificateChain(resp.Resource);

            if (defaultChain.MatchesPreferredChain(preferredChain) || !resp.Links.Contains("alternate"))
            {
                return(defaultChain);
            }

            var alternateLinks = resp.Links["alternate"].ToList();

            foreach (var alternate in alternateLinks)
            {
                resp = await Context.HttpClient.Post <string>(Context, alternate, null, false);

                var chain = new CertificateChain(resp.Resource);

                if (chain.MatchesPreferredChain(preferredChain))
                {
                    return(chain);
                }
            }

            return(defaultChain);
        }
Beispiel #2
0
        public void FailWhenMissingIntermediateCert()
        {
            var pem =
                string.Join(Environment.NewLine,
                            File.ReadAllText("./Data/leaf-cert.pem").Trim(),
                            File.ReadAllText("./Data/test-root.pem").Trim());

            var chain = new CertificateChain(pem);

            Assert.Throws <AcmeException>(() => chain.ToPem());
        }
Beispiel #3
0
        public void CanGenerateFullChainPem()
        {
            var pem =
                string.Join(Environment.NewLine,
                            File.ReadAllText("./Data/leaf-cert.pem").Trim(),
                            File.ReadAllText("./Data/test-ca2.pem").Trim(),
                            File.ReadAllText("./Data/test-root.pem").Trim());

            var chain  = new CertificateChain(pem);
            var result = chain.ToPem();

            Assert.Equal(pem.Replace("\r", "").Trim(), result.Replace("\r", "").Trim());
        }
Beispiel #4
0
        public void CanGenerateFullChainPemWithKey()
        {
            var key = KeyFactory.NewKey(KeyAlgorithm.ES256);

            var pem =
                string.Join(Environment.NewLine,
                            File.ReadAllText("./Data/cert.pem").Trim());

            var expectedPem =
                key.ToPem().Trim() +
                Environment.NewLine +
                pem +
                Environment.NewLine +
                File.ReadAllText("./Data/dst-root-ca-x3.pem").Trim();

            var chain  = new CertificateChain(pem);
            var result = chain.ToPem(key);

            Assert.Equal(expectedPem.Replace("\r", "").Trim(), result.Replace("\r", "").Trim());
        }