My goal was to create a private key and to encrypt it with a strong cipher. That key would be used as a root certificate for an internal Certification Authority.
However, eventhough openssl supports AES 128 GCM, I cannot generate and encrypt a key using this encryption algorithm. OpenSSL reports error writing key
. The AES 128/256 GCM both failed, however AES 128 CBC worked. What am I doing wrong? Do I need extra parameters when using GCM?
Here is the command:
$ openssl genpkey -out ca.key.pem -aes-128-gcm -algorithm rsa -pkeyopt rsa_keygen_bits:4096
The output is this:
.........................................................................+++
............................+++
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
Error writing key
:error:23077006:PKCS12 routines:PKCS12_pbe_crypt:EVP lib:p12_decr.c:96:
:error:2306C067:PKCS12 routines:PKCS12_item_i2d_encrypt:encrypt error:p12_decr.c:175:
:error:2307D067:PKCS12 routines:PKCS8_encrypt:encrypt error:p12_p8e.c:88:
Note: most online resources are out-dated (footnote-1) and using the superseded genrsa, or -nodes/-des flags. So I use those online resources as a basis, plus the (also quite outdated) man pages of openssl and the "-help" flag of the various openssl commands to create the above, IMHO up-to-date, command.
In the above command, I've tried to replace -aes-128-gcm
with:
-aes-256-gcm
-aes-128-xts
-aes-256-xts
And all failed. The XTS ones failed with the following error:
:error:0D0A706C:asn1 encoding routines:PKCS5_pbe2_set_iv:cipher has no object identifier:p5_pbev2.c:103:
:error:2307D00D:PKCS12 routines:PKCS8_encrypt:ASN1 lib:p12_p8e.c:79:
Using:
-aes-128-cbc (like in an example in the man page from genpkey)
-aes128
-aes256
All worked fine.
Strangely all of the above ciphers are supported by the version of openssl I'm using.
$ openssl enc -help 2>&1 | grep aes | egrep "128|256"
-aes-128-cbc -aes-128-cfb -aes-128-cfb1
-aes-128-cfb8 -aes-128-ctr -aes-128-ecb
-aes-128-gcm -aes-128-ofb -aes-128-xts
-aes-192-gcm -aes-192-ofb -aes-256-cbc
-aes-256-cfb -aes-256-cfb1 -aes-256-cfb8
-aes-256-ctr -aes-256-ecb -aes-256-gcm
-aes-256-ofb -aes-256-xts -aes128
-aes192 -aes256
Note: tested on Ubuntu 14.04.2, Debian 7.8 and CentOS 7. All exhibited the same behaviour.
footnote-1: If you google "openssl generate self signed root certificate", none of the 5 first results tells you to encrypt your root private certificate with something better than triple DES!?! One link of the 5 1st links advise for 4096 bit, whereas the other provide 2048 or 1024!?! Most do not provide any cipher flag, so the key is not encrypted. Actually, only the 7th link does a decent job at explaining what and how to do it.
Update 20161218: Tested again without success on Ubuntu 16.04 LTS with openssl 1.0.2g.