Skip to content

Commit 88d70a2

Browse files
committed
Thanks to United Access GmbH added support for oldest JCOP 2.4.1 and 2.4.2 cards
1 parent 7a8626c commit 88d70a2

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/com/mysmartlogon/gidsApplet/CRTKeyFile.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void importKey(byte[] buffer, short offset, short length) throws InvalidA
122122
// focused on A5 tag
123123
short innerPos = 0, innerLen = 0;
124124
short pos = 0, len = 0;
125-
// keytype is missing for symetric key
125+
// keytype is missing for symmetric key
126126
byte keytype = 1;
127127
byte keyref = 0;
128128
if (buffer[offset] != (byte) 0xA5) {
@@ -140,7 +140,7 @@ public void importKey(byte[] buffer, short offset, short length) throws InvalidA
140140
}
141141
keytype = buffer[(short) (pos+2)];
142142
} catch (NotFoundException e) {
143-
// optional tag: default = symetric key
143+
// optional tag: default = symmetric key
144144
} catch (InvalidArgumentsException e) {
145145
ISOException.throwIt(ISO7816.SW_DATA_INVALID);
146146
}
@@ -167,7 +167,7 @@ public void importKey(byte[] buffer, short offset, short length) throws InvalidA
167167

168168
pos += 1 + UtilTLV.getLengthFieldLength(buffer, (short)(pos+1));
169169
if (keytype == 1) {
170-
importSymetricKey(buffer, pos, len);
170+
importSymmetricKey(buffer, pos, len);
171171
} else if (keytype == 2) {
172172
importRsaKey(buffer, pos, len);
173173
} else {
@@ -247,11 +247,17 @@ private void importRsaKey(byte[] buffer, short offset, short length) throws Inva
247247
}
248248
len = UtilTLV.decodeLengthField(buffer, (short)(pos+1));
249249
pos += 1 + UtilTLV.getLengthFieldLength(buffer, (short)(pos+1));
250-
// the minidriver may prepend a 00 before (len = len+1) and the javacard don't like it => remove the 00
250+
// the minidriver may prepend a 00 before (len = len+1) and the javacards don't like it => remove the 00
251251
if ((len & 0x0F) == (byte) 1 && buffer[pos] == 0) {
252252
len -= 1;
253253
pos++;
254254
}
255+
// one byte too small?
256+
if ((len & 0x0F) == (byte) 0x0F) {
257+
len += 1;
258+
pos--;
259+
buffer[pos] = (byte) 0x00;
260+
}
255261
try {
256262
rsaPrKey.setP(buffer, pos, len);
257263
} catch(CryptoException e) {
@@ -271,6 +277,11 @@ private void importRsaKey(byte[] buffer, short offset, short length) throws Inva
271277
len -= 1;
272278
pos++;
273279
}
280+
if ((len & 0x0F) == (byte) 0x0F) {
281+
len += 1;
282+
pos--;
283+
buffer[pos] = (byte) 0x00;
284+
}
274285
rsaPrKey.setQ(buffer, pos, len);
275286
pos += len;
276287
// d mod p-1
@@ -279,10 +290,15 @@ private void importRsaKey(byte[] buffer, short offset, short length) throws Inva
279290
}
280291
len = UtilTLV.decodeLengthField(buffer, (short)(pos+1));
281292
pos += 1 + UtilTLV.getLengthFieldLength(buffer, (short)(pos+1));
282-
if ((len & 0x0F) == (byte) 1 && buffer[pos] == 0) {
293+
if (((len & 0x0F) == (byte) 0x01) && (buffer[pos] == 0)) {
283294
len -= 1;
284295
pos++;
285296
}
297+
if ((len & 0x0F) == (byte) 0x0F) {
298+
len += 1;
299+
pos--;
300+
buffer[pos] = (byte) 0x00;
301+
}
286302
rsaPrKey.setDP1(buffer, pos, len);
287303
pos += len;
288304
// d mod q-1
@@ -295,6 +311,11 @@ private void importRsaKey(byte[] buffer, short offset, short length) throws Inva
295311
len -= 1;
296312
pos++;
297313
}
314+
if ((len & 0x0F) == (byte) 0x0F) {
315+
len += 1;
316+
pos--;
317+
buffer[pos] = (byte) 0x00;
318+
}
298319
rsaPrKey.setDQ1(buffer, pos, len);
299320
pos += len;
300321
// q-1 mod p
@@ -307,6 +328,11 @@ private void importRsaKey(byte[] buffer, short offset, short length) throws Inva
307328
len -= 1;
308329
pos++;
309330
}
331+
if ((len & 0x0F) == (byte) 0x0F) {
332+
len += 1;
333+
pos--;
334+
buffer[pos] = (byte) 0x00;
335+
}
310336
rsaPrKey.setPQ(buffer, pos, len);
311337
pos += len;
312338

@@ -324,7 +350,7 @@ private void importRsaKey(byte[] buffer, short offset, short length) throws Inva
324350
}
325351
}
326352

327-
private void importSymetricKey(byte[] buffer, short offset, short length) {
353+
private void importSymmetricKey(byte[] buffer, short offset, short length) {
328354
clearContents();
329355
byte[] key = new byte[length];
330356
Util.arrayCopyNonAtomic(buffer, offset, key, (short) 0, length);

0 commit comments

Comments
 (0)