what-the-bank/sources/org/jmrtd/PassportApduService.java

595 lines
28 KiB
Java

package org.jmrtd;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.Provider;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import net.sf.scuba.smartcards.APDUEvent;
import net.sf.scuba.smartcards.APDUListener;
import net.sf.scuba.smartcards.APDUWrapper;
import net.sf.scuba.smartcards.CardService;
import net.sf.scuba.smartcards.CardServiceException;
import net.sf.scuba.smartcards.CommandAPDU;
import net.sf.scuba.smartcards.ISOFileInfo;
import net.sf.scuba.smartcards.ResponseAPDU;
import net.sf.scuba.tlv.TLVInputStream;
import o.ghS;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.crypto.tls.CipherSuite;
/* loaded from: classes6.dex */
public class PassportApduService extends CardService {
public static final byte CAN_PACE_KEY_REFERENCE = 2;
private static final byte INS_PACE_GENERAL_AUTHENTICATE = -122;
public static final byte MRZ_PACE_KEY_REFERENCE = 1;
public static final byte PIN_PACE_KEY_REFERENCE = 3;
public static final byte PUK_PACE_KEY_REFERENCE = 4;
private static final long serialVersionUID = 2451509825132976178L;
private byte[] atr;
private transient Cipher cipher;
private transient Mac mac;
private CardService service;
private static final Logger LOGGER = Logger.getLogger("org.jmrtd");
private static final Provider BC_PROVIDER = JMRTDSecurityProvider.getBouncyCastleProvider();
protected static final byte[] APPLET_AID = {ISOFileInfo.A0, 0, 0, 2, 71, 16, 1};
private static final IvParameterSpec ZERO_IV_PARAM_SPEC = new IvParameterSpec(new byte[]{0, 0, 0, 0, 0, 0, 0, 0});
private Collection<APDUListener> plainTextAPDUListeners = new HashSet();
private int plainAPDUCount = 0;
public PassportApduService(CardService cardService) throws CardServiceException {
this.service = cardService;
try {
this.mac = Mac.getInstance("ISO9797Alg3Mac", BC_PROVIDER);
this.cipher = Cipher.getInstance("DESede/CBC/NoPadding");
} catch (GeneralSecurityException e) {
LOGGER.log(Level.SEVERE, "Unexpected security exception during initialization", (Throwable) e);
throw new CardServiceException(e.toString());
}
}
@Override // net.sf.scuba.smartcards.CardService
public void open() throws CardServiceException {
if (!this.service.isOpen()) {
this.service.open();
}
this.atr = this.service.getATR();
}
@Override // net.sf.scuba.smartcards.CardService
public boolean isOpen() {
boolean isOpen;
synchronized (this) {
isOpen = this.service.isOpen();
}
return isOpen;
}
@Override // net.sf.scuba.smartcards.CardService
public ResponseAPDU transmit(CommandAPDU commandAPDU) throws CardServiceException {
ResponseAPDU transmit;
synchronized (this) {
transmit = this.service.transmit(commandAPDU);
}
return transmit;
}
@Override // net.sf.scuba.smartcards.CardService
public void close() {
CardService cardService = this.service;
if (cardService != null) {
cardService.close();
}
}
@Override // net.sf.scuba.smartcards.CardService
public void addAPDUListener(APDUListener aPDUListener) {
this.service.addAPDUListener(aPDUListener);
}
@Override // net.sf.scuba.smartcards.CardService
public void removeAPDUListener(APDUListener aPDUListener) {
this.service.removeAPDUListener(aPDUListener);
}
private ResponseAPDU transmit(APDUWrapper aPDUWrapper, CommandAPDU commandAPDU) throws CardServiceException {
ResponseAPDU transmit = transmit(aPDUWrapper != null ? aPDUWrapper.wrap(commandAPDU) : commandAPDU);
short sw = (short) transmit.getSW();
try {
if (aPDUWrapper != null) {
try {
if (transmit.getBytes().length == 2) {
StringBuilder sb = new StringBuilder("Exception during transmission of wrapped APDU\nC=");
sb.append(ghS.c(commandAPDU.getBytes()));
throw new CardServiceException(sb.toString(), sw);
}
transmit = aPDUWrapper.unwrap(transmit);
} catch (Exception e) {
if (e instanceof CardServiceException) {
throw ((CardServiceException) e);
}
StringBuilder sb2 = new StringBuilder("Exception during transmission of wrapped APDU\nC=");
sb2.append(ghS.c(commandAPDU.getBytes()));
sb2.append("\n");
sb2.append(e.getMessage());
throw new CardServiceException(sb2.toString(), sw);
}
}
return transmit;
} finally {
int i = this.plainAPDUCount + 1;
this.plainAPDUCount = i;
notifyExchangedPlainTextAPDU(i, commandAPDU, transmit);
}
}
public void sendSelectApplet(APDUWrapper aPDUWrapper, byte[] bArr) throws CardServiceException {
synchronized (this) {
CommandAPDU commandAPDU = new CommandAPDU(0, -92, 4, 12, bArr);
checkStatusWordAfterFileOperation(commandAPDU, transmit(aPDUWrapper, commandAPDU));
}
}
public void sendSelectFile(short s) throws CardServiceException {
synchronized (this) {
sendSelectFile(null, s);
}
}
public void sendSelectFile(APDUWrapper aPDUWrapper, short s) throws CardServiceException {
synchronized (this) {
CommandAPDU commandAPDU = new CommandAPDU(0, -92, 2, 12, new byte[]{(byte) (s >> 8), (byte) s}, 0);
ResponseAPDU transmit = transmit(aPDUWrapper, commandAPDU);
if (transmit == null) {
return;
}
checkStatusWordAfterFileOperation(commandAPDU, transmit);
}
}
public byte[] sendReadBinary(short s, int i, boolean z) throws CardServiceException {
byte[] sendReadBinary;
synchronized (this) {
sendReadBinary = sendReadBinary(null, s, i, z);
}
return sendReadBinary;
}
/* JADX WARN: Removed duplicated region for block: B:26:0x005e */
/* JADX WARN: Removed duplicated region for block: B:32:0x006f A[Catch: all -> 0x00c6, TryCatch #2 {, blocks: (B:19:0x0025, B:21:0x004a, B:23:0x004e, B:24:0x005b, B:30:0x0069, B:32:0x006f, B:34:0x0078, B:35:0x007d, B:37:0x0087, B:38:0x008e, B:40:0x0091, B:43:0x0095, B:46:0x0099, B:47:0x005f, B:50:0x0057, B:54:0x0040), top: B:16:0x0022 }] */
/* JADX WARN: Removed duplicated region for block: B:37:0x0087 A[Catch: all -> 0x00c6, TryCatch #2 {, blocks: (B:19:0x0025, B:21:0x004a, B:23:0x004e, B:24:0x005b, B:30:0x0069, B:32:0x006f, B:34:0x0078, B:35:0x007d, B:37:0x0087, B:38:0x008e, B:40:0x0091, B:43:0x0095, B:46:0x0099, B:47:0x005f, B:50:0x0057, B:54:0x0040), top: B:16:0x0022 }] */
/* JADX WARN: Removed duplicated region for block: B:47:0x005f A[Catch: all -> 0x00c6, TryCatch #2 {, blocks: (B:19:0x0025, B:21:0x004a, B:23:0x004e, B:24:0x005b, B:30:0x0069, B:32:0x006f, B:34:0x0078, B:35:0x007d, B:37:0x0087, B:38:0x008e, B:40:0x0091, B:43:0x0095, B:46:0x0099, B:47:0x005f, B:50:0x0057, B:54:0x0040), top: B:16:0x0022 }] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public byte[] sendReadBinary(net.sf.scuba.smartcards.APDUWrapper r11, int r12, int r13, boolean r14) throws net.sf.scuba.smartcards.CardServiceException {
/*
Method dump skipped, instructions count: 201
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: org.jmrtd.PassportApduService.sendReadBinary(net.sf.scuba.smartcards.APDUWrapper, int, int, boolean):byte[]");
}
public byte[] sendGetChallenge() throws CardServiceException {
byte[] sendGetChallenge;
synchronized (this) {
sendGetChallenge = sendGetChallenge(null);
}
return sendGetChallenge;
}
public byte[] sendGetChallenge(APDUWrapper aPDUWrapper) throws CardServiceException {
byte[] data;
synchronized (this) {
data = transmit(aPDUWrapper, new CommandAPDU(0, -124, 0, 0, 8)).getData();
}
return data;
}
public byte[] sendInternalAuthenticate(APDUWrapper aPDUWrapper, byte[] bArr) throws CardServiceException {
byte[] data;
synchronized (this) {
if (bArr != null) {
if (bArr.length == 8) {
data = transmit(aPDUWrapper, new CommandAPDU(0, -120, 0, 0, bArr, 256)).getData();
}
}
throw new IllegalArgumentException("rndIFD wrong length");
}
return data;
}
public byte[] sendMutualAuth(byte[] bArr, byte[] bArr2, byte[] bArr3, SecretKey secretKey, SecretKey secretKey2) throws CardServiceException {
byte[] doFinal;
byte[] bArr4 = bArr2;
synchronized (this) {
if (bArr != null) {
try {
if (bArr.length == 8) {
if (bArr4 == null || bArr4.length != 8) {
bArr4 = new byte[8];
}
if (bArr3 == null || bArr3.length != 16) {
throw new IllegalArgumentException("kIFD wrong length");
}
if (secretKey == null) {
throw new IllegalArgumentException("kEnc == null");
}
if (secretKey2 == null) {
throw new IllegalArgumentException("kMac == null");
}
Cipher cipher = this.cipher;
IvParameterSpec ivParameterSpec = ZERO_IV_PARAM_SPEC;
cipher.init(1, secretKey, ivParameterSpec);
byte[] bArr5 = new byte[32];
System.arraycopy(bArr, 0, bArr5, 0, 8);
System.arraycopy(bArr4, 0, bArr5, 8, 8);
System.arraycopy(bArr3, 0, bArr5, 16, 16);
byte[] doFinal2 = this.cipher.doFinal(bArr5);
if (doFinal2.length != 32) {
StringBuilder sb = new StringBuilder("Cryptogram wrong length ");
sb.append(doFinal2.length);
throw new IllegalStateException(sb.toString());
}
this.mac.init(secretKey2);
byte[] doFinal3 = this.mac.doFinal(Util.pad(doFinal2, 8));
if (doFinal3.length != 8) {
throw new IllegalStateException("MAC wrong length");
}
byte[] bArr6 = new byte[40];
System.arraycopy(doFinal2, 0, bArr6, 0, 32);
System.arraycopy(doFinal3, 0, bArr6, 32, 8);
ResponseAPDU transmit = transmit(new CommandAPDU(0, -126, 0, 0, bArr6, 40));
if (transmit == null) {
throw new CardServiceException("Mutual authentication failed, received null response APDU");
}
byte[] bytes = transmit.getBytes();
short sw = (short) transmit.getSW();
if (bytes == null) {
throw new CardServiceException("Mutual authentication failed, received empty data in response APDU", sw);
}
if (sw != -28672) {
ResponseAPDU transmit2 = transmit(new CommandAPDU(0, -126, 0, 0, bArr6, 0));
bytes = transmit2.getBytes();
sw = (short) transmit2.getSW();
}
if (bytes.length != 42) {
StringBuilder sb2 = new StringBuilder("Mutual authentication failed: expected length: 40 + 2, actual length: ");
sb2.append(bytes.length);
throw new CardServiceException(sb2.toString(), sw);
}
this.cipher.init(2, secretKey, ivParameterSpec);
doFinal = this.cipher.doFinal(bytes, 0, bytes.length - 10);
if (doFinal.length != 32) {
StringBuilder sb3 = new StringBuilder("Cryptogram wrong length ");
sb3.append(doFinal.length);
throw new IllegalStateException(sb3.toString());
}
}
} catch (GeneralSecurityException e) {
throw new CardServiceException(e.toString());
}
}
throw new IllegalArgumentException("rndIFD wrong length");
}
return doFinal;
}
public void sendMutualAuthenticate(APDUWrapper aPDUWrapper, byte[] bArr) throws CardServiceException {
synchronized (this) {
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(0, -126, 0, 0, bArr)).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending External Authenticate failed.", sw);
}
}
}
public void sendMSEKAT(APDUWrapper aPDUWrapper, byte[] bArr, byte[] bArr2) throws CardServiceException {
synchronized (this) {
byte[] bArr3 = new byte[bArr.length + (bArr2 != null ? bArr2.length : 0)];
System.arraycopy(bArr, 0, bArr3, 0, bArr.length);
if (bArr2 != null) {
System.arraycopy(bArr2, 0, bArr3, bArr.length, bArr2.length);
}
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(0, 34, 65, CipherSuite.TLS_DH_anon_WITH_AES_128_GCM_SHA256, bArr3)).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending MSE KAT failed", sw);
}
}
}
public void sendMSESetDST(APDUWrapper aPDUWrapper, byte[] bArr) throws CardServiceException {
synchronized (this) {
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(0, 34, 129, CipherSuite.TLS_RSA_PSK_WITH_AES_128_CBC_SHA256, bArr)).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending MSE Set DST failed", sw);
}
}
}
public void sendMSESetATExtAuth(APDUWrapper aPDUWrapper, byte[] bArr) throws CardServiceException {
synchronized (this) {
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(0, 34, 129, CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256, bArr)).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending MSE AT failed", sw);
}
}
}
/* JADX WARN: Removed duplicated region for block: B:11:0x0093 A[Catch: all -> 0x009b, TRY_ENTER, TryCatch #0 {, blocks: (B:19:0x0003, B:22:0x000c, B:24:0x0032, B:25:0x0046, B:11:0x0093, B:12:0x009a, B:16:0x0088, B:28:0x003d, B:3:0x005c), top: B:18:0x0003, inners: #1 }] */
/* JADX WARN: Removed duplicated region for block: B:16:0x0088 A[Catch: all -> 0x009b, TRY_LEAVE, TryCatch #0 {, blocks: (B:19:0x0003, B:22:0x000c, B:24:0x0032, B:25:0x0046, B:11:0x0093, B:12:0x009a, B:16:0x0088, B:28:0x003d, B:3:0x005c), top: B:18:0x0003, inners: #1 }] */
/* JADX WARN: Removed duplicated region for block: B:5:0x0086 */
/* JADX WARN: Removed duplicated region for block: B:8:0x0091 A[DONT_GENERATE] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void sendMSESetATIntAuth(net.sf.scuba.smartcards.APDUWrapper r10, java.lang.String r11, java.math.BigInteger r12) throws net.sf.scuba.smartcards.CardServiceException {
/*
r9 = this;
monitor-enter(r9)
if (r12 == 0) goto L5c
java.math.BigInteger r0 = java.math.BigInteger.ZERO // Catch: java.lang.Throwable -> L9b
int r0 = r12.compareTo(r0) // Catch: java.lang.Throwable -> L9b
if (r0 >= 0) goto Lc
goto L5c
Lc:
java.util.logging.Logger r0 = org.jmrtd.PassportApduService.LOGGER // Catch: java.lang.Throwable -> L9b
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L9b
java.lang.String r2 = "DEBUG: explicit case, keyId == "
r1.<init>(r2) // Catch: java.lang.Throwable -> L9b
r1.append(r12) // Catch: java.lang.Throwable -> L9b
java.lang.String r1 = r1.toString() // Catch: java.lang.Throwable -> L9b
r0.info(r1) // Catch: java.lang.Throwable -> L9b
byte[] r11 = r9.toOIDBytes(r11) // Catch: java.lang.Throwable -> L9b
byte[] r12 = org.jmrtd.Util.i2os(r12) // Catch: java.lang.Throwable -> L9b
r0 = -124(0xffffffffffffff84, float:NaN)
byte[] r12 = org.jmrtd.Util.wrapDO(r0, r12) // Catch: java.lang.Throwable -> L9b
java.io.ByteArrayOutputStream r0 = new java.io.ByteArrayOutputStream // Catch: java.lang.Throwable -> L9b
r0.<init>() // Catch: java.lang.Throwable -> L9b
r0.write(r11) // Catch: java.io.IOException -> L3c java.lang.Throwable -> L9b
r0.write(r12) // Catch: java.io.IOException -> L3c java.lang.Throwable -> L9b
r0.close() // Catch: java.io.IOException -> L3c java.lang.Throwable -> L9b
goto L46
L3c:
r11 = move-exception
java.util.logging.Logger r12 = org.jmrtd.PassportApduService.LOGGER // Catch: java.lang.Throwable -> L9b
java.util.logging.Level r1 = java.util.logging.Level.WARNING // Catch: java.lang.Throwable -> L9b
java.lang.String r2 = "Exception"
r12.log(r1, r2, r11) // Catch: java.lang.Throwable -> L9b
L46:
net.sf.scuba.smartcards.CommandAPDU r11 = new net.sf.scuba.smartcards.CommandAPDU // Catch: java.lang.Throwable -> L9b
r4 = 0
r5 = 34
r6 = 65
r7 = 164(0xa4, float:2.3E-43)
byte[] r8 = r0.toByteArray() // Catch: java.lang.Throwable -> L9b
r3 = r11
r3.<init>(r4, r5, r6, r7, r8) // Catch: java.lang.Throwable -> L9b
net.sf.scuba.smartcards.ResponseAPDU r10 = r9.transmit(r10, r11) // Catch: java.lang.Throwable -> L9b
goto L84
L5c:
java.util.logging.Logger r0 = org.jmrtd.PassportApduService.LOGGER // Catch: java.lang.Throwable -> L9b
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L9b
java.lang.String r2 = "DEBUG: implicit case, keyId == "
r1.<init>(r2) // Catch: java.lang.Throwable -> L9b
r1.append(r12) // Catch: java.lang.Throwable -> L9b
java.lang.String r12 = r1.toString() // Catch: java.lang.Throwable -> L9b
r0.info(r12) // Catch: java.lang.Throwable -> L9b
net.sf.scuba.smartcards.CommandAPDU r12 = new net.sf.scuba.smartcards.CommandAPDU // Catch: java.lang.Throwable -> L9b
r2 = 0
r3 = 34
r4 = 65
r5 = 164(0xa4, float:2.3E-43)
byte[] r6 = r9.toOIDBytes(r11) // Catch: java.lang.Throwable -> L9b
r1 = r12
r1.<init>(r2, r3, r4, r5, r6) // Catch: java.lang.Throwable -> L9b
net.sf.scuba.smartcards.ResponseAPDU r10 = r9.transmit(r10, r12) // Catch: java.lang.Throwable -> L9b
L84:
if (r10 != 0) goto L88
r10 = -1
goto L8d
L88:
int r10 = r10.getSW() // Catch: java.lang.Throwable -> L9b
short r10 = (short) r10
L8d:
r11 = -28672(0xffffffffffff9000, float:NaN)
if (r10 != r11) goto L93
monitor-exit(r9)
return
L93:
net.sf.scuba.smartcards.CardServiceException r11 = new net.sf.scuba.smartcards.CardServiceException // Catch: java.lang.Throwable -> L9b
java.lang.String r12 = "Sending MSE AT failed"
r11.<init>(r12, r10) // Catch: java.lang.Throwable -> L9b
throw r11 // Catch: java.lang.Throwable -> L9b
L9b:
r10 = move-exception
monitor-exit(r9)
throw r10
*/
throw new UnsupportedOperationException("Method not decompiled: org.jmrtd.PassportApduService.sendMSESetATIntAuth(net.sf.scuba.smartcards.APDUWrapper, java.lang.String, java.math.BigInteger):void");
}
public void sendMSESetATMutualAuth(APDUWrapper aPDUWrapper, String str, int i, byte[] bArr) throws CardServiceException {
synchronized (this) {
if (str == null) {
throw new IllegalArgumentException("OID cannot be null");
}
byte[] oIDBytes = toOIDBytes(str);
if (i != 1 && i != 2 && i != 3 && i != 4) {
StringBuilder sb = new StringBuilder("Unsupported key type reference (MRZ, CAN, etc), found ");
sb.append(i);
throw new IllegalArgumentException(sb.toString());
}
byte[] wrapDO = Util.wrapDO(ISOFileInfo.FILE_IDENTIFIER, new byte[]{(byte) i});
if (bArr != null) {
bArr = Util.wrapDO((byte) -124, bArr);
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
byteArrayOutputStream.write(oIDBytes);
byteArrayOutputStream.write(wrapDO);
if (bArr != null) {
byteArrayOutputStream.write(bArr);
}
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(0, 34, CipherSuite.TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256, CipherSuite.TLS_DH_DSS_WITH_AES_128_GCM_SHA256, byteArrayOutputStream.toByteArray())).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending MSE AT failed", sw);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Error while copying data", (Throwable) e);
throw new IllegalStateException("Error while copying data");
}
}
}
private byte[] toOIDBytes(String str) {
try {
TLVInputStream tLVInputStream = new TLVInputStream(new ByteArrayInputStream(new ASN1ObjectIdentifier(str).getEncoded()));
tLVInputStream.b();
tLVInputStream.c();
byte[] d = tLVInputStream.d();
tLVInputStream.close();
return Util.wrapDO(Byte.MIN_VALUE, d);
} catch (IOException e) {
Logger logger = LOGGER;
Level level = Level.WARNING;
StringBuilder sb = new StringBuilder("Unexpected exception interpreting OID \"");
sb.append(str);
sb.append("\"");
logger.log(level, sb.toString(), (Throwable) e);
StringBuilder sb2 = new StringBuilder("Illegal OID: \"");
sb2.append(str);
sb2.append("\" (");
sb2.append(e.getMessage());
sb2.append(")");
throw new IllegalArgumentException(sb2.toString());
}
}
public byte[] sendGeneralAuthenticate(APDUWrapper aPDUWrapper, byte[] bArr, boolean z) throws CardServiceException {
byte[] unwrapDO;
synchronized (this) {
ResponseAPDU transmit = transmit(aPDUWrapper, new CommandAPDU(z ? 0 : 16, -122, 0, 0, Util.wrapDO((byte) 124, bArr), 256));
short sw = (short) transmit.getSW();
if (sw != -28672) {
throw new CardServiceException("Sending general authenticate failed", sw);
}
unwrapDO = Util.unwrapDO((byte) 124, transmit.getData());
}
return unwrapDO;
}
public void sendPSOExtendedLengthMode(APDUWrapper aPDUWrapper, byte[] bArr, byte[] bArr2) throws CardServiceException {
synchronized (this) {
byte[] bArr3 = new byte[bArr.length + bArr2.length];
System.arraycopy(bArr, 0, bArr3, 0, bArr.length);
System.arraycopy(bArr2, 0, bArr3, bArr.length, bArr2.length);
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(0, 42, 0, CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, bArr3)).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending PSO failed", sw);
}
}
}
public void sendPSOChainMode(APDUWrapper aPDUWrapper, byte[] bArr, byte[] bArr2) throws CardServiceException {
int i;
int i2;
synchronized (this) {
int length = bArr.length + bArr2.length;
byte[] bArr3 = new byte[length];
System.arraycopy(bArr, 0, bArr3, 0, bArr.length);
System.arraycopy(bArr2, 0, bArr3, bArr.length, bArr2.length);
if (length > 223) {
int i3 = length / 223;
if (i3 * 223 < length) {
i3++;
}
int i4 = 0;
for (int i5 = 0; i5 < i3 - 1; i5++) {
short sw = (short) transmit(aPDUWrapper, new CommandAPDU(16, 42, 0, CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, bArr3, i4, length)).getSW();
if (sw != -28672) {
throw new CardServiceException("Sending PSO failed", sw);
}
length -= 223;
i4 += 223;
}
i = length;
i2 = i4;
} else {
i = length;
i2 = 0;
}
short sw2 = (short) transmit(aPDUWrapper, new CommandAPDU(0, 42, 0, CipherSuite.TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256, bArr3, i2, i)).getSW();
if (sw2 != -28672) {
throw new CardServiceException("Sending PSO failed", sw2);
}
}
}
public void addPlainTextAPDUListener(APDUListener aPDUListener) {
Collection<APDUListener> collection = this.plainTextAPDUListeners;
if (collection != null) {
collection.add(aPDUListener);
}
}
public void removePlainTextAPDUListener(APDUListener aPDUListener) {
Collection<APDUListener> collection = this.plainTextAPDUListeners;
if (collection != null) {
collection.remove(aPDUListener);
}
}
protected void notifyExchangedPlainTextAPDU(int i, CommandAPDU commandAPDU, ResponseAPDU responseAPDU) {
Collection<APDUListener> collection = this.plainTextAPDUListeners;
if (collection == null || collection.size() <= 0) {
return;
}
APDUEvent aPDUEvent = new APDUEvent(this, "PLAINTEXT", i, commandAPDU, responseAPDU);
Iterator<APDUListener> it = this.plainTextAPDUListeners.iterator();
while (it.hasNext()) {
it.next().exchangedAPDU(aPDUEvent);
}
}
private static void checkStatusWordAfterFileOperation(CommandAPDU commandAPDU, ResponseAPDU responseAPDU) throws CardServiceException {
short sw = (short) responseAPDU.getSW();
StringBuilder sb = new StringBuilder("CAPDU = ");
sb.append(ghS.c(commandAPDU.getBytes()));
sb.append(", RAPDU = ");
sb.append(ghS.c(responseAPDU.getBytes()));
String obj = sb.toString();
if (sw != -28672) {
if (sw != 27010) {
if (sw == 27266) {
throw new CardServiceException("File not found, ".concat(String.valueOf(obj)), sw);
}
if (sw != 27013 && sw != 27014) {
throw new CardServiceException("Error occured, ".concat(String.valueOf(obj)), sw);
}
}
throw new CardServiceException("Access to file denied, ".concat(String.valueOf(obj)), sw);
}
}
public void setService(CardService cardService) {
this.service = cardService;
}
@Override // net.sf.scuba.smartcards.CardService
public byte[] getATR() {
return this.atr;
}
}