Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] COSE Key Encoding is Invalid #697

Open
ben-krieger opened this issue Sep 23, 2024 · 0 comments
Open

[BUG] COSE Key Encoding is Invalid #697

ben-krieger opened this issue Sep 23, 2024 · 0 comments

Comments

@ben-krieger
Copy link
Member

Describe the bug
When encoding a COSE key, the key type is not set. From the COSE spec (https://datatracker.ietf.org/doc/html/rfc8152#section-7), the key type (label 1) is required:

The element "kty" is a required element in a COSE_Key map.

To Reproduce
Perform DI with COSE key encoding selected. In the SetCredentials message, see that the manufacturer public key's body decodes to:

{
  -1: 2,
  -2: h'604DB2D960A7956C9CEEDB86829305437AC50BF2AEE118FD49FD969674FDCF5ED09F64AC9414DF9CC7CCD7016BAC9F54',
  -3: h'0080F0C0E50F803702D0741ABD8248AD1255991CF2A5B92082E3E5578ADAD8D99BC82002FCF3E136EF5BEC21697BC23A69'
}

Expected behavior
COSE Key should have kty set. Since only EC2 keys are supported, this means:

{
  1: 2,
  -1: 2,
  -2: h'604DB2D960A7956C9CEEDB86829305437AC50BF2AEE118FD49FD969674FDCF5ED09F64AC9414DF9CC7CCD7016BAC9F54',
  -3: h'0080F0C0E50F803702D0741ABD8248AD1255991CF2A5B92082E3E5578ADAD8D99BC82002FCF3E136EF5BEC21697BC23A69'
}

Additional context
The code that needs to be fixed is here:

case COSEKEY: {
final ECPublicKey ec = (ECPublicKey) chain[0].getPublicKey();
final byte[] x = ec.getW().getAffineX().toByteArray();
final byte[] y = ec.getW().getAffineY().toByteArray();
final CoseKey coseKey = new CoseKey();
coseKey.setX(x);
coseKey.setY(y);
coseKey.setCurve(new AlgorithmFinder().getCoseKeyCurve(keyType));
ownerKey.setBody(AnyType.fromObject(coseKey));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant