List of usage examples for javax.smartcardio CardException printStackTrace
public void printStackTrace()
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@SuppressWarnings("unused") private List<Byte> listCounters(int pin) { ByteBuffer buf = ByteBuffer.allocate(10); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.listCounters, 0, 0, 4 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { 0 }); buf.position(0);/* w w w .j a v a 2 s . com*/ try { if (printInput) System.out.println("Input for listCounters: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from listCounters: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { List<Byte> counters = new ArrayList<Byte>(); byte[] counterIDs = response.getData(); for (byte counterID : counterIDs) { counters.add(counterID); } return counters; } } catch (CardException e) { e.printStackTrace(); } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
public List<Byte> listCredentialIDs(int pin) { ByteBuffer buf = ByteBuffer.allocate(10); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.listCredentials, 0, 0, 4 }); buf.put(this.pinToByteArr(pin)); buf.put((byte) 0); buf.position(0);//from www. j a v a 2 s. co m try { if (printInput) System.out.println("Input for listCredentials: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from listCredentials: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { List<Byte> credentialIDs = new ArrayList<Byte>(); byte[] creds = response.getData(); for (byte cred : creds) { credentialIDs.add(cred); } return credentialIDs; } } catch (CardException e) { e.printStackTrace(); return null; } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
/** * /*from w ww .j ava2 s . c om*/ * @param pin * @param counterID * @return the 7-byte stream keyID || index || threshold || cursor(4 bytes). */ private byte[] readCounter(int pin, int counterID) { byte[] data = new byte[5]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); data[4] = (byte) counterID; ByteBuffer buf = ByteBuffer.allocate(11); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.readCounter, 0, 0, 5 }); buf.put(data); buf.put((byte) 7); buf.position(0); try { if (printInput) System.out.println("Input for readCounter: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from readCounter: " + response); System.out.println("With data: " + Arrays.toString(response.getData())); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { return response.getData(); } else { return null; } } catch (CardException e) { e.printStackTrace(); return null; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode deleteBlob(int pin, URI uri) { byte[] uriBytes = null; uriBytes = this.uriToByteArr(uri); if (uriBytes.length > 199) { return SmartcardStatusCode.REQUEST_URI_TOO_LONG; }/* w w w . j av a2 s . co m*/ // BLOB CACHE! blobCache.remove(uri); blobUrisCache.remove(uri); byte[] data = new byte[4 + uriBytes.length]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); System.arraycopy(uriBytes, 0, data, 4, uriBytes.length); ByteBuffer buf = ByteBuffer.allocate(9 + uriBytes.length); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.removeBlob, 0, 0, (byte) data.length }); buf.put(data); buf.position(0); try { if (printInput) System.out.println("Input for removeBlob: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from removeBlob: " + response); return this.evaluateStatus(response); } catch (CardException e) { e.printStackTrace(); return null; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
/** * @param pin/*from w w w. j av a2 s .c o m*/ * @param issuerID * @return byte array containing: groupID || genID1 || genID2 || numpres || counterID */ private byte[] readIssuer(int pin, int issuerID) { if (cachedIssuerByteArray.containsKey(issuerID)) { byte[] cached = cachedIssuerByteArray.get(issuerID); System.out.println("ReadIssuer - use cached : " + (cached == null ? null : Arrays.toString(cached))); return cached; } byte[] data = new byte[5]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); data[4] = (byte) issuerID; ByteBuffer buf = ByteBuffer.allocate(11); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.readIssuer, 0, 0, 5 }); buf.put(data); buf.put((byte) 5); buf.position(0); try { if (printInput) System.out.println("Input for readIssuer: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from readIssuer: " + response); System.out.println("With the data: " + Arrays.toString(response.getData())); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { cachedIssuerByteArray.put(issuerID, response.getData()); return response.getData(); } } catch (CardException e) { e.printStackTrace(); } cachedIssuerByteArray.put(issuerID, null); return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
private BigInteger getGenerator(int pin, int groupID, int genID) { if (cachedGenerator.containsKey(groupID + ":" + genID)) { BigInteger cached = cachedGenerator.get(groupID + ":" + genID); System.out.println("Cached readGenerator: " + groupID + " : " + genID + " : " + cached); return cached; }//ww w .j a va 2 s . c o m ByteBuffer buf = ByteBuffer.allocate(15); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.readGenerator, 0, 0, 0, 0, 6 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { (byte) groupID, (byte) genID, 0, 0 }); buf.position(0); try { if (printInput) System.out.println("Input for readGenerator: " + groupID + " : " + genID + " : " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(readGenerator)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(readGenerator)", false); System.out.println("Response from readGenerator: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { BigInteger generator = new BigInteger(1, response.getData()); System.out.println("Generator - is : " + groupID + " : " + genID + " : " + generator); cachedGenerator.put(groupID + ":" + genID, generator); return generator; } } catch (CardException e) { e.printStackTrace(); } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
/** * /*from w w w . j a v a2s .c o m*/ * @param pin * @param groupID * @param compType 0: modulus, 1: group order 2: cofactor * @return */ private BigInteger getGroupComponent(int pin, int groupID, int compType) { if (cachedGroupComponent.containsKey(groupID + ":" + compType)) { BigInteger cached = cachedGroupComponent.get(groupID + ":" + compType); System.out.println("Cached readGroupComponent: " + groupID + " : " + compType + " : " + cached); return cached; } ByteBuffer buf = ByteBuffer.allocate(15); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.readGroupComponent, 0, 0, 0, 0, 6 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { (byte) groupID, (byte) compType, 0, 0 }); buf.position(0); try { if (printInput) System.out.println("Input for readGroupComponent: " + groupID + " : " + compType + " : " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(readGroupComponent)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(readGroupComponent)", false); System.out.println("Response from readGroupComponent: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { BigInteger groupComponent = new BigInteger(1, response.getData()); System.out.println("GroupComponent - is : " + groupID + " : " + compType + " : " + groupComponent); cachedGroupComponent.put(groupID + ":" + compType, groupComponent); return groupComponent; } } catch (CardException e) { e.printStackTrace(); } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public BigInteger computeCredentialFragment(int pin, URI credentialId) { //fragment is equal to the public key of a credential if (cachedCredentialFragment.containsKey(credentialId)) { BigInteger cached = cachedCredentialFragment.get(credentialId); System.out.println("Cached getCredentialPublicKey: " + credentialId + " - " + cached); return cached; }// ww w . ja va 2 s. co m int credID = this.getCredentialIDFromUri(pin, credentialId); ByteBuffer buf = ByteBuffer.allocate(14); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.getCredentialPublicKey, 0, 0, 0, 0, 5 }); buf.put(this.pinToByteArr(pin)); buf.put((byte) credID); buf.put(new byte[] { 0, 0 }); buf.position(0); try { if (printInput) System.out.println( "Input for getCredentialPublicKey: " + credentialId + " : " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getCredentialPublicKey)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getCredentialPublicKey)", false); System.out.println("Response from getCredentialPublicKey (fragment): " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { System.out.println("And this is the output: " + Arrays.toString(response.getData())); BigInteger credentialFragment = new BigInteger(1, response.getData()); System.out.println("which gives this BigInteger: " + credentialFragment); cachedCredentialFragment.put(credentialId, credentialFragment); return credentialFragment; } } catch (CardException e) { e.printStackTrace(); } return null; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public BigInteger computeScopeExclusivePseudonym(int pin, URI scope) { if (cachedScopeExclusivePseudonym.containsKey(scope)) { BigInteger pv = cachedScopeExclusivePseudonym.get(scope); System.out.println("Cached from getScopeExclusivePseudonym: " + scope + " : " + pv); return pv; }/* w w w . ja v a2 s . c om*/ try { byte[] scopeBytes = this.uriToByteArr(scope); if (scopeBytes.length > 2044) { throw new RuntimeException("The inputted scope is too large."); } byte[] begin = new byte[] { (byte) this.ABC4TRUSTCMD, this.getScopeExclusivePseudonym, 0, 0, 0 }; ByteBuffer buf = ByteBuffer.allocate(9 + 4 + scopeBytes.length); buf.put(begin); buf.put(this.intLengthToShortByteArr(4 + scopeBytes.length)); buf.put(this.pinToByteArr(pin)); buf.put(scopeBytes); buf.put(new byte[] { 0, 0 }); buf.position(0); if (printInput) System.out.println("Input for getScopeExclusivePseudonym: " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getScopeExclusivePseudonym)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(getScopeExclusivePseudonym)", false); System.out.println("Response from getScopeExclusivePseudonym: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { BigInteger pv = new BigInteger(1, response.getData()); cachedScopeExclusivePseudonym.put(scope, pv); return pv; } return null; } catch (CardException e) { e.printStackTrace(); return null; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
/** * Returns the number of uris read, no of uris remaining to be read. *//*from w w w . j a v a 2 s.c o m*/ private byte[] getBlobUrisHelper(int pin, Set<URI> uris, byte nread) { ByteBuffer buf = ByteBuffer.allocate(14); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.listBlobs, 0, 0, 0, 0, 5 }); buf.put(this.pinToByteArr(pin)); buf.put(new byte[] { nread, 0, 0 }); //first arg is how many URIs we read so far. buf.position(0); try { if (printInput) System.out.println("Input for listBlobs: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from listBlobs: " + response); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return null; } byte[] data = response.getData(); System.out.println("data: " + Arrays.toString(data)); int index = 0; while (true) { if ((index + 2) == data.length) { //at the end, so the last two bytes is the updated number of read URIs and the number of unread URIs // System.out.println("data.length: " + data.length); // System.out.println("index: " + index); nread = data[index]; byte unread = data[index + 1]; System.out.println("nread: " + nread); System.out.println("unread: " + unread); return new byte[] { nread, unread }; } else { byte uriSize = data[index]; byte[] uri = new byte[uriSize]; System.arraycopy(data, index + 1, uri, 0, uriSize); uris.add(this.byteArrToUri(uri)); index += uriSize + 1; } } } catch (CardException e) { e.printStackTrace(); return null; } }