-
Notifications
You must be signed in to change notification settings - Fork 284
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
How can I sign a message and verify it using ED25519 keys? #2203
Comments
Check the documentation: |
Already did that and many other tweaks. I ended up creating keys in NodeJS with crypto.generateKeyPairSync() and going back to RSA. Not satisfied, but it'll have to do. |
If you have reasonable cause to believe it's an issue with node.js, please open a bug over at nodejs/node and I'll take a look - but please include a full reproducer, keys and all. Thanks. |
I just used the script above. The keys were generated with PuTTYgen and named accordingly (ed25519, ed25519_2, rsa; .pub, .pem, .ppk) (for keys array, key is set to choose which pair to use). |
As @bnoordhuis said, we would need the exact input files to reproduce this and tell you where the problem is. |
Not your core key parsing issue but in the case of |
Closing due to lack of information from @Dubz. |
Got to the same issue, but probably for different reason (ed25519 key pair generated via lib sodium). More explanation can be found here panva/paseto#8 . The decoder http://lapo.it/asn1js/ also helps for inspecting the key format. |
Not sure why @tniessen closed this honestly. Still likely an issue, but I'm no longer in need of this so not my problem anymore. To anyone else trying to do something along the lines of this, good luck to you. Might as well just use RSA keys for now since they don't seem to want to update it to support ED25519. |
Seems to work for me. (culled your code down a bit)
|
But since you clearly disagree, I will reopen your issue. @Dubz wrote:
To anyone else trying to do something along the lines of this, communicate with us. Don't just vanish and expect us to magically solve your problems. Node.js is an open-source project, @Dubz. If you want something implemented/fixed, either do it yourself and create a PR, or talk to us. We don't work for you. |
As I stated in the OP,
To be clear, I never expected anything. Like I said, I was just asking for assistance to see if I was misunderstanding the module. Like I said, I'm no longer building the project that I wanted this for, so it doesn't really matter to me what you do with this thread. At this point, it'd just be a POC for someone with more experience with this module to confirm my original theory that ED25519 keys are not supported. |
@Dubz I apologize if it seemed to you like we don't want Ed25519 to work, that is not the case. I implemented and tested a big part of it myself.
The reason I asked you to do this is because I tested ED25519 with various input files, and couldn't reproduce your issue. Since I wasn't working on Windows at the time, I didn't have PuTTY installed. I downloaded PuTTYgen, started it, generated a key, and exported it. It seems that none of the formats provided by the PuTTYgen GUI are standard key formats. That makes sense, given that PuTTYgen is not a general purpose key management tool, but only designed for SSH. Node.js is not an SSH tool, and won't accept non-standard key formats. I know that you have moved on, but how did you convert these SSH files to actual keys before passing them to Node.js? Just so I can reproduce the issue by following in your steps. |
That is a fair enough reason for this and I can understand. I apologize for being short about it before, just had a trend of various "nobody is getting anything done around here" going on and my patience was running rather thin at the time for simple things.
That would make sense, and I was slightly aware of that, but wasn't fully sure if that would be an actual issue or not. I think I just had different expectations at the time.
Referencing the lines here, I just loaded them as text: // Load the files (that exist)
key.pem = (fs.existsSync("./" + key.name + ".pem")) ? fs.readFileSync("./" + key.name + ".pem") : false;
key.ppk = (fs.existsSync("./" + key.name + ".ppk")) ? fs.readFileSync("./" + key.name + ".ppk") : false;
key.pub = (fs.existsSync("./" + key.name + ".pub")) ? fs.readFileSync("./" + key.name + ".pub") : false; Later loading the contents to the object, with the given password at the top of the script: key.private = crypto.createPrivateKey({key: key.pem, passphrase: key.passphrase}); So in other words, the value for the first item IIRC, the end goal was to have a private key on each server to "identify" itself, and a public key on the receiving ends to verify its signature. Basically similar to how known_hosts works via SSH, but across Node.JS connections. Wasn't sure of the best route to implement this at that time. Even if this isn't the best method, it would still be good to learn as to why that wasn't working for me. The process on the signing side would be, load the private key file, sign data, send it over. Receiving server would use that servers public key to then verify the signed data's authenticity. key.public = crypto.createPublicKey({key: key.pub}); (again, the text contents of the key file) It's been so long I'm not really sure what was working and what wasn't, but I do remember testing both RSA and ED25519 versions, as well as using the private key object to generate the public key object (not ideal, obviously), and using the public key file to generate the public key object. |
@Dubz Thanks for your patience and the explanation :) The problem: The files produced by PuTTYgen are not really keys, so Node.js won't recognize them. They are really just meant to be used with SSH tools. If you open them in a text editor, you'll notice that they begin with
or
The solution: What you wanted to do is perfectly reasonable and possible. You could either somehow convert the SSH keys into real keys, or you could use tools such as openssl to produce the keys:
(Or generate the keys from within Node.js, of course.) These files are actual keys, so they begin with the usual
and
|
This still doesn't work on Repro: const crypto = require('crypto')
const fs = require('fs')
const publicKey = fs.readFileSync('id_node_test_ed25519', { encoding: 'utf-8' })
const privateKey = fs.readFileSync('id_node_test_ed25519.pub', {
encoding: 'utf-8',
})
const message = 'Hello world!'
console.log(message)
const signature = crypto.sign(null, Buffer.from(message), privateKey)
console.log(signature)
const verified = crypto.verify(null, Buffer.from(message), publicKey, signature)
console.log('Match:', verified) test private key: -----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACB5fUJwP/RSBUfbkEmL/9VEPu38KxHLwcngUdEBI//ILQAAAJiZVyEDmVch
AwAAAAtzc2gtZWQyNTUxOQAAACB5fUJwP/RSBUfbkEmL/9VEPu38KxHLwcngUdEBI//ILQ
AAAEDIn37veTsezaiUpPrlfjRdLt/MGvdtn674olN1xVeC9nl9QnA/9FIFR9uQSYv/1UQ+
7fwrEcvByeBR0QEj/8gtAAAAE2FsZXMubWVuemVsQG1lbnplbGEBAg==
-----END OPENSSH PRIVATE KEY----- test public key:
|
@alesmenzel Please read #2203 (comment) (the comment right above yours). The private key and public key files produced by |
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. |
I am trying to have servers connect to a centralized server. To validate their identity, I am opting to use encryption/signing keys. I would prefer to use ED25519 if possible, but if I'm mistaking their ability for this, please let me know.
Also, please note that this is not SSL/SSH. This is just general data that will be passed along an application that also accepts clients (hence the verification necessity). The keys will serve to prove the server really is a server, and give it the necessary rights/access for more methods.
I've tried RSA and I can get it partially working, but I cannot get it to load the public key properly.
Here's what I've got so far. Only dependencies are the keys, which anyone can generate. I am using ed25519 and RSA 4096-bit for this test.
If I use the private key object to create the public key object, it works. If I use the public key to ry and create the public key object, it fails. Obviously I need to be able to have the public key on a separate server to verify without the private key, so that's where I'm stumped. This is for RSA. ED25519, can't even get the private key object.
RSA public key object error:
ED25519 private key object error:
They error with the same reason, but I have no idea what that is. Any help would be greatly appreciated!!!
The text was updated successfully, but these errors were encountered: