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


Java CardResponse.getSW方法代码示例

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


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

示例1: getChallenge

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
/**
 * EMV 4.2 Book 3, section 6.5.6
 * The GET CHALLENGE command is used to obtain an unpredictable number from 
 * the ICC for use in a security-related procedure. 
 * The challenge shall be valid only for the next issued command.
 * 
 * Used eg when enciphering the PIN
 * 
 * @return an 8-byte unpredictable number generated by the ICC, 
 *    or a zero length byte array if the card does not support the command or the response data length != 8 
 * @throws TerminalException 
 */
private byte[] getChallenge() throws TerminalException {

    byte[] command;

    Log.commandHeader("Send GET CHALLENGE command");
    command = EMVAPDUCommands.getChallenge();

    //Parse raw bytes only, no BERTLV
    CardResponse getChallengeResponse = EMVUtil.sendCmdNoParse(terminal, command);
    
    
    if (getChallengeResponse.getSW() == SW.SUCCESS.getSW()) {
        //The data field of the response message should contain an 
        //8-byte unpredictable number generated by the ICC
        byte[] challenge = getChallengeResponse.getData();
        return challenge;
    }
    return new byte[0];
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:32,代码来源:EMVSession.java

示例2: externalAuthenticate

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
/**
 *
 * @param cryptogram mandatory 8 bytes from issuer
 * @param proprietaryData optional 1-8 bytes (proprietary)
 * @throws TerminalException
 */
public void externalAuthenticate(byte[] cryptogram, byte[] proprietaryData) throws TerminalException {

    EMVApplication app = card.getSelectedApplication();

    verifyAppInitialized(app);

    byte[] command;

    Log.commandHeader("Send EXTERNAL AUTHENTICATE command");

    command = EMVAPDUCommands.externalAuthenticate(cryptogram, proprietaryData);
    CardResponse externalAuthenticateResponse = EMVUtil.sendCmd(terminal, command);
    //No data field is returned in the response message
    //'9000' indicates a successful execution of the command.
    //'6300' indicates "Issuer authentication failed".

    if (externalAuthenticateResponse.getSW() != SW.SUCCESS.getSW()) {
        if (externalAuthenticateResponse.getSW() == SW.AUTHENTICATION_FAILED.getSW()) {
            throw new SmartCardException("Issuer authentication failed");
        }
        throw new SmartCardException("Unexpected response: " + Util.short2Hex(externalAuthenticateResponse.getSW()));
    }
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:30,代码来源:EMVSession.java

示例3: process

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
@Override
public boolean process(SmartCard card, CardConnection terminal) throws TerminalException {
    Log.debug("Attempting to read storage card");
    
    byte SW1;
    byte SW2;
    byte[] command;
    CardResponse response;
    byte[] data;
    
    //6a 81 = Function not supported
    //90 00 = Success 
    Log.commandHeader("PS/SC GET DATA: UID (Command handled by terminal when card is contactless)");

    command = Util.fromHexString("ff ca 00 00 00"); //PC/SC 2.01 part 3 GetData: UID
    response = EMVUtil.sendCmdNoParse(terminal, command);
    SW1 = (byte) response.getSW1();
    SW2 = (byte) response.getSW2();
    if (response.getSW() == SW.SUCCESS.getSW()) {
        
    }
    
    Log.commandHeader("PC/SC GET DATA: Historical bytes (Command handled by terminal when card is contactless)");

    command = Util.fromHexString("ff ca 01 00 00"); //PC/SC 2.01 part 3 GetData: historical bytes from the ATS of a ISO 14443 A card without CRC
    response = EMVUtil.sendCmdNoParse(terminal, command);
    SW1 = (byte) response.getSW1();
    SW2 = (byte) response.getSW2();
    if (response.getSW() == SW.SUCCESS.getSW()) {
        
    }
    
    //Read Binary

    //    Warning
    //      6281 Part of returned data may be corrupted.
    //        82 End of file reached before reading expected number of bytes.
    //      6981 Command incompatible.
    //        82 Security status not satisfied.
    //        86 Command not allowed.
    //      6A81 Function not supported.
    //        82 File not found / Addressed block or byte does not exist.
    //
    //    Error
    //      6CXX Wrong length (wrong number Le; 'XX' is the exact number). 
    
    int addressMSB = 0;
    int addressLSB = 0;
    while(addressMSB < 256) {
        Log.commandHeader("PC/SC Read Binary (Storage Card)");
        command = Util.fromHexString("FF B0 00 00 00"); //with Le
        command[2] = (byte)addressMSB;
        command[3] = (byte)addressLSB;
        response = EMVUtil.sendCmdNoParse(terminal, command);
        SW1 = response.getSW1();
        SW2 = response.getSW2();
        data = response.getData();
        if(data.length > 0 && response.getSW() == SW.SUCCESS.getSW()){
            addressLSB++;
            if(addressLSB > 255) {
                addressLSB = 0;
                addressMSB++;
            }
            continue;
        }
        break;
    } 
    return false; //Don't handle exclusively. The card may have more applications or other functionality
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:70,代码来源:StorageCardHandler.java

示例4: selectApplication

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
public void selectApplication(EMVApplication app) throws TerminalException {

        if (app == null) {
            throw new IllegalArgumentException("Parameter 'app' cannot be null");
        }
        if (!contextInitialized) {
            throw new SmartCardException("Card not initialized. Call initCard() first");
        }
        EMVApplication currentSelectedApp = card.getSelectedApplication();
        if (currentSelectedApp != null && app.getAID().equals(currentSelectedApp.getAID())) {
            throw new SmartCardException("Application already selected. AID: " + app.getAID());
        }

        AID aid = app.getAID();
        byte[] command;

        Log.commandHeader("Select application by AID");
        command = EMVAPDUCommands.selectByDFName(aid.getAIDBytes());

        CardResponse selectAppResponse = EMVUtil.sendCmd(terminal, command);

        if (selectAppResponse.getSW() == SW.SELECTED_FILE_INVALIDATED.getSW()) {
            //App blocked
            Log.info("Application BLOCKED");
            //TODO abort execution if app blocked?
            //throw new SmartCardException("EMVApplication " + Util.byteArrayToHexString(aid.getAIDBytes()) + " blocked");
        }

        EMVUtil.parseFCIADF(selectAppResponse.getData(), app);

        //Example Response from previous command:
        //      6f 37
        //      84 07 //AID
        //            a0 00 00 00 03 10 10
        //      a5 2c
        //            50 04 //Application Label (= VISA)
        //                  56 49 53 41
        //            87 01 //Application priority indicator
        //                  02
        //            9f 38 06 //PDOL
        //                     9f 1a
        //                           02
        //                     5f 2a
        //                           02
        //            5f 2d 04 //Language Preference
        //                     6e 6f 65 6e (= no en)
        //            9f 11 01 //Issuer code table index
        //                     01
        //            9f 12 0c //Application Preferred name
        //                     56 49 53 41 20 43 6c 61 73 73 69 63 (= VISA Classic)



        //The card supplies the PDOL (if present) to the terminal as part of the FCI
        //provided in response to the SELECT FILE (Application Definition File) command

        //If PDOL present, the ICC requires parameters from the Terminal.
        //In this specific example:
        //9F1A = Indicates the country code of the terminal, represented according to ISO 3166
        //578 Norway = 0x0578
        //5F2A = Transaction Currency Code: Indicates the currency code of the transaction according to ISO 4217 (numeric 3)
        //NORWAY  Norwegian Krone  NOK  578  == 0x0578
        //PDOL response data (used in the GET PROCESSING OPTS command) = 05 78 05 78

        getCard().setSelectedApplication(app);

    }
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:68,代码来源:EMVSession.java

示例5: processVerifyPIN

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
private boolean processVerifyPIN(boolean encipherPin) throws TerminalException {

        EMVApplication app = card.getSelectedApplication();
        
        if(app.getPINTryCounter() == -1) { //-1 means we have not tried reading the PIN Try Counter before
            readPINTryCounter();
        }
        
        if(app.getPINTryCounter() == 0) {
            Log.debug("PIN Try limit exeeded. Unable to verify PIN.");
            EMVTerminal.getTerminalVerificationResults().setPinTryLimitExceeded(true);
            return false;
        }
        
        byte[] command;
        
        while(app.getPINTryCounter() != 0) {
        
            PasswordCallback pinInput = EMVTerminal.getPinInput();
            
            char[] pin = pinInput.getPassword();
            pinInput.clearPassword();
            
            if(pin == null) { //Input aborted by user or failed
                Log.debug("PIN input aborted or failed.");
                return false;
            }
            
            if(encipherPin) {                
                //Recover the public key to be used for PIN encipherment
                ICCPublicKeyCertificate iccPKCert = app.getICCPublicKeyCertificate();
                if(iccPKCert == null || !iccPKCert.validate() || iccPKCert.getICCPublicKey() == null) {
                    Log.debug("Unable to encipher PIN: ICC Public Key Certificate not valid");
                    return false;
                }
                
                //Get unpredictable number from ICC
                byte[] challenge = getChallenge();
                if(challenge.length != 8) {
                    Log.debug("Unable to encipher PIN: GET CHALLENGE returned response length "+challenge.length);
                    return false;
                }
                
                //TODO encipher PIN
            }
            
            command = EMVAPDUCommands.verifyPIN(pin, !encipherPin);
            Arrays.fill(pin, ' ');
            
            Log.commandHeader("Send VERIFY (PIN) command");

            CardResponse verifyResponse = EMVUtil.sendCmd(terminal, command);

            if (verifyResponse.getSW() == SW.SUCCESS.getSW()) {
                //Try to update PTC
                if(app.getPINTryCounter() != -2) { //-2 means app does not support the command
                    readPINTryCounter();
                }
                return true;
            } else {
                if (verifyResponse.getSW() == SW.COMMAND_NOT_ALLOWED_AUTHENTICATION_METHOD_BLOCKED.getSW()
                        || verifyResponse.getSW() == SW.COMMAND_NOT_ALLOWED_REFERENCE_DATA_INVALIDATED.getSW()) {
                    Log.info("No more retries left. CVM blocked");
                    EMVTerminal.getTerminalVerificationResults().setPinTryLimitExceeded(true);
                    app.setPINTryCounter(0);
                    return false;
                } else if (verifyResponse.getSW1() == (byte) 0x63 && (verifyResponse.getSW2() & (byte)0xF0) == (byte) 0xC0) {
                    int numRetriesLeft = (verifyResponse.getSW2() & 0x0F);
                    Log.info("Wrong PIN. Retries left: "+numRetriesLeft);
                    app.setPINTryCounter(numRetriesLeft);
                } else {
                    String description = SW.getSWDescription(verifyResponse.getSW());
                    Log.info("Application returned unexpected Status: 0x"+Util.short2Hex(verifyResponse.getSW()) 
                            + (description != null && !description.isEmpty()?" ("+description+")":""));
                    return false;
                }
            }
        }
        EMVTerminal.getTerminalVerificationResults().setPinTryLimitExceeded(true);
        return false;
    }
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:82,代码来源:EMVSession.java

示例6: generateAC

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
public void generateAC(byte[] iccDynamicNumber) throws TerminalException {
    /**
     * p1 &= 0b00111111 = AAC = reject transaction (EMVApplication Authentication Cryptogram)
     * p1 &= 0b10111111 = TC = proceed offline (Transaction Certificate)
     * p1 &= 0b01111111 = ARQC = go online (Authorization Request Cryptogram                                                                            ) +
     * 0x00 = CDA signature not requested
     * 0x10 = CDA signature requested
     */

    EMVApplication app = card.getSelectedApplication();

    verifyAppInitialized(app);

    byte[] command;

    Log.commandHeader("Send GENERATE APPLICATION CRYPTOGRAM command");

    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    byte[] authorizedAmount = Util.fromHexString("00 00 00 00 00 01");
    byte[] secondaryAmount = Util.fromHexString("00 00 00 00 00 00");
    byte[] tvr = Util.fromHexString("00 00 00 00 00");
    byte[] transactionCurrencyCode = Util.fromHexString("09 78");
    byte[] transactionDate = Util.fromHexString("09 07 30");
    byte[] transactionType = Util.fromHexString("21");
    byte[] terminalUnpredictableNumber = Util.generateRandomBytes(4);
    //iccDynamicNumber
    byte[] dataAuthCode = app.getSignedStaticApplicationData().getDataAuthenticationCode();

    buf.write(authorizedAmount, 0, authorizedAmount.length);
    buf.write(secondaryAmount, 0, secondaryAmount.length);
    buf.write(tvr, 0, tvr.length);
    buf.write(transactionCurrencyCode, 0, transactionCurrencyCode.length);
    buf.write(transactionDate, 0, transactionDate.length);
    buf.write(transactionType, 0, transactionType.length);
    buf.write(terminalUnpredictableNumber, 0, terminalUnpredictableNumber.length);
    buf.write(iccDynamicNumber, 0, iccDynamicNumber.length);
    buf.write(dataAuthCode, 0, dataAuthCode.length);

    //0x40 = TC
    //0x80 = ARQC
    command = EMVAPDUCommands.generateAC((byte) 0x40, buf.toByteArray());
    CardResponse generateACResponse = EMVUtil.sendCmd(terminal, command);
    //'9000' indicates a successful execution of the command.

    if (generateACResponse.getSW() != SW.SUCCESS.getSW()) {
        throw new SmartCardException("Unexpected response: " + Util.short2Hex(generateACResponse.getSW()));
    } else {
        //TODO
        Log.info("TODO GenerateAC success");

        //80 response message template 1 contatenated values
        //77 BER-TLV encoded
    }
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:55,代码来源:EMVSession.java

示例7: initCard

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
public EMVCard initCard() throws TerminalException {
    card = new EMVCard(new sasc.iso7816.ATR(seConn.getATR()));

    // ATR file
    String command = "00 A4 00 00 02 2F01";
    CardResponse response = seConn.transmit(fromHex(command));
    if (response.getSW() == SW.SUCCESS.getSW()) {
        card = new EMVCard(new sasc.iso7816.ATR(response.getData()));
    } else {
        Log.d(TAG, "ATR file not found. Will use dummy. Response: "
                + response);
        card = new EMVCard(
                new sasc.iso7816.ATR(
                        Hex.fromHex("3B 8A 80 01 00 31 C1 73 C8 40 00 00 90 00 90")));
    }

    // try to select the PPSE (Proximity Payment System Environment)
    // 2PAY.SYS.DDF01
    Log.d(TAG, "SELECT FILE 2PAY.SYS.DDF01 to get the PPSE directory");
    command = EMVAPDUCommands.selectPPSE();
    CardResponse selectPPSEdirResponse = EMVUtil.sendCmd(seConn, command);
    short sw = selectPPSEdirResponse.getSW();
    if (sw == SW.SUCCESS.getSW()) {
        Log.d(TAG, "***************************************************");
        // PPSE is available
        DDF ppse = PPSE.parse(selectPPSEdirResponse.getData(), card);
        Log.d(TAG, "Name: " + new String(ppse.getName()));
        Log.d(TAG, "PPSE DDF: " + ppse.toString());
        card.setType(EMVCard.Type.CONTACTLESS);
        card.setPSE(ppse);

        // loopback command test
        response = EMVUtil.sendCmd(seConn, "80ee00000301020300");
        Log.d(TAG, "loopback response: " + response.toString());
    }

    // Still no applications?
    if (card.getApplications().isEmpty()) {
        Log.d(TAG,
                "No PSE '2PAY.SYS.DDF01' or application(s) found. Might not be an EMV card. Is Wallet locked?");
    }

    cardInitalized = true;
    return card;
}
 
开发者ID:gsbabil,项目名称:ClassicNFC,代码行数:46,代码来源:SEEMVSession.java

示例8: selectApplication

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
public void selectApplication(EMVApplication app) throws TerminalException {
    if (app == null) {
        throw new IllegalArgumentException("Parameter 'app' cannot be null");
    }

    if (!cardInitalized) {
        throw new SmartCardException(
                "Card not initialized. Call initCard() first");
    }

    EMVApplication currentSelectedApp = card.getSelectedApplication();
    if (currentSelectedApp != null
            && app.getAID().equals(currentSelectedApp.getAID())) {
        throw new SmartCardException("Application already selected. AID: "
                + app.getAID());
    }

    AID aid = app.getAID();
    Log.d(TAG, "Select application by AID: " + aid);
    String command = EMVAPDUCommands.selectByDFName(aid.getAIDBytes());
    CardResponse selectAppResponse = EMVUtil.sendCmd(seConn, command);

    if (selectAppResponse.getSW() == SW.SELECTED_FILE_INVALIDATED.getSW()) {
        // App blocked
        Log.i(TAG, "Application BLOCKED");
        // TODO abort execution if app blocked?
        throw new SmartCardException("EMVApplication "
                + Util.byteArrayToHexString(aid.getAIDBytes()) + " blocked");
    }

    if (selectAppResponse.getSW() != SW.SUCCESS.getSW()) {
        Log.e(TAG, "Can't select app. Card response: " + selectAppResponse);
        return;
    }

    ApplicationDefinitionFile adf = EMVUtil.parseFCIADF(
            selectAppResponse.getData(), app);
    Log.d(TAG, "ADF: " + adf);

    getCurrentCard().setSelectedApplication(app);
}
 
开发者ID:gsbabil,项目名称:ClassicNFC,代码行数:42,代码来源:SEEMVSession.java


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