ServerTrustManager

public final class ServerTrustManager

A class conforming to the URLCredentialProvider protocol. This class is the default credential provider for URLAuthenticationMethod.serverTrust The purpose of this class is to make certificate pinning easy to setup. All the heavy lifting is done by this class and APIRequestType. The caller only needs to call the necessary API to pin a certificate or spki fingerprint for their server.

  • Uses the provided certificate to pin the SPKI for the specified host. If SPKI cannot be extracted for the specified certificate then this falls back to public key pinning.

    Declaration

    Swift

    public static func pin(certificate: SecCertificate, forHost host: String)
    Parameters
    certificate

    SecCertificate object to pin

    host

    The host name string to pin for this certificate. e.g. www.microstrategy.com

  • Pins the SPKI fingerprint for the specified host.

    Declaration

    Swift

    public static func pin(spkiFingerprint fingerprint: String, forHost host: String)
    Parameters
    spkiFingerprint

    SPKI bytes -> SHA 256 -> base64 string

    host

    The host name string to pin for this SPKI. e.g. www.microstrategy.com

  • Discard any pinning data for the specified host name.

    Declaration

    Swift

    public static func unpinTLSCertificate(forHost host: String)