Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PassportApplet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Josh Ji
PassportApplet
Commits
b27a470a
Commit
b27a470a
authored
Sep 16, 2021
by
Josh Ji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some scripts
parent
e3667545
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
51 deletions
+138
-51
.idea/vcs.xml
.idea/vcs.xml
+6
-0
build.gradle
build.gradle
+45
-0
src/main/java/josh/passport/BERTLVScanner.java
src/main/java/josh/passport/BERTLVScanner.java
+1
-1
src/main/java/josh/passport/PassportApplet.java
src/main/java/josh/passport/PassportApplet.java
+67
-31
src/main/java/josh/passport/PassportCrypto.java
src/main/java/josh/passport/PassportCrypto.java
+19
-19
No files found.
.idea/vcs.xml
0 → 100644
View file @
b27a470a
<?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
build.gradle
View file @
b27a470a
...
...
@@ -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
src/main/java/josh/passport/BERTLVScanner.java
View file @
b27a470a
...
...
@@ -55,7 +55,7 @@ public class BERTLVScanner {
isPrimitive
=
true
;
break
;
case
0x20
:
isPrimitive
=
false
;
isPrimitive
=
false
;
// is constructed
break
;
}
switch
(
b
&
0x1F
)
{
...
...
src/main/java/josh/passport/PassportApplet.java
View file @
b27a470a
This diff is collapsed.
Click to expand it.
src/main/java/josh/passport/PassportCrypto.java
View file @
b27a470a
...
...
@@ -272,10 +272,10 @@ public class PassportCrypto {
// }
public
short
unwrapCommandAPDU
(
byte
[]
ssc
,
APDU
apdu
)
{
byte
[]
buf
=
apdu
.
getBuffer
();
byte
[]
buf
fer
=
apdu
.
getBuffer
();
short
apdu_p
=
(
short
)
(
ISO7816
.
OFFSET_CDATA
&
0xff
);
short
start_p
=
apdu_p
;
short
lc
=
(
short
)
(
buf
[
ISO7816
.
OFFSET_LC
]
&
0xff
);
short
lc
=
(
short
)
(
buf
fer
[
ISO7816
.
OFFSET_LC
]
&
0xff
);
short
le
=
0
;
short
do87DataLen
=
0
;
short
do87Data_p
=
0
;
...
...
@@ -287,11 +287,11 @@ public class PassportCrypto {
incrementSSC
(
ssc
);
if
(
buf
[
apdu_p
]
==
(
byte
)
0x87
)
{
if
(
buf
fer
[
apdu_p
]
==
(
byte
)
0x87
)
{
apdu_p
++;
// do87
if
((
buf
[
apdu_p
]
&
0xff
)
>
0x80
)
{
do87LenBytes
=
(
short
)
(
buf
[
apdu_p
]
&
0x7f
);
if
((
buf
fer
[
apdu_p
]
&
0xff
)
>
0x80
)
{
do87LenBytes
=
(
short
)
(
buf
fer
[
apdu_p
]
&
0x7f
);
apdu_p
++;
}
else
{
do87LenBytes
=
1
;
...
...
@@ -300,11 +300,11 @@ public class PassportCrypto {
ISOException
.
throwIt
(
PassportApplet
.
SW_INTERNAL_ERROR
);
}
for
(
short
i
=
0
;
i
<
do87LenBytes
;
i
++)
{
do87DataLen
+=
(
short
)
((
buf
[(
short
)(
apdu_p
+
i
)]
&
0xff
)
<<
(
short
)
((
do87LenBytes
-
1
-
i
)
*
8
));
do87DataLen
+=
(
short
)
((
buf
fer
[(
short
)(
apdu_p
+
i
)]
&
0xff
)
<<
(
short
)
((
do87LenBytes
-
1
-
i
)
*
8
));
}
apdu_p
+=
do87LenBytes
;
if
(
buf
[
apdu_p
]
!=
1
)
{
if
(
buf
fer
[
apdu_p
]
!=
1
)
{
ISOException
.
throwIt
(
PassportApplet
.
SW_INTERNAL_ERROR
);
}
// store pointer to data and defer decrypt to after mac check (do8e)
...
...
@@ -313,31 +313,31 @@ public class PassportCrypto {
do87DataLen
--;
// compensate for 0x01 marker
}
if
(
buf
[
apdu_p
]
==
(
byte
)
0x97
)
{
if
(
buf
fer
[
apdu_p
]
==
(
byte
)
0x97
)
{
// do97
if
(
buf
[++
apdu_p
]
!=
1
)
if
(
buf
fer
[++
apdu_p
]
!=
1
)
ISOException
.
throwIt
(
PassportApplet
.
SW_INTERNAL_ERROR
);
le
=
(
short
)
(
buf
[++
apdu_p
]
&
0xff
);
le
=
(
short
)
(
buf
fer
[++
apdu_p
]
&
0xff
);
apdu_p
++;
}
// do8e
if
(
buf
[
apdu_p
]
!=
(
byte
)
0x8e
)
{
if
(
buf
fer
[
apdu_p
]
!=
(
byte
)
0x8e
)
{
ISOException
.
throwIt
(
PassportApplet
.
SW_INTERNAL_ERROR
);
}
if
(
buf
[++
apdu_p
]
!=
8
)
{
if
(
buf
fer
[++
apdu_p
]
!=
8
)
{
ISOException
.
throwIt
(
ISO7816
.
SW_DATA_INVALID
);
}
// verify mac
initMac
(
Signature
.
MODE_VERIFY
);
updateMac
(
ssc
,
(
short
)
0
,
(
short
)
ssc
.
length
);
updateMac
(
buf
,
(
short
)
0
,
hdrLen
);
updateMac
(
buf
fer
,
(
short
)
0
,
hdrLen
);
updateMac
(
PAD_DATA
,
(
short
)
0
,
hdrPadLen
);
if
(!
verifyMacFinal
(
buf
,
if
(!
verifyMacFinal
(
buf
fer
,
start_p
,
(
short
)
(
apdu_p
-
1
-
start_p
),
buf
,
buf
fer
,
(
short
)(
apdu_p
+
1
)))
{
ISOException
.
throwIt
(
ISO7816
.
SW_CONDITIONS_NOT_SATISFIED
);
}
...
...
@@ -347,16 +347,16 @@ public class PassportCrypto {
if
(
do87DataLen
!=
0
)
{
// decrypt data, and leave room for lc
decryptInit
();
plaintextLength
=
decryptFinal
(
buf
,
plaintextLength
=
decryptFinal
(
buf
fer
,
do87Data_p
,
do87DataLen
,
buf
,
buf
fer
,
(
short
)
(
hdrLen
+
1
));
plaintextLc
=
PassportUtil
.
calcLcFromPaddedData
(
buf
,
plaintextLc
=
PassportUtil
.
calcLcFromPaddedData
(
buf
fer
,
(
short
)
(
hdrLen
+
1
),
do87DataLen
);
buf
[
hdrLen
]
=
(
byte
)
(
plaintextLc
&
0xff
);
buf
fer
[
hdrLen
]
=
(
byte
)
(
plaintextLc
&
0xff
);
}
return
le
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment