NIOSSLPKCS12Bundle

public struct NIOSSLPKCS12Bundle

A container of a single PKCS#12 bundle.

PKCS#12 is a specification that defines an archive format for storing multiple cryptographic objects together in one file. Its most common usage, and the one that SwiftNIO is most interested in, is its use to bundle one or more X.509 certificates (NIOSSLCertificate) together with an associated private key (NIOSSLPrivateKey).

Working with TLSConfiguration

In many cases users will want to configure a TLSConfiguration with the data from a PKCS#12 bundle. This object assists in unpacking that bundle into its associated pieces.

If you have a PKCS12 bundle, you configure a TLSConfiguration like this:

let p12Bundle = NIOSSLPKCS12Bundle(file: pathToMyP12)
let config = TLSConfiguration.forServer(certificateChain: p12Bundle.certificateChain,
                                        privateKey: p12Bundle.privateKey)

The created TLSConfiguration can then be safely used for your endpoint.

  • Undocumented

    Declaration

    Swift

    public let certificateChain: [NIOSSLCertificate]
  • Undocumented

    Declaration

    Swift

    public let privateKey: NIOSSLPrivateKey
  • Create a NIOSSLPKCS12Bundle from the given bytes in memory, optionally decrypting the bundle with the given passphrase.

    Declaration

    Swift

    public init<Bytes>(buffer: [UInt8], passphrase: Bytes?) throws where Bytes : Collection, Bytes.Element == UInt8

    Parameters

    buffer

    The bytes of the PKCS#12 bundle.

    passphrase

    The passphrase used for the bundle, as a sequence of UTF-8 bytes.

  • Create a NIOSSLPKCS12Bundle from the given bytes on disk, optionally decrypting the bundle with the given passphrase.

    Declaration

    Swift

    public init<Bytes>(file: String, passphrase: Bytes?) throws where Bytes : Collection, Bytes.Element == UInt8

    Parameters

    file

    The path to the PKCS#12 bundle on disk.

    passphrase

    The passphrase used for the bundle, as a sequence of UTF-8 bytes.

  • Create a NIOSSLPKCS12Bundle from the given bytes on disk, assuming it has no passphrase.

    If the bundle does have a passphrase, call init(file:passphrase:) instead.

    Declaration

    Swift

    public init(file: String) throws

    Parameters

    file

    The path to the PKCS#12 bundle on disk.

  • Create a NIOSSLPKCS12Bundle from the given bytes in memory, assuming it has no passphrase.

    If the bundle does have a passphrase, call init(buffer:passphrase:) instead.

    Declaration

    Swift

    public init(buffer: [UInt8]) throws

    Parameters

    buffer

    The bytes of the PKCS#12 bundle.