Is it possible to generate certificate signing request(.csr) using security framework in iOS?

后端 未结 2 2108
抹茶落季
抹茶落季 2021-01-06 11:21

I would like to make HTTPS request with a server require client-certificate authentication. I looked into this Creating a SecCertificateRef for NSURLConnection Authenticatio

相关标签:
2条回答
  • 2021-01-06 11:59

    To anyone who comes across this in the future, I encountered outfoxx's Shield library which makes it super easy to create CSRs via Swift.

    0 讨论(0)
  • 2021-01-06 12:02

    There is no explicit support for CSR in Security Framework in iOS. However, it is not that difficult to build CSR 'manually' - it is just ASN.1 DER block of data that are available at iOS runtime.

    Here is pseudo code of that:

    1. Use SecKeyGeneratePair() from Security Framework to create fresh public/private key
    2. Implement getPublicKeyBits method to retrieve NSData-form of fresh public key (see https://developer.apple.com/library/ios/samplecode/CryptoExercise/Introduction/Intro.html )
    3. Implement getPrivateKey method to retrieve SecKeyRef from Keychain
    4. Follow http://www.ietf.org/rfc/rfc2986.txt to construct ASN.1 DER of CSR in NSMutableData
    5. Use CC_SHA1_* to create signature hash of Certification Request Info (part of CSR)
    6. Use SecKeyRawSign and private key to sign CSR

    This will create proper CSR (in form of NSData) that can be sent to CA for approval.

    My implementation is available on GitHub: http://github.com/ateska/ios-csr .

    0 讨论(0)
提交回复
热议问题