DEV Community

jeffrey
jeffrey

Posted on

COSE key thumbprints need canonical members, not a hash of the serialized key

COSE key thumbprints need canonical members, not a hash of the serialized key

A key identifier is easy to add at the edge of a protocol and surprisingly difficult to define consistently. If two systems hash different encodings of the same public key, they create two identifiers for one credential. If they include optional metadata, a harmless key update can change the identifier and break trust. RFC 9679 defines a COSE Key Thumbprint to avoid those outcomes by specifying the key members that participate in the hash and the canonical encoding used to compute it.

The distinction between a key and its representation is central. A COSE key can contain optional fields such as a key identifier, algorithm hint, operations, or trusted issuer data. Those fields can help routing or policy, but they are not all part of the cryptographic identity. The thumbprint is calculated from the required members for the key type, not from whatever byte sequence happened to arrive over the network.

Canonical input prevents accidental aliases

The RFC defines required members for supported key types and a deterministic CBOR encoding for them. An elliptic-curve public key, for example, is identified by its key type, curve, x coordinate, and y coordinate. The producer sorts and encodes those members according to the specification. The recipient performs the same calculation and compares the result.

If one implementation preserves map ordering, integer encoding, or optional labels from its parser, the digest may differ even when the public key is the same. This is a correctness problem before it is a security problem. A verifier should use a tested library or follow the canonicalization algorithm exactly, then compare the full digest with a constant-time operation where that matters.

A thumbprint is an identity, not a trust decision

Matching a thumbprint proves that two systems identified the same structured key material. It does not prove that the key belongs to the expected person, workload, or issuer. A trust store must still authorize the key for the relevant purpose. A key identifier in a message can route the verifier to a candidate key, but the attacker-controlled identifier must not bypass signature validation.

The practical design is to store both the canonical thumbprint and the policy that grants trust. The policy should include the issuer or enrollment source, allowed algorithms, usage, owner, and expiration or review date. If a key is re-enrolled under a new trust path but retains the same public key, the thumbprint may be unchanged while the authorization decision changes. Do not let a stable identifier erase that policy history.

Migration needs collision and ambiguity tests

When adding thumbprint support, test keys with optional metadata, different map orderings, unsupported algorithms, duplicate members, and malformed coordinates. Confirm that a key with an unexpected type is rejected rather than hashed under a convenient fallback. Confirm that a key ID field is not silently substituted for the thumbprint.

Clients should also log the key type, algorithm, thumbprint prefix or full identifier, and the trust decision. Avoid logging private key material or unnecessary certificate subjects. A mismatch should produce a specific event, because it can indicate a parser difference, an enrollment error, or an attempt to substitute a key with a similar label.

Make the identifier useful to operators

A canonical key thumbprint gives support teams a stable way to correlate one public key across applications, registries, and device inventories. It can also support deduplication during certificate or credential migration. The value comes from a narrow definition: compute the same hash over the same required members, then apply an explicit authorization policy.

The question to ask during review is not whether a thumbprint is present. Ask which members were hashed, which library performed the canonical encoding, and how a future key algorithm will extend the rule. A thumbprint without that operational context becomes another opaque identifier that teams copy between systems but cannot safely rotate.

References

Top comments (0)