20
Cryptographic Smart Card Driver Development Guide
// 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 );
long idLong = byteArrayToLong( Arrays.copy( digest.getDigest(), 0, 8 ) );
// Using friendly display name
return new SmartCardID( idLong , ID_STRING, getSmartCard() );
}
/**
* Converts <code>array</code> into a long integer (Note: the returned value should
* be considered as an unsigned value).
* @throws IllegalArgumentException if <code>array</code> contains a number bigger
* than 64 bits.
*
* Note:
* If your cryptographic smart card driver is only designed to work with
* BlackBerry Version 4.2 or later, you can replace this method with a call to
* CryptoByteArrayArithmetic.valueOf( byte [] ).
*
*/
private long byteArrayToLong( byte[] array )
{
if ( array == null ) {
throw new IllegalArgumentException();
}
// Remove the leading zeros from given byte[] and returns a new byte[] without them.
int zeros = 0;
for ( int i = 0; i < array.length && array[i] == 0; i++ ){
zeros++;
}
Summary of Contents for JAVA DEVELOPMENT ENVIRONMENT - - CRYPTOGRAPHIC SMART CARD DRIVER - DEVELOPMENT GUIDE
Page 4: ......
Page 6: ......
Page 14: ...10 Cryptographic Smart Card Driver Development Guide...
Page 17: ...13 2 Testing a cryptographic smart card driver...
Page 18: ...14 Cryptographic Smart Card Driver Development Guide...
Page 34: ...30 Cryptographic Smart Card Driver Development Guide...
Page 35: ......
Page 36: ...2007 Research In Motion Limited Published in Canada...