我的情况:
我有一个运行 Windows Server 2016 DataCenter OS 的EC2实例。此EC2实例配置为用作 CA 和 IIS 服务器(我正在测试 cloudhsm ,因此我可以在其中使用多个服务同一台服务器)。我的CA已配置 RSA#Cavium密钥存储提供程序(因为它支持AWS CloudHSM密钥存储提供程序)。现在,从示例.Net WebAPI应用程序中,我可以使用以下代码创建CSR:
private async Task<CertificateSigningResponse> ActualSigningAsync(CertificateSigningRequest csr)
{
CertificateSigningResponse certificateSigningResponse;
try
{
using (RSA rsa = RSA.Create(csr.KeySize))
{
CertificateRequest request = new CertificateRequest("CN=servername-CA2", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
OidCollection oidCollection = new OidCollection();
oidCollection.Add(new Oid("1.3.6.1.5.5.7.3.8"));
request.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, true));
request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(oidCollection, true));
request.CertificateExtensions.Add(new X509SubjectKeyIdentifierExtension(request.PublicKey, false));
var serialNumberInBytes = System.Text.Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());
/*
// below line creates a self signed certificate
var selfSignedCertificate = request.Create(
new X500DistinguishedName("CN=servername-CA2"),
X509SignatureGenerator.CreateForRSA(rsa, RSASignaturePadding.Pkcs1),
DateTimeOffset.Now,
DateTimeOffset.Now.AddMonths(1),
serialNumberInBytes);
*/
var certSigningRequest = request.CreateSigningRequest(X509SignatureGenerator.CreateForRSA(rsa, RSASignaturePadding.Pkcs1));
if (certSigningRequest != null)
{
certificateSigningResponse = PopulateCertificateSigningResponse(JsonConvert.SerializeObject(certSigningRequest), $"Sample Cert with Sl#: {certSigningRequest}");
}
else
{
certificateSigningResponse = PopulateCertificateSigningResponse("", $"Error: {request.PublicKey}");
}
}
}
catch (Exception ex)
{
certificateSigningResponse = PopulateCertificateSigningResponse(string.Empty, ex.Message);
}
return certificateSigningResponse;
}
现在,我想将此CSR发送到我的CA(在EC2上运行)并进行签名。签名后,我想将签名的证书发送回用户。目前,我已将示例webapi应用托管在同一EC2实例上。该应用程序实际上公开了一个端点,我可以通过邮递员访问该端点,并将某些数据作为请求正文(POST)传递。
因此,理想情况下,该应用程序接收我的POST请求并从中提取数据,然后使用该数据创建一个csr。现在,我想将此csr发送到我的CA,对其进行签名,最后将签名的证书返回给用户。下面的伪代码可能会让您对我的要求有所了解:
//pseudo code; not existed
// request is generated in above code
var caService = new CAService();//can use my ca info i.e. name, public dns, ip
var response = await caService.SignAsync(request);//response should be a cert
return response;
我很少看到使用 CertUtilLib / CertEnrollLib 的帖子,但是我想通过完全托管的代码来实现。另外,如果不可能,请给我建议一些替代方法。谢谢。
编辑1(在Michal发表评论之后)
以下是您感兴趣的信息:
当前场景:
我的意图: