本文整理汇总了Java中javax.smartcardio.ResponseAPDU.getSW方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseAPDU.getSW方法的具体用法?Java ResponseAPDU.getSW怎么用?Java ResponseAPDU.getSW使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.smartcardio.ResponseAPDU
的用法示例。
在下文中一共展示了ResponseAPDU.getSW方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAPDU
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
void testAPDU(CardManager cardMngr, String input, String expectedOutput) {
try {
ResponseAPDU response = cardMngr.transmit(new CommandAPDU(hexStringToByteArray(input)));
if (response.getSW() == (ISO7816.SW_NO_ERROR & 0xffff)) {
if (!expectedOutput.isEmpty()) {
byte[] data = response.getData();
String output = Util.bytesToHex(data);
assertTrue(expectedOutput.equalsIgnoreCase(output), "Result provided by card mismatch expected");
}
}
else {
assertTrue(false, String.format("Card failed with 0x%x", response.getSW()));
}
}
catch (Exception e) {
e.printStackTrace();
assertTrue(false, "Card transmit failed with execption");
}
}
示例2: setAuth0
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Set the page from which authentication is required. The default is
* 48, which means no restriction.
*
* <p>For example, if {@code page} is 20 then authentication is
* required from page 20 until the end of the memory. Whether it is only
* write restricted or read and write restricted depends on auth1.
*
* @param page page number from which authentication is required
* @return <code>true</code> if set successfully
*/
public boolean setAuth0(int page) {
if (page < 0 || page > 48) {
return false;
}
byte[] apdu = new byte[9];
apdu[0] = (byte) 0xFF;
apdu[1] = (byte) 0xD6;
apdu[2] = 0x00;
apdu[3] = 0x2A;
apdu[4] = 0x04;
apdu[5] = (byte) page;
apdu[6] = apdu[7] = apdu[8] = 0x00;
CommandAPDU command = new CommandAPDU(apdu);
ResponseAPDU response = transmit(command);
feedback(command, response);
if (response.getSW() == (0x90 << 8 | 0x00)) {
return true;
}
return false;
}
示例3: setAuth1
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Set write or read+write restriction on page range set in auth1.
*
* @param allowRead {@code true} to allow read and prevent write,
* {@code false} to prevent both read and write
* @return {@code true} on success
*/
public boolean setAuth1(boolean allowRead) {
byte[] apdu = new byte[9];
apdu[0] = (byte) 0xFF;
apdu[1] = (byte) 0xD6;
apdu[2] = 0x00;
apdu[3] = 0x2B;
apdu[4] = 0x04;
apdu[6] = apdu[7] = apdu[8] = 0x00;
if (allowRead) {
apdu[5] = 0x01;
} else {
apdu[5] = 0x00;
}
CommandAPDU command = new CommandAPDU(apdu);
ResponseAPDU response = transmit(command);
feedback(command, response);
if (response.getSW() == (0x90 << 8 | 0x00)) {
return true;
}
return false;
}
示例4: read
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Read a 4-byte page.
*
* @param page the page number to be read (0<=page<=43)
* @return a 4-byte array with the page contents in hexadecimal, or
* {@code null} on error
*/
public byte[] read(int page) {
if (page < 0 || page > 43) {
return null;
}
byte[] apdu = {(byte) 0xFF, (byte) 0xB0, 0x00, (byte) page, 0x04};
CommandAPDU command = new CommandAPDU(apdu);
ResponseAPDU response = transmit(command);
feedback(command, response);
if (response.getSW() != (0x90 << 8 | 0x00)) {
return null;
}
return response.getData();
}
示例5: update
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Update a 4-byte user page.
*
* @param page the number of the page to be updated (4<=page<=39)
* @param data a 4-byte array containing the data in hexadecimal
* @return {@code true} on success
*/
public boolean update(int page, byte[] data) {
if (page < 4 || page > 39) {
// outside of user memory
return false;
}
byte[] apdu = new byte[9];
apdu[0] = (byte) 0xFF;
apdu[1] = (byte) 0xD6;
apdu[2] = 0x00;
apdu[3] = (byte) page;
apdu[4] = 0x04;
System.arraycopy(data, 0, apdu, 5, 4);
CommandAPDU command = new CommandAPDU(apdu);
ResponseAPDU response = transmit(command);
feedback(command, response);
if (response.getSW() != (0x90 << 8 | 0x00)) {
return false;
}
return true;
}
示例6: verifyPukDirect
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
private ResponseAPDU verifyPukDirect(int retriesLeft, CCIDFeature directPinVerifyFeature)
throws IOException, CardException, UserCancelledException {
this.view.addDetailMessage("direct PUK verification...");
byte[] verifyCommandData = createPINVerificationDataStructure(0x2C);
this.dialogs.showPUKPadFrame(retriesLeft);
ResponseAPDU responseApdu;
try {
responseApdu = directPinVerifyFeature.transmit(verifyCommandData, this.card, this.cardChannel);
} finally {
this.dialogs.disposePINPadFrame();
}
if (0x6401 == responseApdu.getSW()) {
this.view.addDetailMessage("canceled by user");
throw new UserCancelledException();
} else if (0x6400 == responseApdu.getSW()) {
this.view.addDetailMessage("PIN pad timeout");
}
return responseApdu;
}
示例7: getFeaturesUsingPPDU
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
private void getFeaturesUsingPPDU(final Card card) throws CardException {
ResponseAPDU responseAPDU = card.getBasicChannel().transmit(
new CommandAPDU((byte) 0xff, (byte) 0xc2, 0x01, 0x00,
new byte[]{}, 32));
this.logger.debug("PPDU response: "
+ Integer.toHexString(responseAPDU.getSW()));
if (responseAPDU.getSW() == 0x9000) {
byte[] featureBytes = responseAPDU.getData();
this.logger
.debug("CCID FEATURES found using Pseudo-APDU Fallback Strategy");
for (FEATURE feature : FEATURE.values()) {
Integer featureCode = findFeaturePPDU(feature.getTag(),
featureBytes);
if (featureCode != null) {
this.features.put(feature, featureCode);
this.logger.debug("FEATURE " + feature.name() + " = "
+ Integer.toHexString(featureCode));
}
}
this.usesPPDU = true;
} else {
this.logger.error("CCID Features via PPDU Not Supported");
}
}
示例8: unblockPINViaCCIDVerifyPINDirectOfPUK
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
private ResponseAPDU unblockPINViaCCIDVerifyPINDirectOfPUK(
final int retriesLeft) throws IOException, CardException {
this.logger.debug("direct PUK verification...");
getUI().advisePINPadPUKEntry(retriesLeft);
byte[] result;
try {
result = this.transmitCCIDControl(
getCCID().usesPPDU(),
CCID.FEATURE.VERIFY_PIN_DIRECT,
this.getCCID().createPINVerificationDataStructure(
this.getLocale(), CCID.INS.VERIFY_PUK));
} finally {
getUI().advisePINPadOperationEnd();
}
final ResponseAPDU responseApdu = new ResponseAPDU(result);
if (0x6401 == responseApdu.getSW()) {
this.logger.debug("canceled by user");
final SecurityException securityException = new SecurityException(
"canceled by user", new ResponseAPDUException(responseApdu));
throw securityException;
} else if (0x6400 == responseApdu.getSW()) {
this.logger.debug("PIN pad timeout");
}
return responseApdu;
}
示例9: getChallenge
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Returns random data generated by the eID card itself.
*
* @param size
* the size of the requested random data.
* @return size bytes of random data
* @throws CardException
*/
public byte[] getChallenge(final int size) throws CardException {
final ResponseAPDU responseApdu = transmitCommand(
BeIDCommandAPDU.GET_CHALLENGE, new byte[]{}, 0, 0, size);
if (0x9000 != responseApdu.getSW()) {
this.logger.debug("get challenge failure: "
+ Integer.toHexString(responseApdu.getSW()));
throw new ResponseAPDUException("get challenge failure: "
+ Integer.toHexString(responseApdu.getSW()), responseApdu);
}
if (size != responseApdu.getData().length) {
throw new RuntimeException("challenge size incorrect: "
+ responseApdu.getData().length);
}
return responseApdu.getData();
}
示例10: transmitPPDUCommand
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
protected byte[] transmitPPDUCommand(final int controlCode,
final byte[] command) throws CardException {
ResponseAPDU responseAPDU = card.getBasicChannel().transmit(
new CommandAPDU((byte) 0xff, (byte) 0xc2, 0x01, controlCode,
command));
if (responseAPDU.getSW() != 0x9000) {
throw new CardException("PPDU Command Failed: ResponseAPDU="
+ responseAPDU.getSW());
}
if (responseAPDU.getData().length == 0) {
return responseAPDU.getBytes();
} else {
return responseAPDU.getData();
}
}
示例11: deleteAID
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Delete file {@code aid} on the card. Delete dependencies as well if
* {@code deleteDeps} is true.
*
* @param aid
* identifier of the file to delete
* @param deleteDeps
* if true delete dependencies as well
* @throws GPDeleteException
* if the delete command fails with a non 9000 response status
* @throws CardException
* for low-level communication errors
*/
public void deleteAID(AID aid, boolean deleteDeps)
throws GPDeleteException, CardException {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try {
bo.write(0x4f);
bo.write(aid.getLength());
bo.write(aid.getBytes());
} catch (IOException ioe) {
}
CommandAPDU delete = new CommandAPDU(CLA_GP, DELETE, 0x00,
deleteDeps ? 0x80 : 0x00, bo.toByteArray());
ResponseAPDU response = transmit(delete);
notifyExchangedAPDU(delete, response);
short sw = (short) response.getSW();
if (sw != SW_NO_ERROR) {
throw new GPDeleteException(sw, "Deletion failed, SW: "
+ GPUtil.swToString(sw));
}
}
示例12: testGetChallenge
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
@Test
public void testGetChallenge() throws Exception {
PcscEid pcscEid = new PcscEid(new TestView(), this.messages);
if (false == pcscEid.isEidPresent()) {
LOG.debug("insert eID card");
pcscEid.waitForEidPresent();
}
CardChannel cardChannel = pcscEid.getCardChannel();
int size = 256;
CommandAPDU getChallengeApdu = new CommandAPDU(0x00, 0x84, 0x00, 0x00, new byte[] {}, 0, 0, size);
ResponseAPDU responseApdu;
responseApdu = cardChannel.transmit(getChallengeApdu);
if (0x9000 != responseApdu.getSW()) {
fail("get challenge failure: " + Integer.toHexString(responseApdu.getSW()));
}
LOG.debug("challenge: " + Hex.encodeHexString(responseApdu.getData()));
assertEquals(size, responseApdu.getData().length);
pcscEid.close();
}
示例13: verifyPINViaCCIDDirect
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
private ResponseAPDU verifyPINViaCCIDDirect(final int retriesLeft,
PINPurpose purpose, String applicationName) throws IOException,
CardException {
this.logger.debug("direct PIN verification...");
getUI().advisePINPadPINEntry(retriesLeft, purpose, applicationName);
byte[] result;
try {
result = this.transmitCCIDControl(
getCCID().usesPPDU(),
CCID.FEATURE.VERIFY_PIN_DIRECT,
getCCID().createPINVerificationDataStructure(
this.getLocale(), CCID.INS.VERIFY_PIN));
} finally {
getUI().advisePINPadOperationEnd();
}
final ResponseAPDU responseApdu = new ResponseAPDU(result);
if (0x6401 == responseApdu.getSW()) {
this.logger.debug("canceled by user");
final SecurityException securityException = new SecurityException(
"canceled by user", new ResponseAPDUException(responseApdu));
throw securityException;
} else if (0x6400 == responseApdu.getSW()) {
this.logger.debug("PIN pad timeout");
}
return responseApdu;
}
示例14: selectFile
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
private void selectFile(byte[] fileId) throws CardException,
FileNotFoundException {
CommandAPDU selectFileApdu = new CommandAPDU(0x00, 0xA4, 0x08, 0x0C,
fileId);
ResponseAPDU responseApdu = transmit(selectFileApdu);
if (0x9000 != responseApdu.getSW()) {
throw new FileNotFoundException(
"wrong status word after selecting file: "
+ Integer.toHexString(responseApdu.getSW()));
}
try {
// SCARD_E_SHARING_VIOLATION fix
Thread.sleep(20);
} catch (InterruptedException e) {
throw new RuntimeException("sleep error: " + e.getMessage());
}
}
示例15: openLogicalChannel
import javax.smartcardio.ResponseAPDU; //导入方法依赖的package包/类
/**
* Open a logical channel.
*
* <p>
* Common exceptions:
* <ul>
* <li>JnaCardException(6200): processing warning
* <li>JnaCardException(6881): logical channel not supported
* <li>JnaCardException(6a81): function not supported
* </ul>
*/
@Override public CardChannel openLogicalChannel() throws CardException {
// manage channel: request a new logical channel from 0x01 to 0x13
JnaCardChannel basicChannel = getBasicChannel();
ResponseAPDU response = basicChannel.transmit(new CommandAPDU(0, 0x70, 0x00, 0x00, 1));
int sw = response.getSW();
if (0x9000 == sw) {
byte[] body = response.getData();
if (body.length == 1) {
int channel = 0xff & body[0];
if (channel == 0 || channel > 0x13)
throw new JnaCardException(sw, String.format("Expected manage channel response to contain channel number in 1-19; got %d", channel));
return new JnaCardChannel(this, channel);
} else {
throw new JnaCardException(sw, String.format("Expected body of length 1 in response to manage channel request; got %d", body.length));
}
} else {
throw new JnaCardException(sw, String.format("Error: sw=%04x in response to manage channel command.", sw));
}
}