public void ParseCertificatesResponseInvalidCertificateShouldThrow() { ServerCertificateResponse cert = new ServerCertificateResponse() { Certificate = "InvalidCert" }; Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(cert)); }
public void ParseCertificatesResponseInvalidKeyShouldThrow() { var response = new ServerCertificateResponse() { Certificate = TestCertificateHelper.CertificatePem, PrivateKey = "InvalidKey" }; Assert.Throws <InvalidOperationException>(() => CertificateHelper.ParseCertificateResponse(response)); }
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)); }
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()); }
internal static (X509Certificate2, IEnumerable <X509Certificate2>) ParseCertificateResponse(ServerCertificateResponse response) => ParseCertificateAndKey(response.Certificate, response.PrivateKey);
internal static (X509Certificate2, IEnumerable <X509Certificate2>) ParseCertificateResponse(ServerCertificateResponse response, ILogger logger = null) => ParseCertificateAndKey(response.Certificate, response.PrivateKey, logger);