HaLo: Properly parse keySlotFlags and keySlotFailedAuthCtr in get_data_struct (#324)

This commit is contained in:
Michał Leszczyński
2024-06-17 15:43:39 -07:00
committed by GitHub
parent 30ddd10e44
commit afb12045ac
3 changed files with 20 additions and 9 deletions

View File

@@ -860,8 +860,8 @@ The `spec` value is expected to be formatted as:
Where the acceptable object types are:
* `publicKey` - the uncompressed public key corresponding to the particular key slot;
* `publicKeyAttest` - the public key's attest signature;
* `keySlotFlags` - status flags corresponding to the particular key slot;
* `keySlotFailedAuthCtr` - failed password authentication counter of the particular key slot;
* `keySlotFlags` - status flags corresponding to the particular key slot (returned as an object);
* `keySlotFailedAuthCtr` - failed password authentication counter of the particular key slot (returned as a number);
* `latchValue` - value of the latch (possible object IDs: 1, 2);
* `latchAttest` - attest signature of the latch;
* `graffiti` - value of the rewritable data slot (possible object IDs: 1);

View File

@@ -14,7 +14,7 @@ const EC = require("elliptic").ec;
const CMD = require('./cmdcodes').CMD_CODES;
const pbkdf2 = require('pbkdf2');
const crypto = require('crypto-browserify');
const {KEY_FLAGS} = require("./keyflags");
const {KEY_FLAGS, parseKeyFlags} = require("./keyflags");
const ec = new EC('secp256k1');
@@ -504,11 +504,7 @@ async function cmdGetKeyInfo(options, args) {
return {
keyState: {
isPasswordProtected: !!(keyFlags & KEY_FLAGS.KEYFLG_IS_PWD_PROTECTED),
hasMandatoryPassword: !!(keyFlags & KEY_FLAGS.KEYFLG_MANDATORY_PASSWORD),
rawSignCommandNotUsed: !!(keyFlags & KEY_FLAGS.KEYFLG_SIGN_NOT_USED),
isImported: !!(keyFlags & KEY_FLAGS.KEYFLG_IS_IMPORTED),
isExported: !!(keyFlags & KEY_FLAGS.KEYFLG_IS_EXPORTED),
...parseKeyFlags(keyFlags),
failedAuthCounter: failedAuthCtr
},
publicKey: publicKey.toString('hex'),
@@ -764,6 +760,11 @@ async function cmdGetDataStruct(options, args) {
} else {
value = {"error": 'unknown_' + msgCode.toString()};
}
} else if (item[0] === "keySlotFlags") {
let keyFlags = res.slice(1, len + 1)[0];
value = parseKeyFlags(keyFlags);
} else if (item[0] === "keySlotFailedAuthCtr") {
value = res.slice(1, len + 1)[0];
} else {
const encoding = item[0] !== "graffiti" ? "hex" : "utf-8";

View File

@@ -13,4 +13,14 @@ const KEY_FLAGS = {
KEYFLG_IS_EXPORTED: 0x20
}
module.exports = {KEY_FLAGS};
function parseKeyFlags(keyFlags) {
return {
isPasswordProtected: !!(keyFlags & KEY_FLAGS.KEYFLG_IS_PWD_PROTECTED),
hasMandatoryPassword: !!(keyFlags & KEY_FLAGS.KEYFLG_MANDATORY_PASSWORD),
rawSignCommandNotUsed: !!(keyFlags & KEY_FLAGS.KEYFLG_SIGN_NOT_USED),
isImported: !!(keyFlags & KEY_FLAGS.KEYFLG_IS_IMPORTED),
isExported: !!(keyFlags & KEY_FLAGS.KEYFLG_IS_EXPORTED)
};
}
module.exports = {KEY_FLAGS, parseKeyFlags};