Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
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
b6c256c9
Commit
b6c256c9
authored
Jul 02, 2023
by
Wen Wei Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
the registration code is not in right code section
parent
6568c9ff
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
55 deletions
+55
-55
src/main/java/com/josh/vku2f/CTAP2.java
src/main/java/com/josh/vku2f/CTAP2.java
+55
-55
No files found.
src/main/java/com/josh/vku2f/CTAP2.java
View file @
b6c256c9
...
@@ -416,66 +416,29 @@ public class CTAP2 extends Applet implements ExtendedLength {
...
@@ -416,66 +416,29 @@ public class CTAP2 extends Applet implements ExtendedLength {
* @param dataLength
* @param dataLength
*/
*/
private
void
create_new_cert
(
APDU
apdu
,
short
dataLength
){
private
void
create_new_cert
(
APDU
apdu
,
short
dataLength
){
}
/**
* for alternative framework purpose
* <p>
* input: IDx , PuKp in CBOR form
* return: PuKx, encryptedCx in CBOR form
*/
private
void
getPuKxCx
(
APDU
apdu
,
short
dataLength
)
{
cborDecoder
.
init
(
dataBuffer
,
(
short
)
1
,
dataLength
);
try
{
cborDecoder
.
readMajorType
(
CBORBase
.
TYPE_ARRAY
);
// read IDx
short
length
=
cborDecoder
.
readTextString
(
scratch
,
(
short
)
0
);
idSecret
.
IDx
=
new
DomString
(
scratch
,
length
);
// read PuKp
cborDecoder
.
readByteString
(
scratch
,
(
short
)
0
);
Util
.
arrayCopy
(
scratch
,
(
short
)
8
,
idSecret
.
PuKp
,
(
short
)
1
,
(
short
)
64
);
}
catch
(
UserException
e
)
{
returnError
(
apdu
,
e
.
getReason
());
}
KeyAgreement
keyAgreement
=
KeyAgreement
.
getInstance
(
KeyAgreement
.
ALG_EC_SVDP_DH
,
false
);
keyAgreement
.
init
(
attestationKeyPair
.
getPrivate
());
keyAgreement
.
generateSecret
(
idSecret
.
PuKp
,
(
short
)
0
,
(
short
)
65
,
idSecret
.
sharedSecret
,
(
short
)
0
);
idSecret
.
initAesKey
();
idSecret
.
encryptCx
();
// make output cbor
cborEncoder
.
init
(
dataBuffer
,
(
short
)
0
,
(
short
)
1200
);
cborEncoder
.
startArray
((
short
)
2
);
// put PuKx
short
length
=
attestationKeyPair
.
getPubkey
(
scratch
,
(
short
)
0
);
cborEncoder
.
encodeByteString
(
scratch
,
(
short
)
0
,
length
);
// init hkdf
// init hkdf
/*
/*
* TODO
* TODO
* This IV should be extracted from APDU
* This IV should be extracted from APDU
* when card initialization with IDP.
* when card initialization with IDP.
* Do not use the '0' bytes array as IV.
* Do not use the '0' bytes array as IV.
*
*
*/
*/
byte
[]
iv
=
new
byte
[
32
];
byte
[]
iv
=
new
byte
[
32
];
this
.
hkdf
=
new
HKDF
(
idSecret
.
getRxRp
(),
iv
);
this
.
hkdf
=
new
HKDF
(
idSecret
.
getRxRp
(),
iv
);
/*
/*
* TODO
* TODO
* Need to modify this to generate a HMAC with HKDF Chain
* Need to modify this to generate a HMAC with HKDF Chain
* modify the original algorithm to new process
* modify the original algorithm to new process
* Process:
* Process:
* Generate a random number as Nonce
* Generate a random number as Nonce
* calculate H(H(IV) || H(Nonce))
* calculate H(H(IV) || H(Nonce))
* calculate HMAC(output_key, H(IV||Nonce))
* calculate HMAC(output_key, H(IV||Nonce))
* Returns
* Returns
* H(H(IV) || H(Nonce))
* H(H(IV) || H(Nonce))
* Nonce
* Nonce
* HMAC(output_key, H(IV||Nonce))
* HMAC(output_key, H(IV||Nonce))
* Iteration(Counter)
* Iteration(Counter)
*/
*/
byte
[]
nonce
=
new
byte
[
32
];
byte
[]
nonce
=
new
byte
[
32
];
byte
[]
prk
=
new
byte
[
32
];
byte
[]
prk
=
new
byte
[
32
];
...
@@ -502,7 +465,7 @@ public class CTAP2 extends Applet implements ExtendedLength {
...
@@ -502,7 +465,7 @@ public class CTAP2 extends Applet implements ExtendedLength {
hkdf
.
getNextOutputKey
(
new
byte
[
32
],
(
short
)
32
,
output_key
,
(
short
)
32
);
hkdf
.
getNextOutputKey
(
new
byte
[
32
],
(
short
)
32
,
output_key
,
(
short
)
32
);
// using output key to calculate HMAC
// using output key to calculate HMAC
HMAC
hmac
=
new
HMAC
(
output_key
);
HMAC
hmac
=
new
HMAC
(
output_key
);
hmac
.
update
(
ret2
,
(
short
)
0
,
(
short
)
length
);
hmac
.
update
(
ret2
,
(
short
)
0
,
(
short
)
32
);
hmac
.
doFinal
(
ret2
,
(
short
)
32
);
hmac
.
doFinal
(
ret2
,
(
short
)
32
);
// ret2
// ret2
// | ----- 32 byte is H(H(IV)||H(Nonce)) ----- | ----- 32 byte HMAC -----|
// | ----- 32 byte is H(H(IV)||H(Nonce)) ----- | ----- 32 byte HMAC -----|
...
@@ -515,6 +478,43 @@ public class CTAP2 extends Applet implements ExtendedLength {
...
@@ -515,6 +478,43 @@ public class CTAP2 extends Applet implements ExtendedLength {
// HMAC(output_key, H(IV||Nonce)) 32 bytes ret2[32:64]
// HMAC(output_key, H(IV||Nonce)) 32 bytes ret2[32:64]
// Iteration(Counter) 4 bytes integer : counter
// Iteration(Counter) 4 bytes integer : counter
// total return length : 100 bytes
// total return length : 100 bytes
}
/**
* for alternative framework purpose
* <p>
* input: IDx , PuKp in CBOR form
* return: PuKx, encryptedCx in CBOR form
*/
private
void
getPuKxCx
(
APDU
apdu
,
short
dataLength
)
{
cborDecoder
.
init
(
dataBuffer
,
(
short
)
1
,
dataLength
);
try
{
cborDecoder
.
readMajorType
(
CBORBase
.
TYPE_ARRAY
);
// read IDx
short
length
=
cborDecoder
.
readTextString
(
scratch
,
(
short
)
0
);
idSecret
.
IDx
=
new
DomString
(
scratch
,
length
);
// read PuKp
cborDecoder
.
readByteString
(
scratch
,
(
short
)
0
);
Util
.
arrayCopy
(
scratch
,
(
short
)
8
,
idSecret
.
PuKp
,
(
short
)
1
,
(
short
)
64
);
}
catch
(
UserException
e
)
{
returnError
(
apdu
,
e
.
getReason
());
}
KeyAgreement
keyAgreement
=
KeyAgreement
.
getInstance
(
KeyAgreement
.
ALG_EC_SVDP_DH
,
false
);
keyAgreement
.
init
(
attestationKeyPair
.
getPrivate
());
keyAgreement
.
generateSecret
(
idSecret
.
PuKp
,
(
short
)
0
,
(
short
)
65
,
idSecret
.
sharedSecret
,
(
short
)
0
);
idSecret
.
initAesKey
();
idSecret
.
encryptCx
();
// make output cbor
cborEncoder
.
init
(
dataBuffer
,
(
short
)
0
,
(
short
)
1200
);
cborEncoder
.
startArray
((
short
)
2
);
// put PuKx
short
length
=
attestationKeyPair
.
getPubkey
(
scratch
,
(
short
)
0
);
cborEncoder
.
encodeByteString
(
scratch
,
(
short
)
0
,
length
);
cborEncoder
.
encodeByteString
(
idSecret
.
encryptedCx
,
(
short
)
0
,
(
short
)
idSecret
.
encryptedCx
.
length
);
cborEncoder
.
encodeByteString
(
idSecret
.
encryptedCx
,
(
short
)
0
,
(
short
)
idSecret
.
encryptedCx
.
length
);
// generate HMAC
// generate HMAC
...
...
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