SDK Configuration
The overall SDK interfaces may be accessed as follows:
- Java
- Objective-C
- Swift
import com.criticalblue.approovsdk.Approov;
#import <Approov/Approov.h>
import Approov
Note that the iOS SDK is actually written in Objective-C and the method references are described in this way. Other code examples in the documentation are in Swift, using the automatically generated bindings to the SDK methods.
Initialization
- Java
- Objective-C
- Swift
/**
* Initialize the Approov SDK. This must be called prior to any other methods on the Approov
* SDK. The SDK is initialized with an application context, an initial configuration, an optional
* update configuration, and a comment. The initial configuration is either a short initialization
* string or a signed JWT token string that is obtained from the Approov CLI tool and contains all
* the necessary parameters to initialize the SDK. An updated configuration may be transmitted
* while the SDK is in use and this must be stored in the local storage of the app. If the string
* "auto" is provided as the update configuration parameter then the SDK will manage its own update
* configuration storage. If the comment parameter starts with "options:" then options can be
* provided to the initialization. Typically the SDK can only be initialized once, although
* subsequent calls with exactly the same parameters are ignored (with a return value of false
* indicating that no change was made). If the comment starts with "reinit" then this allows the
* SDK to be reinitialized with a different account.
*
* Calling this method may cause an asynchronous background fetch to be initiated. If the app
* has been previously launched then this may perform a full resumption to fetch Approov tokens and
* secure strings to minimize the latency when an explicit fetch is subsequently made. Otherwise
* a fetch is only made if the InitFetch SDK configuration option has been enabled for the account.
*
* @param appContext is the application context to use
* @param initialConfig is the initial configuration short init string or JWT and must be present
* @param updateConfig is any update configuration JWT, "auto" or null if there is none
* @param comment is an optional comment that may provide initialization/reinitialization options,
* or null otherwise
* @return true if the SDK was initialized, false if it didn't need to be because it was already
* initialized with the same parameters
* @throws IllegalArgumentException if provided configuration is not valid
*/
public static boolean initialize(Context appContext, String initialConfig, String updateConfig, String comment) throws IllegalArgumentException;
/**
* Initialize the Approov SDK. This must be called prior to any other methods on the Approov
* SDK. The SDK is initialized with an initial configuration, an optional update configuration
* and a comment. The initial configuration is either a short initialization string or a signed JWT
* token string that is obtained from the Approov CLI tool and contains all necessary parameters to
* initialize the SDK. An updated configuration may be transmitted while the SDK is in use and this
* must be stored in the local storage of the app. If the string "auto" is provided as the update
* configuration parameter then the SDK will manage its own update configuration storage. If the
* comment parameter starts with "options:" then options can be provided to the initialization.
* Typically the SDK can only be initialized once, although subsequent calls with exactly the same
* parameters are ignored (with a return value of NO indicating that no change was made) and do not
* generate an error. If the comment starts with "reinit" then this allows the SDK to be
* reinitialized with a different account.
*
* Calling this method may cause an asynchronous background fetch to be initiated. If the app
* has been previously launched then this may perform a full resumption to fetch Approov tokens and
* secure strings to minimize the latency when an explicit fetch is subsequently made. Otherwise
* a fetch is only made if the InitFetch SDK configuration option has been enabled for the account.
*
* @param initialConfig is the initial configuration which is either a short init string or full
* JWT and must be present
* @param updateConfig is any update configuration JWT, "auto" or nil if there is none
* @param comment is an optional comment that may provide initialization/reinitialization options,
* or nil otherwise
* @param error the reference to an error object which will be set if an error occurred
* @return YES if the Approov framework was successfully initialized or NO if there was an error or
* if the SDK didn't need to be initialized because it was previously initialized with the same
* parameters
*/
+ (BOOL)initialize:(nonnull NSString *)initialConfig updateConfig:(nullable NSString *)updateConfig
comment:(nullable NSString * )comment error:(NSError *_Nullable *_Nullable)error;
/**
* Initialize the Approov SDK. This must be called prior to any other methods on the Approov
* SDK. The SDK is initialized with an initial configuration, an optional update configuration
* and a comment. The initial configuration is either a short initialization string or a signed JWT
* token string that is obtained from the Approov CLI tool and contains all necessary parameters to
* initialize the SDK. An updated configuration may be transmitted while the SDK is in use and this
* must be stored in the local storage of the app. If the string "auto" is provided as the update
* configuration parameter then the SDK will manage its own update configuration storage. If the
* comment parameter starts with "options:" then options can be provided to the initialization.
* Typically the SDK can only be initialized once, although subsequent calls with exactly the same
* parameters are ignored (with a return value of NO indicating that no change was made) and do not
* generate an error. If the comment starts with "reinit" then this allows the SDK to be
* reinitialized with a different account.
*
* Calling this method may cause an asynchronous background fetch to be initiated. If the app
* has been previously launched then this may perform a full resumption to fetch Approov tokens and
* secure strings to minimize the latency when an explicit fetch is subsequently made. Otherwise
* a fetch is only made if the InitFetch SDK configuration option has been enabled for the account.
*
* @param initialConfig is the initial configuration which is either a short init string or full
* JWT and must be present
* @param updateConfig is any update configuration JWT, "auto" or nil if there is none
* @param comment is an optional comment that may provide initialization/reinitialization options,
* or nil otherwise
* @param error the reference to an error object which will be set if an error occurred
* @return YES if the Approov framework was successfully initialized or NO if there was an error or
* if the SDK didn't need to be initialized because it was previously initialized with the same
* parameters
*/
class func initialize(_ initialConfig: String, updateConfig: String?, comment: String?) throws
Configuration Fetching
- Java
- Objective-C
- Swift
/**
* Fetches the current configuration for the SDK. This may be the initial configuration or may
* be a new updated configuration returned from the Approov cloud service. Such updates of the
* configuration allow new sets of certificate pins and other configuration to be passed to
* an app instance that is running in the field.
*
* Normally this method returns immediately with the latest configuration that is cached in the
* SDK. However, if the configuration has not been refreshed at all from the Approov server since
* the app started, then there will be a short blocking delay as an attempt will be made to fetch
* the latest configuration from the Approov servers.
*
* Note that the returned configuration should generally be kept in local storage for the app
* so that it can be made available on initialization of the Approov SDK next time the app
* is started.
*
* It is possible to see if a new configuration becomes available from the isConfigChanged()
* method of the TokenFetchResult. This changed flag is only cleared for future token fetches
* if a call to this method is made.
*
* @return String representation of the configuration
*/
public static final String fetchConfig();
/**
* Fetches the current configuration for the SDK. This may be the initial configuration or may
* be a new updated configuration returned from the Approov cloud service. Such updates of the
* configuration allow new sets of certificate pins and other configuration to be passed to
* an app instance that is running in the field.
*
* Normally this method returns immediately with the latest configuration that is cached in the
* SDK. However, if the configuration has not been refreshed at all from the Approov server since
* the app started, then there will be a short blocking delay as an attempt will be made to fetch
* the latest configuration from the Approov servers.
*
* Note that the returned configuration should generally be kept in local storage for the app
* so that it can be made available on initialization of the Approov SDK next time the app
* is started.
*
* It is possible to see if a new configuration becomes available from the isConfigChanged
* property of the TokenFetchResult. This changed flag is only cleared for future token fetches
* if a call to this method is made.
*
* @return String representation of the configuration or nil if SDK not initialized
*/
+ (nullable NSString *)fetchConfig;
/**
* Fetches the current configuration for the SDK. This may be the initial configuration or may
* be a new updated configuration returned from the Approov cloud service. Such updates of the
* configuration allow new sets of certificate pins and other configuration to be passed to
* an app instance that is running in the field.
*
* Normally this method returns immediately with the latest configuration that is cached in the
* SDK. However, if the configuration has not been refreshed at all from the Approov server since
* the app started, then there will be a short blocking delay as an attempt will be made to fetch
* the latest configuration from the Approov servers.
*
* Note that the returned configuration should generally be kept in local storage for the app
* so that it can be made available on initialization of the Approov SDK next time the app
* is started.
*
* It is possible to see if a new configuration becomes available from the isConfigChanged
* property of the TokenFetchResult. This changed flag is only cleared for future token fetches
* if a call to this method is made.
*
* @return String representation of the configuration or nil if SDK not initialized
*/
class func fetchConfig() -> String?
Pins Extraction
- Java
- Objective-C
- Swift
/**
* Fetches the pins from the current configuration of the SDK. This is returned as
* as map from URL domain (hostname only) to the possible pins for that domain. If there is
* no map entry for a domain then that indicates that the connection is not specifically
* pinned. The type of pin requested determines the data in each of the pins. This is typically
* the base64 encoding of the hash of some aspect of the certificate. A connection is considered
* to be valid if any certificate in the chain presented is one with the same hash as one in
* the array of hashes. Note that if the isForceApplyPins flag was set on the last Approov
* token fetch then this clears the flag for future fetches as it indicates that the latest
* pin information has been read. Pins may be returned with "*" as the domain as these represent
* the trusted root pins of all the acceptable certificate authorities.
*
* Normally this method returns immediately with the latest pins that are cached in the
* SDK. However, if no pins are available at all then there will be a short blocking delay as an
* attempt will be made to fetch them from the Approov servers.
*
* @param pinType is the type of pinning information that is required
* @return Map from domain to the list of strings providing the pins
*/
public static final Map<String, List<String>> getPins(String pinType);
/**
* Provide access to the API-Pins information held in the current app configuration. This is a helper method that avoids
* the need for the app to access the configuration directly. Pins of a particular type are retrieved. If the
* SDK has not be initialized then nil is returned. A connection is considered to be valid if any certificate
* in the chain presented has the same hash as one in the list of hashes for the domain. Note that if the isForceApplyPins
* flag was set on the last Approov token fetch then this clears the flag for future fetches as it indicates that the
* latest pin information has been read. Pins may be returned with "*" as the domain as these represent the trusted
* root pins of all the acceptable certificate authorities.
*
* Normally this method returns immediately with the latest pins that are cached in the
* SDK. However, if no pins are available at all then there will be a short blocking delay as an
* attempt will be made to fetch them from the Approov servers.
*
* @param pinType is the format of the pins that should be retrieved
* @result NSDictionary mapping from domain names to a list of pins in base64 format for that domain
*/
+ (nullable NSDictionary<NSString *, NSArray<NSString *> *> *)getPins:(nonnull NSString *)pinType;
/**
* Provide access to the API-Pins information held in the current app configuration. This is a helper method that avoids
* the need for the app to access the configuration directly. Pins of a particular type are retrieved. If the
* SDK has not be initialized then nil is returned. A connection is considered to be valid if any certificate
* in the chain presented has the same hash as one in the list of hashes for the domain. Note that if the isForceApplyPins
* flag was set on the last Approov token fetch then this clears the flag for future fetches as it indicates that the
* latest pin information has been read. Pins may be returned with "*" as the domain as these represent the trusted
* root pins of all the acceptable certificate authorities.
*
* Normally this method returns immediately with the latest pins that are cached in the
* SDK. However, if no pins are available at all then there will be a short blocking delay as an
* attempt will be made to fetch them from the Approov servers.
*
* @param pinType is the format of the pins that should be retrieved
* @result NSDictionary mapping from domain names to a list of pins in base64 format for that domain
*/
class func getPins(_ pinType: String) -> [String : [String]]?
Pins JSON Extraction
- Java
- Objective-C
- Swift
/**
* Fetches the pins from the current configuration of the SDK. This is returned as
* JSON which defines a map from URL domain (hostname only) to the possible pins for
* that domain. If there is no map entry for a domain then that indicates that the connection
* is not specifically pinned. The type of pin requested determines the data in each of the
* pins. This is typically the base64 encoding of a hash of some aspect of the certificate.
* A connection is considered to be valid if any certificate in the presented chain has a hash
* that matches one in the array of hashes for the domain. Note that if the isForceApplyPins flag
* was set on the last Approov token fetch then this clears the flag for future fetches as it
* indicates that the latest pin information has been read. The special domain "*" may be present
* to provide the full list of trusted root pins for all accepted certificate authorities.
*
* Normally this method returns immediately with the latest pins that are cached in the
* SDK. However, if no pins are available at all then there will be a short blocking delay as an
* attempt will be made to fetch them from the Approov servers.
*
* @param pinType is the type of pinning information that is required
* @return JSON representation of the pins
*/
public static final String getPinsJSON(String pinType);
/**
* Provide access to the API pin information held in the current app configuration. This method provides the information in
* marshalled JSON form. Pins of a particular type are retrieved. If the SDK has not be initialized then nil is returned. Note that
* if the isForceApplyPins flag was set on the last Approov token fetch then this clears the flag for future fetches as it indicates
* that the latest pin information has been read. Pins may be returned with "*" as the domain as these represent the trusted
* root pins of all the acceptable certificate authorities.
*
* Normally this method returns immediately with the latest pins that are cached in the
* SDK. However, if no pins are available at all then there will be a short blocking delay as an
* attempt will be made to fetch them from the Approov servers.
*
* @param pinType is the format of the pins that should be retrieved
* @result String representation of the JSON representing the pins, or nil if the SDK has not been initialized
*/
+ (nullable NSString *)getPinsJSON:(nonnull NSString *)pinType;
/**
* Provide access to the API pin information held in the current app configuration. This method provides the information in
* marshalled JSON form.Pins of a particular type are retrieved. If the SDK has not be initialized then nil is returned. Note that
* if the isForceApplyPins flag was set on the last Approov token fetch then this clears the flag for future fetches as it indicates
* that the latest pin information has been read. Pins may be returned with "*" as the domain as these represent the trusted
* root pins of all the acceptable certificate authorities.
*
* Normally this method returns immediately with the latest pins that are cached in the
* SDK. However, if no pins are available at all then there will be a short blocking delay as an
* attempt will be made to fetch them from the Approov servers.
*
* @param pinType is the format of the pins that should be retrieved
* @result String representation of the JSON representing the pins, or nil if the SDK has not been initialized
*/
class func getPinsJSON(_ pinType: String) -> String?
Getting the Device ID
- Java
- Objective-C
- Swift
/**
* Gets the device ID used by Approov to identify the particular app installation that the SDK is running
* in. Different Approov apps on the same device will return a different ID. The ID may be changed by an
* uninstall and reinstall of the app.
*
* @return String representation of the deviceID.
*/
public static final String getDeviceID();
/**
* Gets the device ID used by Approov to identify the particular app installation that the SDK is running
* in. Different Approov apps on the same device will return a different ID. The ID may be changed by an
* uninstall and reinstall of the app.
*
* @return String of device ID or nil if SDK not initialized.
*/
+ (nullable NSString *)getDeviceID;
/**
* Gets the device ID used by Approov to identify the particular app installation that the SDK is running
* in. Different Approov apps on the same device will return a different ID. The ID may be changed by an
* uninstall and reinstall of the app.
*
* @return String of device ID or nil if SDK not initialized.
*/
class func getDeviceID() -> String?
Getting the Installation Public Key
- Java
- Objective-C
- Swift
/**
* Gets the installation public key created when the app is run for the first time. The private key is used
* to sign getInstallMessageSignature() messages and the public key may also be included in Approov
* tokens. The key is provided base64 DER encoded in an ASN.1 format. The key is always EC using the
* P-256 curve.
*
* @return installation public key has base64 DER encoded ASN.1 string
*/
public static final String getInstallPublicKey();
/**
* Gets the installation public key created when the app is run for the first time. The private key is used
* to sign getInstallMessageSignature() messages and the public key may also be included in Approov
* tokens. The key is provided base64 DER encoded in an ASN.1 format. The key is always EC using the
* P-256 curve.
*
* @return installation public key has base64 DER encoded ASN.1 string
*/
+ (nullable NSString *)getInstallPublicKey;
/**
* Gets the installation public key created when the app is run for the first time. The private key is used
* to sign getInstallMessageSignature() messages and the public key may also be included in Approov
* tokens. The key is provided base64 DER encoded in an ASN.1 format. The key is always EC using the
* P-256 curve.
*
* @return installation public key has base64 DER encoded ASN.1 string
*/
class func getInstallPublicKey() -> String?
Development Key
- Java
- Objective-C
- Swift
/**
* Sets a development key on the SDK. This may provide a key indicating that
* the app is a development version and it should pass attestation even
* if the app is not registered or it is running on an emulator. The development
* key value can be rotated at any point in the account if a version of the app
* containing the development key is accidentally released. This is primarily
* used for situations where the app package must be modified or resigned in
* some way as part of the testing process.
*
* @param key is the development key value to be set, which may be null
*/
public static final void setDevKey(String key);
/**
* Sets a development key on the SDK. This may be used to force a build of the app
* to always pass attestation, even if the app itself is not registered or it is
* being run on a simulator. This is to allow testing when the app might have to
* be resigned to run on a particular test environment and the signing certificate
* is either not known or not easily accessible. The development key is defined at
* the account level and can be changed at any point.
*
* @param key is the development key to be set, which may be nil
*/
+ (void)setDevKey:(nullable NSString *)key;
/**
* Sets a development key on the SDK. This may be used to force a build of the app
* to always pass attestation, even if the app itself is not registered or it is
* being run on a simulator. This is to allow testing when the app might have to
* be resigned to run on a particular test environment and the signing certificate
* is either not known or not easily accessible. The development key is defined at
* the account level and can be changed at any point.
*
* @param key is the development key to be set, which may be nil
*/
class func setDevKey(_ key: String)