本文整理汇总了Java中javacard.framework.ISOException.throwIt方法的典型用法代码示例。如果您正苦于以下问题:Java ISOException.throwIt方法的具体用法?Java ISOException.throwIt怎么用?Java ISOException.throwIt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javacard.framework.ISOException
的用法示例。
在下文中一共展示了ISOException.throwIt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lock
import javacard.framework.ISOException; //导入方法依赖的package包/类
private void lock(Object objToLock, short lockIndex) {
if (lockedObjects[lockIndex] != null && !lockedObjects[lockIndex].equals(objToLock)) {
ISOException.throwIt(ReturnCodes.SW_LOCK_OBJECT_MISMATCH);
}
// Next position in array signalizes logical lock (null == unlocked, !null == locked)
if (lockedObjects[(short) (lockIndex + 1)] == null) {
lockedObjects[(short) (lockIndex + 1)] = objToLock; // lock logically by assigning object reference to [i + 1]
} else {
// this array is already locked, raise exception (incorrect sequence of locking and unlocking)
ISOException.throwIt(ReturnCodes.SW_LOCK_ALREADYLOCKED);
}
if (PROFILE_LOCKED_OBJECTS) {
// If enabled, check status of all other objects and mark these that are currently locked
short profileLockOffset = (short) (lockIndex * (short) ((short) lockedObjects.length / 2)); // Obtain section of profileLockedObjects array relevant for current object
for (short i = 0; i < (short) lockedObjects.length; i += 2) {
if (lockedObjects[(short) (i + 1)] != null) {
// Object at index i is locked, mark it to corresponding position in profileLockedObjects by setting value to 1
profileLockedObjects[(short) (profileLockOffset + (short) (i / 2))] = 1;
}
}
}
}
示例2: MPCApplet
import javacard.framework.ISOException; //导入方法依赖的package包/类
public MPCApplet() {
m_ecc = new ECConfig((short) 256);
m_ecc.bnh.bIsSimulator = bIsSimulator;
m_curve = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r);
ECPointBuilder.allocate(m_curve, m_ecc);
ECPointBase.allocate(m_curve);
if (m_ecc.MULT_RSA_ENGINE_MAX_LENGTH_BITS < (short) 1024) {
ISOException.throwIt(Consts.SW_INCORRECTJCMATHLIBSETTINGS);
}
m_cryptoOps = new MPCCryptoOps(m_ecc);
m_quorums = new QuorumContext[Consts.MAX_QUORUMS];
for (short i = 0; i < (short) m_quorums.length; i++) {
m_quorums[i] = new QuorumContext(m_ecc, m_curve, m_cryptoOps);
}
// Generate random unique card ID
cardIDLong = new byte[Consts.CARD_ID_LONG_LENGTH];
m_cryptoOps.randomData.generateData(cardIDLong, (short) 0, (short) cardIDLong.length);
}
示例3: copy
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* Copies {@code other} into this. No size requirements. If {@code other}
* has more digits then the superfluous leading digits of {@code other} are
* asserted to be zero. If this bignat has more digits than its leading
* digits are correctly initilized to zero. This function will not change size
* attribute of this object.
*
* @param other
* Bignat to copy into this object.
*/
public void copy(Bignat other) {
short this_start, other_start, len;
if (this.size >= other.size) {
this_start = (short) (this.size - other.size);
other_start = 0;
len = other.size;
} else {
this_start = 0;
other_start = (short) (other.size - this.size);
len = this.size;
// Verify here that other have leading zeroes up to other_start
for (short i = 0; i < other_start; i ++) {
if (other.value[i] != 0) {
ISOException.throwIt(ReturnCodes.SW_BIGNAT_INVALIDCOPYOTHER);
}
}
}
if (this_start > 0) {
// if this bignat has more digits than its leading digits are initilized to zero
Util.arrayFillNonAtomic(this.value, (short) 0, this_start, (byte) 0);
}
Util.arrayCopyNonAtomic(other.value, other_start, this.value, this_start, len);
}
示例4: n_mod_exp
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* Calculates {@code res := base ** exp mod mod} using RSA engine.
* Requirements:
* 1. Modulo must be either 521, 1024, 2048 or other lengths supported by RSA (see appendzeros() and mod() method)
* 2. Base must have the same size as modulo (see prependzeros())
* @param baseLen length of base rounded to size of RSA engine
* @param base value of base (if size is not equal to baseLen then zeroes are appended)
* @param exponent array with exponent
* @param exponentLen length of exponent
* @param modulo value of modulo
* @param resultArray array for the computed result
* @param resultOffset start offset of resultArray
*/
private short n_mod_exp(short baseLen, Bignat base, byte[] exponent, short exponentLen, Bignat modulo, byte[] resultArray, short resultOffset) {
// Verify if pre-allocated engine match the required values
if (bnh.fnc_NmodE_pubKey.getSize() < (short) (modulo.length() * 8)) {
// attempt to perform modulu with higher or smaller than supported length - try change constant MODULO_ENGINE_MAX_LENGTH
ISOException.throwIt(ReturnCodes.SW_BIGNAT_MODULOTOOLARGE);
}
if (bnh.fnc_NmodE_pubKey.getSize() < (short) (base.length() * 8)) {
ISOException.throwIt(ReturnCodes.SW_BIGNAT_MODULOTOOLARGE);
}
// Potential problem: we are changing key value for publicKey already used before with occ.bnHelper.modCipher.
// Simulator and potentially some cards fail to initialize this new value properly (probably assuming that same key object will always have same value)
// Fix (if problem occure): generate new key object: RSAPublicKey publicKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, (short) (baseLen * 8), false);
bnh.fnc_NmodE_pubKey.setExponent(exponent, (short) 0, exponentLen);
bnh.lock(bnh.fnc_deep_resize_tmp);
modulo.append_zeros(baseLen, bnh.fnc_deep_resize_tmp, (short) 0);
bnh.fnc_NmodE_pubKey.setModulus(bnh.fnc_deep_resize_tmp, (short) 0, baseLen);
bnh.fnc_NmodE_cipher.init(bnh.fnc_NmodE_pubKey, Cipher.MODE_DECRYPT);
base.prepend_zeros(baseLen, bnh.fnc_deep_resize_tmp, (short) 0);
// BUGBUG: Check if input is not all zeroes (causes out-of-bound exception on some cards)
short len = bnh.fnc_NmodE_cipher.doFinal(bnh.fnc_deep_resize_tmp, (short) 0, baseLen, resultArray, resultOffset);
bnh.unlock(bnh.fnc_deep_resize_tmp);
return len;
}
示例5: isLocked
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* Check if provided object is logically locked
* @param objToUnlock object to be checked
* @return true of array is logically locked, false otherwise
*/
public boolean isLocked(Object objToUnlock) {
if (!bLockingActive) {
return false;
}
// Find object to unlock
short i;
for (i = 0; i < (short) lockedObjects.length; i += 2) {
if (lockedObjects[i] != null && lockedObjects[i].equals(objToUnlock)) {
return lockedObjects[(short) (i + 1)] != null;
}
}
// If reached here, required object was not found
if (i == (short) lockedObjects.length) {
ISOException.throwIt(ReturnCodes.SW_LOCK_OBJECT_NOT_FOUND);
}
return false;
}
示例6: decodeLength
import javacard.framework.ISOException; //导入方法依赖的package包/类
public static short decodeLength(byte[] buf, short offset) {
short off = offset;
byte b = buf[off];
short s = buf[off];
if ((b & (byte) 0x80) != 0) {
off += 1;
if (b == (byte) 0x81) {
s = (short) (0x00FF & buf[off]);
} else if (b == (byte) 0x82) {
s = Util.getShort(buf, off);
} else {
ISOException.throwIt(ISO7816.SW_UNKNOWN);
}
}
return s;
}
示例7: process
import javacard.framework.ISOException; //导入方法依赖的package包/类
public void process(APDU apdu) throws ISOException {
if (selectingApplet())
return;
byte[] buffer = apdu.getBuffer();
switch (buffer[ISO7816.OFFSET_CLA]) {
case (byte) 0x00: // ISO as described in specs
case (byte) 0x10: // Chaining
process_real_commands(apdu, buffer);
break;
case (byte) 0x80: // Proprietary: setting/getting values
process_mock_commands(apdu, buffer);
break;
default:
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
break;
}
}
示例8: storeVariableLength
import javacard.framework.ISOException; //导入方法依赖的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: send_array
import javacard.framework.ISOException; //导入方法依赖的package包/类
public static void send_array(byte[] array, short offset, short len) {
// get buffer
APDU apdu = APDU.getCurrentAPDU();
// This method is failsafe.
if ((short)(offset + len) > (short)array.length)
len = (short) (array.length - offset);
// Copy data
Util.arrayCopyNonAtomic(array, offset, apdu.getBuffer(), (short)0, len);
// Check if setOutgoing() has already been called
if (apdu.getCurrentState() == APDU.STATE_OUTGOING) {
apdu.setOutgoingLength(len);
apdu.sendBytes((short)0, len);
} else {
apdu.setOutgoingAndSend((short)0, len);
}
// Exit normal code flow
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
示例10: ListObjects
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* This function returns a list of current objects and their properties including id,
* size, and access control. This function must be initially called with the reset
* option. The function only returns one object information at a time and must be
* called in repetition until SW_SUCCESS is returned with no further data.
* Applications cannot rely on any special ordering of the sequence of returned objects.
*
* ins: 0x58
* p1: 0x00 (reset and get first entry) or 0x01 (next entry)
* p2: 0x00
* data: none
* return: [object_id(4b) | object_size(4b) | object_ACL(6b)]
*/
private void ListObjects(APDU apdu, byte[] buffer) {
// Checking P1 & P2
if (buffer[ISO7816.OFFSET_P2] != (byte) 0x00)
ISOException.throwIt(SW_INCORRECT_P2);
byte expectedBytes = (byte) (buffer[ISO7816.OFFSET_LC]);
if (expectedBytes < ObjectManager.RECORD_SIZE)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
boolean found = false; // Suppress compiler warning
if (buffer[ISO7816.OFFSET_P1] == LIST_OPT_RESET)
found = om.getFirstRecord(buffer, (short) 0);
else if (buffer[ISO7816.OFFSET_P1] != LIST_OPT_NEXT)
ISOException.throwIt(SW_INCORRECT_P1);
else
found = om.getNextRecord(buffer, (short) 0);
if (found)
apdu.setOutgoingAndSend((short) 0, (short) ObjectManager.RECORD_SIZE);
else
ISOException.throwIt(SW_SEQUENCE_END);
}
示例11: DeleteObject
import javacard.framework.ISOException; //导入方法依赖的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);
}
示例12: processGetResponse
import javacard.framework.ISOException; //导入方法依赖的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]);
}
示例13: processPerformSecurityOperation
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* \brief Process the PERFORM SECURITY OPERATION apdu (INS=2A).
*
* This operation is used for cryptographic operations
* (Computation of digital signatures, decrypting.).
*
* \param apdu The PERFORM SECURITY OPERATION apdu.
*
* \throw ISOException SW_SECURITY_STATUS_NOT_SATISFIED, SW_INCORRECT_P1P2 and
* the ones from computeDigitalSignature() and decipher().
*/
private void processPerformSecurityOperation(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
if( ! pin.isValidated() ) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
if(p1 == (byte) 0x9E && p2 == (byte) 0x9A) {
computeDigitalSignature(apdu);
} else if(p1 == (byte) 0x80 && p2 == (byte) 0x86) {
decipher(apdu);
} else {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
}
示例14: processPutData
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* \brief Process the PUT DATA apdu (INS=DB).
*
* PUT DATA is currently used for private key import.
*
* \throw ISOException SW_SECURITY_STATUS_NOT_SATISFIED, SW_INCORRECT_P1P2
*/
private void processPutData(APDU apdu) throws ISOException {
byte[] buf = apdu.getBuffer();
byte p1 = buf[ISO7816.OFFSET_P1];
byte p2 = buf[ISO7816.OFFSET_P2];
if( ! pin.isValidated() ) {
ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED);
}
if(p1 == (byte) 0x3F && p2 == (byte) 0xFF) {
if( ! DEF_PRIVATE_KEY_IMPORT_ALLOWED) {
ISOException.throwIt(SW_COMMAND_NOT_ALLOWED_GENERAL);
}
importPrivateKey(apdu);
} else {
ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
}
}
示例15: getEcFpFieldLength
import javacard.framework.ISOException; //导入方法依赖的package包/类
/**
* \brief Get the field length of an EC FP key using the amount of bytes
* of a parameter (e.g. the prime).
*
* \return The bit length of the field.
*
* \throw ISOException SC_FUNC_NOT_SUPPORTED.
*/
private short getEcFpFieldLength(short bytes) {
switch(bytes) {
case 24:
return KeyBuilder.LENGTH_EC_FP_192;
case 28:
return LENGTH_EC_FP_224;
case 32:
return LENGTH_EC_FP_256;
case 40:
return LENGTH_EC_FP_320;
case 48:
return LENGTH_EC_FP_384;
case 64:
return LENGTH_EC_FP_512;
case 66:
return LENGTH_EC_FP_521;
default:
ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED);
return 0;
}
}