@@ -723,7 +723,7 @@ private void makeCredential(APDU apdu, short lc, byte[] buffer) {
723723 }
724724 continue ;
725725 case 0x07 : // options
726- readIdx = processOptionsMap (apdu , buffer , readIdx , lc , true );
726+ readIdx = processOptionsMap (apdu , buffer , readIdx , lc , true , true );
727727 continue ;
728728 case 0x08 : // pinAuth
729729 // Read past this, because we need the pinProtocol option first
@@ -1978,7 +1978,7 @@ private void getAssertion(final APDU apdu, final short lc, final byte[] buffer,
19781978
19791979 break ;
19801980 case 0x05 : // options
1981- readIdx = processOptionsMap (apdu , buffer , readIdx , lc , false );
1981+ readIdx = processOptionsMap (apdu , buffer , readIdx , lc , false , false );
19821982 break ;
19831983 case 0x06 : // pinAuth
19841984 pinAuthIdx = readIdx ;
@@ -2555,10 +2555,11 @@ private void defaultOptions() {
25552555 * @param readIdx Read index into request buffer
25562556 * @param lc Length of incoming request, as sent by the platform
25572557 * @param requireUP Disallow UP=false, and set UP=true afterwards if option omitted
2558+ * @param allowRK If false, error on the RK option (with any value)
25582559 *
25592560 * @return New read index after consuming the options map object
25602561 */
2561- private short processOptionsMap (APDU apdu , byte [] buffer , short readIdx , short lc , boolean requireUP ) {
2562+ private short processOptionsMap (APDU apdu , byte [] buffer , short readIdx , short lc , boolean requireUP , boolean allowRK ) {
25622563 short numOptions = getMapEntryCount (apdu , buffer [readIdx ++]);
25632564 if (readIdx >= lc ) {
25642565 sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_INVALID_CBOR );
@@ -2586,6 +2587,9 @@ private short processOptionsMap(APDU apdu, byte[] buffer, short readIdx, short l
25862587 } else {
25872588 sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_CBOR_UNEXPECTED_TYPE );
25882589 }
2590+ if (!allowRK ) {
2591+ sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_INVALID_OPTION );
2592+ }
25892593 } else {
25902594 short pOrVPos = ++readIdx ;
25912595
@@ -3254,9 +3258,6 @@ private short consumeMapAndGetID(APDU apdu, byte[] buffer, short readIdx, short
32543258 if (isType && foundType ) {
32553259 sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_INVALID_CBOR );
32563260 }
3257- /*if (keyLen == 4 && buffer[readIdx] == 'i' && buffer[(short)(readIdx+1)] == 'c'
3258- && buffer[(short)(readIdx+2)] == 'o' && buffer[(short)(readIdx+3)] == 'n') {
3259- }*/
32603261
32613262 readIdx += keyLen ;
32623263 if (readIdx >= lc ) {
@@ -3269,7 +3270,7 @@ private short consumeMapAndGetID(APDU apdu, byte[] buffer, short readIdx, short
32693270 }
32703271 short idPos = readIdx ;
32713272
3272- byte valLen = 0 ;
3273+ short valLen = 0 ;
32733274 if (valDef == 0x78 || valDef == 0x58 ) {
32743275 if (isId ) {
32753276 if (valDef == 0x78 && byteString ) {
@@ -3292,6 +3293,13 @@ private short consumeMapAndGetID(APDU apdu, byte[] buffer, short readIdx, short
32923293 if (readIdx >= lc ) {
32933294 sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_INVALID_CBOR );
32943295 }
3296+ } else if (valDef == 0x79 ) {
3297+ if (isId ) {
3298+ // Whoa nelly.
3299+ sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_CBOR_UNEXPECTED_TYPE );
3300+ }
3301+ valLen = Util .getShort (buffer , readIdx );
3302+ readIdx += 2 ;
32953303 } else if (valDef >= 0x60 && valDef < 0x78 ) {
32963304 if (isId && byteString ) {
32973305 sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_CBOR_UNEXPECTED_TYPE );
@@ -3316,7 +3324,7 @@ private short consumeMapAndGetID(APDU apdu, byte[] buffer, short readIdx, short
33163324
33173325 if (isId ) {
33183326 foundId = true ;
3319- transientStorage .setStoredVars (idPos , valLen );
3327+ transientStorage .setStoredVars (idPos , ( byte ) valLen );
33203328 }
33213329
33223330 if (!foundType && isType && checkTypePublicKey ) {
@@ -3326,7 +3334,7 @@ private short consumeMapAndGetID(APDU apdu, byte[] buffer, short readIdx, short
33263334 CannedCBOR .PUBLIC_KEY_TYPE , (short ) 0 , valLen ) == 0 ;
33273335 }
33283336
3329- readIdx += ub ( valLen ) ;
3337+ readIdx += valLen ;
33303338 if (readIdx >= lc ) {
33313339 sendErrorByte (apdu , FIDOConstants .CTAP2_ERR_INVALID_CBOR );
33323340 }
0 commit comments