Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

Does anyone know how to use openssl to generate certificate for the following public key type: 1) DSA - For DHE_DSS key exchange. 2) Diffie-Hellman - For DH_DSS and DH_RSA key exchange. 3) ECDH - For ECDH_ECDSA and ECDH_RSA key exchange. 4) ECDSA - For ECDHE_ECDSA key exchange.

Most that I can find online teaches you how to generate a RSA type certificate though.

share|improve this question
    
Funny you should mention this. I had to do this a few days ago. And then threw away my notes... –  LateralFractal Oct 22 '13 at 10:28
add comment

1 Answer

up vote 3 down vote accepted

For a DSA key pair, use this:

openssl dsaparam -genkey 1024 -out dsakey.pem

where "1024" is the size in bits. The first DSA standard mandated that the size had to be a multiple of 64, in the 512..1024 range. Then another version deprecated sizes below 1024, so a valid DSA key size had length 1024 bits and nothing else. Current version specifies that a valid DSA key has length 1024, 2048 or 3072 bits. OpenSSL accepts other lengths. If you want to maximize interoperability, use 1024 bits.

For an ECDSA key pair, use this:

openssl ecparam -genkey -out eckey.pem -name prime256v1

To see what curve names are supported by OpenSSL, use: openssl ecparam -list_curves

(For optimal interoperability, stick to NIST curve P-256, that OpenSSL knows under the name "prime256v1".)

Once you have a DSA or ECDSA key pair, you can generate a self-signed certificate containing the public key, and signed with the private key:

openssl req -x509 -new -key dsakey.pem -out cert.pem

(Replace "dsakey.pem" with "eckey.pem" to use the EC key generated above.)


For Diffie-Hellman (with or without elliptic curves), things are more complex, because DH is not a signature algorithm:

  • You will not be able to produce a self-signed certificate with a DH key.
  • You cannot either make a PKCS#10 request for a certificate with a DH key, because a PKCS#10 request is supposed to be self-signed (this self-signature is used as a proof of possession).

While OpenSSL, the library, has the support needed for issuing a certificate which contains a DH public key; this page may contain pointers. The challenge is to convince OpenSSL, the command-line tool, to do it. In the jungle of the OpenSSL documentation, I have not found a complete way to do it. Key pairs are easy enough to generate, though.

To generate a DH key pair, with the OpenSSL command-line tool, you have to do it in two steps:

openssl dhparam -out dhparam.pem 1024
openssl genpkey -paramfile dhparam.pem -out dhkey.pem

For an ECDH key pair, use this:

openssl ecparam -out ecparam.pem -name prime256v1
openssl genpkey -paramfile ecparam.pem -out ecdhkey.pem

However, it so happens that the format for certificates containing ECDH public keys is completely identical to the format for certificates containing ECDSA public keys; indeed, the format contains "an EC public key" without indication of the intended algorithm (ECDH or ECDSA). Therefore, any private key and certificates for ECDSA (private key for generating ECDSA signatures, certificate self-signed or signed by any other CA) will be fit for ECDH-* cipher suites.

The one case that I don't know how to produce with the OpenSSL command-line tool is a static Diffie-Hellman (non-EC) certificate. Note, though, that OpenSSL does not support SSL/TLS with static DH cipher suites either, so even if you could produce the certificate, it would not work with OpenSSL.

(And, in fact, nobody uses static DH in practice.)

share|improve this answer
    
One question though, why nobody uses static DH in practice? Practically,if I use DH-RSA, wouldn't it provides good security as well? –  Ming Oct 23 '13 at 1:51
    
There is no known security issue with static DH. But nobody wants to use DH because it would be hard to test and would not promote interoperability, because... nobody uses DH. The source of the issue is that back in the early 1990s, when SSL and X.509 were in their infancy, the standard describing DH was not free (and is still not), so open source developers had a preference for RSA. –  Tom Leek Oct 23 '13 at 10:49
    
Also, DHE-RSA (or any other cipher suite with ephemeral DH or ECDH) provides Perfect Forward Secrecy, which is a nice thing to have. –  Tom Leek Oct 23 '13 at 10:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.