APDU Command and Secure Access Module (SAM) Development Using EMDK

A Alan Dimaano 3 years 6 months ago
235 2 0

I'm relatively new to EMDK and Secure Access Module programming.
 
I have a SAM that contains a key that I need to access an RF ID ... do you guys have any kind of sample codes that I can look into to do this?
 
I'm also receiving a 'AV2 authentication failed' (Mifare SAM AV2) whenever I try to communicate with the SAM card. It gives me the impression that  I need to pass an authentication layer before I can access the key hosted in a DF sector of the SAM card.
 
I really need help. I'm desperate.
 
Below is the 'onOpened' code snippet of what I'm trying to do:
 
====================
 
@Overridepublic void onOpened(EMDKManager emdkManager) {
   this.emdkManager = emdkManager;
 
  Log.i("onOpened called", " ");
   status.append("\nApplication Initialized.");
 
   if (this.emdkManager != null) {
 
   secureNfcMgr = (SecureNfcManager) emdkManager
  .getInstance(EMDKManager.FEATURE_TYPE.SECURENFC);
 
   if (secureNfcMgr != null) {
 
   try {
   samType = secureNfcMgr.getAvailableSam();
 
   status.append(newline + newline + samType   + " SAM is available on the device.");
 
   if (samType.equals(SecureNfcManager.SamType.MIFARE)) {
 
   mifareSam = (MifareSam) secureNfcMgr   .getSamInstance(samType);
 
   mMifareDesfire = (MifareDesfire) secureNfcMgr   .getTagTechInstance(SecureNfcManager.TagTechType.MIFARE_DESFIRE);
 
  MifareSam.SamMode samMode = mifareSam.connect();
  MifareSam.SamInfo samInfo = mifareSam.getSamInfo();
 
   // SamKey required for the SAM to Host authentication.   SamKey samKey = new SamKey();
  samKey.keyNum = 0x08;
  samKey.keyVer = 0x01;
   byte[] KEY_AES128_DEFAULT = {0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0,};
   byte[] SELECT = {
  (byte) 0xC0, // CLA Class   (byte) 0xA4, // INS Instruction   (byte) 0x00, // P1 Parameter 1   (byte) 0x00, // P2 Parameter 2   (byte) 0x02,
  (byte) 0x4F00 // Select the   };
   mifareSam.authenticateSam(KEY_AES128_DEFAULT, samKey, null);
 
   mifareSam.close();
 
   //setButtonEnabled(true);   status.append(newline + newline + samMode
  + " SAM host authentication successful.");
   //statusTV.setText(status);   textViewInfo.setText(status);
 
  } else if (samType.equals(SecureNfcManager.SamType.NONE)) {
 
   status.append(newline + newline   + "SAM not available in the device");
 
  AlertDialog.Builder dlgAlert = new AlertDialog.Builder(
   this);
 
  dlgAlert.setMessage("Please insert the SAM into the device and try again.");
  dlgAlert.setTitle("Error Message...");
  dlgAlert.setPositiveButton("OK", null);
  dlgAlert.setCancelable(true);
  dlgAlert.create().show();
 
  dlgAlert.setPositiveButton("Ok",
   new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog,
   int which) {
 
  }
  });
  }
  } catch (SecureNfcException e1) {
 
  e1.printStackTrace();
   status.append(newline + newline + newline   + "SecureNfcException Exception : "   + e1.getResult().getDescription());
 
  } catch (MifareSamException e) {
 
  e.printStackTrace();
 
   //setButtonEnabled(false);   status.append(newline + newline + "MifareSam Exception : "   + e.getMessage());
   //statusTV.setText(status);   textViewInfo.setText(status);
  Log.e("mifare error -- ", e.getMessage());
  }
 
  }
 
  }
 
 
}
 
====================

Please Register or Login to post a reply

2 Replies

S Saravana Damodaram

Getting the following response for Get Key entry :
01 01 01 36 00 FE 00 00 01 FF 00 44

Please let me know how to parse through for the Key number and key version for the Host authentication.

E Efkan YILMAZ

Hello Alan, Have you tried the Secure NFC Sample app with your SAM card? I'm wondering if you may have a SAM card that is not provisioned correctly. We also have a programmers guide that may help. Secure NFC Programmer’s - Zebra Technologies Online Documentation

CONTACT
Can’t find what you’re looking for?