microsoft / security-utilities

Security utilities for key generation, string redaction, etc.
MIT License
24 stars 9 forks source link

Api updates to unify all key creation through a common helper. #92

Closed michaelcfanning closed 1 week ago

michaelcfanning commented 1 week ago

Previously, we appear to have shipped 1.6.0 without including the ComputeCommonAnnotatedHash API. This API as authored required a CASK secret to operate but this is clearly not sufficient: providers that update their logic for producing derived keys and hashes may need to operate against a legacy secret that drives the signing process. To add this capability, however, we need to update the API to accept all the data (i.e., the CASK reserved platform + provider data) that is possible to encoded in a key. This was not previously required because we flowed that data from the CASK signing secret. This has the added benefit of allowing users to decide whether to flow data from a primary CASK key or to override it.

While making this change, I decided to take the plunge and simply make our key generation logic use a Base62 checksum. One positive result is that every test key (by CASK specification) will generate a legal key (because these specified patterns will never produce a special character that's illegal in CASK). We already had to use Base62 for the derived and hashed key cases; it is not a stretch to do so for primary keys. I've left back-up logic in the API for handling the case where the checksum is expressed as decoded base64 bytes. That means this library will continue to handle any historical key minters that are producing the older checksums.

This work also revealed a couple of small bugs related to the new hashing API: we needed to update our common regex to understand the H reserved key kind denoting this type and I fixed an issue in the literal generation logic that was not properly encoding D for derived keys and H for hashed.