Commit b27a470a authored by Josh Ji's avatar Josh Ji

add some scripts

parent e3667545
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -54,4 +54,49 @@ javacard{ ...@@ -54,4 +54,49 @@ javacard{
} }
} }
} }
scripts {
script {
name 'select'
apdu '00a4040007a0000002471001'
}
script{
name 'testing'
apdu '00ff000000'
}
script {
name 'putData_MRZ'
apdu '00da00621d401bc009413132333435363738c106393930393232c206323231323331'
}
script{
name 'create_file_DG1'
apdu '00e00000066304005a010100'
}
task {
name 'put_data_mrz'
scripts 'select','putData_MRZ'
}
task {
name 'create_file'
scripts 'select','create_file_DG1'
}
script{
name 'select_file_DG1'
apdu '00a4000002010100'
}
script{
name 'update_binary_DG1'
apdu '00000000'
}
task {
name 'update_binary_DG1'
scripts 'select','select_file_DG1','update_binary_DG1'
}
task {
name 'select_file_dg1'
scripts 'select', 'select_file_DG1'
}
}
} }
\ No newline at end of file
...@@ -55,7 +55,7 @@ public class BERTLVScanner { ...@@ -55,7 +55,7 @@ public class BERTLVScanner {
isPrimitive = true; isPrimitive = true;
break; break;
case 0x20: case 0x20:
isPrimitive = false; isPrimitive = false; // is constructed
break; break;
} }
switch (b & 0x1F) { switch (b & 0x1F) {
......
...@@ -272,10 +272,10 @@ public class PassportCrypto { ...@@ -272,10 +272,10 @@ public class PassportCrypto {
// } // }
public short unwrapCommandAPDU(byte[] ssc, APDU apdu) { public short unwrapCommandAPDU(byte[] ssc, APDU apdu) {
byte[] buf = apdu.getBuffer(); byte[] buffer = apdu.getBuffer();
short apdu_p = (short) (ISO7816.OFFSET_CDATA & 0xff); short apdu_p = (short) (ISO7816.OFFSET_CDATA & 0xff);
short start_p = apdu_p; short start_p = apdu_p;
short lc = (short) (buf[ISO7816.OFFSET_LC] & 0xff); short lc = (short) (buffer[ISO7816.OFFSET_LC] & 0xff);
short le = 0; short le = 0;
short do87DataLen = 0; short do87DataLen = 0;
short do87Data_p = 0; short do87Data_p = 0;
...@@ -287,11 +287,11 @@ public class PassportCrypto { ...@@ -287,11 +287,11 @@ public class PassportCrypto {
incrementSSC(ssc); incrementSSC(ssc);
if (buf[apdu_p] == (byte) 0x87) { if (buffer[apdu_p] == (byte) 0x87) {
apdu_p++; apdu_p++;
// do87 // do87
if ((buf[apdu_p] & 0xff) > 0x80) { if ((buffer[apdu_p] & 0xff) > 0x80) {
do87LenBytes = (short) (buf[apdu_p] & 0x7f); do87LenBytes = (short) (buffer[apdu_p] & 0x7f);
apdu_p++; apdu_p++;
} else { } else {
do87LenBytes = 1; do87LenBytes = 1;
...@@ -300,11 +300,11 @@ public class PassportCrypto { ...@@ -300,11 +300,11 @@ public class PassportCrypto {
ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR); ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR);
} }
for (short i = 0; i < do87LenBytes; i++) { for (short i = 0; i < do87LenBytes; i++) {
do87DataLen += (short) ((buf[(short)(apdu_p + i)] & 0xff) << (short) ((do87LenBytes - 1 - i) * 8)); do87DataLen += (short) ((buffer[(short)(apdu_p + i)] & 0xff) << (short) ((do87LenBytes - 1 - i) * 8));
} }
apdu_p += do87LenBytes; apdu_p += do87LenBytes;
if (buf[apdu_p] != 1) { if (buffer[apdu_p] != 1) {
ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR); ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR);
} }
// store pointer to data and defer decrypt to after mac check (do8e) // store pointer to data and defer decrypt to after mac check (do8e)
...@@ -313,31 +313,31 @@ public class PassportCrypto { ...@@ -313,31 +313,31 @@ public class PassportCrypto {
do87DataLen--; // compensate for 0x01 marker do87DataLen--; // compensate for 0x01 marker
} }
if (buf[apdu_p] == (byte) 0x97) { if (buffer[apdu_p] == (byte) 0x97) {
// do97 // do97
if (buf[++apdu_p] != 1) if (buffer[++apdu_p] != 1)
ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR); ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR);
le = (short) (buf[++apdu_p] & 0xff); le = (short) (buffer[++apdu_p] & 0xff);
apdu_p++; apdu_p++;
} }
// do8e // do8e
if (buf[apdu_p] != (byte) 0x8e) { if (buffer[apdu_p] != (byte) 0x8e) {
ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR); ISOException.throwIt(PassportApplet.SW_INTERNAL_ERROR);
} }
if (buf[++apdu_p] != 8) { if (buffer[++apdu_p] != 8) {
ISOException.throwIt(ISO7816.SW_DATA_INVALID); ISOException.throwIt(ISO7816.SW_DATA_INVALID);
} }
// verify mac // verify mac
initMac(Signature.MODE_VERIFY); initMac(Signature.MODE_VERIFY);
updateMac(ssc, (short)0, (short)ssc.length); updateMac(ssc, (short)0, (short)ssc.length);
updateMac(buf, (short)0, hdrLen); updateMac(buffer, (short)0, hdrLen);
updateMac(PAD_DATA, (short)0, hdrPadLen); updateMac(PAD_DATA, (short)0, hdrPadLen);
if (!verifyMacFinal(buf, if (!verifyMacFinal(buffer,
start_p, start_p,
(short) (apdu_p - 1 - start_p), (short) (apdu_p - 1 - start_p),
buf, buffer,
(short)(apdu_p + 1))) { (short)(apdu_p + 1))) {
ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED); ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
} }
...@@ -347,16 +347,16 @@ public class PassportCrypto { ...@@ -347,16 +347,16 @@ public class PassportCrypto {
if (do87DataLen != 0) { if (do87DataLen != 0) {
// decrypt data, and leave room for lc // decrypt data, and leave room for lc
decryptInit(); decryptInit();
plaintextLength = decryptFinal(buf, plaintextLength = decryptFinal(buffer,
do87Data_p, do87Data_p,
do87DataLen, do87DataLen,
buf, buffer,
(short) (hdrLen + 1)); (short) (hdrLen + 1));
plaintextLc = PassportUtil.calcLcFromPaddedData(buf, plaintextLc = PassportUtil.calcLcFromPaddedData(buffer,
(short) (hdrLen + 1), (short) (hdrLen + 1),
do87DataLen); do87DataLen);
buf[hdrLen] = (byte) (plaintextLc & 0xff); buffer[hdrLen] = (byte) (plaintextLc & 0xff);
} }
return le; return le;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment