当前位置: 首页>>代码示例>>Java>>正文


Java APDU.getIncomingLength方法代码示例

本文整理汇总了Java中javacard.framework.APDU.getIncomingLength方法的典型用法代码示例。如果您正苦于以下问题:Java APDU.getIncomingLength方法的具体用法?Java APDU.getIncomingLength怎么用?Java APDU.getIncomingLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javacard.framework.APDU的用法示例。


在下文中一共展示了APDU.getIncomingLength方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: KeyGen_StoreCommitment

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * Upon the generation of the triplet, the members perform a pairwise
 * exchange of their commitments by the end of which, they all hold a
 * set H = {h1,h2, ..,ht }. The commitment exchange terminates when |Hq | =
 * t ∀q ∈ Q
 * @param apdu 
 */
void KeyGen_StoreCommitment(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short len = apdu.getIncomingLength();
    
    short paramsOffset = GetOperationParamsOffset(Consts.INS_KEYGEN_STORE_COMMITMENT, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_StoreCommitment);
    
    // Store provided commitment
    short playerId = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_PLAYERID_OFFSET));
    short commitmentLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENTLENGTH_OFFSET));
    quorumCtx.StoreCommitment(playerId, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTORECOMMITMENT_COMMITMENT_OFFSET), commitmentLen);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:23,代码来源:MPCApplet.java

示例2: 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;
}
 
开发者ID:crocs-muni,项目名称:ECTester,代码行数:19,代码来源:AppletUtil.java

示例3: GetOperationParamsOffset

import javacard.framework.APDU; //导入方法依赖的package包/类
short GetOperationParamsOffset(byte operationCode, APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short dataLen = apdu.getIncomingLength();
    // Check correctness of basic structure and expected operation
    short offset = ISO7816.OFFSET_CDATA;
    if (apdubuf[offset] != Consts.TLV_TYPE_MPCINPUTPACKET) ISOException.throwIt(Consts.SW_INVALIDPACKETSTRUCTURE);
    offset++;
    short packetLen = Util.getShort(apdubuf, offset);
    if (packetLen < 1 || packetLen > dataLen) ISOException.throwIt(Consts.SW_INVALIDPACKETSTRUCTURE); // at least 1 byte of packet content required for operationCode
    offset += 2;
    if (apdubuf[offset] != operationCode) ISOException.throwIt(Consts.SW_INVALIDPACKETSTRUCTURE);

    return offset;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:15,代码来源:MPCApplet.java

示例4: Personalize_Init

import javacard.framework.APDU; //导入方法依赖的package包/类
void Personalize_Init(APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    short len = apdu.getIncomingLength();

    // TODO: check state
    // TODO: check authorization
    // TODO: generate card long-term signature key
    // TODO: clear QuorumContext[] 
    // TODO: change state
    // TODO: export card public info
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:12,代码来源:MPCApplet.java

示例5: Personalize_SetUserAuthPubKey

import javacard.framework.APDU; //导入方法依赖的package包/类
void Personalize_SetUserAuthPubKey(APDU apdu) {
    byte[] buffer = apdu.getBuffer();
    short len = apdu.getIncomingLength();

    // TODO: check state
    // TODO: set long-term authorization key for subsequent operations
    // TODO: change state
    // TODO: export card public info
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:10,代码来源:MPCApplet.java

示例6: KeyGen_StorePublicKey

import javacard.framework.APDU; //导入方法依赖的package包/类
/**
 * Verify the validity of Y’s elements against their previous commitments KeyGen_StoreCommitment().
 * If one or more commitments fail the verification then the member infers that an error (either intentional or
 * unintentional) occurred and the protocol is terminated.
 * @param apdu 
 */
void KeyGen_StorePublicKey(APDU apdu) {
    byte[] apdubuf = apdu.getBuffer();
    short len = apdu.getIncomingLength();

    short paramsOffset = GetOperationParamsOffset(Consts.INS_KEYGEN_STORE_PUBKEY, apdu);
    // Parse incoming apdu to obtain target quorum context
    QuorumContext quorumCtx = GetTargetQuorumContext(apdubuf, paramsOffset);
    // Verify authorization
    quorumCtx.VerifyCallerAuthorization(apdu, StateModel.FNC_QuorumContext_SetYs);
    // Store provided public key 
    short playerId = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTOREPUBKEY_PLAYERID_OFFSET));
    short pubKeyLen = Util.getShort(apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEYLENGTH_OFFSET));
    quorumCtx.SetYs(playerId, apdubuf, (short) (paramsOffset + Consts.PACKET_PARAMS_KEYGENSTOREPUBKEY_PUBKEY_OFFSET), pubKeyLen);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:21,代码来源:MPCApplet.java

示例7: doVerifyPin

import javacard.framework.APDU; //导入方法依赖的package包/类
private void doVerifyPin(APDU apdu) throws ISOException {
    byte[] buf = apdu.getBuffer();
    byte p1 = buf[ISO7816.OFFSET_P1];
    byte p2 = buf[ISO7816.OFFSET_P2];
    short lc = apdu.setIncomingAndReceive();

    if ((p1 != (byte) 0x00 && p1 != (byte) 0xFF) || (p2 != (byte) 0x80)) {
        ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2);
    }

    if (p1 == (byte) 0xFF) {
        authenticated[0] = false;
        ISOException.throwIt(ISO7816.SW_NO_ERROR);
    }

    if ((lc != apdu.getIncomingLength()) || lc != (short) 8) {
        ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
    }

    if (pin.getTriesRemaining() == 0) {
        ISOException.throwIt(SW_AUTHENTICATION_METHOD_BLOCKED);
    }

    // Check the PIN.
    if (!pin.check(buf, apdu.getOffsetCdata(), (byte) lc)) {
        // Authentication failed
        authenticated[0] = false;
        ISOException.throwIt((short) (SW_PIN_TRIES_REMAINING
                | pin.getTriesRemaining()));
    } else {
        // Authentication successful
        authenticated[0] = true;
        ISOException.throwIt(ISO7816.SW_NO_ERROR);
    }
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:36,代码来源:CryptonitApplet.java

示例8: 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);
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:35,代码来源:CryptonitApplet.java

示例9: 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);
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:39,代码来源:CryptonitApplet.java

示例10: 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;
    }
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:38,代码来源:CryptonitApplet.java

示例11: 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();
    }
}
 
开发者ID:mbrossard,项目名称:cryptonit-applet,代码行数:69,代码来源:CryptonitApplet.java

示例12: 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);
    }
}
 
开发者ID:philipWendland,项目名称:IsoApplet,代码行数:57,代码来源:IsoApplet.java

示例13: 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();
}
 
开发者ID:philipWendland,项目名称:IsoApplet,代码行数:53,代码来源:IsoApplet.java


注:本文中的javacard.framework.APDU.getIncomingLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。