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

Browser-compatible version #1195

Open
lsd-cat opened this issue Jun 23, 2024 · 5 comments
Open

Browser-compatible version #1195

lsd-cat opened this issue Jun 23, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@lsd-cat
Copy link

lsd-cat commented Jun 23, 2024

Description
I need to use a minimal subset of Sigstore function, only for validation, inside a browser extension. While there are polyfills and stuff like browserify, I did not have much success with them, and I think that when doing delicate crypto I should not rely on automatic fillings.

I would like to work on achieving this, and could use some guidance and insights on the possible issues and, if there is interest, how to structure things in order to have them integrated here.

So far, I have started porting the core package, and these are my ideal steps on which I have experimented a bit:

  1. Swapping Buffer for the both node and browser native Uint8Array
  2. Porting the crypto to the Web Crypto API
  3. Build using vite
  4. Port the tests to something vite-compatible

I think that overall, having a verifying only minimal implementation should not be a very long job.

@lsd-cat lsd-cat added the enhancement New feature or request label Jun 23, 2024
@lsd-cat
Copy link
Author

lsd-cat commented Jun 23, 2024

Sample porting of core to Uint8Array only here: lsd-cat@934a73a

image

@lsd-cat
Copy link
Author

lsd-cat commented Jun 23, 2024

I have worked both on points 2 and 3, also porting the already existing tests to vitest as possible.

At the moment, the Sigstore core module successfully builds with vite. Also, almost all tests are passing, with the exception of some verify cases returning false instead of true that I will investigate soon.

The modified crypto.ts contains the crypto logic using the Web Crypto API. It's not perfect, and it probably cannot ever natively supports all algorithms that are currently supported by Sigstore, however most standard cases (P-256, P-384, P-521 - SHA-256, SHA-384, SHA-512) are either already covered or should be doable.

image

@lsd-cat
Copy link
Author

lsd-cat commented Jun 24, 2024

I am having a hard time verifying signatures :/ somehow the verify() from the Web Crypto API seems to always fail, there might be an issue in the input format, but I would expect it to throw an exception instead.

I am testing with the publickey, data, and signature from

describe('when the signature is valid', () => {

And indeed it successfully verifies in python, and of course in the original Node native code, but not using crypto.subtle. I am attaching the test scripts for reference.

test.js.txt
test.py.txt

Edit: this is the answer:

The main problem is that both codes use different signature formats:
sign_payload() in the Python code generates an ECDSA signature in ASN.1/DER format. The WebCrypto API on the other hand can only handle the IEEE P1363 format.

@lsd-cat
Copy link
Author

lsd-cat commented Jun 24, 2024

Fixed that, now all tests are passing using vitest and using browser-only native methods :D

Does not mean it's fully compatible, but it's a good start!

image

@lsd-cat
Copy link
Author

lsd-cat commented Jun 24, 2024

Next step would be to port the verify package, and my understanding is that it depends on:

  • core -> we have it!
  • bundle -> if protobuf bindings works, then should be trivial
  • tuf -> depends on local files or external requests: it needs to be decided how to handle those
  • rekor-types -> should be trivial
  • protobuf-specs -> just need to find out if the currently built files work in browsers out of the box

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

No branches or pull requests

1 participant