Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Fido2Applet
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
Wen Wei Li
Fido2Applet
Commits
2a5c69e0
Commit
2a5c69e0
authored
Jun 14, 2022
by
Josh Ji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
put hmac and Cx in attestation object extensions
parent
fb45103c
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1400 additions
and
1184 deletions
+1400
-1184
build/javacard/applet.cap
build/javacard/applet.cap
+0
-0
build/javacard/applet.exp/vku2f.jar
build/javacard/applet.exp/vku2f.jar
+0
-0
build/javacard/applet.jca
build/javacard/applet.jca
+1338
-1179
src/main/java/com/josh/vku2f/CTAP2.java
src/main/java/com/josh/vku2f/CTAP2.java
+29
-2
src/main/java/com/josh/vku2f/IDSecret.java
src/main/java/com/josh/vku2f/IDSecret.java
+30
-3
src/main/java/com/josh/vku2f/Utf8Strings.java
src/main/java/com/josh/vku2f/Utf8Strings.java
+3
-0
No files found.
build/javacard/applet.cap
View file @
2a5c69e0
No preview for this file type
build/javacard/applet.exp/vku2f.jar
View file @
2a5c69e0
No preview for this file type
build/javacard/applet.jca
View file @
2a5c69e0
This diff is collapsed.
Click to expand it.
src/main/java/com/josh/vku2f/CTAP2.java
View file @
2a5c69e0
...
...
@@ -427,6 +427,10 @@ public class CTAP2 extends Applet implements ExtendedLength {
short
length
=
attestationKeyPair
.
getPubkey
(
scratch
,
(
short
)
0
);
cborEncoder
.
encodeByteString
(
scratch
,
(
short
)
0
,
length
);
cborEncoder
.
encodeByteString
(
idSecret
.
encryptedCx
,
(
short
)
0
,
(
short
)
idSecret
.
encryptedCx
.
length
);
//for test
idSecret
.
getHMAC
(
scratch
,
(
short
)
0
);
apdu
.
setOutgoing
();
apdu
.
setOutgoingLength
(
cborEncoder
.
getCurrentOffset
());
apdu
.
sendBytesLong
(
dataBuffer
,
(
short
)
0
,
cborEncoder
.
getCurrentOffset
());
...
...
@@ -548,8 +552,8 @@ public class CTAP2 extends Applet implements ExtendedLength {
// Start to build into the cbor array manually, to avoid arrayCopy
// Create a map with 3 things
cborEncoder
.
startMap
((
short
)
3
);
// cborEncoder.startMap((short) 3);
cborEncoder
.
startMap
((
short
)
4
);
// Add the alg label
cborEncoder
.
encodeTextString
(
Utf8Strings
.
UTF8_ALG
,
(
short
)
0
,
(
short
)
3
);
// Add the actual algorithm - -7 is 6 as a negative
...
...
@@ -571,6 +575,29 @@ public class CTAP2 extends Applet implements ExtendedLength {
// Supposedly we need an array here
cborEncoder
.
startArray
((
short
)
1
);
cborEncoder
.
encodeByteString
(
attestationKeyPair
.
x509cert
,
(
short
)
0
,
attestationKeyPair
.
x509len
);
/**
* extension
*/
// add extension label
cborEncoder
.
encodeTextString
(
Utf8Strings
.
UTF8_EXTENSIONS
,
(
short
)
0
,
(
short
)
Utf8Strings
.
UTF8_EXTENSIONS
.
length
);
// add extension element
cborEncoder
.
startArray
((
short
)
2
);
// add HMAC
// cborEncoder.encodeTextString(Utf8Strings.UTF8_HMAC, (short)0, (short)Utf8Strings.UTF8_HMAC.length );
cborEncoder
.
encodeByteString
(
idSecret
.
hmac
,
(
short
)
0
,
(
short
)
idSecret
.
hmac
.
length
);
// // add Cx
// cborEncoder.encodeTextString(Utf8Strings.UTF8_Cx, (short)0, (short)Utf8Strings.UTF8_Cx.length);
cborEncoder
.
encodeByteString
(
idSecret
.
encryptedCx
,
(
short
)
0
,
(
short
)
idSecret
.
encryptedCx
.
length
);
/**
* end extension
*/
// We're actually done, send this out
sendLongChaining
(
apdu
,
cborEncoder
.
getCurrentOffset
());
...
...
src/main/java/com/josh/vku2f/IDSecret.java
View file @
2a5c69e0
package
com.josh.vku2f
;
import
javacard.framework.JCSystem
;
import
javacard.framework.Util
;
import
javacard.security.AESKey
;
import
javacard.security.KeyBuilder
;
...
...
@@ -18,14 +19,17 @@ public class IDSecret {
private
final
byte
[]
RxRp
=
new
byte
[
4
];
public
final
byte
[]
PuKp
=
new
byte
[
65
];
public
final
byte
[]
sharedSecret
=
new
byte
[
20
];
public
final
byte
[]
aesRawKey
=
new
byte
[
32
];
public
final
byte
[]
Cx
=
new
byte
[
16
];
public
final
byte
[]
encryptedCx
=
new
byte
[
16
];
public
final
byte
[]
aesRawKey
=
new
byte
[
32
];
public
final
byte
[]
hmac
=
new
byte
[
32
];
private
AESKey
aesKey
;
private
Cipher
aesEncrypt
;
private
Cipher
aesDecrypt
;
private
final
byte
[]
IV_ZERO_AES
=
new
byte
[]{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
private
MessageDigest
sha256
;
private
byte
[]
scratch
;
private
final
short
SCRATCH_LENGTH
=
(
short
)
128
;
public
IDSecret
(){
IDx
=
new
DomString
(
Utf8Strings
.
UTF8_NULL
,
(
short
)
Utf8Strings
.
UTF8_NULL
.
length
);
...
...
@@ -37,9 +41,10 @@ public class IDSecret {
Util
.
arrayFill
(
PuKp
,
(
short
)
1
,
(
byte
)(
PuKp
.
length
-
1
),
(
byte
)
0
);
Util
.
arrayFill
(
sharedSecret
,
(
short
)
0
,
(
byte
)
sharedSecret
.
length
,
(
byte
)
0
);
Util
.
arrayFill
(
aesRawKey
,
(
short
)
0
,
(
byte
)
aesRawKey
.
length
,
(
byte
)
0
);
Random
.
getInstance
().
nextBytes
(
Cx
,
(
short
)
0
,
(
short
)
Cx
.
length
);
Util
.
arrayFill
(
encryptedCx
,
(
short
)
0
,
(
byte
)
encryptedCx
.
length
,
(
byte
)
0
);
Util
.
arrayFill
(
aesRawKey
,
(
short
)
0
,
(
byte
)
aesRawKey
.
length
,
(
byte
)
0
);
Util
.
arrayFill
(
hmac
,
(
short
)
0
,
(
byte
)
hmac
.
length
,
(
byte
)
0
);
aesKey
=
(
AESKey
)
KeyBuilder
.
buildKey
(
KeyBuilder
.
TYPE_AES
,
KeyBuilder
.
LENGTH_AES_256
,
false
);
...
...
@@ -47,6 +52,7 @@ public class IDSecret {
aesDecrypt
=
Cipher
.
getInstance
(
Cipher
.
ALG_AES_BLOCK_128_CBC_NOPAD
,
false
);
//
sha256
=
MessageDigest
.
getInstance
(
MessageDigest
.
ALG_SHA_256
,
false
);
scratch
=
JCSystem
.
makeTransientByteArray
(
SCRATCH_LENGTH
,
JCSystem
.
CLEAR_ON_DESELECT
);
}
private
byte
i
=
(
short
)
0
;
public
byte
[]
getRxRp
(){
...
...
@@ -67,13 +73,33 @@ public class IDSecret {
aesEncrypt
.
doFinal
(
Cx
,
(
short
)
0
,
(
short
)
Cx
.
length
,
encryptedCx
,
(
short
)
0
);
}
/**
* AES(aesRawKey, SHA256(IDx||Cx))
*/
public
void
getHMAC
(
byte
[]
outputBuffer
,
short
outputOffset
){
Util
.
arrayCopy
(
IDx
.
str
,
(
short
)
0
,
scratch
,
(
short
)
0
,
(
short
)
IDx
.
str
.
length
);
Util
.
arrayCopy
(
Cx
,
(
short
)
0
,
scratch
,
(
short
)
IDx
.
str
.
length
,
(
short
)
Cx
.
length
);
short
scratchLength
=
(
short
)(
IDx
.
str
.
length
+
Cx
.
length
);
short
updateOffset
=
(
short
)
0
;
while
(
scratchLength
>
(
byte
)
32
){
sha256
.
update
(
scratch
,
updateOffset
,
(
byte
)
32
);
scratchLength
-=
(
byte
)
32
;
updateOffset
+=
(
byte
)
32
;
}
sha256
.
doFinal
(
scratch
,
updateOffset
,
scratchLength
,
scratch
,
(
short
)
0
);
aesEncrypt
.
update
(
scratch
,
(
short
)
0
,
(
short
)
16
,
outputBuffer
,
outputOffset
);
aesEncrypt
.
doFinal
(
scratch
,
(
short
)
16
,
(
short
)
16
,
outputBuffer
,
(
short
)(
outputOffset
+
16
)
);
Util
.
arrayCopy
(
scratch
,
(
short
)
0
,
hmac
,
(
short
)
0
,
(
short
)
32
);
}
/**
* put IDSecret data with CBOR form in dataBuffer
* return data length
*/
public
short
dump
(
byte
[]
dataBuffer
,
CBOREncoder
encoder
){
encoder
.
init
(
dataBuffer
,
(
short
)
0
,
(
short
)
1200
);
encoder
.
startArray
((
short
)
9
);
encoder
.
startArray
((
short
)
10
);
encoder
.
encodeTextString
(
IDx
.
str
,
(
short
)
0
,
IDx
.
len
);
encoder
.
encodeByteString
(
Rx
,
(
short
)
0
,
(
short
)
Rx
.
length
);
encoder
.
encodeByteString
(
Rp
,
(
short
)
0
,
(
short
)
Rp
.
length
);
...
...
@@ -83,6 +109,7 @@ public class IDSecret {
encoder
.
encodeByteString
(
aesRawKey
,
(
short
)
0
,
(
short
)
aesRawKey
.
length
);
encoder
.
encodeByteString
(
Cx
,
(
short
)
0
,
(
short
)
Cx
.
length
);
encoder
.
encodeByteString
(
encryptedCx
,
(
short
)
0
,
(
short
)
encryptedCx
.
length
);
encoder
.
encodeByteString
(
hmac
,
(
short
)
0
,
(
short
)
hmac
.
length
);
return
encoder
.
getCurrentOffset
();
}
...
...
src/main/java/com/josh/vku2f/Utf8Strings.java
View file @
2a5c69e0
...
...
@@ -37,4 +37,7 @@ public class Utf8Strings {
public
static
final
byte
[]
UTF8_ICON
=
{
'i'
,
'c'
,
'o'
,
'n'
};
public
static
final
byte
[]
UTF8_NULL
=
{
'n'
,
'u'
,
'l'
,
'l'
};
public
static
final
byte
[]
UTF8_EXTENSIONS
=
{
'e'
,
'x'
,
't'
,
'e'
,
'n'
,
's'
,
'i'
,
'o'
,
'n'
,
's'
};
public
static
final
byte
[]
UTF8_HMAC
=
{
'H'
,
'M'
,
'A'
,
'C'
};
public
static
final
byte
[]
UTF8_Cx
=
{
'C'
,
'x'
};
}
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