List of usage examples for javax.smartcardio CardException printStackTrace
public void printStackTrace()
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public int pinTrialsLeft() { try {// ww w . j ava 2s.co m ResponseAPDU response = this .transmitCommand(new CommandAPDU(this.ABC4TRUSTCMD, this.pinTrialsLeft, 0, 0, 1)); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return response.getData()[0]; } } catch (CardException e) { e.printStackTrace(); } return -1; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public int pukTrialsLeft() { try {/*from ww w .ja v a2s . co m*/ ResponseAPDU response = this .transmitCommand(new CommandAPDU(this.ABC4TRUSTCMD, this.pukTrialsLeft, 0, 0, 1)); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return response.getData()[0]; } } catch (CardException e) { e.printStackTrace(); } return -1; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public short getDeviceID(int pin) { try {//ww w . j a v a 2 s .c o m ResponseAPDU response = this.transmitCommand( new CommandAPDU(this.ABC4TRUSTCMD, this.getDeviceID, 0, 0, this.pinToByteArr(pin), 2)); System.out.println("Response from getdeviceID: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return ByteBuffer.wrap(response.getData()).getShort(); } } catch (CardException e) { e.printStackTrace(); } return -1; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
private void putData(byte[] data) { try {/*from www. j a va 2 s .c o m*/ ByteBuffer buf = ByteBuffer.allocate(7 + data.length); buf.put((byte) this.ABC4TRUSTCMD); buf.put(this.putData); buf.put(new byte[] { 0, 0, 0 }); buf.put(this.intLengthToShortByteArr(data.length)); buf.put(data); buf.position(0); System.out.println("Input to PutData: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from putData: " + response); } catch (CardException e) { e.printStackTrace(); } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode changePin(int pin, int newPin) { byte[] data = new byte[8]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); System.arraycopy(this.pinToByteArr(newPin), 0, data, 4, 4); try {// w w w . jav a 2s . c o m ByteBuffer buf = ByteBuffer.allocate(13); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.changePin, 0, 0, 8 }); buf.put(data); buf.position(0); if (printInput) System.out.println("Input for changePin: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from changePin: " + response); return this.evaluateStatus(response); } catch (CardException e) { e.printStackTrace(); return SmartcardStatusCode.NOT_FOUND; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public BigInteger computeDevicePublicKey(int pin) { ByteBuffer buf = ByteBuffer.allocate(13); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.getDevicePublicKey, 0, 0, 0, 0, 4 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { 0, 0 }); buf.position(0);/*from w w w .java 2 s . c o m*/ try { TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getDevicePublicKey)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getDevicePublicKey)", false); System.out.println("Response from getDevicePublicKey: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return new BigInteger(1, response.getData()); } } catch (CardException e) { e.printStackTrace(); return null; } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
private BigInteger computeDevicePublicKeyResponse(int pin) { ByteBuffer buf = ByteBuffer.allocate(13); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.getDeviceResponse, 0, 0, 0, 0, 4 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { 0, 0 }); buf.position(0);//w ww . j a va2s.com try { if (printInput) System.out.println("Input for getDeviceResponse: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from getDeviceResponse: " + response); System.out.println("And this is the output: " + Arrays.toString(response.getData())); System.out.println("which gives this BigInteger: " + new BigInteger(1, response.getData())); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return new BigInteger(1, response.getData()); } } catch (CardException e) { e.printStackTrace(); } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
private BigInteger computeDevicePublicKeyCommitment(int pin) { ByteBuffer buf = ByteBuffer.allocate(13); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.getDeviceCommitment, 0, 0, 0, 0, 4 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { 0, 0 }); buf.position(0);/*from www .j ava 2 s.co m*/ try { if (printInput) System.out.println("Input for getDeviceCommitment: " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getDeviceCommitment)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getDeviceCommitment)", false); System.out.println("Response from getDeviceCommitment: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { System.out.println("And this is the output: " + Arrays.toString(response.getData())); System.out.println("Or this bigInt: " + new BigInteger(1, response.getData())); return new BigInteger(1, response.getData()); } } catch (CardException e) { e.printStackTrace(); } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public RSAVerificationKey readAuthenticationKey(int pin, int keyID) { byte[] data = new byte[5]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); data[4] = (byte) keyID; ByteBuffer buffer = ByteBuffer.allocate(14); buffer.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.readAuthenticationKey, 0, 0, 0, 0, 5 }); buffer.put(data);//w w w. j ava2 s .co m buffer.put(new byte[] { 0, 0 }); buffer.position(0); try { ResponseAPDU response = this.transmitCommand(new CommandAPDU(buffer)); System.out.println("Response from readAuthenticationKey: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { RSAVerificationKey vkey = new RSAVerificationKey(); vkey.n = new BigInteger(1, response.getData()); return vkey; } return null; } catch (CardException e) { e.printStackTrace(); return null; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
/** * // w w w . ja v a2 s.c o m * @param pin * @param credentialID * @return byte array containing: issuerID || size(v) [2 bytes] || size(kv) [2 bytes] || status || prescount */ private byte[] readCredential(int pin, int credentialID) { byte[] data = new byte[5]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); data[4] = (byte) credentialID; ByteBuffer buf = ByteBuffer.allocate(11); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.readCredential, 0, 0, 5 }); buf.put(data); buf.put((byte) 7); buf.position(0); try { if (printInput) System.out.println("Input for readCredential: " + Arrays.toString(buf.array())); System.out.println("Reading the on-board credential with ID=" + credentialID); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from readCredential: " + response); System.out.println("With the data: " + Arrays.toString(response.getData())); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return response.getData(); } } catch (CardException e) { e.printStackTrace(); } return null; }