diff options
author | Matthew Miller <matthew@millerti.me> | 2022-08-07 11:16:30 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2022-08-07 11:16:36 -0700 |
commit | ed5f914afe0dd2f8e8f65a4fa454ed2749e54373 (patch) | |
tree | fc6dc786af9cbba2d1b65cbf9fbee4ca06636605 /packages/server/src | |
parent | 3a673b2cf940133ed8d3a68e80a95f198b1e6f9e (diff) |
Make error output more useful
Diffstat (limited to 'packages/server/src')
-rw-r--r-- | packages/server/src/metadata/verifyAttestationWithMetadata.ts | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/packages/server/src/metadata/verifyAttestationWithMetadata.ts b/packages/server/src/metadata/verifyAttestationWithMetadata.ts index 9def501..753e667 100644 --- a/packages/server/src/metadata/verifyAttestationWithMetadata.ts +++ b/packages/server/src/metadata/verifyAttestationWithMetadata.ts @@ -65,9 +65,22 @@ export async function verifyAttestationWithMetadata( // Make sure the public key is one of the allowed algorithms if (!foundMatch) { - const debugAlgs = Array.from(keypairCOSEAlgs).join(', '); + const debugMDSAlgs = Array.from(keypairCOSEAlgs); + // Construct some useful error output about the public key + const debugPubKeyAlgInfo: COSEInfo = { + kty: publicKeyCOSEInfo.kty, + alg: publicKeyCOSEInfo.alg, + }; + // Don't output a bunch of bytes for `crv` when the public key is an RSA key + if (publicKeyCOSEInfo.kty !== COSEKTY.RSA) { + debugPubKeyAlgInfo.crv = publicKeyCOSEInfo.crv; + } + + const strPubKeyAlg = JSON.stringify(debugPubKeyAlgInfo); + const strMDSAlgs = JSON.stringify(debugMDSAlgs); + throw new Error( - `Public key algorithm ${publicKeyCOSEInfo} did not match any metadata algorithms [${debugAlgs}]`, + `Public key algorithm ${strPubKeyAlg} did not match any metadata algorithms [${strMDSAlgs}]`, ); } |