Troubleshooting guide

103
5: Using smart cards
* The method returns Integer.MAX_VALUE if an infinite number of attempts are allowed.
*/
protected int getMaxLoginAttemptsImpl() throws SmartCardException
{
return 5;
}
/**
* Retrieve the remaining number of login attempts allowed (before the smart card will
* lock, or Integer.MAX_VALUE if the smart card will not lock.)
*/
protected int getRemainingLoginAttemptsImpl() throws SmartCardException
{
return 4;
}
/**
* Log into the smart card with the given password.
* This method should not bring up the UI.
*/
protected boolean loginImpl( String password ) throws SmartCardException
{
// Create a CommandAPDU which your smart card will understand
CommandAPDU command = new CommandAPDU( (byte)0x00, (byte)0x20, (byte)0x00,
(byte)0x00 );
command.setLcData( password.getBytes() );
ResponseAPDU response = new ResponseAPDU();
sendAPDU( command, response );
// Check for response codes specific to your smart card
if ( response.checkStatusWords( (byte)0x90, (byte)0x00 ) ) {
return true;
}
else if ( response.checkStatusWords( (byte)0x64, (byte)0xF8 ) ) {
throw new SmartCardLockedException();
}
else {
// Authentication failed
return false;
}
}
/**
* Retrieve an ID for this session’s associated smart card.
*/
protected SmartCardID getSmartCardIDImpl() throws SmartCardException
{
// Retrieve a unique ID from the card
byte [] uniqueCardData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b };
// Convert byte array to a long
SHA1Digest digest = new SHA1Digest();
digest.update( uniqueCardData );
byte [] bytesToUse = Arrays.copy( digest.getDigest(), 0, 8 );
long idLong = CryptoByteArrayArithmetic.valueOf( bytesToUse );