Gemalto Ezio Web Connector

 

CAP

Compute CAP tokens through EWC

Once EWC is initialized after a call to the "init" function, your page is able to react on smart card insertion to trigger an operation (see the "initialization" and "detection" pages for more details).

The CAP generation function is not exposed by the top level EWC API. When a smart card is inserted into the reader and validated as usable, a "Connection" object is automatically created by the EWC library. The "Connection" object exposes all functions for CAP operations. The first step is to get the "Connection" object. A reference to this object is passed as argument to the connection callback provided in the "init" function. This reference can also be retrieve directly when the function "getConnection" is called.

The "Connection" object exposes three CAP functions:

  • cap_mode1 function generates a CAP mode1 token
  • cap_mode2 function generates a CAP mode2 token
  • cap_mode3 function generates a CAP mode3 token

Because the card holder have to validate the transaction parameter used for token generation, each CAP function is asynchronous. The final result is reported to the web page by the callback provided as parameter of the chosen CAP function.

// Create a callback to treat the return of the CAP asynchronous function
var resultCallback = {
  
  success : function( a_oConnection, a_sToken, a_sUmpredictableNumber ) {
    
    // Reset the token display on the HTML page
    var sMessage = "Your token " + a_sToken + " has been successfully generated.";
    
    // From specific PCR as Ezio Shield Branch reader the card holder can specify
    // the unpredictable number directly from the PCR (you only have to send
    // the CAP Mode3 command with a 'FFFFFFFF' template as unpredictable number).
    // In this case, the 'success' function must manage a new and last parameter to
    // get the value typed by the card holder
    if ( a_sUmpredictableNumber ) {
      
      sMessage += " The card holder has specified " + a_sUmpredictableNumber + " as unpredictable number";
    }
  
    alert(sMessage);

  },

  failure : function( a_oConnection, a_oError ) {
  
    var sMessage = "Your token has NOT been generated.";
    sMessage += " Error (" + a_oError.errorCode + ").";
    sMessage += " Message (" + a_oError.message + ")";

    alert(sMessage);
  }
  
};

// Collect the end-user information to operate the CAP
var sUnpredictableNumber = ...
var sAmount = ...
var sCurrency = ...
var sPassCode = ...
  
// An optional array of decimal strings containing the TDS data.
// If used, this array must have at least 1 element and no more than 10 elements.
// Example: ["12345", "123"]
var aTdsData = ...
  
// Retrieve the Connection object attached to the smart card inserted into the reader
var cnx = enex.getConnection( );
if ( !cnx ) {
  
  return;
}

// Depending the MODE that is targeted, perform the CAP operation
switch( cap_mode_chosen_in_your_web_application ) {

  case "1":
    cnx.cap_mode1( resultCallback, sUnpredictableNumber, sAmount, sCurrency, sPassCode );
  break;
  
  case "2":
   cnx.cap_mode2( resultCallback, aTdsData, sPassCode );
  break;
  
  case "3":
    cnx.cap_mode3( resultCallback, sUnpredictableNumber, aTdsData, sPassCode );
  break;
}  
                    

Try it !

Enter the required data to generate your CAP token and click the button to send the CAP command.