Purpose
The purpose of this WIKI is to list the location where you can find the documentation for Android Client Development
Overview
The Afaria static link library (SLL) is provided to allow app developers to retrieve configuration data, client certificates, and other resources from the Afaria package server.
Requirements
In order to use any of the calls in the static library, the Afaria client must be first installed and provisioned on your Android device. Additionally, before an Afaria client can retrieve the data from the Afaria package server, the device must connect to the Afaria server at least once.
Project setup
Adding the Afaria library to your project
The first step to use the Afaria client library is to add it to your application's project in Eclipse. Right click on your project in the left pane and select 'Properties.'
Select ‘Java Build Path’ in the left pane, and then select the ‘Libraries’ tab in the right pane.
Click on ‘Add External JARs…’ in the right pane; select the ‘AfariaLib’ directory; select the "AfariaSLL.jar" file; and click "Open."
You will need to import the SeedDataAPI class anywhere you make calls to the library.
Calling the Afaria SLL
Calls to the Afaria library generally work like this:
- The app calls the Afaria SLL initialize function passing along the app’s context.
- The app declares a SeedDataCredentials object with a username, password, and an optional domain.
- The app calls the SLL passing in the SeedDataCredentials.
- When the SLL is finished, it will return the SeedData file location for retrieveSeedData, and the X509Certificate object for retrieveCertificate.
The SeedDataCredentials object is only required if Authentication is enabled for the Afaria package server.
Working with SeedDataAPI
A SeedDataAPI object can be instantiated as follows, being sure to use your app's own context:
SeedDataAPI.initialize (this );
To retrieve a configuration file:
SeedDataCredentials sdc =new SeedDataCredentials("user", "pass");
String SeedFileLocation = SeedDataAPI.retrieveSeedData (sdc);
These two code snippets are all that your app needs to complete the steps outlined above in regard to retrieving seed data.
The SeedDataAPI methods
Following is a brief description of the methods that are used by the app to receive seed data and certificates.
initialize
This method will initialize the SeedDataAPI with the calling application’s context so that it may be used later to retrieve information about the calling application.
retrieveSeedData
This method will download the seed data file from the Afaria package server and return the location of that file back to the calling application.
retrieveCertificate
This method will send a request for a certificate to the Afaria package server. The request will be sent to the configured CA for verification. The CA will then return a certificate to the Afaria package server, which will then return that certificate to the Afaria SLL to be initialized into an X509Certificate object. This object will then be passed back to the calling application.
Synchronous implementation
The methods in the library consist of blocking calls. Since these methods are blocking, they will return only after completing all necessary network access. There is a list of return values publically available from the SeedDataAPIException class in the Afaria SLL.
AFARIA_CLIENT_NOT_INSTALLED = 0;
NO_DATA_AVAILABLE = 1;
COULD_NOT_CONTACT_SERVER = 2;
UNKNOWN = 101;
AUTHENTICATION_FAILED = 110;
Methods used by the synchronous implementation
Retrieving seed data
public static String retrieveSeedData(SeedDataCredentials credentials)
throws SeedDataAPIException
This method is used to retrieve seed data from the Afaria package server. The Afaria SLL will communicate with the Afaria client to get all of the required information to query the package server for the calling application’s seed data. The Afaria SLL will then use the credentials, if supplied, to contact the package server and download the seed data.
The credentials parameter is a SeedDataCredentials object that the application must initialize with a username, password, and optional domain to be used for Authentication on the package server. If there is no Authentication enabled on the package server, a null object can be passed into the function.
The function will return a String object that is the path to the file containing the Seed Data for the calling application.
The function will throw a SeedDataAPIException if there are any issues while attempting to retrieve the seed data from the package server.
The return values for these methods are:
- AFARIA_CLIENT_NOT_INSTALLED – Afaria Client not installed
- NO_DATA_AVAILABLE – No data available for the calling application
- COULD_NOT_CONTACT_SERVER – Couldn’t contact package server
- AUTHENTICATION_FAILED – HTTP Authentication required or Authentication Failed
- UNKNOWN – An unknown issue occurred, generally the message contains more information
Retrieving Certificates
public static X509Certificate retrieveCertificate(RSAPublicKey publicKey, RSAPrivateKey privateKey, String commonName, String challengeCode, SeedDataCredentials credentials)
throws SeedDataAPIException
This method is used to retrieve signed certificates for a supplied public key pair.
The privateKey parameter is a RSAPrivateKey object; the publicKey parameter is a RSAPublicKey object; and the commonName and challengeCode parameters are both String objects.
The credentials parameter is a SeedDataCredentials object that the application must initialize with a username, password, and optional domain to be used for Authentication on the package server. If there is no Authentication enabled on the package server, a null object can be passed into the function. This method will generate a Certificate Signing Request (CSR) and send it to the package server, which will then forward the CSR to the configured CA.
The function will return an X509Certificate object that the SLL retrieved from the package server.
The function will throw a SeedDataAPIException if there are any issues while attempting to retrieve the certificate from the package server.
The possible exception values are:
- AFARIA_CLIENT_NOT_INSTALLED – Afaria Client not installed
- NO_DATA_AVAILABLE – No data available for the calling application
- COULD_NOT_CONTACT_SERVER – Couldn’t contact package server
- AUTHENTICATION_FAILED – HTTP Authentication required or Authentication Failed
- UNKNOWN – An unknown issue occurred, generally the message contains more information