-
Notifications
You must be signed in to change notification settings - Fork 4
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
Derive Key #83
base: main
Are you sure you want to change the base?
Derive Key #83
Conversation
@oleiade I have sat down to write this a couple times and seems that I haven't gotten it all out at once... so here I go again. I have been looking at the implementation in node written in c++ to get an idea of what implementation of the spec looks like. I believe I understand what the spec desires to be implemented but I have a few questions still:
For the moment those are the main 2 but I think others might present themselves in discussion of these. |
webcrypto/algorithm.go
Outdated
@@ -178,6 +187,8 @@ func isRegisteredAlgorithm(algorithmName string, forOperation string) bool { | |||
return isAesAlgorithm(algorithmName) | |||
case OperationIdentifierSign, OperationIdentifierVerify: | |||
return algorithmName == HMAC || algorithmName == ECDSA | |||
case OperationIdentifierDeriveBits, OperationGetKeyLength: |
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.
Shouldn't it be OperationIdentifierDeriveKey
instead? 🙇♂️ (note that maybe deriveKey
might rely on the bits derivation under the hood and I'm not just aware of it)
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.
Yeah that is what I found the step 2 in the spec here for deriveKey requires deriveBits. So I think the issues for deriveBits need worked on first before I can continue so that is my current side mission 😄 I also realized that step 6 requires a "get key length" which was the util function I was referring to in my part 2 of the question from the other day. I think that is also going to be needed for the deriveBits issues so 2 birds 1 stone type of thing going on. Either way I am fairly sure that function will need to be our own implementation because I am not seeing it in any of the libraries that you mentioned.
Hi @catdevman 👋🏻 This looks good and as if it's going in the right direction, great work so far 👏🏻 1If I understood your question correctly (feel free to clarify if you think I did not 🙂):, I believe we've been doing this to have the same types as described in the specs and the operations described on them as methods. For instance, the AESCBCParams implements the encrypt and decrypt operations defined by the spec as methods. The general idea is to try to stick to what the spec describes as closely as possible. In these cases, I believe the initial intent was to avoid having super-long function names. 2Regarding implementing algorithms, please do not implement those yourselves. This library has a strict policy to stick to either the standard library or a proven set of community libraries. Here are the libraries I recommend you use: I have also needed clarification in the initial implementation by how to match the algorithms the specification defines, and how to stick to it. After consulting with some of Grafana's security team members, my key learning is that, in this case, one does not need to understand the steps of each algorithm but rather match the algorithm described to a concrete operation in an existing library implementation of the algorithm. For instance, where the specification might enter into details about the different steps of AES encryption and include those in their steps, we, as implementers, can most likely stick to the encrypt operation of the AES go package to perform all those operations in one go. The same goes for other algorithms. If you end up implementing the concrete steps of ECDH key derivation, you're most likely doing something wrong and should instead look into figuring out how to use one of the ECDH package's operations directly instead 🙂 Moving onLet me know if this is helpful, and don't hesitate to ask further questions, happy to help 🙇🏻 |
@oleiade Do you think you could help me come up with some test use cases for I started with one here(but I don't think that is quite right and the spec hasn't really helped me figure out what my test should look like): |
oh never mind I just found some good ones from the node repo. |
Hey @catdevman 👋🏻 We actually use an existing and official set of tests for testing the WebCrypto module implementation: https://github.com/web-platform-tests/wpt More specifically, we need the implementation of If you take a look at the The concrete steps in your case would probably look like the following:
Once all (if not most) of the tests pass, we'll be good to go 👍🏻 I'll admit this can be somewhat tedious work, so don't hesitate to let us know if we can help in any way, along the implementation. Happy to help, and even jump on a call if that's useful at any point in time 🙇🏻 |
@oleiade Can you also share how to run these tests. I have been do |
@oleiade I edited my above comment... but from what I can tell the tests run from the
|
For now I will add them into the |
Regarding the Can you give a shot to this approach for dervive key, and let me know if that works out? 🙇🏻 |
…multiple implementations determining what was handed to the DeriveBits function
Hey @catdevman ! Just a bit of context for tests in this repository. We mostly use two types of tests here. The first is against the WebAPI test suite, which aims to test the compatibility of k6's implementation of the WebCrypto API with the standard. It's the one that @oleiade mentioning here. However, it usually isn't ideal as a standard. Unfortunately, the WebAPI test suite didn't cover all the cases we had, especially considering that K6 was specific. That's why we came up with the idea of golden tests, which run against the examples and validate that they work (or at least do not throw exceptions) with every commit. Hope that explains! |
Yes that is very helpful explain @olegbespalov |
No description provided.