Skip to content

SSL Pinning with FSNetwork

Brett Weissbart edited this page Sep 23, 2020 · 1 revision

Flagship 10 adds support for SSL pinning functionality to FSNetwork.

When pinning is enabled for a request, FSNetwork will use native networking stacks (OKHTTP 3 for Android and AFNetworking on iOS) as Axios is a fully JavaScript implementation and thus doesn't support the functionality. FSNetwork will continue to use Axios when pinning is not explicitly enabled.

Available methods: GET, POST, PUT, DELETE

NOTE: Methods PATCH and HEAD are not available with SSL Pinning feature.

Step 1: Create SSL Certificate

To generate ssl certificates for the resource:

  1. Get certificates for the domain:
$ openssl s_client -showcerts -connect your.domain.name:443
  1. Save certificates:
$ nano certificate.pem
  1. Convert it to .cer with this command:
$ openssl x509 -in certificate.pem -outform der -out certificate.cer

Step 2: Register Certificate with Flagship

  1. Move generated .cer certificates to the project folder. (e.g. /youproject/assets/ssl)

  2. Register certificates in env file configuration

{
    ...envConfig,
    "pinnedCerts": [ 
       {
          "baseUrl": "https://your.domain.name",  
          "path": "assets/ssl/certificate.cer"
       }
    ]
}
  1. Initialize project. The CLI tools will automatically add certificates from env to the iOS and Android directories.

Step 3: Use SSL Pinning with FSNetwork

To use SSL Pinning with FSNetwork add the pinnedCertificate property to the FSNetworkConfiguration configuration.

// from env
import { env } from '@brandingbrand/app';

const dataSource = new FSNetwork({
    ...configuration,
    pinnedCertificates: env.pinnedCerts
});

// manually 
const dataSource = new FSNetwork({
    ...configuration,
    pinnedCertificates: [
       {
          "baseUrl": "https://your.domain.name",
          "path": "assets/ssl/certificate.cer"
       }
   ]
});

The ssl pinning will be applied only for sources that mentioned in pinnedCertificate object. Otherwise, FSNetwork will use axios.

Clone this wiki locally