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

Implement webcrypto import ECDSA key and export as SPKI #200

Merged
merged 49 commits into from
Jan 3, 2024

Conversation

ospfranco
Copy link
Collaborator

@ospfranco ospfranco commented Dec 1, 2023

This is the first step towards implementing webcrypto (actually all the other encryption algorithms). Instead of following the same route we took when we first implemented the other Node APIs, I have massively simplified the JS side of things, relying on TypeScript instead of raw validation and callbacks.

It also unlocks a lot of the necessary infrastructure to continue implementing the rest of webcrypto or even maybe swapping the old implementations for a more orderly one (we just need to copy the individual implementations e.g. crypto_ec.cc).

I added a test just for the use case a client needed: import raw ECDSA key and exporting it as SPKI, but getting the rest done should now be peanuts (at least for import/export).

I've also solved some minor issues on the UI of the test app.

This branch work is based on #199, so it would be good to merge that one first.

@mrousavy
Copy link
Member

mrousavy commented Dec 7, 2023

Thanks for this PR as well, this is really amazing stuff Oscar!!!! ❤️

It's quite a big PR though, give us some time to go through the changes - we'll internally go through everything this week :)

@Szymon20000
Copy link
Member

Awesome stuff @ospfranco!
Let's first merge #199 as those prs seems to share some changes.

@boorad boorad mentioned this pull request Dec 12, 2023
6 tasks
@ospfranco
Copy link
Collaborator Author

I see there are some conflicts now, I will resolve them later. It also is somehow not picking up the changes that were just merged. I will take a look at all of those later.

# Conflicts:
#	android/build.gradle
#	example/src/testing/TestList.ts
#	src/keys.ts
@ospfranco
Copy link
Collaborator Author

Ready for review @Szymon20000 @mrousavy

@Szymon20000
Copy link
Member

Will try to review over the weekend. Thanks!


void PKEY_SPKI_Export(
KeyObjectData* key_data,
ByteSource* out) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious... is this pattern of a void function and passing in the return value as an argument the one we should use?

Or should the function return the value?

I'm asking, because I am attempting to use std::variant in another PR, and am having to deal with these ByteSource values in MGLWebCrypto.cpp

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is c style of pointer passing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but is there any performance advantage? Should we use the C++ return values style? Should we be consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just the code from Node. Don't deviate too much as sometimes multiple params need to be returned and pointer passing is the easiest way. Otherwise, you will end up creating a bunch of unnecessary structs. The node code also serves as a reference for a proper implementation.


// const generateKeyPair = promisify(_generateKeyPair);

// function verifyAcceptableEcKeyUse(name, isPublic, usages) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all of those comments?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slowly uncommenting some of them (most🤞)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just the remaining source code for the rest of the web crypto implementation. It will come back as the rest of the API is filled.

@Szymon20000
Copy link
Member

Looks good to me! However, it's not clear what is implemented in webcrypto and what is not. We probably should throw some errors if something is not implemented. Currently from what I understand we just commented out unimplemented methods?

@ospfranco
Copy link
Collaborator Author

Looks good to me! However, it's not clear what is implemented in webcrypto and what is not. We probably should throw some errors if something is not implemented. Currently from what I understand we just commented out unimplemented methods?

Unimplemented methods will not be there on the typescript types, error should be thrown for the current import/export code when trying to select a non-supported algo I believe.

@ospfranco
Copy link
Collaborator Author

Ping @Szymon20000

@Szymon20000 Szymon20000 merged commit 430ed77 into margelo:main Jan 3, 2024
5 of 6 checks passed
@Szymon20000
Copy link
Member

@ospfranco merged :)

@ospfranco
Copy link
Collaborator Author

Nice! @mrousavy let me know when you release it :)

@mrousavy
Copy link
Member

mrousavy commented Jan 3, 2024

Sure, thanks!

We got some iOS build error to figure out first and we'll probably also pull in the other PR, then we'll release it :)

@ospfranco ospfranco deleted the ECDSA branch January 3, 2024 13:36
@boorad boorad mentioned this pull request Apr 18, 2024
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

4 participants