6

I have noticed that a number of different web and mail server software allow or require you to provide the TLS certificate (including server certificate, CA intermediate certificate, and CA root certificate) and private key in a single .pem file.

So, the server sends the certificate(s) to every client attempting to connect, but, of course, you want to keep your private key secure and secret. So, how does this work when they are all in the same file? Does the software know to only send the certificate parts and never send the private key, even though they are in the same file?

Thank you.

2 Answers 2

5

Does the software know to only send the certificate parts and never send the private key, even though they are in the same file?

Yes.

4
  • Thanks. Is there a simple way for you to elaborate on how this works?
    – user981178
    Oct 2, 2013 at 19:29
  • 1
    In the same way you put several things into one file, the server can open the file and take the things out separately. A PEM file is one way of many to give information to the server (see serverfault.com/a/9717/57144 ). When you make an SSL connection, you are not transferring 'files' from web server to browser, but SSL connection data. Files only exist on filesystems and file sharing connections like NFS. When a file is opened, the content can be used and split and processed any way the software wants, it doesn't all have to stay together in one lump. Oct 2, 2013 at 19:38
  • Thanks again. Maybe it uses the -----Begin ...----- and -----End ...----- declarations to help it determine what parts to send what parts not to send?
    – user981178
    Oct 2, 2013 at 19:42
  • 1
    Almost certainly yes. stackoverflow.com/a/7539644 Oct 2, 2013 at 19:55
0

So, the server sends the certificate(s) to every client attempting to connect, but, of course, you want to keep your private key secure and secret.

If you don't trust the software which you are providing your PEM file to, you can encrypt the key before writing it to the PEM file. This will prevent anyone from using it without the passphrase.

The OpenSSL rsa command uses the -in to designate the input file, and -out to designate the encrypted output file. You need to also pass it the cipher. A sample command looks like this:

openssl rsa -AES256 -in key.pem -out encryptedKey.pem

You will be prompted for the passphrase. Now you can append encryptedKey.pem to your public certificate PEM, and be fairly confident that it will be safe from all bu the most determined attackers.

Note that this uses the AES256 cipher. It is your responsibility to use a cipher that is modern and secure.

When you need to use that key at the command line, OpenSSL will prompt you for the passphrase. Libraries like pyOpenSSL have overridden signatures that take a cipher and passphrase for encrypting the key, and which take only a passphrase for decrypting the encrypted key.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .