-
Notifications
You must be signed in to change notification settings - Fork 348
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
Add ncrypto dependency, implement key handling operations #3463
Conversation
dc7c1a4
to
b1546c4
Compare
050b394
to
82287e0
Compare
The generated output of |
6492b8c
to
ac64627
Compare
71b1cb4
to
7f8727a
Compare
b231446
to
f1adaf1
Compare
f1adaf1
to
c32c8ba
Compare
2143423
to
71959bb
Compare
Amazing work as always @jasnell. There are some TS related comments that I'm not happy about, but we can fix it afterwards. No need to block progress! |
71959bb
to
13de810
Compare
While this is generally ready to go for workerd, the production project uses a different version of boringssl that will require some additional tweaks in ncrypto to get working. This PR will remain in draft until those are done. |
45074d7
to
56857fc
Compare
56857fc
to
186fa11
Compare
Does this unblock some of Line 250 in 186fa11
|
@vicb ... it adds implementations for the following:
With caveats, of course. Key generation of DSA and DH key pairs do not work, for instance, due to current limitations in boringssl. There will be several followup PRs soon with more implementation detail. |
@panva ... fyi ... just a heads up that this is landing. |
@jasnell thanks for the heads up. I think it's a move in the right direction for compatibility. That being said I'm switching jose fully to WebCryptoAPI with a new major and ESM-only as soon as 20.19.0 releases with unflagged require(esm). It will still support KeyObject as inputs (and will use KeyObject.prototype.toCryptoKey to crossover KeyObject to CryptoKey efficiently) and will also use If you don't support KeyObject.prototype.toCryptoKey yet I'd suggest getting that in. |
Yep, |
@panva could you expand how you will use that? FYI when using node compatibility with workerd, the return value could be different from an import. |
@vicb here are all three instances in the v6.x-wip state at the moment https://github.com/panva/jose/blob/151000e84b94551e7408f988e3d52f8ccf530a64/src/lib/asn1.ts#L253-L266 I am specifically not interested in using an import() here because of how bundlers tend to either error out or insert shitty polyfills when they detect node modules in non-node runtime targets. |
Thanks - I'll look more deeply next week. One thing that could be better for workers is that you have an adapter that could be implemented for different platforms. i.e. import type { X509Certificate } from "node:crypto";
interface CryptoAdapter {
X509Certificate: X509Certificate;
// ...
} You can have a default impl based on get For workers (Note that we do not polyfill |
@vicb how can i enable node-compat in this capnp definition here, that way I could easily test the impact of node compat on jose (which i've seen people struggle with when node compat is enabled for them in wrangler) I ask because when I add
That's certainly not expected just because a compat flag was added so I'm assuming I'm doing something wrong. Repro with
|
That should do. However the recommended way it to use Also note that when using wrangler, we add polyfills when the node compatibility is activated ( If you want to test with the polyfill, you would have to use For example, instead of invoking |
@vicb i get the same failure regardless of the compat flag version. the test works as expected without a node compact flag |
Yep, that's expected because they should be the same :) To debug that, it's probably easier to create a // worker.ts
export default {
async fetch(request, env, ctx) {
// call your test from here (i.e. run.ts)
await test();
return new Response('Hello World!');
},
}; Then you can Let me know if you need more info (feel free to email me at the address on my GH profile). |
…#3463) * Add ncrypto dependency * Use ncrypto for key derivation operations * Use ncrypto for spkac apis * Use ncrypto for prime generation/checks * Refinements to the node:crypto SecretKey impl * Begin working on createPrivateKey * Implement more of the private key details * Implement createPublicKey * Consolidate ncrypto::Buffer creation into utility * Handle additional code review nits * node:crypto asymmetric key jwk export * Implement JWK import/export for RSA, EC, OKP keys * Temporarily use ncrypto dev branch * Remove now obsolete todo comment * Support creating public key from PrivateKeyObject * Implement generateKey()/generateKeySync() for aes/hmac keys * Address review feedback * Argument validation for generateKeyPair * Implement more key pair generation * Additional keygen details * Fixups to support internal use of boringssl+fips * Temporarily use ncrypto dev branch * Add some additional comments/notes on crypto keys impl * Update ncrypto details in WORKSPACE
Still very much a work in progress.
This is gonna be a big one.