Skip to content

Commit 392f4b6

Browse files
committed
Fix initialization order
1 parent 3871640 commit 392f4b6

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/main/java/us/q3q/fido2/FIDO2Applet.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,16 +1440,18 @@ private short checkIfPubKeyBlockSupported(APDU apdu, byte[] buffer, short readId
14401440
sendErrorByte(apdu, FIDOConstants.CTAP2_ERR_MISSING_PARAMETER);
14411441
}
14421442

1443-
byte algIntType = buffer[readIdx++];
1444-
if (algIntType == 0x26) { // ES256...
1443+
short algIntType = ub(buffer[readIdx++]);
1444+
if (algIntType == 0x0026) { // ES256...
14451445
transientStorage.setStoredVars((short) 1, (byte) 1);
1446-
} else if (algIntType == 0x38 || algIntType == 0x18) {
1446+
} else if (algIntType == 0x0038 || algIntType == 0x0018) {
14471447
readIdx++;
1448-
} else if (algIntType == 0x39 || algIntType == 0x19) {
1448+
} else if (algIntType == 0x0039 || algIntType == 0x0019) {
14491449
readIdx += 2;
1450-
} else if (!(algIntType >= (byte)0x20 && algIntType <= (byte)0x37)
1451-
&& !(ub(algIntType) >= 0x00 && algIntType <= (byte) 0x17)) {
1452-
sendErrorByte(apdu, FIDOConstants.CTAP2_ERR_CBOR_UNEXPECTED_TYPE);
1450+
} else {
1451+
if (!(algIntType >= 0x0020 && algIntType <= 0x0037)
1452+
&& !(algIntType >= 0x0000 && algIntType <= 0x0017)) {
1453+
sendErrorByte(apdu, FIDOConstants.CTAP2_ERR_CBOR_UNEXPECTED_TYPE);
1454+
}
14531455
}
14541456

14551457
// Skip "type" val
@@ -6607,7 +6609,7 @@ private void handleClientPinGetRetries(APDU apdu) {
66076609
private void forceInitKeyAgreementKey() {
66086610
P256Constants.setCurve((ECKey) authenticatorKeyAgreementKey.getPrivate());
66096611
P256Constants.setCurve((ECKey) authenticatorKeyAgreementKey.getPublic());
6610-
if (!makeGoodKeyPair(authenticatorKeyAgreementKey, bufferMem, (short) 0)) {
6612+
if (!makeGoodKeyPair(authenticatorKeyAgreementKey, bufferMem, (short) (bufferMem.length - 128))) {
66116613
throwException(ISO7816.SW_DATA_INVALID);
66126614
}
66136615
keyAgreement.init(authenticatorKeyAgreementKey.getPrivate());
@@ -7133,8 +7135,6 @@ private void initTransientStorage(APDU apdu) {
71337135
}
71347136
permissionsRpId = getTempOrFlashByteBuffer((short)(RP_HASH_LEN + 1), permRpIdInRam);
71357137

7136-
initKeyAgreementKeyIfNecessary();
7137-
71387138
if (availableMem >= (short)(targetMemAmount + 32)) {
71397139
targetMemAmount += 32;
71407140
sharedSecretAESKey = getTransientAESKey();
@@ -7154,6 +7154,8 @@ private void initTransientStorage(APDU apdu) {
71547154
}
71557155
bufferMem = getTempOrFlashByteBuffer(BUFFER_MEM_SIZE, requestBufferInRam);
71567156

7157+
initKeyAgreementKeyIfNecessary();
7158+
71577159
// Five things are truly random and persist until we hard-FIDO2-reset the authenticator:
71587160
// - The wrapping key (generated at first use of the applet)
71597161
// - the salt we use for deriving keys from PINs

0 commit comments

Comments
 (0)