Skip to content

Commit c8b61d9

Browse files
committed
Documentation and structure touch-ups
1 parent 59e2db4 commit c8b61d9

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ private void makeCredential(APDU apdu, short lc, byte[] buffer) {
918918
// ... but it might not match the user ID we're requesting...
919919
if (userIdLen == residentKeys[i].getUserIdLength()) {
920920
// DECRYPT the encrypted user ID we stored for this RK, so we can compare
921-
AESKey key = getAESKeyForRK(i, residentKeys[i].getCredProtectLevel());
921+
AESKey key = getAESKeyForExistingRK(i);
922922
residentKeys[i].unpackUserID(key, symmetricUnwrapper, scratchUserIdBuffer, scratchUserIdOffset);
923923

924924
if (Util.arrayCompare(
@@ -988,7 +988,7 @@ private void makeCredential(APDU apdu, short lc, byte[] buffer) {
988988
effectiveCredBlobLen = 0;
989989
}
990990

991-
AESKey key = getAESKeyForRK(targetRKSlot, effectiveCPLevel);
991+
AESKey key = getAESKeyForCreatingWithCredProtectLevel(effectiveCPLevel);
992992
residentKeys[targetRKSlot] = new ResidentKeyData(
993993
random, key, symmetricWrapper,
994994
counter,
@@ -2443,7 +2443,7 @@ private void getAssertion(final APDU apdu, final short lc, final byte[] buffer,
24432443
outputBuffer[outputIdx++] = 0x07; // map key: largeBlobKey
24442444
outputIdx = encodeIntLenTo(outputBuffer, outputIdx, (byte) 32, true);
24452445
residentKeys[rkMatch].emitLargeBlobKey(
2446-
getAESKeyForRK(rkMatch, residentKeys[rkMatch].getCredProtectLevel()), symmetricWrapper,
2446+
getAESKeyForExistingRK(rkMatch), symmetricWrapper,
24472447
outputBuffer, outputIdx);
24482448
outputIdx += 32;
24492449
}
@@ -5260,13 +5260,25 @@ private void handleEnumerateRPs(APDU apdu, short startOffset) {
52605260
sendNoCopy(apdu, writeOffset);
52615261
}
52625262

5263-
private AESKey getAESKeyForRK(short rkIndex, byte credProt) {
5263+
/**
5264+
* Gets the AES key to use when creating a new resident key
5265+
*
5266+
* @param credProt The cred protect level of the new key
5267+
* @return An AES key object to pass to ResidentKeyData methods
5268+
*/
5269+
private AESKey getAESKeyForCreatingWithCredProtectLevel(byte credProt) {
52645270
final boolean highSec = !LOW_SECURITY_MAXIMUM_COMPLIANCE && (!USE_LOW_SECURITY_FOR_SOME_RKS || credProt > 2);
52655271
return highSec ? highSecurityWrappingKey : lowSecurityWrappingKey;
52665272
}
52675273

5274+
/**
5275+
* Gets the AES key used for the data associated with the given RK
5276+
*
5277+
* @param rkIndex Index of the RK in the store
5278+
* @return An AES key object to pass to ResidentKeyData methods
5279+
*/
52685280
private AESKey getAESKeyForExistingRK(short rkIndex) {
5269-
return getAESKeyForRK(rkIndex, residentKeys[rkIndex].getCredProtectLevel());
5281+
return getAESKeyForCreatingWithCredProtectLevel(residentKeys[rkIndex].getCredProtectLevel());
52705282
}
52715283

52725284
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void setUser(AESKey key, Cipher wrapper, byte[] userIdBuffer, short userI
156156
wrapper.init(key, Cipher.MODE_ENCRYPT, userIV, (short) 0, (short) userIV.length);
157157
wrapper.doFinal(userIdBuffer, userIdOffset, MAX_USER_ID_LENGTH,
158158
userId, (short) 0);
159-
userIdBuffer[userIdLength + 1] = 0x00;
159+
userIdBuffer[(short)(userIdLength + 1)] = 0x00;
160160
this.userIdLength = userIdLength;
161161
}
162162

0 commit comments

Comments
 (0)