amazon-web-services - 如何从 Java 中的 AWS 证书管理器访问证书详细信息和私钥以构建 SSLContext?
问题描述
我正在从此代码中获取证书,但没有获取私钥
AWSCertificateManager client = AWSCertificateManagerClientBuilder.standard()
.withRegion(Regions.#####)
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.build();
GetCertificateRequest req = new GetCertificateRequest();
req.setCertificateArn("################################");
// Retrieve the certificate and certificate chain.
// If you recently requested the certificate, loop until it has been created.
GetCertificateResult result = null;
long totalTimeout = 120000l;
long timeSlept = 0l;
long sleepInterval = 10000l;
while (result == null && timeSlept < totalTimeout) {
try {
result = client.getCertificate(req);
String certificate = result.getCertificate();
String certificate_chain = result.getCertificateChain();
}
catch (RequestInProgressException ex) {
Thread.sleep(sleepInterval);
}
catch (ResourceNotFoundException ex)
{
throw ex;
}
catch (InvalidArnException ex)
{
throw ex;
}
timeSlept += sleepInterval;
}
解决方案
AWS Certificate Manager 有两个主要选项,Certificates
和Private CA
.
用于 ACM 集成服务的免费公有证书 使用 AWS
Certificate Manager,预置用于 ACM 集成服务(例如 Elastic Load Balancing 和 API Gateway)的公有或私有 SSL/TLS 证书无需额外费用。您为运行应用程序而创建的 AWS 资源付费。对于私有证书,ACM Private CA 使您能够按月为您创建的服务和证书付费。当您创建更多私有证书时,您为每个证书支付更少的费用。
所以基本上Certificates
由 AWS 管理,并与其他服务集成。在此选项中,您不能将此证书与其他非 AWS 资源一起使用,因此您无法访问证书私钥。
使用Private CA
AWS 为您管理 CA。您可以创建证书,在这种情况下,您可以完全访问此证书,甚至是私钥。它不与其他 AWS 服务集成。
如果您想获取证书以在您的实例中使用,例如 Apache 或 Nginx。最好的方法是在您的实例前面放置一个 ALB。ALB 将使用来自 ACM 的公共证书。
在此之后,您可以决定是否要在 ALB 和您的实例之间进行加密。
如果您想要进行端到端加密,您可以使用自签名证书,因为 ALB 不会对其进行验证,或者您可以使用来自 ACM Private CA 的一个证书。
推荐阅读
- html - 在隐藏的动态 html 表单中更改值
- ms-access - 根据选择字段附加不同行的 SQL 是什么?
- html - 不同网站的文本元素大小不同
- wordpress - 从我的自定义 wordpress 插件创建 Txt 文件
- javascript - 400 Bad Request:浏览器发送了一个服务器无法理解的请求
- spring-boot - SpringBoot 在运行 Junit 测试时禁用 DataSourceAutoconfigure 错误
- python - AttributeError:“WebElement”对象没有属性“Send_Keys”
- javascript - 在 React 中将变量传递给 axios 请求
- r - 如何在图中找到给定 y 值的特定 x 值?
- gsap - Barba.js & GSAP 新元素出现在旧元素消失之前