|
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.
Take care of the following prerequisites before you begin with SDK setup:
cipher.json
file which contains configuration data necessary to set up the SDK. Contact Zeta in case if you haven't received the file.Follow the steps below to integrate 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:
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.
allprojects { repositories { .... maven { credentials { username = "<username>" password = "<password>" } url 'https://apollo-sdk.zetaapps.in/repository/maven-releases/' authentication { basic(BasicAuthentication) } } maven { credentials { username = "<username>" password = "<password>" } url 'https://apollo-sdk.zetaapps.in/repository/maven-snapshots/' authentication { basic(BasicAuthentication) } } .... } } configurations.all { // Add this if you face issue related to rxjava2 resolutionStrategy.force "io.reactivex.rxjava2:rxandroid:2.1.0" } } |
|
In your module app-level gradle file, add the following rules:
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 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 Cipher SDK dependencies for the latest version.
Follow the steps below to set up the SDK:
A configuration file contains all the 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.
In the onCreate()
method of your application class, create a in.android.zeta.cipher
instance.
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) .setNotificationIcon(notificationResourceId) // Use this to set the notification icon when using Swipe to Authenticate. Required if using swipe to authenticate. .build(); |
If you are using Timber for logging, please initialize it after this step. |
Cipher SDK maintains various pieces of sensitive information like Super PIN, secrets. The SDK stores this sensitive information in a Secured Store. Cipher SDK supports the following Secured Store implementations:
Cipher SDK provides an implementation of the Secured Store out of the box. The SDK provided secured store supports the following:
Device lock:
The device lock is enabled by default. To disable the device lock, add setUseDeviceLock(false) 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.
Ensure you run setParentActivityForAuth before accessing the Super PIN and Swipe to Authenticate functionalities . |
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 secured store to store sensitive data.
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); } |
Cipher SDK is a stateful SDK. Before you start using the Super PIN feature of SDK, take care of the following:
Use isSecureStoreSetupRequired()
to check if you need to execute this step. Call setupSecuredStore(activity, listener) to set up the Secured Store.
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:
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 } |
The Swipe to Authenticate flow is set up along with the set up of the Super PIN flow. At Zeta, we use Firebase Cloud Messaging (FCM) to deliver Swipe to Authenticate notifications to your app. You should set up a Firebase project for your app if you have not done that already. Here are the details on how to do this. After setting up the Firebase project for your app, please share your FCM server key with our team at Zeta. We will use your FCM server key to deliver notifications to your app from our server. You will receive senderId
which you can use to identify the push sent by Zeta to your app. If you don’t receive a senderId
, there is an alternate way to identify the Swipe to Authenticate push as mentioned in Listen to Swipe to Authenticate Push.
Your app should have Draw over other apps permission to show Swipe to Authenticate prompt over other apps or when your app is closed. Otherwise, you will be notified about the a Swipe to Authenticate request on the notification tray. |
You should override your onNewToken() inside your FirebaseMessagingService
. Then call onPushTokenUpdated() whenever you receive a callback for the new push token. This helps us to keep the push token synced in our servers and ensure a hassle-free push experience. You can use the following code snippet.
override fun onNewToken(token: String) { cipherService.onPushTokenUpdated() } |
When you receive a push notification inside the overridden onMessageReceived() method of your FirebaseMessagingService
, you should relay that RemoteMessage
received to Cipher SDK if you receive the message from our senderID
. You can use handleNotification() method to relay the push message object to the Cipher SDK. You can use the following code snippet.
override fun onMessageReceived(remoteMessage: RemoteMessage) { if(<zeta_sender_id>.equals(remoteMessage.from)) { cipherService.handleNotification(remoteMessage) } } |
Alternatively, you can also look for the key acsRequestOTP
in the data payload of the RemoteMessage. You can use the following code snippet
override fun onMessageReceived(remoteMessage: RemoteMessage) { if(remoteMessage.getData().containsKey("acsRequestOTP")) { cipherService.handleNotification(remoteMessage) } } |
Cipher SDK provides a set of public APIs which are useful to set up the SDK and access its functionalities.
You can access the Cipher SDK by going through the authentication process. First, you should generate an authentication token (tenantAuthToken) and then call this API. Ensure to call this API to refresh the authentication token in every launch of the app.
authenticate(tenantAuthToken: String) - Returns void |
If a call to isSecureStoreSetUpRequired()
returns true, you are ready to set up the Secured Store by triggering the setUpSecuredStore()
.
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 Authenticate and Super PIN.
isSecureStoreSetupRequired() - Return boolean |
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.
setupSecuredStore(activity: Activity, listener: SecureStoreSetupListener) - Returns void |
If a call to isSuperPinSetupDone()
API returns true, you can generate a Super PIN to secure the store by triggering setupSuperPin(listener: SetupSuperPinListener)
API.
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.
isSuperPinSetupDone() - Returns boolean |
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.
setupSuperPin(listener: SetupSuperPinListener) |
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.
getSuperPin(GetSuperPinListener listener) |
Set the parent activity on top of which we want to show the Super PIN or device lock. Use this option when you are setting up the Secured Store using the SDK implementation.
setParentActivityForAuth(Activity activity) |
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.
setCipherStateUpdateListener(listener: CipherStateUpdateListener) |
This method is deprecated and no longer advised to be used. Instead use the the listeners in the different methods. |
This method helps you to communicate the notification data payload to the Cipher SDK. If you receive a notification from our senderID, you should relay the notification to the SDK and it will take care of the notification .
handleNotification(data: Map<String, String>) - Returns void |
Please ensure that you call this method on every update of the firebase push token. See Monitor token generation for more details.
onPushTokenUpdated() - Return void |
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. After a logout call, the SDK reaches the initial state, and then you should set up the SDK again from the first step.
A simple logout is available by using:
cipherService.logout() |
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:
code
: Error code related to the response.traceId
: Trace ID which can be provided to Zeta support for identifying the root cause.errorType
: Type of error.There are two kinds of exceptions that Cipher SDK can throw:
SdkAuthException
CardsSdkException
All the exception classes extend the |
The sample error response below shows server-side error code and message returned in case of any error:
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 Code | Description |
---|---|
| Exception thrown due to bad request. |
ERR_002 | Internal server error. Try again. |
ERR_003 | Internal SDK error. Try logging out and then log in. |
SDKAUTH_ERR_001 | Following are the potential reasons for failure of an authentication token:
|
SDKAUTH_ERR_002 | Internal error caused while trying to authenticate the user. |
CIPHERSDK_ERR_001 | Error occurred when user cancels the Secured Store setup. |
To know more about exceptions and error codes handling, contact Zeta. |
|