List of usage examples for java.nio ByteBuffer put
public ByteBuffer put(ByteBuffer src)
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public int init(int newPin, SystemParameters pseuParams, RSAKeyPair rootKey, short deviceId) { if (this.wasInit()) { return -1; }/*from ww w . ja v a 2s. c o m*/ try { byte[] deviceID = ByteBuffer.allocate(2).putShort(deviceId).array(); this.setAuthenticationKey(rootKey.getN(), 0, null); byte[] deviceKeySize = this.intLengthToShortByteArr(pseuParams.deviceSecretSizeBytes); byte[] idAndDeviceKeySize = new byte[] { deviceID[0], deviceID[1], deviceKeySize[0], deviceKeySize[1] }; ByteBuffer buf = ByteBuffer.allocate(13); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.initializeDevice, 0, 0, 0, 0, 4 }); buf.put(idAndDeviceKeySize); buf.put(new byte[] { 0, 0 }); buf.position(0); if (printInput) System.out.println("Input to initialize device: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return -1; } byte[] pinAndPuk = SmartcardCrypto.decrypt(response.getData(), rootKey); byte[] pin = new byte[4]; byte[] puk = new byte[8]; System.arraycopy(pinAndPuk, 0, pin, 0, 4); System.arraycopy(pinAndPuk, 4, puk, 0, 8); String ipin = "", ipuk = ""; for (int i = 0; i < 4; i++) { ipin += (char) (pin[i] & 0xFF); } for (int i = 0; i < 8; i++) { ipuk += (char) (puk[i] & 0xFF); } if (this.changePin(Integer.parseInt(ipin), newPin) != SmartcardStatusCode.OK) { System.out.println("Could not change pin."); return -1; } System.out.println("Now initializing group stuff"); int mode = this.getMode(); if (this.setGroupComponent(mode, pseuParams.p.toByteArray(), 0, 0, null) != SmartcardStatusCode.OK) { return -1; } if (this.setGroupComponent(mode, pseuParams.subgroupOrder.toByteArray(), 0, 1, null) != SmartcardStatusCode.OK) { return -1; } BigInteger f = pseuParams.p.subtract(BigInteger.ONE).divide(pseuParams.subgroupOrder); //cofactor this.setGroupComponent(mode, f.toByteArray(), 0, 2, null); //then add a generator of the subgroup q if (this.setGenerator(mode, pseuParams.g.toByteArray(), 0, 1, null) != SmartcardStatusCode.OK) { return -1; } //set prover byte[] data = new byte[5 + MAX_CREDENTIALS + 1]; data[0] = 1; //id 1 int ksize = pseuParams.zkChallengeSizeBytes * 2 + pseuParams.zkStatisticalHidingSizeBytes; byte[] ksize_bytes = this.intLengthToShortByteArr(ksize); data[1] = ksize_bytes[0]; data[2] = ksize_bytes[1]; // as large as the subgroup order is -1 to prevent overflow. int csize = pseuParams.zkChallengeSizeBytes; byte[] csize_bytes = this.intLengthToShortByteArr(csize); data[3] = csize_bytes[0]; data[4] = csize_bytes[1]; // challenge size: 256 bit = 32 bytes (as per default in SystemParameters) for (int i = 0; i <= MAX_CREDENTIALS; i++) { //0 means it accepts both credentials and scope-exclusive stuff. //1,2,3,... means it accepts credentials with id 1,2,3,... data[i + 5] = (byte) i; } buf = ByteBuffer.allocate(5 + data.length); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.setProver, 0, 0, (byte) data.length }); buf.put(data); buf.position(0); System.out.println("Input to prover: " + Arrays.toString(buf.array())); response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from setProver: " + response); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return -1; } //After init, one should call setIssuer which creates a group and counter. return Integer.parseInt(ipuk); } catch (CardException e) { e.printStackTrace(); return -1; } }
From source file:com.healthmarketscience.jackcess.Table.java
/** * Add multiple rows to this table, only writing to disk after all * rows have been written, and every time a data page is filled. * @param inRows List of Object[] row values * @param writeRowBufferH TempBufferHolder used to generate buffers for * writing the row data *//* w w w.j av a 2 s . c o m*/ private void addRows(List<? extends Object[]> inRows, TempBufferHolder writeRowBufferH) throws IOException { if (inRows.isEmpty()) { return; } // copy the input rows to a modifiable list so we can update the elements List<Object[]> rows = new ArrayList<Object[]>(inRows); ByteBuffer[] rowData = new ByteBuffer[rows.size()]; for (int i = 0; i < rows.size(); i++) { // we need to make sure the row is the right length and is an Object[] // (fill with null if too short). note, if the row is copied the caller // will not be able to access any generated auto-number value, but if // they need that info they should use a row array of the right // size/type! Object[] row = rows.get(i); if ((row.length < _columns.size()) || (row.getClass() != Object[].class)) { row = dupeRow(row, _columns.size()); // we copied the row, so put the copy back into the rows list rows.set(i, row); } // fill in autonumbers handleAutoNumbersForAdd(row); // write the row of data to a temporary buffer rowData[i] = createRow(row, writeRowBufferH.getPageBuffer(getPageChannel())); if (rowData[i].limit() > getFormat().MAX_ROW_SIZE) { throw new IOException("Row size " + rowData[i].limit() + " is too large"); } } ByteBuffer dataPage = null; int pageNumber = PageChannel.INVALID_PAGE_NUMBER; for (int i = 0; i < rowData.length; i++) { int rowSize = rowData[i].remaining(); // get page with space dataPage = findFreeRowSpace(rowSize, dataPage, pageNumber); pageNumber = _addRowBufferH.getPageNumber(); // write out the row data int rowNum = addDataPageRow(dataPage, rowSize, getFormat(), 0); dataPage.put(rowData[i]); // update the indexes RowId rowId = new RowId(pageNumber, rowNum); for (IndexData indexData : _indexDatas) { indexData.addRow(rows.get(i), rowId); } } writeDataPage(dataPage, pageNumber); // Update tdef page updateTableDefinition(rows.size()); }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardBackup backupAttendanceData(int pin, String password) { SmartcardBackup backup = new SmartcardBackup(); ByteBuffer buf = ByteBuffer.allocate(21); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.backupDevice, 0, 0, 0, 0, 0x0C }); buf.put(this.pinToByteArr(pin)); byte[] password_bytes = Utils.passwordToByteArr(password); if (password_bytes == null) { return null; }/*from w ww . j ava 2s . c om*/ buf.put(password_bytes); buf.put(new byte[] { 0, 0 }); buf.position(0); try { //First we backup the device-specific stuff. pin, puk and deviceSecret is encrypted and //deviceID and deviceURI is stored in plain text ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from backupDevice: " + response); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return null; } backup.macDevice = response.getData(); backup.deviceID = this.getDeviceID(pin); backup.deviceUri = this.getDeviceURI(pin); //Then we backup the counters. counterID, index and cursor is encrypted, but //the threshold and keyID is hidden. Thus we need to save those along with the counterID //in cleartext. We assume that the key is put on the card in the initialization phase. // buf = ByteBuffer.allocate(18); // buf.put(new byte[]{(byte)this.ABC4TRUSTCMD, this.backupCounters, 0, 0, 0x0C}); // buf.put(this.pinToByteArr(pin)); // buf.put(password_bytes); // buf.put((byte)0); // buf.position(0); // response = this.transmitCommand(new CommandAPDU(buf)); // System.out.println("Response from backupCounters: " + response); // if(this.evaluateStatus(response) == SmartcardStatusCode.OK){ // backup.macCounters = response.getData(); // }else{ // backup.macCounters = null; // } // // List<Byte> credentials = this.listCredentialIDs(pin); // for(Byte credID : credentials){ // byte[] credInfo = this.readCredential(pin, credID); // byte status = credInfo[5]; // System.out.println("backing up credential: "+this.getCredentialUriFromID(pin, credID)+" with status: " + status); // if(status != 2){ // //Credential is either just created, and thus not backed up, // //OR done presenting (limited amount of presentations), thus not backupable. // continue; // } // buf = ByteBuffer.allocate(22); // buf.put(new byte[]{(byte)this.ABC4TRUSTCMD, (byte) this.backupCredential, 0, 0, 0, 0, 0x0D}); // buf.put(this.pinToByteArr(pin)); // buf.put(password_bytes); // buf.put(credID); // buf.put(new byte[]{0, 0}); // buf.position(0); // response = this.transmitCommand(new CommandAPDU(buf)); // System.out.println("Response from backupCredentials: " + response); // if(this.evaluateStatus(response) != SmartcardStatusCode.OK){ // return null; // } // backup.macCredentials.put(credID, response.getData()); // } //Create AES key using the PIN and Password of the user final byte[] IV = new byte[16]; new SecureRandom().nextBytes(IV); Cipher cipher = getAESKey(salt, password, IV, true); backup.IV = IV; //finally we backup the blobstore Map<URI, SmartcardBlob> blobs = this.getBlobs(pin); Map<URI, byte[]> encBlobs = new HashMap<URI, byte[]>(); try { for (URI uri : blobs.keySet()) { String uriString = uri.toString(); if (uriString.startsWith(IdemixCryptoEngineUserImpl.IdmxCredential) || uriString.startsWith(UProveCryptoEngineUserImpl.UProveCredential)) { continue; } byte[] blob = blobs.get(uri).blob; encBlobs.put(uri, cipher.doFinal(blob)); } } catch (Exception e) { throw new RuntimeException("Could not encrypt blobstore", e); } backup.blobstore = encBlobs; } catch (CardException e) { e.printStackTrace(); return null; } return backup; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public ZkProofCommitment prepareZkProof(int pin, Set<URI> credentialIds, Set<URI> scopeExclusivePseudonyms, boolean includeDevicePublicKeyProof) { TimingsLogger.logTiming("HardwareSmartcard.prepareZkProof", true); ZkProofCommitment comm = new ZkProofCommitment(); SystemParameters params = this.getSystemParameters(pin); comm.spec = new ZkProofSpecification(params); comm.spec.parametersForPseudonyms = params; comm.spec.credentialBases = new HashMap<URI, GroupParameters>(); comm.spec.credFragment = new HashMap<URI, BigInteger>(); for (URI courseId : credentialIds) { byte credID = this.getCredentialIDFromUri(pin, courseId); byte[] cred = this.readCredential(pin, credID); byte issuerID = cred[0]; GroupParameters groupParams = this.getGroupParameters(pin, issuerID); comm.spec.credentialBases.put(courseId, groupParams); comm.spec.credFragment.put(courseId, this.computeCredentialFragment(pin, courseId)); }//from w w w . j av a2 s . c om comm.spec.scopeExclusivePseudonymValues = new HashMap<URI, BigInteger>(); byte[] data = new byte[5]; System.arraycopy(this.pinToByteArr(pin), 0, data, 0, 4); data[4] = 1; //ProverID - TODO: hardcoded to 1 as of now. Assuming there can be only 1 for the pilot byte[] proofSession = null; ByteBuffer buf = ByteBuffer.allocate(11); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.startCommitments, 0, 0, 5 }); buf.put(data); buf.put((byte) 16); buf.position(0); try { if (printInput) System.out.println("Input for startCommitments: " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(startCommitments)", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(startCommitments)", false); System.out.println("Response from startCommitments: " + response); System.out.println("And this is the output: " + Arrays.toString(response.getData())); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return null; } proofSession = response.getData(); } catch (CardException e) { throw new RuntimeException("PrepareZkProof crashed.", e); } //ProofStatus set to 1 comm.nonceCommitment = proofSession; if (includeDevicePublicKeyProof) { comm.spec.devicePublicKey = this.computeDevicePublicKey(pin); comm.commitmentForDevicePublicKey = this.computeDevicePublicKeyCommitment(pin); } boolean notEnoughAttendance = false; for (URI uri : credentialIds) { byte credID = this.getCredentialIDFromUri(pin, uri); byte[] credInfo = readCredential(pin, credID); //byte issuerID = credInfo[0]; //byte counterID = this.readIssuer(pin, issuerID)[4]; byte status = credInfo[5]; byte presentOrIssuance = this.getIssuanceCommitment; String command = "getIssuanceCommitment"; //System.out.println("\nStatus of credential before commitments are made: " + status); if (status == 2) { //credential has already been issued. So we assume we want to present it. command = "getPresentationCommitment"; presentOrIssuance = this.getPresentationCommitment; } /* if(counterID != 0){ //Counter active. We must know if the attendance is high enough. byte[] counterInfo = readCounter(pin, counterID); int index = counterInfo[1]; int threshold = counterInfo[2]; if(index < threshold && presentOrIssuance == this.getPresentationCommitment){ //Not enough attendance. aborting at the end; Done because of timing attacks. notEnoughAttendance = true; } } */ buf = ByteBuffer.allocate(14); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, presentOrIssuance, 0, 0, 0, 0, 5 }); buf.put(this.pinToByteArr(pin)); buf.put(credID); buf.put(new byte[] { 0, 0 }); buf.position(0); try { if (printInput) System.out.println("Input for " + command + ": " + Arrays.toString(buf.array())); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(" + command + ")", true); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); TimingsLogger.logTiming("HardwareSmartcard.transmitCommand(" + command + ")", false); System.out.println("Response from " + command + ": " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { comm.commitmentForCreds.put(uri, new BigInteger(1, response.getData())); } else { return null; } } catch (CardException e) { throw new RuntimeException("PrepareZkProof crashed.", e); } } for (URI scope : scopeExclusivePseudonyms) { BigInteger pseudonymCommitment = this.getScopeExclusiveCommitment(pin, scope); comm.commitmentForScopeExclusivePseudonyms.put(scope, pseudonymCommitment); comm.spec.scopeExclusivePseudonymValues.put(scope, this.computeScopeExclusivePseudonym(pin, scope)); } if (notEnoughAttendance) { System.out.println("Because of not enough attendance?"); TimingsLogger.logTiming("HardwareSmartcard.prepareZkProof", false); return null; } else { TimingsLogger.logTiming("HardwareSmartcard.prepareZkProof", false); return comm; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode incrementCourseCounter(int pin, RSAKeyPair key, URI issuerId, int lectureId) { //First check if the counter is enabled. //TODO! // TrustedIssuerParameters tip = this.getIssuerParameters(pin, issuerId); // if(!tip.course.isActivated()){ // if(!tip.course.updateLectureId(lectureId)){ // //Course not yet issued! // return SmartcardStatusCode.NOT_MODIFIED; // } // }//w w w. j av a 2 s . c o m //auth data should be counterID||cursor , with cursor having the updated value. byte counterID = this.getIssuerIDFromUri(pin, issuerId); //IssuerID is the same as CounterID if the counter exists. byte keyID = this.readCounter(pin, counterID)[0]; byte[] data = new byte[5]; data[0] = counterID; System.arraycopy(this.getNewCursor(lectureId), 0, data, 1, 4); byte[] challenge = this.getNewNonceForSignature(); byte[] sig = SmartcardCrypto.generateSignature(data, challenge, key, this.rand).sig; //sig = this.removeSignBit(sig); ByteBuffer buf = ByteBuffer.allocate(7 + 1 + sig.length); byte[] bufferLength = ByteBuffer.allocate(2).putShort((short) (sig.length + 1)).array(); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.incrementCounter, 0, 0, 0 }); buf.put(bufferLength); buf.put(keyID); buf.put(sig); buf.position(0); try { byte[] counterInfo = this.readCounter(pin, counterID); byte index = counterInfo[1]; if (printInput) System.out.println("Input for incrementCounter: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from incrementCounter: " + response); if (this.evaluateStatus(response) == SmartcardStatusCode.OK) { //ensure that counter was increased or return not modified byte[] newCounterInfo = this.readCounter(pin, counterID); int newIndex = newCounterInfo[1]; if (index == newIndex) { return SmartcardStatusCode.NOT_MODIFIED; } else { return SmartcardStatusCode.OK; } } return this.evaluateStatus(response); } catch (CardException e) { e.printStackTrace(); return SmartcardStatusCode.NOT_FOUND; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode restoreAttendanceData(int pin, String password, SmartcardBackup backup) { //restore device URI SmartcardBlob deviceUriBlob = new SmartcardBlob(); try {// ww w .j a v a 2s . c o m deviceUriBlob.blob = backup.deviceUri.toASCIIString().getBytes("US-ASCII"); } catch (UnsupportedEncodingException e1) { return SmartcardStatusCode.BAD_REQUEST; } this.storeBlob(pin, Smartcard.device_name, deviceUriBlob); try { ByteBuffer buf; if (backup.macCounters != null && backup.macCounters.length != 0) { buf = ByteBuffer.allocate(17); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.restoreCounters, 0, 0, 0x0C }); buf.put(this.pinToByteArr(pin)); buf.put(Utils.passwordToByteArr(password)); buf.position(0); this.putData(backup.macCounters); //put the encrypted data in the buffer ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from restoreCounters: " + response); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return this.evaluateStatus(response); } } for (byte credID : backup.macCredentials.keySet()) { buf = ByteBuffer.allocate(17); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, (byte) this.restoreCredential, 0, 0, 0x0C }); buf.put(this.pinToByteArr(pin)); buf.put(Utils.passwordToByteArr(password)); buf.position(0); if (printInput) System.out.println("Input for for restoreCredential: " + Arrays.toString(buf.array())); this.putData(backup.macCredentials.get(credID));//put the encrypted data in the buffer ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from restoreCredential: " + response); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return this.evaluateStatus(response); } } //restoring the blob-store, but remove the current blob-store first (in particular remove the pseudonym that no longer works.) Set<URI> blobs = this.getBlobUris(pin); for (URI uri : blobs) { this.deleteBlob(pin, uri); } try { for (URI uri : backup.blobstore.keySet()) { //decrypt blobs before putting them in. byte[] encedBlob = backup.blobstore.get(uri); Cipher cipher = getAESKey(salt, password, backup.IV, false); byte[] blob = cipher.doFinal(encedBlob); SmartcardBlob SCBlob = new SmartcardBlob(); SCBlob.blob = blob; this.storeBlob(pin, uri, SCBlob); } } catch (Exception e) { throw new RuntimeException("Could not decrypt blobs", e); } //finally restore the device - this means also restoring the pin, so using the provided pin no longer works. buf = ByteBuffer.allocate(17); buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.restoreDevice, 0, 0, 0x0C }); buf.put(this.pinToByteArr(pin)); buf.put(Utils.passwordToByteArr(password)); buf.position(0); this.putData(backup.macDevice); //put the encrypted data in the buffer ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from restoreDevice: " + response); if (this.evaluateStatus(response) != SmartcardStatusCode.OK) { return this.evaluateStatus(response); } } catch (CardException e) { e.printStackTrace(); return SmartcardStatusCode.NOT_FOUND; } return SmartcardStatusCode.OK; }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode addUProveIssuerParameters(RSAKeyPair rootKey, URI parametersUri, UProveParams uProveParams) {/* ww w.j a v a 2 s.co m*/ byte issuerID = this.getNewIssuerID(parametersUri); byte groupID = issuerID; byte genID1 = 1; byte genID2 = 0; byte numPres = 0; //unlimited presentations - limit not used in the pilot byte counterID = 0; //no counter present ByteBuffer buf = ByteBuffer.allocate(11); //SET ISSUER(BYTE issuerID, groupID, genID1, genID2, numpres, counterID) byte[] data = new byte[] { issuerID, groupID, genID1, genID2, numPres, counterID }; buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.setIssuer, 0, 0, 6 }); buf.put(data); buf.position(0); try { //Before setting the issuer, we must create a group, generators as well as a counter int mode = this.getMode(); this.setGroupComponent(mode, uProveParams.p.toByteArray(), groupID, 0, rootKey); this.setGroupComponent(mode, uProveParams.q.toByteArray(), groupID, 1, rootKey); this.setGroupComponent(mode, uProveParams.f.toByteArray(), groupID, 2, rootKey); this.setGenerator(mode, uProveParams.g.toByteArray(), groupID, genID1, rootKey); //prior to the actual command, if we are in working mode, //we have to authenticate the input data first. if (mode == 2) { System.out.println("Can only use addIssuerParameters in root mode"); return SmartcardStatusCode.UNAUTHORIZED; } System.out.println("Input for setIssuer: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from setIssuer: " + response); return this.evaluateStatus(response); } catch (CardException e) { //TODO: Error handling. Remove stuff again if something fails. e.printStackTrace(); return SmartcardStatusCode.NOT_FOUND; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode addIssuerParameters(RSAKeyPair rootKey, URI parametersUri, CredentialBases credBases) {//from www. jav a 2 s. c om byte issuerID = this.getNewIssuerID(parametersUri); byte groupID = issuerID; byte genID1 = 1;//R0 byte genID2 = 2;//S byte numPres = 0; //unlimited presentations - limit not used in the pilot byte counterID = 0; //no counter present ByteBuffer buf = ByteBuffer.allocate(11); //SET ISSUER(BYTE issuerID, groupID, genID1, genID2, numpres, counterID) byte[] data = new byte[] { issuerID, groupID, genID1, genID2, numPres, counterID }; buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.setIssuer, 0, 0, 6 }); buf.put(data); buf.position(0); try { //Before setting the issuer, we must create a group with generators. Idemix uses unknown order. int mode = this.getMode(); SmartcardStatusCode status; status = this.setGroupComponent(mode, credBases.n.toByteArray(), groupID, 0, rootKey); if (status != SmartcardStatusCode.OK) { return status; } status = this.setGenerator(mode, credBases.R0.toByteArray(), groupID, genID1, rootKey); if (status != SmartcardStatusCode.OK) { return status; } status = this.setGenerator(mode, credBases.S.toByteArray(), groupID, genID2, rootKey); if (status != SmartcardStatusCode.OK) { return status; } //prior to the actual command, if we are in working mode, //we have to authenticate the input data first. if (mode == 2) { System.out.println("Can only use addIssuerParameters in root mode"); return SmartcardStatusCode.UNAUTHORIZED; } System.out.println("Input for set Issuer: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from setIssuer: " + response); return evaluateStatus(response); } catch (CardException e) { //TODO: Error handling. Remove stuff again if something fails. e.printStackTrace(); return SmartcardStatusCode.NOT_FOUND; } }
From source file:eu.abc4trust.smartcard.HardwareSmartcard.java
@Override public SmartcardStatusCode addIssuerParametersWithAttendanceCheck(RSAKeyPair rootKey, URI parametersUri, int keyIDForCounter, CredentialBases credBases, RSAVerificationKey courseKey, int minimumAttendance) { byte issuerID = this.getNewIssuerID(parametersUri); byte groupID = issuerID; byte genID1 = 1; byte genID2 = 2; byte numPres = 0; //unlimited presentations - limit not used in the pilot byte counterID = issuerID; ByteBuffer buf = ByteBuffer.allocate(11); //SET ISSUER(BYTE issuerID, groupID, genID1, genID2, numpres, counterID) byte[] data = new byte[] { issuerID, groupID, genID1, genID2, numPres, counterID }; buf.put(new byte[] { (byte) this.ABC4TRUSTCMD, this.setIssuer, 0, 0, 6 }); buf.put(data);/*from w w w. j a v a2s . com*/ buf.position(0); try { //Before setting the issuer, we must create a group, generators as well as a counter int mode = this.getMode(); this.setGroupComponent(mode, credBases.n.toByteArray(), groupID, 0, rootKey); this.setGenerator(mode, credBases.R0.toByteArray(), groupID, genID1, rootKey); this.setGenerator(mode, credBases.S.toByteArray(), groupID, genID2, rootKey); byte[] cursor = this.getNewCursor(0); //Create a new key with keyID that counter can use. this.setAuthenticationKey(courseKey.n, keyIDForCounter, rootKey); this.setCounter(counterID, keyIDForCounter, 0, minimumAttendance, cursor, rootKey); //prior to the actual command,if we are in working mode, //we have to authenticate the input data first. if (mode == 2) { System.out.println("Can only use addIssuerParameters in root mode"); return SmartcardStatusCode.UNAUTHORIZED; } System.out.println("Input to setIssuer: " + Arrays.toString(buf.array())); ResponseAPDU response = this.transmitCommand(new CommandAPDU(buf)); System.out.println("Response from setIssuer: " + response); if (evaluateStatus(response) == SmartcardStatusCode.OK) { // SmartcardStatusCode code = this.storeIssuerUriAndID(pin, parametersUri, issuerID); // if(code != SmartcardStatusCode.OK){ // System.err.println("Could not store the issuerURI and ID on the card, but the issuer itself is still stored on the card. Returned code: " + code); // return code; // } } return this.evaluateStatus(response); } catch (CardException e) { //TODO: Error handling. Remove stuff again if something fails. e.printStackTrace(); return SmartcardStatusCode.NOT_FOUND; } }
From source file:com.inclouds.hbase.rowcache.RowCache.java
/** * CHECKED 2 add column.//from ww w . jav a2s . c om * * @param buf * the buf * @param bundle * the bundle * @return the int */ private int addColumn(ByteBuffer buf, List<KeyValue> bundle) { if (bundle.size() == 0) return 0; byte[] column = getColumn(bundle.get(0)); byte[] col = column; buf.putInt(col.length); buf.put(col); int startPosition = buf.position(); int totalVersions = 0; // size = col (4) + num versions (4) + col length int size = 2 * Bytes.SIZEOF_INT + col.length; // Skip total versions skip(buf, Bytes.SIZEOF_INT); while (Bytes.equals(column, col)) { size += addKeyValue(buf, bundle.get(0)); totalVersions++; bundle.remove(0); if (bundle.size() == 0) break; col = getColumn(bundle.get(0)); } // Put total versions buf.putInt(startPosition, totalVersions); return size; }