Computing an Unlock Response
To compute an unlock response, complete the following steps:
-
Set up search criteria based on credential type (optional), parent wallet (required), and application ID (required).
CopyCriteria[] criteria =
{new Criteria(CCMConstants.CRITERIA_CRED_TYPE, CCMConstants.CRITERIA_COMPARISON_EQUAL, CCMConstants.CRED_ID_TYPE_PIN),
new Criteria(CCMConstants.
CRITERIA_CRED_APPLICATION_ID, CCMConstants.CRITERIA_COMPARISON_EQUAL, CCMConstants.CRED_ID_TYPE_PIN),
new Criteria(CCMConstants.
CRITERIA_CRED_PARENT_WALLET, CCMConstants.CRITERIA_COMPARISON_EQUAL, walletId.getId())
}; -
Find credential IDs for all credentials to be unlocked:
CopyCredentialId[] credIds = cm.findCredentialIds(criteria, maxItem);
-
Initiate an offline unlock transaction:
CopyTransactionId txId = cm.operateCredential(credIds[0], CCMConstants.OPER_ID_CRED_UNLOCK, new Parameter[0]);
-
Continually check for pending external operations:
CopyExternalOperation[] exOps = new ExternalOperation[0];
do{
exOps = cm.getNextExternalOperations(txId, exOps);
// do step 5 here
...
} while( exOps.length > 0); -
Iterate through the returned list of external operations:
Copyfor (int i = 0; i < exOps.length; i++){
String scriptType = exOps[i].getType(); String script = exOps[i].getScript();
// do the following steps here
...
}-
Check the script type (AI) and the script (challenge) itself:
Copyif (scriptType.equals(“AI”) &&
script.equals(CCMConstants.CRED_EXOP_GETCHALLENGE))
// Note: Currently the value of the script type is always “AI”
// To obtain the challenge from a card that is offline
// (For example: ActivClient)
String challenge = ..........; // challenge code format
// XXXXXXXXXXXXXXXX
// Set the challenge as the response parameter for the external operation Parameter[] responseParams = { new Parameter (
CCMConstants.CRED_EXOP_GETCHALLENGE_RESPONSE, challenge);
exOps[i].setResponseParameters(responseParams);
}
-
Check the script type (AI) and the script (unlock) itself:
Copyelse if (scriptType.equals(“AI”) &&
script.equals(CCMConstants.CRED_EXOP_UNLOCK)){
/* Note: At this point, the script indicates the unlock code has been provisioned, and an offline unlock is requested */ System.out.println(exOps[i].getParameter()[0]);
}
-
-
Commit the credential transaction outside the do loop:
Copycm.commitCredentialTransaction(txId);