本文整理汇总了Java中javacard.framework.APDU.getOffsetCdata方法的典型用法代码示例。如果您正苦于以下问题:Java APDU.getOffsetCdata方法的具体用法?Java APDU.getOffsetCdata怎么用?Java APDU.getOffsetCdata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.framework.APDU
的用法示例。
在下文中一共展示了APDU.getOffsetCdata方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
示例3: 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);
}
示例4: 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);
}
示例5: doChangePIN
import javacard.framework.APDU; //导入方法依赖的package包/类
private void doChangePIN(APDU apdu) {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
short lc = apdu.setIncomingAndReceive();
short off = apdu.getOffsetCdata();
if (p1 != (byte) 0x00 || (p2 != (byte) 0x80)) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
if (pin.getTriesRemaining() == 0) {
ISOException.throwIt(SW_AUTHENTICATION_METHOD_BLOCKED);
}
if ((lc != apdu.getIncomingLength()) || lc != (short) 16) {
ISOException.throwIt((short) 0x6480);
}
for (short i = 0; i < (short) 16; i++) {
if (((buf[(short) (i + off)] < 0x30)
|| (buf[(short) (i + off)] > 0x39))
&& (buf[(short) (i + off)] != 0xFF)) {
ISOException.throwIt((short) 0x6480);
}
}
if (!pin.check(buf, off, (byte) 8)) {
// Authentication failed
authenticated[0] = false;
ISOException.throwIt((short) (SW_PIN_TRIES_REMAINING
| pin.getTriesRemaining()));
}
pin.update(buf, (short) (off + 8), (byte) 8);
}
示例6: doGetData
import javacard.framework.APDU; //导入方法依赖的package包/类
private void doGetData(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
short lc = apdu.setIncomingAndReceive();
short offset = apdu.getOffsetCdata();
if (p1 != (byte) 0x3F || p2 != (byte) 0xFF) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
if (lc != apdu.getIncomingLength()) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
if (buf[offset] != (byte) 0x5C) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
if (buf[(short) (offset + 1)] == 0x1) {
if (buf[(short) (offset + 2)] == (byte) 0x7E) {
io.sendFile(FileIndex.DISCOVERY, apdu, (short) 0);
return;
}
} else if (buf[(short) (offset + 1)] == 0x3) {
if ((buf[(short) (offset + 2)] != (byte) 0x5F)
|| (buf[(short) (offset + 3)] != (byte) 0xC1)
|| (buf[(short) (offset + 4)] == (byte) 0x4)
|| (buf[(short) (offset + 4)] > (byte) 0xA)) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
byte id = (byte) (buf[(byte) (offset + 4)] - 1);
if (((id == (byte) 0x2) || (id == (byte) 0x7)
|| (id == (byte) 0x8)) && !authenticated[0]) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
io.sendFile(id, apdu, (short) 0);
return;
}
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
示例7: doGenerateKeyPair
import javacard.framework.APDU; //导入方法依赖的package包/类
private void doGenerateKeyPair(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
short lc = apdu.setIncomingAndReceive();
short offset = apdu.getOffsetCdata();
if ((p1 != (byte) 0x00) || (keyMapping(p2) == (byte) 0xFF)) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
if (!authenticated[0]) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
if ((lc != apdu.getIncomingLength()) || (lc < 5)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
if (Util.arrayCompare(buf, offset, new byte[]{
(byte) 0xAC, (byte) 0x03, (byte) 0x80, (byte) 0x01
}, (byte) 0, (byte) 4) != 0) {
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
}
switch (buf[(short) (offset + 4)]) {
case 0x07: // RSA: 2048
doGenRSA(apdu, buf[ISO7816.OFFSET_P2]);
break;
case 0x11: // ECC: Curve P-256
doGenEC(apdu, buf[ISO7816.OFFSET_P2], (short) 256);
break;
case 0x14: // ECC: Curve P-384
doGenEC(apdu, buf[ISO7816.OFFSET_P2], (short) 384);
break;
default:
ISOException.throwIt(ISO7816.SW_WRONG_DATA);
break;
}
}
示例8: doChainingOrExtAPDU
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Receive the data sent by chaining or extended apdus and store it in ram_buf.
*
* This is a convienience method if large data has to be accumulated using command chaining
* or extended apdus. The apdu must be in the INITIAL state, i.e. setIncomingAndReceive()
* might not have been called already.
*
* \param apdu The apdu object in the initial state.
*
* \throw ISOException SW_WRONG_LENGTH
*/
private short doChainingOrExtAPDU(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
short recvLen = apdu.setIncomingAndReceive();
short offset_cdata = apdu.getOffsetCdata();
// Receive data (short or extended).
while (recvLen > 0) {
if((short)(ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] + recvLen) > RAM_BUF_SIZE) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
Util.arrayCopyNonAtomic(buf, offset_cdata, ram_buf, ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS], recvLen);
ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] += recvLen;
recvLen = apdu.receiveBytes(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 + ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS]);
ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS] = 0;
return recvLen;
}
}
示例9: doSelect
import javacard.framework.APDU; //导入方法依赖的package包/类
private void doSelect(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
final byte[] apt = {
/* Application property template */
(byte) 0x61, (byte) 0x16,
/* - Application identifier of application */
(byte) 0x4F, (byte) 0x0B,
(byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x08,
(byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x01,
(byte) 0x00,
/* - Coexistent tag allocation authority */
(byte) 0x79, (byte) 0x07,
/* - Application identifier */
(byte) 0x4F, (byte) 0x05,
(byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x08
};
if ((p1 == (byte) 0x04) && (p2 == (byte) 0x00)) {
short l = apdu.setIncomingAndReceive();
short offset = apdu.getOffsetCdata();
final byte[] aid1 = {
(byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x08
};
final byte[] aid2 = {
(byte) 0xA0, (byte) 0x00, (byte) 0x00, (byte) 0x03,
(byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x10,
(byte) 0x00
};
if (((l == (short) aid1.length)
&& (Util.arrayCompare(buf, offset, aid1, (byte) 0, (byte) aid1.length) == 0))
|| ((l == (short) aid2.length)
&& (Util.arrayCompare(buf, offset, aid2, (byte) 0, (byte) aid2.length) == 0))) {
io.sendBuffer(apt, (short) apt.length, apdu);
return;
}
}
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
示例10: doPutData
import javacard.framework.APDU; //导入方法依赖的package包/类
private void doPutData(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
byte cla = buf[ISO7816.OFFSET_CLA];
short lc = apdu.setIncomingAndReceive();
short offset = apdu.getOffsetCdata();
byte id;
if (p1 != (byte) 0x3F || p2 != (byte) 0xFF) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
if ((cla != 0x0) && (cla != 0x10)) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
if (!authenticated[0]) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
if (io.isLoaded()) {
io.receiveFile(buf, offset, lc);
if (cla == 0x00) {
io.clear();
}
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
if (lc != apdu.getIncomingLength() || lc < (byte) 0x06) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
if (buf[offset] == (byte) 0x5C) {
if ((buf[(short) (offset + 1)] != (byte) 0x03)
|| (buf[(short) (offset + 2)] != (byte) 0x5F)
|| (buf[(short) (offset + 3)] != (byte) 0xC1)) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
id = (byte) (buf[(short) (offset + 4)] - 1);
if ((id == (byte) 0x03)
|| (id > (byte) 0x0A)) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
offset += 5;
} else if (buf[offset] == (byte) 0x7E) {
id = FileIndex.DISCOVERY;
offset += 1;
} else {
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
return;
}
if (buf[offset] != (byte) 0x53) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
}
BERTLV btlv = new BERTLV(buf, (short) (offset + 1),
(short) (apdu.getOffsetCdata() + lc));
short l = btlv.readLength();
short off = btlv.getOffset();
io.createFile(id, (short) (l + (off - offset)));
io.receiveFile(buf, offset, (short) (lc - (offset - apdu.getOffsetCdata())));
if (cla == 0x00) {
io.clear();
}
}
示例11: processVerify
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Process the VERIFY apdu (INS = 20).
*
* This apdu is used to verify a PIN and authenticate the user. A counter is used
* to limit unsuccessful tries (i.e. brute force attacks).
*
* \param apdu The apdu.
*
* \throw ISOException SW_INCORRECT_P1P2, ISO7816.SW_WRONG_LENGTH, SW_PIN_TRIES_REMAINING.
*/
private void processVerify(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
short offset_cdata;
short lc;
// P1P2 0001 only at the moment. (key-reference 01 = PIN)
if(buf[ISO7816.OFFSET_P1] != 0x00 || buf[ISO7816.OFFSET_P2] != 0x01) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
// Bytes received must be Lc.
lc = apdu.setIncomingAndReceive();
if(lc != apdu.getIncomingLength()) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
offset_cdata = apdu.getOffsetCdata();
// Lc might be 0, in this case the caller checks if verification is required.
if((lc > 0 && (lc < PIN_MIN_LENGTH) || lc > PIN_MAX_LENGTH)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
// Caller asks if verification is needed.
if(lc == 0
&& state != STATE_CREATION
&& state != STATE_INITIALISATION) {
// Verification required, return remaining tries.
ISOException.throwIt((short)(SW_PIN_TRIES_REMAINING | pin.getTriesRemaining()));
} else if(lc == 0
&& (state == STATE_CREATION
|| state == STATE_INITIALISATION)) {
// No verification required.
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
// Pad the PIN if not done by caller, so no garbage from the APDU will be part of the PIN.
Util.arrayFillNonAtomic(buf, (short)(offset_cdata + lc), (short)(PIN_MAX_LENGTH - lc), (byte) 0x00);
// Check the PIN.
if(!pin.check(buf, offset_cdata, PIN_MAX_LENGTH)) {
fs.setUserAuthenticated(false);
ISOException.throwIt((short)(SW_PIN_TRIES_REMAINING | pin.getTriesRemaining()));
} else {
fs.setUserAuthenticated(true);
}
}
示例12: 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;
short offset_cdata;
if(state != STATE_OPERATIONAL_ACTIVATED) {
ISOException.throwIt(ISO7816.SW_COMMAND_NOT_ALLOWED);
}
// Bytes received must be Lc.
lc = apdu.setIncomingAndReceive();
if(lc != apdu.getIncomingLength()) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
offset_cdata = apdu.getOffsetCdata();
// Length of data field.
if(lc < (short)(PUK_LENGTH + PIN_MIN_LENGTH)
|| lc > (short)(PUK_LENGTH + PIN_MAX_LENGTH)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
// We expect the PUK followed by a new PIN.
if(p1 != (byte) 0x00 || p2 != (byte) 0x01) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
// Check the PUK.
if(!puk.check(buf, offset_cdata, PUK_LENGTH)) {
ISOException.throwIt((short)(SW_PIN_TRIES_REMAINING | puk.getTriesRemaining()));
}
// If we're here, the PUK was correct.
// Pad the new PIN, if not done by caller. We don't want any gargabe from the APDU buffer to be part of the new PIN.
Util.arrayFillNonAtomic(buf, (short)(offset_cdata + lc), (short)(PUK_LENGTH + PIN_MAX_LENGTH - lc), (byte) 0x00);
// Set the PIN.
pin.update(buf, (short)(offset_cdata+PUK_LENGTH), PIN_MAX_LENGTH);
pin.resetAndUnblock();
}