-
Notifications
You must be signed in to change notification settings - Fork 173
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
Typings #295
Typings #295
Conversation
…tureAlgorithm, TransformationAlgorithm into interfaces
This is some nice work here, and I have no objection to merging it as-is, but it is incomplete. Ideally we'd as JSDoc references in the code to further improve the experience of working with this library, but, at a minimum, we should sort out our long-standing issues with |
You might be interested in some documentation about how to use TypeScript with JS projects. I think this command is great for getting things going and making sure we have complete coverage: |
If we can get this to a good place, I can do a |
Is complete coverage actually needed here? |
I agree but maybe that is a new PR.
|
Can this |
I have experimented with JSDoc references, and generating types with |
We can move to JS classes if that would help. They are supported in Node@14, which is our new minimum. |
@shunkica , I gave these a quick overview, and they look fine to me. Types are those things that sometimes you have to iterate over, but it isn't a breaking change, so I'm not worried. When you're happy with this, ping me and I'll approve and merge it. then we can fix that |
…mType To TransformAlgorithmType
@cjbarth It's not perfect but it's better than it was. If you have no changes to add consider this done for now. |
So, I'm late to the party, but I think I have caught up with what's happening here. Bare with me -- read this slowly because this should clear up a lot of confusion. I know I can be a bit long-winded, but I promise this will shed some light on the madness. Private Keys and Public Keys@shunkica , @cjbarth , @LoneRifle I ended up having to learn a lot more about digital signatures than I ever really wanted to learn in order to make a PR a few months ago. According to the Wikipedia on Digital Signatures (and you can verify this on the command line with openssl):
So this means that either a private key or a public key (i.e. a certificate) can be used to generate the signature itself. The API specs that dragged me into this project in the first place even say that the service will generate a signature in the response based on the public key I use in my request (e.g. a Current xml-crypto ImplementationSo, with that understanding of the digital signatures, lets look at the two ways that
When generating a signature, one need only set When validating a signature, The Reason for the Confusionyou cannot use the same instance of The solution
ConclusionAgain, sorry for the long explanation, but the situation needs to be understood holistically in order to put |
@djaqua That is a really good analysis. As a point of clarification, only a private key can generate a signature, and a public key is used to validate a signature. A public key and be derived from a private key. Having said that, please have a look at this PR and see the changes that are being made to clarify all this and see if that makes sense with with what you've recently researched. |
This is incorrect, you can not generate a signature with the public key. The public key (BinarySecurityToken in wssecurity) is used to validate the signature. The fact that the signingKey property was used to load the public key for validation has been rectified by cjbarth in #301, where he changed it into signingCert.
You can validate the signature with the private key because you can generate a public key from a private key. But the person validating the signature will (should) not have you private key. |
Yes, my bad. I was working from some notes I wrote several months ago. In my notes, under the "Digital Signatures" section, I noted that its based on Public Key Encryption, and under Public Key Encryption, I noted that data can be encrypted with a Public Key and require a Private Key for decryption, so I assumed that detail applied to Digital Signatures as well. And, upon further inspection, the API specs that I mentioned do indicate that content would be encrypted using the Public Key provided by the caller and that the signature generated in the response could be verified with their certificate, but its been a few months since I read that exact detail, so I assumed it applied to both encryption and digital signatures. So yes, my bad; I have since updated my notes. Ironically, I misread the Wikipedia quote -- it specifically says that it should be infeasible to generate a valid signature without a private key. That said, the implementation details I provided in my response ("Current xml-crypto Implementation") still apply regardless of my misunderstanding of what should and should not be possible. I looked at the PR @cjbarth and added a comment. I'm about to start another discussion, so be ready! |
Update the typings with improved type annotations and documentation
I don't know what to do with
KeyInfo
.Right now the
StringKeyInfo
constructor accepts only a string, but I think there is no obstacle for it accepting acrypto.KeyLike
(which is an alias forstring|Buffer|KeyObject
, because the key is only ever used when it is passed tocrypto.Verify
andcrypto.Sign
Also the getKey function declares that it returns a
Buffer
, but currently it can return either string for StringKeyInfo or Buffer for FileKeyInfo.Maybe something like this can be done: