Public Key pinning

The Gini iOS SDK allows you to enable public key pinning with the Gini API through the [TrustKit]( library. In case you want to implement it, first you have to add pod Gini-iOS-SDK/Pinning below pod Gini-iOS-SDK in your Podfile. Once you have imported it, you just need to pass a dictionary with all the parameters required into one of the GINISDKBuilder initializers, as follows:

let trustKitConfig = [
            kTSKSwizzleNetworkDelegates: false,
            kTSKPinnedDomains: [
                "": [
                    kTSKPublicKeyAlgorithms: [kTSKAlgorithmRsa2048],
                    kTSKPublicKeyHashes: [
                        // OLD * public key
                        // NEW * public key
                    ],]]] as [String : Any]

let sdk = GINISDKBuilder.anonymousUser(withClientID: "your_client_id",
                                       clientSecret: "your_client_secret",
                                       userEmailDomain: "your_user_email_domain"
                                       publicKeyPinningConfig: trustKitConfig).build()
NSDictionary *trustKitConfig = @{
kTSKPinnedDomains: @{
        @"" : @{
                kTSKPublicKeyAlgorithms : @[kTSKAlgorithmRsa2048],
                kTSKPublicKeyHashes : @[
                        // OLD * public key
                        // NEW * public key

GiniSDK *sdk = [[GINISDKBuilder anonymousUserWithClientID:@"your_client_id"
                                   publicKeyPinningConfig:trustKitConfig] build];

If kTSKEnforcePinning is set to false, any SSL connection will be block even if the pinning fails. When it is enabled, it requires at least two hashes (the second one is a backup hash). When using TrustKit some messages are shown in the console log. It is possible to either specify a custom log for messages or disable it altogether (setting it as nil). To do so just use the TrustKit.setLoggerBlock method before initializing the trustKitConfig.


The above digests serve as an example only. You should always create the digest yourself from the Gini API’s public key and use that one (see below). If you received a digest from us then always validate it by comparing it to the digest you created from the public key (see below). Failing to validate a digest may lead to security vulnerabilities.

Extract Hash From

The current Gini API public key SHA256 hash digest in Base64 encoding can be extracted with the following openssl commands:

$ openssl s_client -servername -connect | openssl x509 -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

Extract Hash From Public Key

You can also extract the hash from a public key. The following example shows how to extract it from a public key named

$ cat | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64