本文介紹了使用Java為AWS IoT創(chuàng)建自簽名證書的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有一個(gè)根CA證書及其私鑰(CAcert.pem和CApvtkey.key)。
已在AWS IoT核心上注冊(cè)根CA證書。這將用于自簽名和驗(yàn)證其他證書以進(jìn)行身份驗(yàn)證。
我正在嘗試使用Java創(chuàng)建由我的根CA證書簽名的證書,但運(yùn)氣不是很好。
AWS IoT Java SDK提供生成證書以及在AWS上注冊(cè)/激活證書的功能,但我不知道如何使用我的根CA證書簽名和激活它們。
我只有這個(gè):
//Previous code sets up thing name etc...
CreateThingResult resp1 = client.createThing(thingRequest);
CreateKeysAndCertificateRequest req = new CreateKeysAndCertificateRequest();
req.setSetAsActive(true);
CreateKeysAndCertificateResult resp2 = client.createKeysAndCertificate(req);
client.attachThingPrincipal(new AttachThingPrincipalRequest().
withPrincipal(resp2.getCertificateArn()).withThingName("Java-App_Thing"));
有人知道如何創(chuàng)建將由CA證書簽名的證書嗎?
aws
所以推薦答案的文檔相當(dāng)模糊。我也有同樣的問(wèn)題。我是這樣修好它的。假設(shè)您已向AWS IoT注冊(cè)了您的CA,
即使您為您上載的CA啟用自動(dòng)注冊(cè),AWS IoT也不允許設(shè)備連接。證書將有幾個(gè)選項(xiàng)用于JIT(準(zhǔn)時(shí))注冊(cè)。
-
創(chuàng)建Lamba,在一定條件下激活設(shè)備;
列出MQTT上的事件以激活證書;
注冊(cè)公鑰。
選項(xiàng)1和2在AWS文檔中進(jìn)行了說(shuō)明
https://docs.aws.amazon.com/iot/latest/developerguide/auto-register-device-cert.html
選項(xiàng)3的執(zhí)行步驟:
-
注冊(cè)該物品
software.amazon.awssdk.services.iot.IotClient iotClient = IotClient.create()
//This allows AWS Credentials to be picked up using DefaultAWSCredentialsProviderChain
CreateThingRequest thingToBeCreated =
CreateThingRequest.builder().thingName("Unique Id of Device").build();
iotClient.createThing(thingToBeCreated);
-
注冊(cè)并激活設(shè)備的公鑰。
RegisterCertificateRequest registerCertificateRequest = RegisterCertificateRequest.builder()
.caCertificatePem("CA Pem as String")
.certificatePem("Device Public Key in Pem as String")
.setAsActive(true)
.build();
final RegisterCertificateResponse registerCertificateResponse = iotClient.registerCertificate(registerCertificateRequest);
-
將證書附加到該物件。
AttachThingPrincipalRequest attachThingPrincipalRequest = AttachThingPrincipalRequest.builder()
.thingName("Unique Id of Device")
.principal(registerCertificateResponse.certificateArn())
.build();
iotClient.attachThingPrincipal(attachThingPrincipalRequest);
-
可選,將策略附加到該對(duì)象,使其可以連接。
AttachPolicyRequest attachPolicyRequest = AttachPolicyRequest.builder()
.policyName("policy_that_allow_device_connections")
.target(registerCertificateResponse.certificateArn())
.build();
iotClient.attachPolicy(attachPolicyRequest);
這篇關(guān)于使用Java為AWS IoT創(chuàng)建自簽名證書的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,






