javaaws-sdkx509certificateaws-iotaws-sdk-java

Is there a way to fetch common name of AWS IoT core certificate


I have registered a certificate in AWS IoT core. The next step is to create a thing and attach this certificate to the thing. My requirement is that the certificate's common name must be the name of the thing to be created. Does anyone know if there is a way to fetch the common name of the certificate? If yes, could you please help me out here. Thanks in advance :)

P.S. I am trying to do this in Java


Solution

  • If you know the certificate ARN, you could use the CLI command "describe-certificate" to get the entire certificate, and then use a Java library like BouncyCastle to parse the certificate for its common name.

    It might also be possible to do what you want without ever parsing the certificate directly yourself using just-in-time-provisioning. This process lets you set up a CA certificate so that anytime a certificate issued by it connects, it will parse the common name (AWS::IoT::Certificate::CommonName) and create a thing using the common name & attach the certificate and a policy you specify to that thing.