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

crypto: expose OpenSSL's x.509 API #2492

Closed
silverwind opened this issue Aug 22, 2015 · 13 comments
Closed

crypto: expose OpenSSL's x.509 API #2492

silverwind opened this issue Aug 22, 2015 · 13 comments
Labels
crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. openssl Issues and PRs related to the OpenSSL dependency.

Comments

@silverwind
Copy link
Contributor

To generate self-signed x.509 certificates and private keys from within an application, modules like pem have to rely on spawning the system's OpenSSL, which is problematic as it can be out of date or worse, not available at all (Windows).

I think it would make sense to expose the following APIs from the bundled OpenSSL through crypto:

  • generate a private key
  • generate a self-signed certificate
  • generate dh parameters

Accompaning the above, I could also see the following:

  • read a private key's size
  • read certificate fields
  • read dh parameters's key size
@silverwind silverwind added crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. openssl Issues and PRs related to the OpenSSL dependency. labels Aug 22, 2015
@silverwind
Copy link
Contributor Author

I wonder if something like this should live in tls or crypto. @indutny any feedback?

@indutny
Copy link
Member

indutny commented Aug 27, 2015

It should be crypto for sure. Can't it be done in binary addons?

It feels like we are trying to workaround problems with C++ addons by moving everything into the core. I don't like this tendency.

cc @bnoordhuis

@silverwind
Copy link
Contributor Author

I think we can strike dh parameters (prime) generation off that list, as these seem to be obtainable through crypto.createDiffieHellman(keysize).getPrime() which I assume can be fed directly into TLS's dhparam option.

@silverwind
Copy link
Contributor Author

can be fed directly into TLS's dhparam option.

I take that back. Pretty sure the docs on dhparam are actually lacking and it only accepts PEM formatted dh parameters, not raw primes in buffer format. Is this correct?

cc: @shigeki

@indutny
Copy link
Member

indutny commented Sep 13, 2015

@silverwind this is correct.

@silverwind
Copy link
Contributor Author

@indutny yeah, I figured out generating dhparam in node yesterday, thanks to your nice asn.1 module :)

@shigeki
Copy link
Contributor

shigeki commented Sep 14, 2015

@silverwind Yes, the supported format of dhparam is PEM of PKCS#3 in buffer.
F.Y.I. In the future, DH prime/base will not be explicitly written as a parameter and be changed to be written and negotiable in a built-in named group as https://tools.ietf.org/html/draft-ietf-tls-tls13-07 and https://tools.ietf.org/html/draft-ietf-tls-tls13-07#section-6.3.1.4.2 . So we will be able to write it as ffdhe2048 such like prime256v1 in ecparam.

@calvinmetcalf
Copy link
Contributor

openssl related stuff might be a good candidate for things that should be in core due to how easy it is to get openssl wrong with consequences that can popup in unexpected ways

@Trott
Copy link
Member

Trott commented Jun 8, 2016

Is there consensus that this does or doesn't belong in core? Or is that still up for debate?

@jasnell
Copy link
Member

jasnell commented Jun 9, 2016

I don't think there's consensus that it doesn't belong, but neither is there consensus that it would make it in. I think it's safe to say that it's unlikely this would make it in.

@bnoordhuis
Copy link
Member

I wouldn't necessarily object such additions but it's a bit of a slippery slope. For example:

generate a self-signed certificate

Self-signed certificates are useless except for testing, so the logical next step is to support certificate signing using a CA key.

But once you allow that, you can make a case that creating CA keys with node should also be possible. And once that is in, it should probably also be taught how to do CRL management, etc., etc.

It would be a lot easier to simply link the openssl apps into the node binary so you could node genrsa -out key.pem 2048. :-)

@Trott
Copy link
Member

Trott commented Jul 7, 2017

This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that.

@Trott Trott closed this as completed Jul 7, 2017
@TomasHubelbauer
Copy link

TomasHubelbauer commented Nov 8, 2020

Sorry to revive an old issue, but I'm wondering what the state of things is in 2020? Is it possible using the Node's crypto module only to create a certificate, a key pair and then sign the certificate using the private key and serialize both to PEM without shelling out to OpenSSL? Essentially I'm wondering if this https://flaviocopes.com/express-https-self-signed-certificate/ can be done purely in NodeJS.

generate a self-signed certificate

I want to do this programmatically and in a cross-platform way for testing, hence my interest. The closest I found was:

https://stackoverflow.com/a/31624843/2715716

This uses Forge which I'd like to avoid (I'd rather use a built-in module for this, it doesn't feel right for crypto to be done by a non built-in module to me).

https://stackoverflow.com/q/51942824/2715716

This generates the key-pair and signs a general payload with it, but it doesn't contain code showing how to generate a payload that would encode a certificate. I'm neither capable enough to write that code myself nor knowledgeable enough to know whether that is possible given the above described constraints, and while I don't expect anyone more capable or knowledgeable than me to whip up this code, I'd be grateful for an answer to whether this is possible and what would it take.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Issues and PRs related to the crypto subsystem. feature request Issues that request new features to be added to Node.js. openssl Issues and PRs related to the OpenSSL dependency.
Projects
None yet
Development

No branches or pull requests

8 participants