When attempting to change PICC key settings on DESFire EV1 cards I get the following error: com.nxp.nfclib.exceptions.PICCException: Integrity Error SW2 = 30
at com.nxp.nfclib.desfire.DESFireUtil.invalidResponse(:229)
at com.nxp.nfclib.desfire.DESFireEV1.changeKeySettings(:879)
Here is a minimal example code causing this:
public void initNewCard(IDESFireEV1 card) {
log("Connecting to card reader");
card.getReader().connect();
log("Starting to init card with id %s, selecting app", Utilities.dumpBytes(card.getUID()));
card.selectApplication(0);
String status = card.getAuthStatus();
log("Current auth status %s", status);
EV1PICCKeySettings keySettings = (EV1PICCKeySettings) card.getKeySettings();
log(
"PICC settings: %s %s",
String.valueOf(keySettings.isPiccKeySettingsChangeable()),
String.valueOf(keySettings.isPiccMasterKeyChangeable())
);
log("Authenticating");
default2KDESAuthenticate(card);
status = card.getAuthStatus();
log("Current auth status %s", status);
card.changeKeySettings(makeInUsePICCKeySettings()); // this changeKeySettings() call causes the exception
}
private EV1PICCKeySettings makeInUsePICCKeySettings() {
EV1PICCKeySettings.Builder builder = new EV1PICCKeySettings.Builder();
builder.setPiccKeySettingsChangeable(true)
.setPiccMasterKeyChangeable(true)
.setAuthenticationRequiredForApplicationManagement(false)
.setAuthenticationRequiredForDirectoryConfigurationData(false);
return builder.build();
}
I would like to kindly ask for your help with this issue. I have tried formatting the cards and otherwise writing to them seems to work. Am I doing something wrong?
The relevant output is:
Connecting to card reader
Starting to init card with id 0x042A43B2EC6A80, selecting app
Current auth status Not Authenticated
PICC settings: true true
Authenticating
Current auth status Native
Hello,
have you received the ats for the desfire card?
Vincent