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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for the subtle.encrypt feature #24

Closed
wants to merge 22 commits into from

Conversation

oleiade
Copy link
Member

@oleiade oleiade commented Nov 23, 2022

馃毇 This is a work in progress, and is based on #9 馃毇

Checklist

  • Fulfill description
  • Ensure provided iv are taken into account
  • Add Web Platform Tests
  • Merge only when the feature/generate_key is merged

@oleiade oleiade marked this pull request as draft November 23, 2022 09:38
@oleiade oleiade force-pushed the feature/encrypt branch 2 times, most recently from 5084bd4 to 0d3e32a Compare November 28, 2022 14:29
In order to ease integration into k6 (which is compatible with  Go
up to version 1.18), we set our target Go version to 1.18.
This commit is an a almost verbatim (curated) copy of the Web Platform
Tests for the WebCryptoAPI:
https://github.com/web-platform-tests/wpt/tree/master/WebCryptoAPI

We've also (imported and) adapted some of their helpers  to suit our
needs and play well in the context of the goja runtime.
This commit splits the Algorithm Normalization algorithm away from the
algorithm.go file into a dedicated normalization.go file. The reasoning
behind that was that we do all sorts of normalization and validation in
the context of the project, and it would be more thematic and easier to
maintain/comprehend if those functions and types lived in a dedicated
file.
The SubtleCrypto.generateKey() operation allows user to produce
cryptographic random keys of various types. They return a CryptoKey object
which holds, besides key-related information, a private handle on the
key's bytes.

As described in the specification:
https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-generateKey

And as demonstrated here:
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
It is a common need in the WebCrypto implementation, beyond simply
generating keys, to be able to easily produce the intersection of two
sets, or two check if a slice contains a given value. This commit
introduces two helpers to do just that.
In order to decide on which usages a generated CryptoKey is valid for,
we needed a way to quickly find out the allowed usages for each key
format. Inside a given algorithm kind (Rsa, ECDSA, ECDH, etc), different
cipher, and whether the key is public or private, allow for different
usages too.

This commit introduces a method holding a table to obtain this
information from an algorithm name, and crypto key type.
This is a cleanup commit getting rid of miscelaneous changes that are
not justified anymore.
Those functions are test helpers imported from the Web Platform Tests
project: https://github.com/web-platform-tests/wpt/tree/master/WebCryptoAPI.
We adapted them to suit our needs and play well in the context of the
goja runtime.
They heavily depend on the importKey operation, thus, this is blocked
by the importKey operation.
@oleiade oleiade closed this Mar 20, 2023
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

Successfully merging this pull request may close these issues.

None yet

1 participant