public static async Task RsaCertificateCreateIntermediateCaTestAsync() { using (var mock = Setup()) { IKeyStore keys = mock.Create <KeyDatabase>(); IDigestSigner signer = mock.Create <KeyDatabase>(); ICertificateFactory factory = mock.Create <CertificateFactory>(); Key publicKey; KeyHandle issuerKey; Key issuerPublicKey; using (var rsa1 = RSA.Create()) { issuerKey = await keys.ImportKeyAsync("rsa1", rsa1.ToKey()); issuerPublicKey = rsa1.ToKey().GetPublicKey(); } using (var rsa2 = RSA.Create()) { await keys.ImportKeyAsync("rsa2", rsa2.ToKey()); publicKey = rsa2.ToKey().GetPublicKey(); } var now = DateTime.UtcNow; var intca = await factory.CreateCertificateAsync(signer, issuerKey, X500DistinguishedNameEx.Create("CN=leaf"), publicKey, now, now + TimeSpan.FromMinutes(1), SignatureType.PS256, true, sn => { return(new List <X509Extension>()); }); } }
public static async Task RsaCertificateCreateSelfSignedTestAsync() { using (var mock = Setup()) { IKeyStore keys = mock.Create <KeyDatabase>(); IDigestSigner signer = mock.Create <KeyDatabase>(); ICertificateFactory factory = mock.Create <CertificateFactory>(); KeyHandle issuerKey; Key issuerPublicKey; using (var rsa1 = RSA.Create()) { issuerKey = await keys.ImportKeyAsync("rsa1", rsa1.ToKey(), new KeyStoreProperties { Exportable = true }); issuerPublicKey = rsa1.ToKey().GetPublicKey(); } var now = DateTime.UtcNow; var cert = await factory.CreateCertificateAsync(signer, issuerKey, X500DistinguishedNameEx.Create("CN=leaf"), issuerPublicKey, now, now + TimeSpan.FromMinutes(1), SignatureType.RS256, false, sn => { return(new List <X509Extension>()); }); var privateKey = await keys.ExportKeyAsync(issuerKey); using (cert) { var certificate = cert.ToCertificate(); Assert.True(certificate.IsSelfSigned()); Assert.Equal(certificate.GetIssuerSerialNumberAsString(), certificate.GetSerialNumberAsString()); } } }