Computing an Unlock Response

To compute an unlock response, complete the following steps:

  1. Set up search criteria based on credential type (optional), parent wallet (required), and application ID (required).

    Copy
    Criteria[] 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())
    };
  2. Find credential IDs for all credentials to be unlocked:

    Copy
    CredentialId[] credIds = cm.findCredentialIds(criteria, maxItem);
  3. Initiate an offline unlock transaction:

    Copy
    TransactionId txId = cm.operateCredential(credIds[0], CCMConstants.OPER_ID_CRED_UNLOCK, new Parameter[0]);
  4. Continually check for pending external operations:

    Copy
    ExternalOperation[] exOps = new ExternalOperation[0];
    do{
    exOps = cm.getNextExternalOperations(txId, exOps);
    // do step 5 here 
    ...
    } while( exOps.length > 0);
  5. Iterate through the returned list of external operations:

    Copy
    for (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:

      Copy
      if (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:

      Copy
      else 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]);
      }
  6. Commit the credential transaction outside the do loop:

    Copy
    cm.commitCredentialTransaction(txId);
Note: The challenge that is returned from the ActivID CMS server is set in the Response parameter of the external operation.