For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.

Certificate pinning

Use certificate pinning to help prevent man-in-the-middle attacks.

When communicating over public networks it is essential to send and receive information securely. The protocol widely used to secure these communications is SSL/TLS. (SSL/TLS refers to Secure Sockets Layer or to its successor, TLS, or Transport Layer Security.) SSL/TLS uses digital certificates to provide authentication and encryption. To trust that a certificate is genuine and valid, it is digitally signed by a root certificate belonging to a trusted certificate authority (CA). Operating systems and browsers maintain lists of trusted CA root certificates so that they can easily verify certificates that the CAs have issued and signed.

Protocols that rely on certificate chain verification, such as SSL/TLS, are vulnerable to a number of dangerous attacks, including man-in-the-middle attacks, which occur when an unauthorized party is able to view and modify all traffic passing between the mobile device and the backend systems.

IBM MobileFirst™ Platform Foundation provides an API to enable certificate pinning. This API is supported in native iOS, native Android, and cross-platform Cordova MobileFirst applications.

Certificate pinning process

Certificate pinning is the process of associating a host with its expected public key. Because you own both the server-side code and the client-side code, we can configure your client code to accept only a specific certificate for our domain name, instead of any certificate that corresponds to a trusted CA root certificate recognized by the operating system or browser.

A copy of the certificate is placed in your client application. During the SSL handshake (first request to the server), the IBM MobileFirst Platform Foundation client SDK verifies that the public key of the server certificate matches the public key of the certificate that is stored in the app.


If pinning is successful, the public key inside the provided certificate is used to verify the integrity of the MobileFirst Server certificate during the secured request SSL/TLS handshake. If pinning fails, all SSL/TLS requests to the server are rejected by the client application.

Certificate setup

You must use a certificate purchased from a certificate authority. Self-signed certificates are not supported. For compatibility with the supported environments, make sure to use a certificate that is encoded in DER (Distinguished Encoding Rules, as defined in the International Telecommunications Union X.690 standard) format.

You must place the certificate in both the MobileFirst Server and in your application. Place the certificate as follows:

  1. In the MobileFirst Server: (WebSphere® Application Server, WebSphere Application Server Liberty, or Apache Tomcat). Consult the documentation for our specific application server for information about how to configure SSL/TLS and certificates.
  2. In your application:

    • Native iOS: add the certificate to the application bundle
    • Native Android: place the certificate in the assets folder
    • Cross-platform (Cordova): place the certificate in the app-name\www\certificates folder

Certificate pinning API

Certificate pinning consists of a single API method, that has a parameter certificateFilename, where certificateFilename is the name of the certificate file.

Native Android

public void pinTrustedCertificatePublicKey(String certificateFilename) throws IllegalArgumentException



The certificate pinning method will throw an exception in two cases:

  • The file does not exist
  • The file is in the wrong format
Native iOS

pinTrustedCertificatePublicKeyFromFile:(NSString*) certificateFilename;


[[WLClient sharedInstance]pinTrustedCertificatePublicKeyFromFile:@"myCertificate.cer"];

The certificate pinning method will raise an exception in two cases:

  • The file does not exist
  • The file is in the wrong format
Cross-platform (Cordova)


The certificate pinning method returns a promise:

  • The certificate pinning method will call the onSuccess method in case of successful pinning.
  • The certificate pinning method will trigger the onFailure callback in two cases:

    • The file does not exist
    • The file is in the wrong format


Later, if a secured request is made to a server whose certificate is not pinned, the onFailure callback of the specific request (for example, WL.Client.connect or WLResourceRequest) is called.

For more details on the certificate pinning API, see the following reference sections:

Parent topic: Developing the client side of a MobileFirst application