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


Java CardResponse.getSW1方法代码示例

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


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

示例1: readPINTryCounter

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

        EMVApplication app = card.getSelectedApplication();

        verifyAppInitialized(app);

        byte[] command;
        int SW1;
        int SW2;

        Log.commandHeader("Send GET DATA command to find the PIN Try Counter");
        command = EMVAPDUCommands.getPINTryConter();
        CardResponse getDataPINTryCounterResponse = EMVUtil.sendCmd(terminal, command);

        SW1 = (byte) getDataPINTryCounterResponse.getSW1();
        SW2 = (byte) getDataPINTryCounterResponse.getSW2();

        if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
            BERTLV tlv = TLVUtil.getNextTLV(new ByteArrayInputStream(getDataPINTryCounterResponse.getData()));
            app.setPINTryCounter(tlv.getValueBytes()[0]);
        } else {
            app.setPINTryCounter(-2);
        }
    }
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:25,代码来源:EMVSession.java

示例2: readTransactionLog

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
/**
 * Based on a patch by Thomas Souvignet -FR-
 */
private void readTransactionLog(EMVApplication app) throws TerminalException {
    //read all the log records
    LogEntry logEntry = app.getLogEntry();
    int sfi = logEntry.getSFI().getValue();
    for (int recordNum = 1; recordNum <= logEntry.getNumberOfRecords(); recordNum++) {
        Log.commandHeader("Send READ RECORD to read LOG ENTRY SFI " + sfi + " record " + recordNum);

        byte[] command = EMVAPDUCommands.readRecord(recordNum, logEntry.getSFI().getValue());

        CardResponse readAppDataResponse = EMVUtil.sendCmdNoParse(terminal, command);

        byte SW1 = (byte) readAppDataResponse.getSW1();
        byte SW2 = (byte) readAppDataResponse.getSW2();

        if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
            app.addTransactionLogRecord(readAppDataResponse.getData());
        } else if (SW1 == (byte) 0x6a && SW2 == (byte) 0x83) {
            return;
        } else {
            //Any SW1 SW2 other than '9000' passed to the application layer as a result
            //of reading any record shall cause the transaction (not entry log) to be terminated [spec]
            throw new SmartCardException("Reading application data failed for SFI " + sfi + " Record Number: " + recordNum);
        }
    }
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:29,代码来源:EMVSession.java

示例3: initCard

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
public SmartCard initCard() throws TerminalException {

        if (cardInitialized) {
            throw new SmartCardException("Card already initalized. Create new Session to init new card.");
        }

        card = new SmartCard(new sasc.iso7816.ATR(terminal.getATR()));
        Log.debug("terminal: " + terminal);
        Log.debug("ATR: " + Util.prettyPrintHexNoWrap(terminal.getATR()));

        byte[] command;
        int SW1;
        int SW2;

        try {
            Thread.sleep(sessionEnv.getInitialPauseMillis());
        } catch (InterruptedException ex) {
            ex.printStackTrace(System.err);
            Thread.currentThread().interrupt();
            throw new TerminalException(ex);
        }

        if (sessionEnv.getWarmUpCard()) {
            //Some cards/readers seem to misbehave on the first command 
            //(maybe due to premature activation after insertion?)
            //eg if the first command is "select PSE", then the card might
            //return 6985 (Command not allowed; conditions of use not satisfied)
            //We try to work around this by sending a "warm up" command to the card

            Log.commandHeader("SELECT FILE NONEXISTINGFILE to warm up the card/terminal/connection");

            command = EMVAPDUCommands.selectByDFName(Util.fromHexString("4E 4F 4E 45 58 49 53 54 49 4E 47 46 49 4C 45"));

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

            SW1 = (byte) selectNEFResponse.getSW1();
            SW2 = (byte) selectNEFResponse.getSW2();

            //NO-OP
        }

        CardScanner scanner = new CardScanner(card, terminal, sessionEnv);
        scanner.start();

        return card;
    }
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:47,代码来源:CardSession.java

示例4: 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

示例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: internalAuthenticate

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

        if(!canDDABePerformed(app)){
            EMVTerminal.getTerminalVerificationResults().setDDAFailed(true);
            return;
        }
        
        if (app.getSignedDynamicApplicationData() != null) {
            throw new SmartCardException("Signed Dynamic Application Data exists. DDA already performed?");
        }
        
        byte[] command;
        int SW1;
        int SW2;

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

        byte[] authenticationRelatedData = null; //data according to DDOL

        DOL ddol = app.getDDOL();
        if (ddol != null) {
            authenticationRelatedData = EMVTerminal.constructDOLResponse(ddol, app);
        }
        if (authenticationRelatedData == null) {
            authenticationRelatedData = EMVTerminal.getDefaultDDOLResponse(app);
        }

        command = EMVAPDUCommands.internalAuthenticate(authenticationRelatedData);
        //The data field of the command message contains the authentication-related data proprietary to an application. 
        //It is coded according to the DDOL as defined in Book 2.

        //The response contains the "Signed Dynamic EMVApplication Data"
        //See Table 15, book 2 (page 79)
        CardResponse internalAuthenticateResponse = EMVUtil.sendCmd(terminal, command);

        SW1 = (byte) internalAuthenticateResponse.getSW1();
        SW2 = (byte) internalAuthenticateResponse.getSW2();

        if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
            EMVUtil.processInternalAuthResponse(internalAuthenticateResponse.getData(), authenticationRelatedData, app);
            
        }
    }
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:44,代码来源:EMVSession.java

示例7: checkForTransactionLogRecords

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
/**
  * This is an optional command that can be issued (when?)
  * 
  * @throws TerminalException 
  */
 public void checkForTransactionLogRecords() throws TerminalException {
     
     EMVApplication app = card.getSelectedApplication();

     verifyAppInitialized(app);

     if(app.isTransactionLogProcessed()) {
         throw new SmartCardException("Transaction Log has already been processed");
     }
     
     app.setTransactionLogProcessed();
     
     byte[] command;
     int SW1;
     int SW2;
     
     //If the Log Entry data element is present in the FCI Issuer Discretionary Data,
     //then get the Log Format (and proceed to read the log records...)
     Log.commandHeader("Send GET DATA command to find the Log Format");
     command = EMVAPDUCommands.getLogFormat();
     CardResponse getDataLogFormatResponse = EMVUtil.sendCmd(terminal, command);

     SW1 = (byte) getDataLogFormatResponse.getSW1();
     SW2 = (byte) getDataLogFormatResponse.getSW2();

     if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
         BERTLV tlv = TLVUtil.getNextTLV(new ByteArrayInputStream(getDataLogFormatResponse.getData()));
         app.setLogFormat(new LogFormat(tlv.getValueBytes()));

         //Log Entry data element should be located in the FCI Issuer Discretionary Data
         //If it is not, then the app does not support transaction logging.
         //But we try to read the Log Entry with GET DATA if not present in FCI
         if (app.getLogEntry() != null) {
             readTransactionLog(app);
         } else {
	Log.commandHeader("Send GET DATA command to find the Log Entry SFI");
	command = EMVAPDUCommands.getData((byte)0x9f, (byte)0x4d);
	CardResponse getDataLogEntryResponse = EMVUtil.sendCmd(terminal, command);

	SW1 = (byte) getDataLogEntryResponse.getSW1();
	SW2 = (byte) getDataLogEntryResponse.getSW2();

     		if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
		app.setLogEntry(new LogEntry(getDataLogEntryResponse.getData()[0], getDataLogEntryResponse.getData()[1]));
		readTransactionLog(app);
	}
}

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

示例8: testBruteForceRecords

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
/**
     * This method is only for debugging. Not to be used in normal processing
     * 
     * @throws TerminalException 
     */
    public void testBruteForceRecords() throws TerminalException {

        EMVApplication app = card.getSelectedApplication();

        if (app == null) {
            throw new SmartCardException("No application selected. Call selectApplication(Application) and initializeApplicationProcessing() first");
        }

        byte[] command;
        byte SW1;
        byte SW2;

        Log.commandHeader("Brute force SFI & Record numbers (Send READ RECORD)");

        //Valid SFI: 1 to 30
        //Valid Record numbers: 1 to 255

        int numRecordsFound = 0;

        for (int sfi = 1; sfi <= 30; sfi++) {

            for (int recordNum = 1; recordNum <= 255; recordNum++) {

                command = EMVAPDUCommands.readRecord(recordNum, sfi);

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

                SW1 = (byte) readRecordsResponse.getSW1();
                SW2 = (byte) readRecordsResponse.getSW2();

                if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
//                if (SW1 != (byte) 0x6a && (SW2 != (byte) 0x83 || SW2 != (byte) 0x82)) { //This is used to see if we can get any other responses
                    System.out.println("***** BRUTE FORCE FOUND SOMETHING ***** SFI=" + Util.byte2Hex((byte) sfi) + " File=" + recordNum + " SW=" + Util.short2Hex(readRecordsResponse.getSW()));
                    System.out.println(Util.prettyPrintHex(readRecordsResponse.getData()));
                    EMVUtil.parseAppRecord(readRecordsResponse.getData(), app);
                    numRecordsFound++;
                }
            }
        }
        System.out.println("Number of Records found: " + numRecordsFound);
    }
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:47,代码来源:EMVSession.java

示例9: sendCmdInternal

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
private static CardResponse sendCmdInternal(CardConnection terminal, byte[] cmd, boolean doParseTLVData) throws TerminalException {
    byte[] cmdBytes = checkAndAddLeIfMissing(cmd);
    Log.command(Util.prettyPrintHex(cmdBytes));
    long startTime = System.nanoTime();
    CardResponse response = terminal.transmit(cmdBytes);

    //handle procedure bytes here, and not in the lower level TerminalProvider Implementations.
    //That way we can process procedure bytes from any Provider (if they are not handled at that level)

    byte sw1 = (byte) response.getSW1();
    byte sw2 = (byte) response.getSW2();
    byte[] data = response.getData(); //Copy
    Log.debug("Received data+SW1+SW2: " + Util.byteArrayToHexString(data) + " " + Util.byte2Hex(sw1) + " " + Util.byte2Hex((byte) sw2));
    Log.debug("data.length: 0x"+Util.int2Hex(data.length) + " ("+data.length+")");
    if (sw1 == (byte) 0x6c) { //"Wrong length" (resend last command with correct length)
        //Re-issue command with correct length
        cmdBytes[4] = sw2;
        Log.procedureByte("Received procedure byte SW1=0x6c. Re-issuing command with correct length (" + Util.byte2Hex(sw2)+"): "+ Util.byteArrayToHexString(cmdBytes));
        response = terminal.transmit(cmdBytes);
        sw1 = (byte) response.getSW1();
        sw2 = (byte) response.getSW2();
        data = response.getData(); //Copy
        Log.procedureByte("Received data+SW1+SW2: " + Util.byteArrayToHexString(data) + " " + Util.byte2Hex(sw1) + " " + Util.byte2Hex(sw2));
    }

    //Note some non-EMV cards (and terminal software) seem to re-issue the last command with length=SW2 when getting SW1=61
    while (sw1 == (byte) 0x61) { //Procedure byte: send GET RESPONSE to receive more data
        boolean emvMode = true;
        if(emvMode){
            //this command is EMV specific, since EMV locks CLA to 0x00 only (Book 1, 9.3.1.3). ISO7816-4 specifies CLS in GET RESPONSE in "section 5.4.1 Class byte" to be 0x0X
            cmdBytes = new byte[]{(byte) 0x00, (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) sw2};
        }else{
            cmdBytes = new byte[]{cmdBytes[0], (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) sw2};
        }
        Log.procedureByte("Received procedure byte SW1=0x61. Sending GET RESPONSE command: " + Util.byteArrayToHexString(cmdBytes));
        response = terminal.transmit(cmdBytes);
        byte[] newData = response.getData();
        byte[] tmpData = new byte[data.length + newData.length];
        System.arraycopy(data, 0, tmpData, 0, data.length);
        System.arraycopy(newData, 0, tmpData, data.length, newData.length);
        sw1 = (byte) response.getSW1();
        sw2 = (byte) response.getSW2();
        Log.procedureByte("Received newData+SW1+SW2: " + Util.byteArrayToHexString(newData) + " " + Util.byte2Hex(sw1) + " " + Util.byte2Hex(sw2));
        data = tmpData;
    }


    long endTime = System.nanoTime();
    printResponse(response, doParseTLVData);
    Log.debug("Time: " + Util.getFormattedNanoTime(endTime - startTime));
    return response;
}
 
开发者ID:yinheli,项目名称:javaemvreader,代码行数:53,代码来源:EMVUtil.java

示例10: readPSERecords

import sasc.terminal.CardResponse; //导入方法依赖的package包/类
private void readPSERecords(ShortFileIdentifier shortFileIdentifier) throws TerminalException {
    
    byte[] command;
    byte SW1;
    byte SW2;
    
    try {
        int sfi = shortFileIdentifier.getValue();

        byte recordNum = 1;
        do {

            Log.commandHeader("Send READ RECORD to read all records in SFI " + sfi);

            command = EMVAPDUCommands.readRecord((int) recordNum, sfi);

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

            //Example Response from the command above:

            //70 23
            //      61 21
            //            4f 07 //AID
            //                  a0 00 00 00 03 10 10
            //            50 04 //Application Label
            //                  56 49 53 41 (=VISA)
            //            9f 12 0c //Application Preferred Name
            //                     56 49 53 41 20 43 6c 61 73 73 69 63 (=VISA Classic)
            //            87 01 //Application priority indicator
            //                  02


            SW1 = (byte) readRecordResponse.getSW1();
            SW2 = (byte) readRecordResponse.getSW2();

            if (SW1 == (byte) 0x90 && SW2 == (byte) 0x00) {
                EMVUtil.parsePSERecord(readRecordResponse.getData(), card);
            }

            recordNum++;

        } while (SW1 == (byte) 0x90 && SW2 == (byte) 0x00); //while SW1SW2 != 6a83

    } catch(TLVException tlvex) {
        Log.debug(Util.getStackTrace(tlvex));
    }

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


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