Ejemplo n.º 1
0
        public void ParseCertificatesResponseInvalidCertificateShouldThrow()
        {
            ServerCertificateResponse cert = new ServerCertificateResponse()
            {
                Certificate = "InvalidCert"
            };

            Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(cert));
        }
Ejemplo n.º 2
0
        public void ParseCertificatesResponseInvalidKeyShouldThrow()
        {
            var response = new ServerCertificateResponse()
            {
                Certificate = TestCertificateHelper.CertificatePem,
                PrivateKey  = "InvalidKey"
            };

            Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(response));
        }
Ejemplo n.º 3
0
        public static async Task <(X509Certificate2 ServerCertificate, IEnumerable <X509Certificate2> CertificateChain)> GetServerCertificatesFromEdgelet(Uri workloadUri, string workloadApiVersion, string workloadClientApiVersion, string moduleId, string moduleGenerationId, string edgeHubHostname, DateTime expiration)
        {
            if (string.IsNullOrEmpty(edgeHubHostname))
            {
                throw new InvalidOperationException($"{nameof(edgeHubHostname)} is required.");
            }

            ServerCertificateResponse response = await new WorkloadClient(workloadUri, workloadApiVersion, workloadClientApiVersion, moduleId, moduleGenerationId).CreateServerCertificateAsync(edgeHubHostname, expiration);

            return(ParseCertificateResponse(response));
        }
Ejemplo n.º 4
0
        public void ParseCertificatesResponseShouldReturnCert()
        {
            TestCertificateHelper.GenerateSelfSignedCert("top secret").Export(X509ContentType.Cert);
            var response = new ServerCertificateResponse()
            {
                Certificate = $"{TestCertificateHelper.CertificatePem}\n{TestCertificateHelper.CertificatePem}",
                PrivateKey  = TestCertificateHelper.PrivateKeyPem
            };

            (X509Certificate2 cert, IEnumerable <X509Certificate2> chain) = CertificateHelper.ParseCertificateResponse(response);

            var expected = new X509Certificate2(Encoding.UTF8.GetBytes(TestCertificateHelper.CertificatePem));

            Assert.Equal(expected, cert);
            Assert.True(cert.HasPrivateKey);
            Assert.Single(chain);
            Assert.Equal(expected, chain.First());
        }
Ejemplo n.º 5
0
 internal static (X509Certificate2, IEnumerable <X509Certificate2>) ParseCertificateResponse(ServerCertificateResponse response) =>
 ParseCertificateAndKey(response.Certificate, response.PrivateKey);
Ejemplo n.º 6
0
 internal static (X509Certificate2, IEnumerable <X509Certificate2>) ParseCertificateResponse(ServerCertificateResponse response, ILogger logger = null) =>
 ParseCertificateAndKey(response.Certificate, response.PrivateKey, logger);