sonerd
sonerd

Reputation: 13

Convert PEM Response to PCKS12 Data in Swift

We are using AWS iOS SDK for an IoT project in our company. It is a simple application for now. User logs in to our system and tries to connect to the AWS IoT service.

https://github.com/awslabs/aws-sdk-ios-samples/tree/master/IoT-Sample/Swift/IoTSampleSwift

In the sample project above, application generates its own certificate and key pair using AWSIoT SDK. However, in our case, we don't want to generate certificates like this.

We created a Lambda Function on the server side to generate certificates for our users. iOS application requests certificate and as a response server sends a key pair, certificatePem, certificateId and certificate Arn. All of the components are created by AWSIoT SDK, if we use AWSIoTManager.defaultManager(). createKeysAndCertificateFromCsr method.

In this case, we need to import our user identity to the iOS keychain. AWS SDK has another method to handle this problem: AWSIoTManager.importIdentityFromPKCS12Data method

We need to convert the server response to PKCS12Data to use the generated certificate. How can we do this?

Thanks in advance.

Upvotes: 1

Views: 422

Answers (1)

garyw_aws
garyw_aws

Reputation: 101

If you've got the key pair, the certificate PEM, certificate ID, and the certificate ARN, you can use the AWS Mobile SDK for iOS's IoT classes as a reference while implementing code for importing these into the keychain. The AWSIoTKeychain class contains methods for importing keys, and the AWSIoTManager -createKeysAndCertificateFromCsr: method imports the certificate into the keychain. Let us know if that information helps, and thanks for using AWS IoT.

Upvotes: 0

Related Questions