grafana / xk6-webcrypto

WIP implementation of the WebCrypto specification for k6
GNU Affero General Public License v3.0
7 stars 4 forks source link

[1/3] Implement the `generateKey` operation with support for HMAC algorithm #35

Closed oleiade closed 1 year ago

oleiade commented 1 year ago

What is this?

This Pull Request adds support for the HMAC algorithm to the subtle.crypto.generateKey operation.

Our plan moving forward is to go breadth first, and implement as much of the WebCrypto API's surface, and only later to add support for more algorithms. As a result this PR comes in with the intention to support the ability to implement the sign and verify operations to the module.

Just like with encrypt and decrypt, the sign and verify operations test suite rely on the ability to import and export a key of a support algorithm. As a result to support sign and verify with a scope reduced to the HMAC algorithm, we need to implement importKey and exportKey first.

As generateKey laid a good base foundation for implementing importKey and exportKey efficiently with AES support, I decided to once again start with that operation for HMAC.

Because this is the first algorithm past the AES family currently supported, it led to a few valuable redesigns of how the SubtleCrypto.GenerateKey method works at the moment:

  1. It led for instance to introducing the KeyGenerator interface to be able to transparently generate a key, without having to resort to much preparation in the SubtleCrypto.GenerateKey method itself, making us even closer to the specification.
  2. It also led to introduce constructors for the params object, so that we can handle the whole logic of converting goja objects in Go structs in an easier and more "hidden away" manner.