本文整理汇总了Java中javacard.framework.APDU.setIncomingAndReceive方法的典型用法代码示例。如果您正苦于以下问题:Java APDU.setIncomingAndReceive方法的具体用法?Java APDU.setIncomingAndReceive怎么用?Java APDU.setIncomingAndReceive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.framework.APDU
的用法示例。
在下文中一共展示了APDU.setIncomingAndReceive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAPDU
import javacard.framework.APDU; //导入方法依赖的package包/类
public static short readAPDU(APDU apdu, byte[] buffer, short length) {
short read = apdu.setIncomingAndReceive();
read += apdu.getOffsetCdata();
short total = apdu.getIncomingLength();
if (total > length) {
return 0;
}
byte[] apduBuffer = apdu.getBuffer();
short sum = 0;
do {
Util.arrayCopyNonAtomic(apduBuffer, (short) 0, buffer, sum, read);
sum += read;
read = apdu.receiveBytes((short) 0);
} while (sum < total);
return 0;
}
示例2: GenerateKeyPair
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* This function generates a key pair using the card's on board key generation
* process. The key number (or numbers if a key pair is being generated), algorithm
* type, and algorithm parameters are specified by arguments P1 and P2 and by
* provided DATA.
*
* ins: 0x30
* p1: private key number (0x00-0x0F)
* p2: public key number (0x00-0x0F)
* data: [Key Generation Parameters]
* return: none
*/
private void GenerateKeyPair(APDU apdu, byte[] buffer) {
short bytesLeft = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
if (bytesLeft != apdu.setIncomingAndReceive())
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
byte alg_id = buffer[OFFSET_GENKEY_ALG];
switch (alg_id) {
case KeyPair.ALG_RSA:
case KeyPair.ALG_RSA_CRT:
GenerateKeyPairRSA(buffer);
break;
case KeyPair.ALG_EC_FP:
//GenerateKeyPairECFP(buffer);
GeneratePrivateKeyECFP(buffer);
break;
default:
ISOException.throwIt(SW_INCORRECT_ALG);
}
}
示例3: DeleteObject
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* This function deletes the object identified by the provided object ID. The object�s
* space and name will be removed from the heap and made available for other objects.
* The zero flag denotes whether the object�s memory should be zeroed after
* deletion. This kind of deletion is recommended if object was storing sensitive data.
*
* ins: 0x52
* p1: 0x00
* p2: 0x00 or 0x01 for secure erasure
* data: [object_id(4b)]
* return: none
*/
private void DeleteObject(APDU apdu, byte[] buffer) {
if (buffer[ISO7816.OFFSET_P1] != (byte) 0x00)
ISOException.throwIt(SW_INCORRECT_P1);
if ((buffer[ISO7816.OFFSET_P2] != (byte) 0x00) && (buffer[ISO7816.OFFSET_P2] != (byte) 0x01))
ISOException.throwIt(SW_INCORRECT_P2);
short bytesLeft = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
if (bytesLeft != apdu.setIncomingAndReceive())
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (bytesLeft != (short) 0x04)
ISOException.throwIt(SW_INVALID_PARAMETER);
short obj_class = Util.getShort(buffer, ISO7816.OFFSET_CDATA);
short obj_id = Util.getShort(buffer, (short) (ISO7816.OFFSET_CDATA + (short) 2));
// TODO: Here there are 2 object lookups. Optimize, please !
// (single destroy function with logged_ids param)
short base = om.getBaseAddress(obj_class, obj_id);
// Verify that object exists
if (base == MemoryManager.NULL_OFFSET)
ISOException.throwIt(SW_OBJECT_NOT_FOUND);
// Enforce Access Control
if (!om.authorizeDeleteFromAddress(base, logged_ids))
ISOException.throwIt(SW_UNAUTHORIZED);
// Actually delete the object
om.destroyObject(obj_class, obj_id, buffer[ISO7816.OFFSET_P2] == 0x01);
}
示例4: GetObjectSize
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* This function returns the size of an object that has been previously created with
* MSCCreateObject.
*
* ins: 0x57
* p1: 0x00
* p2: 0x00
* data: [object_id(4b)]
* return: [object_size(2b)]
*/
private void GetObjectSize(APDU apdu, byte[] buffer) {
// Checking P1 & P2
if (buffer[ISO7816.OFFSET_P1] != (byte) 0x00)
ISOException.throwIt(SW_INCORRECT_P1);
if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
ISOException.throwIt(SW_INCORRECT_P2);
short bytesLeft = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
if (bytesLeft != apdu.setIncomingAndReceive())
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (bytesLeft != (short) 4)
ISOException.throwIt(SW_INVALID_PARAMETER);
short obj_class = Util.getShort(buffer, ISO7816.OFFSET_CDATA);
short obj_id = Util.getShort(buffer, (short) (ISO7816.OFFSET_CDATA + (short) 2));
short base = om.getBaseAddress(obj_class, obj_id);
// Verify that object exists
if (base == MemoryManager.NULL_OFFSET)
ISOException.throwIt(SW_INVALID_PARAMETER);
// get object size
short obj_size= om.getSizeFromAddress(base);
// Fill the buffer
Util.setShort(buffer, (short) 0, obj_size);
// Send response
apdu.setOutgoingAndSend((short) 0, (short) 2);
}
示例5: computeHmac
import javacard.framework.APDU; //导入方法依赖的package包/类
private void computeHmac(APDU apdu, byte[] buffer) {
if (buffer[ISO7816.OFFSET_P1] != (byte)20 && buffer[ISO7816.OFFSET_P1] != (byte)64)
ISOException.throwIt(SW_INCORRECT_P1);
if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
ISOException.throwIt(SW_INCORRECT_P2);
short avail = Util.makeShort((byte) 0x00, buffer[ISO7816.OFFSET_LC]);
if (apdu.setIncomingAndReceive() != avail)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
short pos= ISO7816.OFFSET_CDATA;//apdu.getOffsetCdata(); //(short) ISO7816.OFFSET_CDATA;
short key_size=Util.getShort(buffer, pos);
pos+=2;
pos+=key_size;
short msg_size=Util.getShort(buffer, pos);
pos+=2;
short hashSize=0;
if (buffer[ISO7816.OFFSET_P1]==(byte)20)
hashSize= HmacSha160.computeHmacSha160(buffer, (short)(ISO7816.OFFSET_CDATA+2), key_size, buffer, pos, msg_size, buffer, (short)0);
else if (buffer[ISO7816.OFFSET_P1]==(byte)64)
hashSize= HmacSha512.computeHmacSha512(buffer, (short)(ISO7816.OFFSET_CDATA+2), key_size, buffer, pos, msg_size, buffer, (short)0);
apdu.setOutgoingAndSend((short) 0, hashSize);
return;
}
示例6: internalAuthenticate
import javacard.framework.APDU; //导入方法依赖的package包/类
private void internalAuthenticate(APDU apdu) {
byte[] buffer = apdu.getBuffer();
// PW1 with 0x82
if (!pins[PIN_INDEX_PW1].isValidated() || !pinSubmitted[1]) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
short len = apdu.setIncomingAndReceive();
if (len > (short) 102 || len != (buffer[ISO7816.OFFSET_LC] & 0xFF)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
if (!authenticationKey.getPrivate().isInitialized()) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
cipherRSA.init(authenticationKey.getPrivate(), Cipher.MODE_ENCRYPT);
cipherRSA.doFinal(buffer, ISO7816.OFFSET_CDATA, len, buffer, (short) 0);
apdu.setOutgoingAndSend((short) 0, RSA_KEY_LENGTH_BYTES);
}
示例7: storeFixedLength
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* Store the fixed length incoming APDU data in a buffer. If the APDU data length is less than the
* maximum length, the data will be padded with zeroes.
*/
void storeFixedLength(APDU apdu, byte[] destination, short offset, short maximum_length) {
byte[] buffer = apdu.getBuffer();
// When writing DOs, PW1 really means PW1 submitted as PW2.
if (!pins[PIN_INDEX_PW3].isValidated()) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
short length = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
if (length > maximum_length || apdu.setIncomingAndReceive() != length) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, destination, offset, length);
if (maximum_length > length) {
Util.arrayFillNonAtomic(destination, (short) (offset + length),
(short) (maximum_length - length), (byte) 0);
}
}
示例8: storeVariableLength
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* Store the incoming APDU data in a fixed buffer, the first byte will contain the data length.
*
* @param pin_type indicates which PIN should be checked.
*/
void storeVariableLength(APDU apdu, byte[] destination, short pin_type) {
byte[] buffer = apdu.getBuffer();
// When writing DOs, PW1 really means PW1 submitted as PW2.
if (!pins[pin_type].isValidated() ||
((pin_type == PIN_INDEX_PW1) && !pinSubmitted[1])) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
short length = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
if ((short) (length + 1) > destination.length || length > (short) 255 ||
apdu.setIncomingAndReceive() != length) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
JCSystem.beginTransaction();
destination[0] = (byte) length;
Util.arrayCopy(buffer, ISO7816.OFFSET_CDATA, destination, (short) 1, length);
JCSystem.commitTransaction();
}
示例9: handleVerifyPin
import javacard.framework.APDU; //导入方法依赖的package包/类
private static void handleVerifyPin(APDU apdu) throws ISOException {
byte[] buffer = apdu.getBuffer();
if ((setup == TC.FALSE) || (setup != TC.TRUE)) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
if (buffer[ISO7816.OFFSET_P1] == P1_GET_REMAINING_ATTEMPTS) {
buffer[0] = walletPin.getTriesRemaining();
apdu.setOutgoingAndSend((short)0, (short)1);
return;
}
apdu.setIncomingAndReceive();
if (buffer[ISO7816.OFFSET_LC] != walletPinSize) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
Util.arrayFillNonAtomic(scratch256, (short)0, WALLET_PIN_SIZE, (byte)0xff);
Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, scratch256, (short)0, walletPinSize);
if (!walletPin.check(scratch256, (short)0, WALLET_PIN_SIZE)) {
if (walletPin.getTriesRemaining() == 0) {
reset();
}
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
}
示例10: handleSetAttestationCert
import javacard.framework.APDU; //导入方法依赖的package包/类
private void handleSetAttestationCert(APDU apdu) throws ISOException {
byte[] buffer = apdu.getBuffer();
short len = apdu.setIncomingAndReceive();
short dataOffset = apdu.getOffsetCdata();
short copyOffset = Util.makeShort(buffer[ISO7816.OFFSET_P1], buffer[ISO7816.OFFSET_P2]);
if ((short)(copyOffset + len) > (short)attestationCertificate.length) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
Util.arrayCopy(buffer, dataOffset, attestationCertificate, copyOffset, len);
if ((short)(copyOffset + len) == (short)attestationCertificate.length) {
attestationCertificateSet = true;
}
}
示例11: handleGetCmac
import javacard.framework.APDU; //导入方法依赖的package包/类
private void handleGetCmac(APDU apdu) {
byte[] buffer = apdu.getBuffer();
short dataLen = apdu.setIncomingAndReceive();
short dataOffset = apdu.getOffsetCdata();
if (dataLen != 32) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
cmac = SignatureX.getInstance(SignatureX.ALG_AES_CMAC16, false);
cmac.init(drngAESKey, Signature.MODE_SIGN);
short sigLen = cmac
.sign(buffer, dataOffset, dataLen, buffer, (short) 0);
apdu.setOutgoingAndSend((short) 0, sigLen);
}
示例12: handleGetPRand
import javacard.framework.APDU; //导入方法依赖的package包/类
private void handleGetPRand(APDU apdu) {
byte[] buffer = apdu.getBuffer();
short dataLen = apdu.setIncomingAndReceive();
short dataOffset = apdu.getOffsetCdata();
random.setSeed(buffer, dataOffset, dataLen);
random.generateData(buffer, (short) 0, (short) 16);
apdu.setOutgoingAndSend((short) 0, (short) 16);
}
示例13: doChainingOrExtAPDUWithBuffer
import javacard.framework.APDU; //导入方法依赖的package包/类
private short doChainingOrExtAPDUWithBuffer(APDU apdu, byte[] databuffer, short bufferlen) throws ISOException {
short recvLen = apdu.setIncomingAndReceive();
byte[] buf = apdu.getBuffer();
// Receive data (short or extended).
while (recvLen > 0) {
if((short)(chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] + recvLen) > bufferlen) {
ISOException.throwIt(ISO7816.SW_FILE_FULL);
}
Util.arrayCopyNonAtomic(buf, ISO7816.OFFSET_CDATA, databuffer, chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS], recvLen);
chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] += recvLen;
recvLen = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
}
if(isCommandChainingCLA(apdu)) {
// We are still in the middle of a chain, otherwise there would not have been a chaining CLA.
// Make sure the caller does not forget to return as the data should only be interpreted
// when the chain is completed (when using this method).
ISOException.throwIt(ISO7816.SW_NO_ERROR);
return (short)0;
} else {
// Chain has ended or no chaining.
// We did receive the data, everything is fine.
// Reset the current position in ram_buf.
recvLen = (short) (recvLen + chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS]);
chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] = 0;
return recvLen;
}
}
示例14: if
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Process the RESET RETRY COUNTER apdu (INS = 2C).
*
* This is used to unblock the PIN with the PUK and set a new PIN value.
*
* \param apdu The RESET RETRY COUNTER apdu.
*
* \throw ISOException SW_COMMAND_NOT_ALLOWED, ISO7816.SW_WRONG_LENGTH, SW_INCORRECT_P1P2,
* SW_PIN_TRIES_REMAINING.
*/
public void processResetRetryCounter(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
short lc;
GidsPIN pin = null;
if(isInInitializationMode) {
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
}
if(p1 == (byte) 0x02) {
// this suppose a previous authentication of the admin via
// external or mutual authenticate
lc = apdu.setIncomingAndReceive();
// only P2 = 80 is specified
if (p2 != (byte) 0x80) {
ISOException.throwIt(ErrorCode.SW_REFERENCE_DATA_NOT_FOUND);
}
try {
pin = GetPINByReference(p2);
} catch(NotFoundException e) {
ISOException.throwIt(ErrorCode.SW_REFERENCE_DATA_NOT_FOUND);
}
if (!CheckExternalOrMutualAuthentication()) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
// Check length.
pin.CheckLength((byte) lc);
// Set PIN value
pin.update(buf, ISO7816.OFFSET_CDATA, (byte)lc);
pin.resetAndUnblock();
// admin is deauthenticated at the end of the process
DeauthenticateAllPin();
} else {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
}
示例15: processGeneralAuthenticate
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Process the general authentication process
*/
public void processGeneralAuthenticate(APDU apdu) {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
short lc;
if(isInInitializationMode) {
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
}
if(p1 != (byte) 0x00 || p2 != (byte) 0x00 ) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
// Bytes received must be Lc.
lc = apdu.setIncomingAndReceive();
short innerPos = 0, innerLen = 0;
if (buf[ISO7816.OFFSET_CDATA] != (byte) 0x7C) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
try {
innerLen = UtilTLV.decodeLengthField(buf, (short) (ISO7816.OFFSET_CDATA+1));
innerPos = (short) (ISO7816.OFFSET_CDATA + 1 + UtilTLV.getLengthFieldLength(buf, (short) (ISO7816.OFFSET_CDATA+1)));
} catch (InvalidArgumentsException e1) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
// inner functions never return if their input tag is found
if (CheckForExternalChallenge(apdu, buf, innerPos, innerLen)) {
return;
}
if (CheckForChallengeResponse(apdu, buf, innerPos, innerLen)) {
return;
}
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}