Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Div
classdeveloper-cookbook-inner-page-title
HTML Table
classtagline-page-title
Table Row (tr)
Table Cell (td)
classtitle-text

Learn how to integrate Cipher SDK on Android device. 

Cipher SDK is a Two Factor Authentication (2FA) solution designed to provide a secure way of verifying transactions. This is achieved by enabling customers to verify their identity. Cipher SDK ensures a safe implementation of 2FA with minimum friction without the need of OTP generation .

In this article, you will learn how to integrate Android Cipher SDK.

Before you begin

Take care of the following prerequisites before you begin with SDK with SDK setup:

  • Minimum Android SDK version required: 19
  • Minimum Java Runtime Environment (JRE) version required: 8
  • Ensure you have a cipher.json file which contains configuration data necessary to set up the SDK. Contact Zeta in case if you haven't received the file.
  • Fusion uses authentication token to token to authenticate the SDK. To know how to generate an authentication token, see SDK Authentication.
  • Minimum Android SDK version required: 19
  • Minimum Java Runtime Environment (JRE) version required: 8
  • Set up a Firebase project for your app and register your Cloud Messaging server key in our dashboard.
Info
titleComing soon.

All new Swipe To Authenticate feature of Cipher SDK will be out soon for integration.

Getting Started with Android Cipher SDK

Follow the steps below to integrate SDK:

  1. First, you should add the SDK to your project or app.
  2. Prepare the SDK setup.
  3. Add the implementation for Secured Store setup.
  4. Configure the API operations of Cipher service.
  5. Now the SDK setup is ready to begin with verifying the SDK.
  6. Finally, call Android Cipher SDK API to clear the session data.
  7. integration process.

Anchor
addthesdk
addthesdk
Step 1:

Add

Adding the SDK

The Android SDK is compatible with apps supporting Android with version 4.4 to 4.4.4 or API level 19 and above. To add the SDK to your project, follow these steps:

  1. Add the following rule to your project-level gradle file. This downloads the Maven repository which holds all the build artifacts and dependencies necessary for your project.

    Code Block
    themeMidnight
    titleProject build.gradle
    linenumberstrue
    collapsetrue
    allprojects {
        repositories {
            ....
            maven {
                credentials  {
                    username = "<username>"
                    password = "<password>"
                }
                url 'httpshttp://apollo-maven172.corp16.zeta64.in117:8081/nexus/content/repositories/releases/'
                authentication {
                    basic(BasicAuthentication)
                }
    maven {https://apollo-maven.corp.zeta.in        }
            maven {
                credentials  {
                    username = "<username>"
                    password = "<password>"
                }
                url 'http://172.16.64.117:8081/nexus/content/repositories/snapshots/'
                authentication {
                    basic(BasicAuthentication)
                }
            }
            ....        
        }
    }
    configurations.all {
        // Add this if you face issue related to rxjava2
        resolutionStrategy.force "io.reactivex.rxjava2:rxandroid:2.1.0"
        }
    }
    Info
    • We recommend to maintain the order of including the repositories as mentioned in the above code for project-level gradle.
    • You will receive a document that contains maven user credentials for the above code.
  2. In your module app-level gradle file, add the following rules:

    Code Block
    themeMidnight
    titleapp build.gradle
    linenumberstrue
    collapsetrue
    android {
    …….
        defaultConfig {
    	//Use this for debug build. 
    multiDexEnabled true
        }
        ........
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        
        kotlin_options = {
           jvmTarget = "1.8"
        }
         // Include this if you face any packing errors ..
        packagingOptions {
            exclude 'META-INF/library_release.kotlin_module'
            exclude 'META-INF/DEPENDENCIES'
        }
        ........
    }
    
    dependencies {
      ………...
      implementation ("in.zeta.apollo:cipher:<cipher_version>")
    }

    Following are the descriptions of different modules in app-level gradle code:

    • multiDexEnabled: Optional. Add this for debugging the build if you overshoot the 64K methods ceiling.

    • compileOptions: Required. Add support for Java 8 language features.

    • packagingOptions: Optional. Add this only if you face packaging error.

    • dependencies: Required. Include Card Cipher SDK dependencies for the latest version.

Anchor
sdksetup
sdksetup
Step 2:

Set

Setting up the SDK

Follow the steps below to set up the SDK:

Add the configuration file

A configuration file contains all the

configurable

properties necessary for activating the SDK. You should add the file to your project (app/src/main/assets/) to prepare your app to work with the SDK. You will receive the configuration file named cipher.json through email. If you haven't received the file, contact Zeta.

Intialize

Initialize the SDK

In the onCreate() method of your application class, create a in.android.zeta.

acs.CipherService

cipher instance.

Code Block
themeMidnight
titleCipherService instance
linenumberstrue
final CipherService cipherService = new CipherBuilder(this)
.setTenantSecuredStoreAccess(securedStoreAccess) // AppSecuredStoreAccess
.
 - To be provided when using the tenant secured store.
.setUseDeviceLock(false) // Enable this when you want to use device lock. Application when setUseCustomStore is set as false. This is set as true by default.
.setUseCustomStore(true)// Set this true if you want to provide an implementation of your own secured store. This is set as false by default.
.setSuperPinExceptionListener(superPinExceptionListener)
.build();
Info

If you are using Timber logging utility, initialize it after initialization of Cipher SDK.

AnchorcreateSecuredStorecreateSecuredStoreStep 3:


Set up the Secured Store

The Cipher SDK maintains various pieces of sensitive information used to generate the Super PIN is stored in the Secured Store accessible through a PIN, pattern and biometric identification. Cipher SDK like Super PIN, secrets. The SDK stores this sensitive information in a Secured Store. Cipher SDK supports the following Secured Store implementations:

SDK implementation

Cipher SDK provides an implementation of the Secured Store out of the box. The SDK provided secured store supports device lock or a Super PIN. the following:

  • Device lock:
    The device lock is enabled by default.

During creation of the CipherService instance using CipherBuilder, you can manage the following SDK customizations:

CipherBuilder. means device lock is disabled. Set this to true, if you want to use device lock. By default this is set as true, when .setUseCustomStore is set as false.
  • CipherBuilder.setUseCustomStore(false) means you want use SDK provided Secured Store. Set this to true, if you want to use your Secured Store. This set as false by default.
    • in CipherService instance of CipherBuilder.

    • SDK Super PIN:
      The SDK uses Super PIN by default if you don't enable device lock and access to your custom secured store. In this case, we prompt you to set up the SDK PIN for securing sensitive data.


    Note

    Ensure you run setParentActivityForAuth before accessing the Super PIN and Swipe to Authenticate functionalities .


    Anchor
    Hosting app’s custom implementation
    Hosting app’s custom implementation
    Hosting app’s custom implementation

    If you want to use your custom secured store, use the setUseCustomStore(bool) API in CipherBuilder. Now you are ready to provide an implementation for the AppSecuredStoreAccess interface using setTenantSecuredStoreAccess() . This interface enables the Cipher SDK secured store to securely store /retrieve sensitive data into your Secured Store.

    Code Block
    themeMidnight
    titleApp Secured Store Access Interface
    linenumberstrue
    collapsetrue
    public interface AppSecuredStoreAccess {
       interface SetaDataInSecureStoreListener {
           void done(final boolean success, final Exception exp);
       }
       void setDataInSecureStore(@NonNull final String key, final byte[] data, @NonNull final SetaDataInSecureStoreListener listener);
       interface GetDataInSecureStore {
           void done(final byte[] data, final Exception exp);
       }
       void getDataFromSecureStore(@NonNull final String key, @NonNull final GetDataInSecureStore listener);
       boolean contains(@NonNull final String key);
    }

    If you haven't provided access to your Secured Store and the device lock is also disabled, contact Zeta for assistance.

    AnchorConfiguretheSDKConfiguretheSDKStep 4: Configure the SDKYou can configure the SDK by providing the implementation for the following Cipher service APIs based on your requirement:

    Anchor
    VerifytheSDK
    VerifytheSDK
    Step 3: Integrating the SDK

    Cipher SDK is a stateful SDK. Before you start using the Super PIN feature of SDK, take care of the following:

    • Set up a Super PIN:
      Use isSuperPinSetupRequired() to check if you need to execute this step. Call setupSuperPin(listener) to set up a Super PIN.

    Once the Super PIN integration flow is successful isSuperPinSetupDone() returns true.

    Following is a code snippet to check the state of the SDK and take appropriate action:

    Code Block
    languagejs
    themeMidnight
    titleCipher Service Actions
    linenumberstrue
    if(cipherService.isSecureStoreSetupRequired()) {
    	// You are now ready to setup the secure store as instructed by the AppSecuredStoreAccess
    } else if(cipherService.isSuperPinSetupRequired()){
    	// You are ready to call setupSuperPin()
    } else if(cipherService.isSuperPinSetupDone()){
    	// You are ready to trigger getSuperPin() API
    }

    Anchor
    ConfiguretheSDK
    ConfiguretheSDK
    API Reference

    Cipher SDK provides a set of public APIs which are useful to set up the SDK and access its functionalities.

    Authenticate the SDK

    To perform authentication, you must provide the authentication token  to the SDK. Use the following API to create an authentication toke n. To You can access the Cipher SDK by going through the authentication process. A call to cipherService.authenticate(tenantAuthToken) API creates an authentication session. This session invokes on the server-side of the SDK with a given expiry time. Ensure to call this API to refresh the authentication session in every launch of the app. To know how to generate an authentication token, see see SDK Authentication.

    Code Block
    themeMidnight
    authenticate(tenantTokentenantAuthToken: String) - Returns void

    Set up Secured Store

    If a call to isSecureStoreSetUpRequired() returns true, you are ready to set up the Secured Store by triggering the setUpSecuredStore().

    1. Check the state of Cipher SDK.

      This API tells if the SDK needs a Secured Store setup. Only after this step, the SDK will be able to set up the Swipe to PayTo Authenticate and Super PIN.

      Code Block
      themeMidnight
      isSecureStoreSetupRequired() - Return boolean
    2. Call setupSecuredStore()

      A call to the API setupSecuredStore() triggers the setup of Secured Store. Ensure you call setupSecureStore() to set up the Secured Store only when isSecureStoreSetupRequired returns true. If the API returns an exception in the listener, call Logout() before retrying.

      Code Block
      themeMidnight
      setupSecuredStore(activity: Activity, listener: SecureStoreSetupListener) - Returns void
    Generate

    Set up the Super PIN

    If a call to isSuperPinSetupDone() API returns true, you can generate a Super PIN to secure the store by triggering setupSuperPin(listener: SetupSuperPinListener) API.

    1. Check the state of Cipher SDK.

      This API tells if the Super PIN setup is done or not. If this method returns true, the Super PIN setup is done. If the Super PIN functionality doesn’t work, the SDK might be in an error state. You can get the error state using the superPinExceptionListener in CipherService instance.

      Code Block
      themeMidnight
      isSuperPinSetupDone() - Returns boolean
    2. Set up the Super PIN
      A call to this API creates a Super PIN. The Super PIN can be setup only when CipherSerivce.isSuperPinSetupRequired() returns true. If this setup fails and issue persists, contact Zeta.

      Code Block
      themeMidnight
      setupSuperPin(listener: SetupSuperPinListener)
    3. Retrieve the Super PIN

      This API returns the Super PIN and it’s Time To Live (TTL) on providing authentication to the Secured Store or device lock. Use this Super PIN to authorize the payment.

      Code Block
      themeMidnight
      getSuperPin(GetSuperPinListener listener)

    Set up a parent activity for Secured Store

    Set the parent activity on top of which we want to show the Super PIN or device lock. This option should be used when the Secured Store is setup set up using the SDK implementation.

    Code Block
    themeMidnight
    setParentActivityForAuth(Activity activity)

    Adding Listener

    You can listen to any change in the state of Cipher SDK integration such as, when an authentication token is required, is Secured Store set up required, can Super PIN be generated.

    Use this method is used to subscribe to SDK state updates.

    Code Block
    themeMidnight
    setCipherStateUpdateListener(listener: CipherStateUpdateListener)
    Infonote

    This method is deprecated and no longer advised to be used. Instead use the the listeners in the different methods.

    AnchorVerifytheSDKVerifytheSDKStep 5: Verify the SDK

    You can instruct the SDK to perform actions based on your configurations. After the Secured Store is setup, you can decide the actions to be taken as shown in the code snippet below:

    Code Block
    languagejs
    themeMidnight
    titleCipher Service Actions
    linenumberstrue
     if(cipherService.isSecureStoreSetupRequired()) {
    	// You are now ready to setup the secure store as instructed by the AppSecuredStoreAccess
    } else if(cipherService.isSuperPinSetupRequired()){
    	// You are ready to call setupSuperPin()
    } else if(cipherService.isSuperPinSetupDone()){
    	// You are ready to trigger getSuperPin() API
    }
    AnchorLogoutLogoutStep 6: LogoutWhen a user logs out from the app, ensure that you clear all the session data. A default call to Logout method is important for the SDK to work properly in next login session.

    Logout

    Ensure to call the Logout API in events like switching the user by logging out from the app. This ensures the latest token is in-place to set up the next authentication session. Thereby, this also validates the local authentication session.

    A simple logout is available by using:

    Code Block
    themeMidnight
    titleLogout
    cipherService.logout()

    Exceptions and error codes

    This section explains various exceptions and error codes thrown by the Cipher SDK and how to handle them. Exceptions provide system error codes along with Throwable message, that helps to recognize and troubleshoot the issue.

    All the exceptions thrown will have the following fields in addition to the message:

    1. code: Error code related to the response.
    2. traceId: Trace ID which can be provided to Zeta support for identifying the root cause.
    3. errorType: Type of error.

    There are two kinds of exceptions that Cipher SDK can throw:

    • SdkAuthException
    • CardsSdkException
    Info

    All the exception classes extend the ApolloException.

    The sample error response below shows server-side error code and message returned in case of any error:

    Code Block
    themeMidnight
    titleSample Error Response
    apollo@console$ in.zeta.apollo.sdkauth.SdkAuthException: The tenantAuthToken token set seems invalid. Please check the parameters and signature to create the token
    SdkAuthException.code: SDKAUTH_ERR_001


    The following table lists the error codes, descriptions and possible solutions. If the issue persists, contact Zeta.

    Error CodeDescription

    ERR_001

    Exception thrown due to bad request.
    ERR_002Internal server error. Try again.
    ERR_003Internal SDK error. Try logging out and then log in.
    SDKAUTH_ERR_001

    Following are the potential reasons for failure of an authentication token:

    • Token is signed with an invalid private key.
    • Token does not contain the configured claim.
    • Token has expired.
    SDKAUTH_ERR_002Internal error caused while trying to authenticate the user.
    CIPHERSDK_ERR_001Error occurred when user cancels the Secured Store setup.
    Info

    To know more about exceptions and error codes handling, contact Zeta.

    Panel
    Div
    classalignLeftIcon

    On this page:

    Table of Contents

    Div
    classhelp-box

    Need Help?

    Drop a mail at fusion-support@zeta.tech or call us on 080-6690 5995.