本文整理汇总了Java中javacard.framework.APDU.setOutgoing方法的典型用法代码示例。如果您正苦于以下问题:Java APDU.setOutgoing方法的具体用法?Java APDU.setOutgoing怎么用?Java APDU.setOutgoing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.framework.APDU
的用法示例。
在下文中一共展示了APDU.setOutgoing方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRSAPublicKey
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Encode a 2048 bit RSAPublicKey according to ISO7816-8 table 3 and send it as a response,
* using an extended APDU.
*
* \see ISO7816-8 table 3.
*
* \param apdu The apdu to answer. setOutgoing() must not be called already.
*
* \param key The RSAPublicKey to send.
* Can be null for the secound part if there is no support for extended apdus.
*/
private void sendRSAPublicKey(APDU apdu, RSAPublicKey key) {
short le = apdu.setOutgoing();
short pos = 0;
ram_buf[pos++] = (byte) 0x7F; // Interindustry template for nesting one set of public key data objects.
ram_buf[pos++] = (byte) 0x49; // "
ram_buf[pos++] = (byte) 0x82; // Length field: 3 Bytes.
ram_buf[pos++] = (byte) 0x01; // Length : 265 Bytes.
ram_buf[pos++] = (byte) 0x09; // "
ram_buf[pos++] = (byte) 0x81; // RSA public key modulus tag.
ram_buf[pos++] = (byte) 0x82; // Length field: 3 Bytes.
ram_buf[pos++] = (byte) 0x01; // Length: 256 bytes.
ram_buf[pos++] = (byte) 0x00; // "
pos += key.getModulus(ram_buf, pos);
ram_buf[pos++] = (byte) 0x82; // RSA public key exponent tag.
ram_buf[pos++] = (byte) 0x03; // Length: 3 Bytes.
pos += key.getExponent(ram_buf, pos);
sendLargeData(apdu, (short)0, pos);
}
示例2: processGetResponse
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Process the GET RESPONSE APDU (INS=C0).
*
* If there is content available in ram_buf that could not be sent in the last operation,
* the host should use this APDU to get the data. The data is cached in ram_buf.
*
* \param apdu The GET RESPONSE apdu.
*
* \throw ISOException SW_CONDITIONS_NOT_SATISFIED, SW_UNKNOWN, SW_CORRECT_LENGTH.
*/
private void processGetResponse(APDU apdu) {
byte[] buf = apdu.getBuffer();
short le = apdu.setOutgoing();
if( ! pin.isValidated() ) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
if(ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] <= (short) 0) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
short expectedLe = ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] > 256 ?
256 : ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING];
if(le != expectedLe) {
ISOException.throwIt( (short)(ISO7816.SW_CORRECT_LENGTH_00 | expectedLe) );
}
sendLargeData(apdu, ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS],
ram_chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING]);
}
示例3: processGetChallenge
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Process the GET CHALLENGE instruction (INS=0x84).
*
* The host may request a random number of length "Le". This random number
* is currently _not_ used for any cryptographic function (e.g. secure
* messaging) by the applet.
*
* \param apdu The GET CHALLENGE apdu with P1P2=0000.
*
* \throw ISOException SW_INCORRECT_P1P2, SW_WRONG_LENGTH, SW_FUNC_NOT_SUPPORTED.
*/
private void processGetChallenge(APDU apdu) {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
if(randomData == null) {
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
}
if(p1 != 0x00 || p1 != 0x00) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
short le = apdu.setOutgoing();
if(le <= 0 || le > 256) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
randomData.generateData(buf, (short)0, le);
apdu.setOutgoingLength(le);
apdu.sendBytes((short)0, le);
}
示例4: get_data
import javacard.framework.APDU; //导入方法依赖的package包/类
public void get_data(APDU apdu, byte[] buf)
{
//verify that the class for this instruction is correct
if((short)(buf[ISO7816.OFFSET_CLA] & 0xFF) != 0x80)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
//check state - this command only works in the PERSO state
if(PROFILE.STATE != PERSO)
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
//check that P1 & P2 are correct
if(buf[ISO7816.OFFSET_P1] != (byte) 0x00 || (byte)buf[ISO7816.OFFSET_P2] != (byte) 0xCF)
ISOException.throwIt((short)0x6A88); //referenced data not found
//build response message
apdu.setOutgoing();
apdu.setOutgoingLength((short)13);
buf[0]=(byte)0xCF; //Key Data Tag
buf[1]=(byte)11; //length
buf[2]=PROFILE.VER_KMC;
Util.arrayCopyNonAtomic(PROFILE.KMC_ID,(short)0,buf,(short)3,(short)6);
Util.arrayCopyNonAtomic(PROFILE.CSN,(short)0,buf,(short)9,(short)4);
apdu.sendBytes((short)0,(short)13);
}
示例5: getMobileKey
import javacard.framework.APDU; //导入方法依赖的package包/类
private void getMobileKey(APDU apdu) throws ISOException {
byte[] apduBuffer = apdu.getBuffer();
// Check if P1=0x00 and P2=0x00.
if (Util.getShort(apduBuffer, ISO7816.OFFSET_P1) != (short) 0x0000) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
short dataLength = apdu.setOutgoing();
// Check if Le=0x00.
if (dataLength != (short) 256) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
// Check if Mobile Key is initialized.
if (!this.dataEncryption.isMobileKeyInit()) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
dataLength = this.dataEncryption.getMobileKey(apduBuffer, (short) 0);
apdu.setOutgoingLength(dataLength);
apdu.sendBytes((short) 0, dataLength);
}
示例6: get_data
import javacard.framework.APDU; //导入方法依赖的package包/类
public void get_data(APDU apdu, byte[] buf) {
// verify that the class for this instruction is correct
if ((short) (buf[ISO7816.OFFSET_CLA] & 0xFF) != 0x80)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
// check state - this command only works in the PERSO state
if (PROFILE.STATE != PERSO)
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
// check that P1 & P2 are correct
if (buf[ISO7816.OFFSET_P1] != (byte) 0x00 || (byte) buf[ISO7816.OFFSET_P2] != (byte) 0xCF)
ISOException.throwIt((short) 0x6A88); //referenced data not found
// build response message
apdu.setOutgoing();
apdu.setOutgoingLength((short) 13);
buf[0] = (byte) 0xCF; //Key Data Tag
buf[1] = (byte) 11; //length
buf[2] = PROFILE.VER_KMC;
Util.arrayCopyNonAtomic(PROFILE.KMC_ID, (short) 0, buf, (short) 3, (short) 6);
Util.arrayCopyNonAtomic(PROFILE.CSN, (short) 0, buf, (short) 9, (short) 4);
apdu.sendBytes((short) 0, (short) 13);
}
示例7: returnPINStatus
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief return information regarding the PIN
*/
public void returnPINStatus(APDU apdu, short id) {
byte[] buf = apdu.getBuffer();
GidsPIN pin = null;
switch(id) {
default:
ISOException.throwIt(ErrorCode.SW_REFERENCE_DATA_NOT_FOUND);
break;
case (short) 0x7F71:
case (short) 0x7F72:
pin = pin_pin;
break;
}
Util.setShort(buf, (short) 0, id);
buf[2] = (byte) 0x06;
buf[3] = (byte) 0x97;
buf[4] = (byte) 0x01;
buf[5] = pin.getTriesRemaining();
buf[6] = (byte) 0x93;
buf[7] = (byte) 0x01;
buf[8] = pin.getTryLimit();
apdu.setOutgoing();
apdu.setOutgoingLength((short)9);
apdu.sendBytes((short) 0, (short) 9);
}
示例8: sendBuffer
import javacard.framework.APDU; //导入方法依赖的package包/类
public void sendBuffer(byte[] buf, short length, APDU apdu) {
short le = apdu.setOutgoing();
short r = 0;
if (le == 0) {
le = (short) (APDU.getOutBlockSize() - 2);
}
if (le > length) {
le = length;
}
if (le < length) {
r = (short) (length - le);
if (r > (short) this.buffer.length) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
this.bools[isLOADED] = true;
this.bools[isFILE] = false;
this.shorts[SIZE] = r;
}
apdu.setOutgoingLength(le);
apdu.sendBytesLong(buf, (short) 0, le);
if (r > 0) {
if (r >= (short) (APDU.getOutBlockSize() - 2)) {
r = 0;
}
Util.arrayCopy(buf, le, this.buffer, (short) 0, r);
ISOException.throwIt((short) (ISO7816.SW_BYTES_REMAINING_00 | r));
} else {
clear();
}
}
示例9: sendFile
import javacard.framework.APDU; //导入方法依赖的package包/类
public void sendFile(short id, APDU apdu, short offset) {
byte[] d = index.entries[id].content;
if (d == null) {
ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);
}
short le = apdu.setOutgoing();
short r = 0;
if (le == 0) {
le = (short) (APDU.getOutBlockSize() - 2);
}
if ((short) (le + offset) > (short) d.length) {
le = (short) (d.length - offset);
}
if ((short) (le + offset) < (short) d.length) {
r = (short) (d.length - (le + offset));
this.bools[isLOADED] = true;
this.bools[isFILE] = true;
this.shorts[OFFSET] = (short) (le + offset);
this.shorts[PATH] = id;
}
apdu.setOutgoingLength(le);
apdu.sendBytesLong(d, offset, le);
if (r > 0) {
if (r >= (short) (APDU.getOutBlockSize() - 2)) {
r = 0;
}
ISOException.throwIt((short) (ISO7816.SW_BYTES_REMAINING_00 | r));
} else {
clear();
}
}
示例10: sendData
import javacard.framework.APDU; //导入方法依赖的package包/类
/********** UTILITY FUNCTIONS **********/
/*
* SendData() wraps the setOutgoing(), setLength(), .. stuff * that could be
* necessary to be fully JavaCard compliant.
*/
private void sendData(APDU apdu, byte[] data, short offset, short size) {
if (size > EXT_APDU_BUFFER_SIZE)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoing();
apdu.setOutgoingLength(size);
apdu.sendBytesLong(data, offset, size);
}
示例11: sendData
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Send the data from ram_buf, using either extended APDUs or GET RESPONSE.
*
* \param apdu The APDU object, in STATE_OUTGOING state.
*
* \param pos The position in ram_buf at where the data begins
*
* \param len The length of the data to be sent. If zero, 9000 will be
* returned
*/
private void sendData(APDU apdu) {
short le;
short remaininglen = 0;
byte data[] = null;
short pos = chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS];
le = apdu.setOutgoing();
// le has not been set
if(le == 0) {
// we get here when called from the Shared VMWare reader
byte ins = apdu.getBuffer()[ISO7816.OFFSET_INS];
if ( ins != GidsApplet.INS_GENERATE_ASYMMETRIC_KEYPAIR) {
le = 256;
} else {
le = 0;
}
}
if (chaining_object[CHAINING_OBJECT] == null) {
data = ram_buf;
remaininglen = chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING];
} else if (chaining_object[CHAINING_OBJECT] instanceof Record) {
Record record = (Record) (chaining_object[CHAINING_OBJECT]);
data = record.GetData();
remaininglen = (short) (((short) data.length) - pos);
} else if (chaining_object[CHAINING_OBJECT] instanceof Record[]) {
data = ram_buf;
remaininglen = copyRecordsToRamBuf(le);
pos = 0;
}
// We have 256 Bytes send-capacity per APDU.
short sendLen = remaininglen > le ? le : remaininglen;
apdu.setOutgoingLength(sendLen);
apdu.sendBytesLong(data, pos, sendLen);
// the position when using Record[] is maintened by copyRecordsToRamBuf
if (chaining_object[CHAINING_OBJECT] == null || !(chaining_object[CHAINING_OBJECT] instanceof Record[])) {
chaining_cache[RAM_CHAINING_CACHE_OFFSET_CURRENT_POS]+= sendLen;
}
if (chaining_object[CHAINING_OBJECT] == null) {
chaining_cache[RAM_CHAINING_CACHE_OFFSET_BYTES_REMAINING] -= sendLen;
}
remaininglen -= sendLen;
if(remaininglen > 0) {
short nextRespLen = remaininglen > 256 ? 256 : remaininglen;
ISOException.throwIt( (short)(ISO7816.SW_BYTES_REMAINING_00 | nextRespLen) );
} else {
Clear(true);
return;
}
}
示例12: computeDigitalSignature
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* \brief Compute a digital signature of the data from the apdu
* using the private key referenced by an earlier
* MANAGE SECURITY ENVIRONMENT apdu.
*
* \attention The apdu should contain a hash, not raw data for RSA keys.
* PKCS1 padding will be applied if neccessary.
*
* \param apdu The PERFORM SECURITY OPERATION apdu with P1=9E and P2=9A.
*
* \throw ISOException SW_CONDITIONS_NOT_SATISFIED, SW_WRONG_LENGTH
* and SW_UNKNOWN.
*/
private void computeDigitalSignature(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
short lc, le;
short sigLen = 0;
PrivateKey rsaKey = null;
byte[] ram_buf = transmitManager.GetRamBuffer();
CRTKeyFile key = (CRTKeyFile) currentKey[0];
switch((byte) (currentAlgorithmRef[0] & 0xF0)) {
case (byte) 0x10:
// padding made off card -> raw encryption to be performed
lc = transmitManager.doChainingOrExtAPDU(apdu);
// RSA signature operation.
rsaKey = key.GetKey().getPrivate();
rsaRawCipher.init(rsaKey, Cipher.MODE_ENCRYPT);
sigLen = rsaRawCipher.doFinal(ram_buf, (short) 0, lc, ram_buf, (short)0);
// A single short APDU can handle 256 bytes - only one send operation neccessary.
le = apdu.setOutgoing();
if(le > 0 && le < sigLen) {
ISOException.throwIt(ISO7816.SW_CORRECT_LENGTH_00);
}
apdu.setOutgoingLength(sigLen);
apdu.sendBytesLong(ram_buf, (short) 0, sigLen);
break;
case (byte) 0x50:
// rsa padding made by the card, only the hash is provided
// Receive.
// Bytes received must be Lc.
lc = apdu.setIncomingAndReceive();
// RSA signature operation.
rsaKey = key.GetKey().getPrivate();
if(lc > (short) 247) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
rsaPkcs1Cipher.init(rsaKey, Cipher.MODE_ENCRYPT);
sigLen = rsaPkcs1Cipher.doFinal(buf, ISO7816.OFFSET_CDATA, lc, ram_buf, (short)0);
/*if(sigLen != 256) {
ISOException.throwIt(ISO7816.SW_UNKNOWN);
}*/
// A single short APDU can handle 256 bytes - only one send operation neccessary.
le = apdu.setOutgoing();
if(le > 0 && le < sigLen) {
ISOException.throwIt(ISO7816.SW_CORRECT_LENGTH_00);
}
apdu.setOutgoingLength(sigLen);
apdu.sendBytesLong(ram_buf, (short) 0, sigLen);
break;
default:
// Wrong/unknown algorithm.
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
}
示例13: getProcessingOptions
import javacard.framework.APDU; //导入方法依赖的package包/类
/**
* Handle Get Processing Options command.
*
* @param apdu
* the incoming <code>APDU</code> object
* @throws ISOException
*/
private void getProcessingOptions(APDU apdu) throws ISOException {
byte[] apduBuffer = apdu.getBuffer();
// DEBUG
Log.v(LOG_TAG, "C-APDU Header: " + DataUtil.byteArrayToHexString(apduBuffer, 0, 5));
ByteBuffer apduByteBuffer = ByteBuffer.wrap(apduBuffer);
// Check if P1=0x00 and P2=0x00.
if (apduByteBuffer.getShort(ISO7816.OFFSET_P1) != (short) 0x0000) {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
// Check if Lc=[number of data bytes read].
// Check if Lc=3.
// Check if Le=0x00.
short len = apdu.setIncomingAndReceive();
// DEBUG
Log.v(LOG_TAG, "C-APDU: " + DataUtil.byteArrayToHexString(apduBuffer, 0, len + 6));
if ((len != (short) (apduBuffer[ISO7816.OFFSET_LC] & (short) 0x00FF)) ||
(len != (short) 3) ||
(apdu.setOutgoing() != (short) 256)) {
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
// Check PDOL data.
apduByteBuffer.position(ISO7816.OFFSET_CDATA);
if (apduByteBuffer.getShort() != (short) 0x8301) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
byte terminalType = apduByteBuffer.get();
// Check if terminal type is offline only.
if ((terminalType == (byte) 0x13) ||
(terminalType == (byte) 0x16) ||
(terminalType == (byte) 0x23) ||
(terminalType == (byte) 0x26) ||
(terminalType == (byte) 0x36)) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
this.pdolData = new byte[1];
this.pdolData[0] = terminalType;
apduByteBuffer.rewind();
// Build response.
apduByteBuffer.put(PayPConstants.TAG_RESPONSE_MESSAGE_TEMPLATE);
// Skip response message template length.
apduByteBuffer.put((byte) 0);
// Skip response message template length.
// Append data elements in response:
// '82' [2] Application Interchange Profile
// '94' [var.] Application File Locator
apduByteBuffer.put(PayPConstants.TAG_AIP);
apduByteBuffer.put((byte) this.cardProfile.getAip().length);
apduByteBuffer.put(this.cardProfile.getAip());
apduByteBuffer.put(PayPConstants.TAG_AFL);
apduByteBuffer.put((byte) this.cardProfile.getAfl().length);
apduByteBuffer.put(this.cardProfile.getAfl());
int rdataLength = apduByteBuffer.position();
// Set response template message length.
apduByteBuffer.put(1, (byte) (rdataLength - 2));
this.apduState = APDU_SENDING;
// DEBUG
Log.v(LOG_TAG, "R-APDU: " + DataUtil.byteArrayToHexString(apduBuffer, 0, rdataLength) + "9000");
apdu.setOutgoingLength((short) rdataLength);
apdu.sendBytes((short) 0, (short) rdataLength);
}