Collect signals from a mobile app
This page provides hands-on tutorials that help you to integrate the Risk Management SDK in your mobile applications. Follow the tutorial's lessons to gradually build a fully functional mobile application.
There is a tutorial section for both the Android and iOS platforms. This is the first part of basic integration that describes the mandatory steps to integrate Risk Management, including project setup, SDK initialization, visitID, and signal collection management.
To get started with the tutorials, find the source code in the GitHub repository for each platform:
Organization of the source code
Each numbered lesson has starter code provided in a corresponding folder in the repository. For each lesson, follow the instructions to complete the source code.
The source code package for each subsequent lesson contains the completed implementation of the previous lesson, so that you can check your work.
The last source code folder in the repository contains a complete and fully functional application, which is similar to the application that you produce when you complete all the tutorial steps.
Tip
If you have an issue when you try to complete a lesson, feel free to skip to the next lesson and look at the completed implementation of the previous lesson.
Collect signals for Android
Perform the following tasks in sequential order to use Risk Management in the host application.
This tutorial includes the following tasks:
- Add risk Management dependencies to the project
- Add permissions
- Create configuration objects
- Certificate pinning
- Initialize Risk Management SDK
- Start prefetch signals
- Request the prefetch status
- Request and process visitID
- Clear transaction resources
- Stop prefetch signals
Add Risk Management dependencies to the project
Use the set of files in the package folder to perform the following steps:
-
Clone the github repository from https://github.com/gemalto/idcloud-fpp-tutorials-android.
-
Create a
libsfolder inidcloud-fpp-tutorials-android/01-ProjectSetup/app. -
Copy the debug version of Risk Management from the
external/debugpackage to the01-ProjectSetup/app/libs/debugfolder. -
Copy the release version of Risk Management from the
external/releasepackage to the01-ProjectSetup/app/libs/releasefolder. -
Copy all AAR files in 3pty and paste them in the
01-ProjectSetup/app/libs/3ptyfolder. -
Copy
proguard-project.txt(the Proguard configuration file) fromexternal/proguardto01-ProjectSetup/app. -
Add the native dependency in the
app/build.gradlefile.sourceSets { debug { jniLibs.srcDirs += ['libs/debug'] } release { jniLibs.srcDirs += ['libs/release'] } } -
Add all the library dependencies in the
app/build.gradlefile. Search forPLACEHOLDER - Jar + Aar Dependencyin 01-ProjectSetup App.dependencies { // Add Risk Management Platform java library releaseImplementation files('libs/release/GAHRiskEngine.jar') debugImplementation files('libs/debug/GAHRiskEngine.jar') // 3pty dependencies implementation fileTree(include: "*.aar", dir: "libs/3pty") // Add JNA dependency api 'net.java.dev.jna:jna:5.5.0@aar' }
Add permissions
To enable Risk Management to work properly, the following permissions are required in the manifest file:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
For details on the permissions needed for different signals, see Risk Management permissions.
Note
Follow the Android specific guidelines for handling risky permissions in and above Android version 6.0 Reference: https://developer.android.com/guide/topics/permissions/overview
Create configuration objects
There are different configuration objects to configure for Risk Management.
These two configuration objects are mandatory:
-
GAHCoreConfig: A mandatory configuration that initializes the core components of Risk Management. -
GAHGemaltoSignalConfig: A mandatory configuration that initializes all parameters related to Thales signals.
The remaining configurations are optional and used for proprietary signal groups.
-
GAHBSecConfigis specific to the proprietary signal groupBehavioSec. Use this configuration if you want to enable theBehavioSecgroup signal collection for the risk calculation. -
GAHTMXConfigis specific to the proprietary signal groupThreatMetrix. Use this configuration if you want to enable theThreatMetrixgroup signal collection for the risk calculation.
The following tables list the configurable parameters from the different configuration classes of Risk Management.
GAHCoreConfig object
| Configurable parameter | Description | Mandatory/Optional |
|---|---|---|
Application |
Application Instance | Mandatory |
Context |
Application context | Mandatory in deprecated API |
URL |
Risk Management back-end URL | Mandatory |
HttpConnectionTimeout |
HTTP connection timeout (seconds) for back-end communication. | Optional |
SignalCollectionGlobalTimeout |
Global timeout for Risk Management to collect all the signals | Optional |
SecureConnectionCertificates |
Certificate for secure communication with the Risk Management back end | Optional |
SecureConnectionPermits |
Permission for secure communication with the Risk Management back end | Optional |
SDKErrorListener |
Listener to determine the action when hooking is detected | Optional |
GAHGemaltoSignalConfig object
| Configurable parameter | Description | Mandatory/Optional |
|---|---|---|
CustomData |
Random byte array that is used as an extra factor for the computation of the device fingerprint | Optional |
LocationAllowedFreshTime |
This is the time allowed to consider cached location signals in milliseconds. If the location value timestamp is within this time frame, the value is used. The default is set to 900000 (15 minutes). | Optional |
LocationFetchTimeout |
This is the time allowed to get the location in milliseconds. If the system does not return the location within this timeout, the location signals are sent as status not found. The default value is set to 50 ms. | Optional |
SignalFetchTimeout |
This is the time allowed to get any signal in milliseconds. If the system does not return a signal within this timeout, the signal is sent as status Signal Timeout with the error code 524 in the signal JSON string. The default value is set to 2000 ms. This timeout is configurable by calling method setSignalCollectionGlobalTimeout(int timeout). |
Optional |
LocationBackgroundCollectionTime |
This is the time allowed to get the location when the application is in the background in milliseconds. The default value is set to 30000 ms. | Optional |
SignalPrefetchTime |
This is the maximum time allowed to prefetch signals and cache the values in seconds. GAHPrefetchStatusCallback is given to the application at the end of this timeout, with the success or failure status of the prefetch. The default value is set to 5 seconds. |
Optional |
SignalCacheTime |
This is the maximum time that prefetched signals are cached in seconds. Signal values older than this timeout are not considered during the risk calculation. The Risk Management SDK collects a fresh value during the very next call to requestVisitId() after the signal cache timeout. The default value is set to 300 seconds. |
Optional |
LocationAccuracy |
In metres, horizontal accuracy, radial with which location co-ordinates are collected. The default value is set to 100m. | Optional |
Builder design pattern
All the configuration classes follow the builder design pattern. Mandatory parameters must be passed to the constructor of the builder, and optional parameters must be set through setters. After all the parameters are set, call build(). Subsequently, the parameters are considered.
Note
Refer to your Thales representative on the following for your organization: * For ThreatMetrix: orgID
Caution
Without a Wi-Fi or data network, the SDK initialization cannot succeed. Signals such as ThreatMetrix can never be collected until the initialization is done again with the availability of the Internet.
Search for PLACEHOLDER - Configuration in placeholder for configuration in Sample App
// Setup core config, set other optional parameters, if required
GAHCoreConfig coreConfig = new GAHCoreConfig.Builder(getApplicationContext(), riskEngineUrl)
.build();
//Setup Signal config, set other optional parameters, if required
GAHGemaltoSignalConfig signalConfig = new GAHGemaltoSignalConfig.Builder()
.build();
Certificate pinning
Certificate pinning is used to check that the risk engine back-end server’s certificate matches a known copy of that certificate at the application.
To use certificate pinning, the application sends the array of X509Certificate to Risk Management’s GAHCoreConfig and sends the GAHCoreConfig object to initialize().
You can also configure the TLS connection settings. Risk Management takes care of the default configurations if this is not set from the application.
//Add the certificates to GAHCoreConfig and pass to initialize
* Set certificate array to GAH Core config */
final X509Certificate[] certificates = new X509Certificate[2];
certificates[0] = AppUtils.getCertificate(this, R.raw.digital_cloud_cert_parent_der);
certificates[1] = AppUtils.getCertificate(this, R.raw.digital_cloud_cert_child_der);
coreConfigBuilder = coreConfigBuilder.setSecureConnectionCertificates(certificates);
if (BuildConfig.DEBUG)
{
coreConfigBuilder = coreConfigBuilder.setSecureConnectionPermits(new GAHCoreConfig
.Permit[]{GAHCoreConfig.Permit.INSECURE_COMMUNICATIONS});
}
Note
-
Certificate pinning is mandatory for the Release variant of the SDK, and is optional for the Debug variant.
-
It is not recommended to override the connection settings, or the attributes and parameters in a production environment. Allowing self-signed and host mismatch configurations reduces the security of the communication link with the server. Insecure connections are not permitted in the Release mode.
The following code snippet shows how to get a certificate in the X509Certificate format. It is assumed that the certificate file is placed in the res/raw folder:
public static X509Certificate getCertificate(Context context, int resId)
{
X509Certificate certificate = null;
InputStream caInput = null;
try {
final CertificateFactory factory = CertificateFactory.getInstance("X.509");
caInput = new BufferedInputStream(context.getResources().openRawResource(resId));
certificate = (X509Certificate) factory.generateCertificate(caInput);
Log.i(TAG, "ca=" + (certificate).getSubjectDN());
} catch (final CertificateException exception) {
Log.e(TAG, exception.getMessage());
}
finally {
if (caInput != null) {
try {
caInput.close();
} catch (IOException ex) {
Log.e(TAG, ex.getMessage());
}
}
}
return certificate;
}
Initialize the Risk Management SDK
Initialize the SDK by passing the mandatory GAHCoreConfig, GAHGemaltoSignalConfig configurations and optionals GAHTMXConfig, GAHBSecConfig configuration. If GAHTMXConfig and GAHBSecConfig are not set, these signal groups are not initiated, and no signal collection is made under them.
During the initialization, the Risk Management SDK internally performs the initialization and signal collection of proprietary SDKs such as ThreatMetrix. When the corresponding initialization and registration are successful, the proprietary SDK signals are collected and stored in cache until SignalCacheTime (configurable parameter in GAHGemaltoSignalConfig), so that these signals are readily available during the next events, such as Login and Add beneficiary.
Note
-
Initialization and signal collection of proprietary groups are time-consuming. Signal collection completion can be verified using the
requestPrefetchStatusAPI explained in start prefetch signals. -
Initialization of the SDK is a one-time process for an app cycle.
-
A
RuntimeExceptionis thrown if the mandatory configurations required forGAHCoreConfigandGAHGemaltoSignalConfigare not passed to theinitialize()method. If the optional configuration is not sent, the SDK assumes that the features are not needed by the application and subsequent use of the feature causes exceptions or errors.
Search for PLACEHOLDER - initialization in the placeholder for initialization in the sample app.
// Pass configuration to core.
GAHCore.initialize(coreConfig, signalConfig);
Start prefetch signals
Prefetching signals means collecting and storing the signal values in the cache for SignalCacheTime (configurable parameter in GAHGemaltoSignalConfig), so that collection time is reduced during the actual transaction action.
This method can either be called from the UI or from a non-UI thread. Basically, signals, which are time-consuming to collect, are identified and prefetched.
Note
No API call to the Risk Management back end is made during the execution of prefetching the signals.
Currently, prefetching collects and caches a few of the signals such as:
- Location signals: Sends a request to the operating system to get the latest location coordinates.
- ThreatMetrix signal: Sends a request to TMX SDK for a new sessionID.
It is recommended to call this method during the launch of a screen containing a transaction event such as Login or Add Beneficiary, so that signals are cached at an early stage before the actual transaction is made.
Caution
-
If the signal values present in the cache are older than
SignalCacheTime, the signals are not considered as part of the request to the Risk Management back end. Instead they are discarded and a request is made to collect the new values. -
The same signal collection and caching process is done for
ThreatMetrixsignal groups during Risk Management initialization. If this needs to be done in some screen later after the initialization, the Prefetch API can be called. Prefetching first checks if a valid signal is already present in the cache before actually collecting the signals.
Search for PLACEHOLDER - Prefetch in the placeholder for prefetch in the sample app.
// Start Signal prefetch
GAHCore.startPrefetchSignals();
Request the prefetch status
Ensure that the signals mentioned in the initialize the Risk Management SDK task (Location, ThreatMetrix) are collected and cached before requesting the visitID from Risk Management.
This can be ensured by requesting for a status callback using the requestPrefetchStatus() method. Callback is invoked at the end of SignalPrefetchTime (configurable in GAHGemaltoSignalConfig class). The error status is received from the callback if all signals are not collected and cached within SignalPrefetchTime.
Note
It is not recommended for the application to perform any transaction, such as login or fund transfer, before signal collection is completed and the statusCode is returned as GAHErrorCodes: .PREFETCH_STATUS_OK.
Risk Management has an internal default timeout of 5 seconds (configurable).
- If all signals are collected, then the status is set as
GAHErrorCodes.PREFETCH_STATUS_OK. - If any of the signals cannot be collected, then the status is
GAHErrorCodes.PREFETCH_STATUS_PARTIAL_OK. - If no signal is collected, then status is set as
GAHErrorCodes.PREFETCH_STATUS_FAILURE.
Failure and partial_ok status can occur due to various reasons, such as:
- Network latency
- Runtime permission is not granted
- GPS feature is not enabled
Ensure all integration steps are followed and the device is connected to the internet with feasible speed to avoid the erroneous condition.
Note
This method waits for SignalPrefetchTime (configurable in GAHGemaltoSignalConfig) to get any signals before invoking the callback, in case the signals are not ready and present in the cache.
If the signal does not have a value in the cache or if it cannot be collected in SignalPrefetchTime, then a callback error is invoked.
Search for PLACEHOLDER - Prefetch Status in the placeholder for the prefetch status check in the sample app.
// Listen to prefetch status
GAHCore.requestPrefetchStatus(this.processPrefetchStatusResponse);
Request and process the visitID
The application requests the visitID from the Risk Management SDK. This visitID can be forwarded by the application back end to the Risk Management back end to receive the decision based on the risk calculated from various signals that are collected by the Risk Management SDK.
Internally, this method fetches all the requested signal values as configured during initialization, then sends the signal JSON to the Risk Management back end and gets the visitID that corresponds to the set of signals present in the request JSON.
The signals mentioned in the initialize the Risk Management SDK task are taken from the cache, and all other signals are collected freshly every time the requestVisitID() call is made.
If the cached signal timestamp is older than SignalCacheTime, the signals cache is discarded and a request is made to collect the new values.
As a new request to collect the signal to be cached is time-consuming, it is recommended to call the prefetch function to ensure that signals are cached before making the call to requestVisitID().
To get the visitID, the application must call the requestVisitID method. Internally, this method runs on a separate worker thread.
The GAHResponseCallback interface is used to get the result from Risk Management:
-
If Risk Management successfully fetches the
visitID, the application gets the callback in thesuccessmethod with thevisitID. -
If Risk Management fails to get the
visitID, it returns the error code and error message in theerrorcallback method.
The requestVisitID method is called to decide the next step of every event, such as:
- Login
- Add beneficiary
- Fund transfer
Search for PLACEHOLDER - Request Visit Id in the sample app.
// Make sure that we have all signals prefetched.
if (statusCode == GAHErrorCodes.PREFETCH_STATUS_OK) {
// With all signals in place. Request Visit ID.
GAHCore.requestVisitID(new GAHResponseCallback() {
@Override
public void success(String visitID) {
processVisitIDResponse(true, visitID);
}
@Override
public void error(int statusCode, String statusMsg) {
processVisitIDResponse(false, statusMsg);
}
});
}
Clear transaction resources
This method is called after every transaction to clear the transaction resources used in Risk Management.
A transaction may be an action in the application such as Login or Add beneficiary.
Note
If the BehavioSec signal group is initialized, this method must be called from a UI thread, which clears some of the information pertaining to UI elements.
Search for PLACEHOLDER - Clear Transaction Resources in the placeholder for clearing transaction resources in the sample app.
// Clear transaction resources
GAHCore.clearTransactionResources();
Stop prefetch signals
Stopping the prefetching of signals results in the termination of the background process of storing values in the cache.
This method can either be called from the UI (main) or a non-UI (background) thread.
Note
It is recommended to call this method during a transaction screen exit where startPrefetchSignals() was previously called.
Search for PLACEHOLDER - Stop Prefetch in the placeholder for stopping prefetch in the sample app.
//Stop signal Prefetch
GAHCore.stopPrefetchSignals();
Collect signals for iOS
Perform the following tasks in sequential order to use the Risk Management in the host application.
This tutorial includes the following tasks:
- Add Risk Management and TrustDefender dependencies to your project
- Add permissions
- Create configuration objects
- Certificate pinning
- Initialize the Risk Management SDK
- Start prefetch signals
- Request the prefetch status
- Request and process the visitID
- Clear transaction resources
- Stop prefetch signals
Add Risk Management and TrustDefender dependencies to your project
A set of files are stored in the package folder for you to perform the following steps:
-
Clone the github repository from https://github.com/gemalto/idcloud-fpp-tutorials-ios and name the project
Risk Management Demo. -
Create a
Frameworksfolder inRisk Management Demo. -
Copy the Debug version of
GAHRiskEngine.xcframeworkfrom theexternal/Debugpackage to theFrameworks/GAHRiskEngine/Debugfolder.
-
Copy the Release version of
GAHRiskEngine.xcframeworkfrom theexternal/Releasepackage to theFrameworks/GAHRiskEngine/Releasefolder.
-
Copy
TrustDefender.frameworkfrom the package path3ptyto theFrameworks/TrustDefenderfolder.
-
Open the
Risk Management Demo/ObjectiveC/01-ProjectSetup/01-ProjectSetup.xcodeproj. Drag the entire new Frameworks folder and drop it in the Xcode project.
-
From the pop-up window, clear the Copy items if needed box, and then select Create Groups and your application target.

The final project structure is as follows:

-
In Build Settings > Search Paths > Framework Search Paths, update the framework search paths based on the build configuration from the respective folders of the frameworks, so that the debug and release versions of the app use the correct binaries.



//:configuration = Debug FRAMEWORK_SEARCH_PATHS = $(inherited) "$(SRCROOT)/../../Frameworks/GAHRiskEngine/Debug/GAHRiskEngine.xcframework" "$(SRCROOT)/../../Frameworks/TrustDefender/TrustDefender.framework" //:configuration = Release FRAMEWORK_SEARCH_PATHS = $(inherited) "$(SRCROOT)/../../Frameworks/GAHRiskEngine/Release/GAHRiskEngine.xcframework" "$(SRCROOT)/../../Frameworks/TrustDefender/TrustDefender.framework" -
Set
TrustDefender.frameworkas the embedded frameworks:- In Xcode 10.4 and earlier, add the TrustDefender framework to the General > Embedded Binaries tab.
- In Xcode 11, set the TrustDefender framework from
Do not EmbedtoEmbed & Signin General > Frameworks, Libraries and Embedded Content.


-
Make sure
GAHRiskEngine.xcframeworkas theDo Not Embedframeworks:- In Xcode 10.4 and earlier, add the
GAHRiskEnginexcframework to the General > Embedded Binaries tab. - In Xcode 11, set the
GAHRiskEnginexcframework fromDo Not Embedin General > Frameworks, Libraries and Embedded Content.

- In Xcode 10.4 and earlier, add the
-
Remove unwanted architectures from the TrustDefender framework:
-
TrustDefender.frameworkBy default, the
TrustDefender.frameworkembedded in the application contains all the architectures:-
For Device: arm64, armv7
-
For Simulator: i386, x86>
Since simulator architectures are not necessary when building the device, these architectures can be removed.
-
-
Load
Strip_Unused_Architectures.shto the Xcode project using the following steps:-
Drag the
Strip_Unused_Architectures.shfile from the deliverable packageexample/objcand drop it in the Xcode project.
-
In the Build Phases tab, add a new
New Run Script Phaseand add this script to the console:/bin/sh Strip_Unused_Architectures.sh

-
Before you can build and run the project, verify that the simulator architectures are removed and the TrustDefender framework is in your final
.appfile in{ProductName}.app/Frameworks/TrustDefender.framework/TrustDefenderRun the LIPO command via a terminal and observe the required architectures:
$ lipo -info {ProductName}.app/Frameworks/TrustDefender.framework/TrustDefenderOutput:
Architectures in the fat file
{ProductName}.app/Frameworks/TrustDefender.framework/TrustDefenderare: arm64
-
-
-
To update the linker flags, add the link flag from Build Settings > Other Linker Flags.

Where:
OTHER_LDFLAGS = -lc++ -all_load -ObjC -
Disable the bitcode. Because Risk Management does not support bitcode, a compilation error is generated when the application tries to use it.

Where:
ENABLE_BITCODE = NO -
Set the Strip Style to
Non-Global SymbolsorAll Symbolsso that all internal symbols or all symbols are removed to reduce symbol visibility. This is shown in the following figure:
Where:
STRIP_STYLE = all -
Set the valid architectures. Risk Management supports only arm64 architectures (see Risk Management variants), therefore a compilation error is generated when the application is built for armv7 architecture.

Where:
VALID_ARCHS = arm64 arm64e -
Enable the Wi-Fi access capability settings for the application in Xcode, to get the network information for a specific network interface. If the device uses Wi-Fi, it requires the Access WiFi Information capability to get the Wi-Fi information.

Note
This setting is only available for Xcode version 10 and later.
Add permissions
Add the required permissions in the Info.plist project file to allow Risk Management to collect all the signals.
For details on the permissions needed for different signals, see Risk Management permissions.
-
Select
Info.plistfrom the application and click Add, -
Select the required option from the list.
Key Description iOS version NSLocationAlwaysUsageDescriptionSpecifies the reason for your app to access the user’s location information at all times. 8.0+ NSLocationWhenInUseUsageDescriptionSpecifies the reason for your app to access the user’s location information while your app is in use. 8.0+ NSLocationAlwaysAndWhenInUseUsageDescriptionSpecifies the reason for your app to access the user’s location information at all times and supports iOS 11 and later. 11.0+
Note
For the iOS guidelines on handling the required permissions in iOS version 9.0 and later, see https://developer.apple.com/documentation/bundleresources/entitlements.
The code snippet for displaying the location permission pop-up window is as follows:
Code placeholder for permissions
/* This triggers the popup to give permission to access location while using the app
Location is one of the signal category which is collected and used for risk calcualation
*/
- (void)getUserAccessPermissionToUseLocationService{
self.locationManager = [CLLocationManager new];
[_locationManager setDelegate:self];
[_locationManager requestWhenInUseAuthorization];
}
/* This triggers the popup to give permission to access location
while using the app Location is one of the signal category which
is collected and used for risk calcualation
*/
func getUserAccessPermissionToUseLocationService() {
self.locationManager = CLLocationManager.init()
self.locationManager!.delegate = self
self.locationManager!.requestWhenInUseAuthorization()
}
Note
To provide location services in the background, use the locationManager requestAlwaysAuthorization API.
Create configuration objects
There are different configuration objects to be configured for Risk Management.
These two configuration objects are mandatory:
-
GAHCoreConfig: This mandatory configuration is used to initialize the core components of Risk Management. -
GAHGemaltoSignalConfig: This mandatory configuration is used to initialize all parameters related to Thales signals.
The remaining configurations are optional and are used for proprietary signal groups:
-
GAHBSecConfig: This configuration is specific to the proprietary signal group BehavioSec. Use this configuration if you want to enable the BehavioSec group signal collection for the risk calculation. -
GAHTMXConfig: This configuration is specific to the proprietary signal group ThreatMetrix. Use this configuration if you want to enable the ThreatMetrix group signal collection for the risk calculation.
The following tables list the configurable parameters from the different configuration classes of Risk Management.
GAHCoreConfig object
| Configurable parameter | Description | Mandatory |
|---|---|---|
Application (Applicable to Android only) |
Application Instance | Mandatory |
Context (Applicable to Android only) |
Application context | Mandatory in deprecated API |
URL |
Risk Management backend URL | Mandatory |
HttpConnectionTimeout |
HTTP connection timeout (seconds) for back-end communication | Optional |
SignalCollectionGlobalTimeout |
Global timeout for Risk Management to collect all the signals | Optional |
SecureConnectionCertificates |
Certificate for secure communication with the Risk Management back end | Optional |
SecureConnectionPermits |
Permission for secure communication with the Risk Management back end | Optional |
SDKErrorListener |
Listener to determine the action when hooking is detected | Optional |
GAHGemaltoSignalConfig object
| Configurable parameter | Description | Mandatory/Optional |
|---|---|---|
CustomData |
This random byte array is used as an extra factor for the computation of the device fingerprint. | Optional |
| LocationAllowedFreshTime | This is the time allowed to consider cached location signals, in milliseconds. If the location value timestamp is within this time frame, the value is used. The default is set to 900000 (15 mins). | Optional |
LocationFetchTimeout |
This is the time allowed to get the location in milliseconds. If the system does not return the location within this timeout, the location signals are sent as status not found. The default value is set to 50 ms. |
Optional |
SignalFetchTimeout |
This is the time allowed to get any signal, in milliseconds. If the system does not return a signal within this timeout, the signal is sent as the status Timeout. The default value is set to 2000 ms. |
Optional |
LocationBackgroundCollectionTime |
This is the time allowed to get the location when the application is at the background, in milliseconds. The default value is set to 30000 ms. | Optional |
SignalPrefetchTime |
This is the maximum time allowed to prefetch signals and cache the values, in seconds. GAHPrefetchStatusCallback is given to the application at the end of this timeout, with the success or failure status of the prefetch. The default value is set to 5 seconds. |
Optional |
SignalCacheTime |
This is the maximum time that prefetched signals are cached, in seconds. Signal values older than this timeout are not considered during risk calculation. The Risk Management SDK collects a fresh value during very the next call to requestVisitId() after a signal cache timeout. The default value is set to 300 seconds. |
Optional |
LocationAccuracy |
Android only. In meters, Horizontal accuracy, radial with which location co-ordinates are collected. The default value is set to 100 m. | Optional |
Note
Refer to your Thales representative on the following for your organization:
- ThreatMetrix: orgID
Caution
Without a Wi-Fi or data network, the SDK initialization cannot be successful and signals such as ThreatMetrix can never be collected until the initialization is done again with the availability of the Internet.
// Setup core config, set other optional params, if required
GAHCoreConfig *coreConfig = [GAHCoreConfig sharedConfigurationWithUrl:kRiskEngineURL];
// Gemalto Signal collection is mandatory.
GAHGemaltoSignalConfig *signalConfig = [GAHGemaltoSignalConfig sharedConfiguration];
// Setup core config, set other optional params, if required
let coreConfig = GAHCoreConfig.sharedConfiguration(withUrl: riskEngineURL)!
// Gemalto Signal collection is mandatory.
let signalConfig = GAHGemaltoSignalConfig.sharedConfiguration()!
Certificate pinning
Certificate pinning is used to check that the risk engine back-end server’s certificate matches a known copy of that certificate at the application.
To use certificate pinning, the application sends the X509Certificate array to Risk Management’s GAHCoreConfig and sends the GAHCoreConfig object to initialize().
You can also configure the TLS connection settings. Risk Management takes care of the default configurations if this is not set from the application.
Note
-
Certificate pinning is mandatory for the Release variant of the SDK. It is optional for the Debug variant.
-
It is not recommended to override the connection settings or attributes or parameters in a production environment. Allowing self-signed and host mismatch configurations reduces the security of the communication link with the server. Insecure connections are not permitted in the Release mode.
Code placeholder for configuration
/* Set certificate array to GAH Core config */
GAHCoreConfig *reConfig = [GAHCoreConfig getsharedConfigManagerObject];
GAHTLSConfiguration *tlsConfiguration = [GAHTLSConfiguration new];
#ifdef DEBUG
[tlsConfiguration setHostnameMismatchAllowed:YES];
[tlsConfiguration setSelfSignedCertAllowed:YES];
[tlsConfiguration setInsecureConnectionAllowed:YES];
#else
[tlsConfiguration setSelfSignedCertAllowed:YES];
#endif
NSString *pathToCert = [[NSBundle mainBundle]pathForResource:@"Thales_eziocloud" ofType:@"cer"];
NSData *localValidCertificate = [NSData dataWithContentsOfFile:pathToCert];
[reConfig GRESTLSConfiguration:@[localValidCertificate] withRESDKTLSConfiguration:tlsConfiguration];
/* Set certificate array to GAH Core config */
let reConfig:GAHCoreConfig = GAHCoreConfig.getsharedConfigManagerObject()
var tlsconfiguration:GAHTLSConfiguration = GAHTLSConfiguration.init()
#if DEBUG
tlsconfiguration.hostnameMismatchAllowed = true
tlsconfiguration.selfSignedCertAllowed = true
tlsconfiguration.insecureConnectionAllowed = true
#else
tlsconfiguration.selfSignedCertAllowed = true
#endif
let pathToCert = Bundle.main.path(forResource: "Thales_eziocloud", ofType: "cer")
let localValidCertificate = NSData.init(contentsOfFile: pathToCert!)
reConfig.grestlsConfiguration([localValidCertificate!] as [Any], withRESDKTLSConfiguration: tlsconfiguration)
For details on the ATS setup required for certificate pinning, see the app transport configuration.
Initialize the Risk Management SDK
To initialize the SDK, pass the GAHCoreConfig, GAHSignalConfig mandatory configurations and GAHTMXConfig and GAHBSecConfig optional configurations. If GAHTMXConfig and GAHBSecConfig are not set, these signal groups are not initiated, and no signal collection is made under them.
During initialization, the Risk Management SDK internally performs the initialization and signal collection of proprietary SDKs, such as ThreatMetrix.
When the corresponding initialization and registration are successful, the proprietary SDK signals are collected and stored in the cache until the SignalCacheTime (a configurable parameter in GAHGemaltoSignalConfig), so that these signals are readily available in the next events, such as Login and Add beneficiary.
Note
-
Initialization and signal collection of proprietary groups are time-consuming. To verify signal collection completion, use the
requestPrefetchStatusAPI, as explained in the start prefetch signals task. -
Initialization of the SDK is a one-time process for an app cycle.
-
A
RuntimeExceptionis thrown if the mandatory configurations required forGAHCoreConfigandGAHGemaltoSignalConfigare not passed to theinitialize()method. If the optional configuration is not sent, the SDK assumes that the features are not needed by the application and subsequent use of the feature causes exceptions or errors.
Code placeholder for initialization
// Pass configuration to core.
[GAHCore initialize:[NSSet setWithObjects:coreConfig, signalConfig, nil]];
// Pass configuration to core.
GAHCore.initialize([coreConfig, signalConfig])
Start prefetch signals
Prefetching signals means collecting and storing signal values in the cache for the SignalCacheTime (a configurable parameter in GAHGemaltoSignalConfig), so that the collection time is reduced during the actual transaction action.
This method can either be called from the UI or from a non-UI thread. Signals that are time-consuming to collect are identified and prefetched.
Note
No API call to the Risk Management back end is made during the execution of prefetching the signals.
Currently, prefetching collects and caches a few of the signals, such as:
-
Location signals: Sends a request to the operating system to get the latest location coordinates.
-
Browser signal (iOS only): Sends a request to the operating system to get the browser agent string.
-
ThreatMetrix signal: Sends a request to the TMX SDK for a new sessionID.
It is recommended to call this method during the launch of a screen containing a transaction event, such as Login and Add beneficiary, so that signals are cached at an early stage before the actual transaction is made.
Caution
-
If the signal values present in the cache are older than
SignalCacheTime, the signals are not considered as part of the request to the Risk Management back end. Instead they are discarded and a request is made to collect the new values. -
The same signal collection and caching process is done for
ThreatMetrixsignal groups during Risk Management initialization. But if this needs to be done in some screen later after the initialization, the Prefetch API can be called. Prefetching first checks whether a valid signal is already present in the cache before actually collecting the signals.
Code placeholder for prefetch
// Start Signal prefetch
[GAHCore startPrefetchSignals];
// Start Signal prefetch
GAHCore.startPrefetchSignals()
Request the prefetch status
Ensure that the signals mentioned in the initialize the Risk Management SDK task (Location, Browser, ThreatMetrix) are collected and cached before requesting the visitID from Risk Management.
This can be ensured by requesting for a status callback using the requestPrefetchStatus() method. Callback is invoked at the end of the SignalPrefetchTime (configurable in the GAHGemaltoSignalConfig class). The error status is received from the callback if all signals are not collected and cached within the SignalPrefetchTime.
Note
It is not recommended for the application to perform any transaction such as login before signal collection is completed and the statusCode is returned as GAHErrorCodes:.PREFETCH_STATUS_OK``.
Risk Management has an internal default timeout of five seconds (configurable).
- If all signals are collected then the status is
GAHErrorCodes.PREFETCH_STATUS_OK. - If any of the signals could not be collected then the status is
GAHErrorCodes.PREFETCH_STATUS_PARTIAL_OK. - If no signal was collected then the status is
GAHErrorCodes.PREFETCH_STATUS_FAILURE.
Failure and partial_ok status can occur due to various reasons, such as:
- Network latency
- Runtime permission is not granted
- GPS feature is not enabled
Ensure that all the integration steps are followed and the device is connected to the internet with reasonable speed to avoid the erroneous condition.
Note
This method wait for SignalPrefetchTime (configurable in GAHGemaltoSignalConfig) to get any signals before invoking the callback, in case the signals are not ready and present in the cache.
Code placeholder for prefetch status
// Listen to prefetch status
[GAHCore requestPrefetchStatus:^(NSInteger statusCode, NSString *statusMessage) {
[self processPrefetchStatusResponse:statusCode statusMessage:statusMessage];
}];
// Listen to prefetch status
GAHCore.requestPrefetchStatus { (statusCode: Int, statusMessage: String?) in
self.processPrefetchStatusResponse(statusCode, statusMessage)
}
Request and process the visitID
The application requests the visitID from the Risk Management SDK. The application back end forwards this visitID to the Risk Management back end to receive the decision based on the risk calculated from various signals that the Risk Management SDK collects.
Internally, this method fetches all the requested signal values as configured during initialization, sends the signal JSON to the Risk Management back end, and gets the visitID corresponding to the set of signals present in the JSON request.
The signals mentioned in the initialize the Risk Management SDK task are taken from the cache and all other signals are collected freshly every time the requestVisitID() call is made.
If the cached signal timestamp is older than SignalCacheTime, the signals cache is discarded and a request is made to collect the new values.
Because a new request to collect the signal to be cached is time-consuming, it is recommended to call the Prefetch function to ensure that signals are cached before making the call to requestVisitID().
To get the visitID, the application must call the requestVisitID method. Internally, this method runs on a separate worker thread.
The GAHResponseCallback interface is used to get the result from Risk Management.
-
If Risk Management successfully fetches the
visitID, the application gets the callback in thesuccessmethod with thevisitID. -
If Risk Management fails to get the
visitID, it returns the error code and error message in theerrorcallback method.
The requestVisitID method is called to decide the next step of every event such as Login or Add beneficiary.
Code placeholder for request visit ID
// Make sure that we have all signals prefetched.
if (statusCode == PREFETCH_STATUS_OK) {
// With all signals in place. Request Visit ID.
[GAHCore requestVisitID:^(NSString *visitID) {
[self processVisitIDResponse:YES value:visitID];
} failure:^(NSInteger errorCode, NSString *errorMessage) {
[self processVisitIDResponse:NO value:errorMessage];
}];
}
// Make sure that we have all signals prefetched.
if (statusCode == PREFETCH_STATUS_OK) {
// With all signals in place. Request Visit ID.
GAHCore.requestVisitID({ (visitId: String?) in
self.processVisitIDResponse(true, visitId)
}) { (errorCode: Int, errorMessage: String?) in
self.processVisitIDResponse(false, errorMessage)
}
}
Clear transaction resources
This method is called after every transaction to clear the transaction resources used in Risk Management.
A transaction can be an action in the application such as Login or Add beneficiary.
Note
If the BehavioSec signal group is initialized, this method must be called from the UI thread, which clears some of the information pertaining to UI elements.
Code placeholder for clear transaction resources
//Clear transaction resources
[GAHCore clearTransactionResources];
//Clear transaction resources
GAHCore.clearTransactionResources()
Stop prefetch signals
Stopping the prefetching signals results in the termination of the background process of storing values in the cache.
This method can either be called from a UI (main) or non-UI (background) thread.
Note
It is recommended to call this method during a transaction screen exit where startPrefetchSignals() was previously called.
Code placeholder for stop prefetch
//Stop signal Prefetch
[GAHCore stopPrefetchSignals];
//Stop signal Prefetch
GAHCore.stopPrefetchSignals()