-
Notifications
You must be signed in to change notification settings - Fork 361
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
feat(crypto): Initial support for SubtleCrypto #698
Conversation
Nice!!!
|
Super nice! Yeah, async needs to use |
@richarddavison Not in this case I think, spawn_exit is only for running background tasks. Here we want to asyncify a blocking task, so you have to use the tokio thread pool for that. Same as when we do file operations. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
This comment was marked as resolved.
This comment was marked as resolved.
I would create a class to wrap the vec at the very least so the user cant assume it is an array. Then we can start implementing the props the spec requires. |
Yes, create a Class for CryptoKey and CryptoKeyPair and keep hidden fields in rust only. Then expose only getters to what you need to provide as read only: #[rquickjs::class]
#[derive(rquickjs::JsLifetime)]
struct CryptoKey<'js>{
algorithm: Object<'js>,
usages: Array<'js>,
...
}
impl<'js> CryptoKey<'js>{
#[qjs(get)]
pub fn algorithm(&self) -> Object<'js> {
self.algorithm.clone()
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work so far! 🥇
This is great. Now we can probably add the CryptoTest from here https://github.com/web-platform-tests/wpt/tree/master |
Thank you. :) I'm always checking the test cases of wpt and looking for any unclear points in the implementation from the test cases. I'd like to incorporate it into the LLRT tests at some point. However, it is unclear whether it conforms to the latest WebCryptoAPI specifications. For example, the generateKey test does not pass any required algorithm parameters other than name, which causes the test to fail. https://github.com/web-platform-tests/wpt/blob/master/WebCryptoAPI/generateKey/successes.js EDIT: I've looked at other test cases, but they don't seem to be compatible with the current SubtleCrypto interface. This is particularly fatal as the argument where the CryptoKey should be passed is an array. For now, I'll go ahead and create a minimal set of my own test cases. |
This comment was marked as resolved.
This comment was marked as resolved.
6aaef4c
to
819dfe4
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting closer 🎉
My point about the class CryptoKeyPair is you can make a rust class that is both readonly and the properties enumerable. IMO cleaner #[rquickjs::class(frozen)]
#[derive(Clone, Trace, rquickjs::JsLifetime)]
pub struct CryptoKeyPair<'js> {
#[qjs(get, enumerable)]
private_key: Class<'js, CryptoKey<'js>>,
#[qjs(get, enumerable)]
public_key: Class<'js, CryptoKey<'js>>,
} |
Yes but the spec uses an object |
03744b3
to
f985a21
Compare
@nabetti1720 thanks for this fantastic PR! Hold off on more implementations according to spec as I'm doing some major refactoring. We can add more implementations in other PRs as this is already quite big :) |
@richarddavison , thank you for your attention to this PR. I agree. I'd like to think about implementing the remaining features after your refactoring is complete. Also, if possible, I would appreciate it if you could release commits little by little. I think not only me but everyone else is looking forward to seeing you complete this work. :) |
Hi @nabetti1720. Id try keeping changes to a minimum and go little by little but I don't want to commit things in a broken state. Since what I'm doing now is refactoring the fundamental enums and more applying SOLID principles there will be a lot of modifications. In summery I'm moving things to shared enums, moving methods to enums, implementing FromJs IntoJs traits where I can and reorganizing by applying stronger separation of concern. Also there was a lot of duplication which is now removed. What's left is derive and then I'll push |
90a033a
to
6bd83c6
Compare
Ok, I pushed what I have right now. This was a major rewrite, I'll try to summarize here:
What's left is fixing broken tests. I'm not a 100% sure we got the verification of usages right, for import they seem to break right now. There is also a big performance hit using RSA but that will be fixed once that crate switches some dependencies. |
Great refactoring! Let me know if there's anything else I should do next.
Indeed, this seems to be an error that occurs when using something that has been exported/imported. EDIT: This is because while the conversion process when the exportKey is in raw mode is implemented, the reverse conversion process for the importKey in raw mode is not implemented. |
Thanks! I'll fix usage checks according to this table:
|
@nabetti1720 we have two options to proceed here, either fix imports or disable imports completely, merge and open a new PR with this capability. This PR is already enormous 👍 |
@richarddavison , Thank you! As you say, this PR is already too big. I think it would be better to disable importKey first and merge it. After that, it would be better to open an issue that we currently know about and work towards resolving it. I'm sorry to trouble you, but could you please merge this PR? Alternatively, if you would like me to take measures to exclude the importKey (stop publishing it, exclude it from the test code), please let me know. |
@nabetti1720 please go ahead! We can just disable the export from the module and add a |
@richarddavison , Instead of skipping all the tests, I kept what I could. All the tests should pass. We can finally see the goal. :) |
@nabetti1720 may i ask which tool presents the compatibility tables in the PR's description? |
Runtime compatibility - https://runtime-compat.unjs.io/ The source for this site is maintained on GitHub at: I cloned it from GitHub and ran it manually on my laptop to analyze it. pnpm run --filter "*llrt-runtime" build && pnpm run --filter "*llrt-runtime" start && pnpm generate:process && pnpm run website |
Ah, so it's not based on WPTs. Thanks |
Issue # (if available)
Closed #184
Description of changes
With this PR, we're making a small step forward with SubtleCrypto.
We're not yet fully web standards compliant, but we wanted to share our progress so far.
At the moment, the following functions are not implemented, but since it will be complicated and time-consuming from here, I would like to make it the next PR.
raw
modeRuntime compatibility (Results on a laptop):
Checklist
tests/unit
and/or in Rust for my feature if neededmake fix
to format JS and apply Clippy auto fixesmake check
types/
directoryBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.