Path: blob/main/crypto/openssl/doc/HOWTO/certificates.txt
34869 views
<DRAFT!>1HOWTO certificates231. Introduction45How you handle certificates depends a great deal on what your role is.6Your role can be one or several of:78- User of some client application9- User of some server application10- Certificate authority1112This file is for users who wish to get a certificate of their own.13Certificate authorities should read https://www.openssl.org/docs/apps/ca.html.1415In all the cases shown below, the standard configuration file, as16compiled into openssl, will be used. You may find it in /etc/,17/usr/local/ssl/ or somewhere else. By default the file is named18openssl.cnf and is described at https://www.openssl.org/docs/apps/config.html.19You can specify a different configuration file using the20'-config {file}' argument with the commands shown below.2122232. Relationship with keys2425Certificates are related to public key cryptography by containing a26public key. To be useful, there must be a corresponding private key27somewhere. With OpenSSL, public keys are easily derived from private28keys, so before you create a certificate or a certificate request, you29need to create a private key.3031Private keys are generated with 'openssl genrsa -out privkey.pem' if32you want an RSA private key, or if you want a DSA private key:33'openssl dsaparam -out dsaparam.pem 2048; openssl gendsa -out privkey.pem dsaparam.pem'.3435The private keys created by these commands are not passphrase protected;36it might or might not be the desirable thing. Further information on how to37create private keys can be found at https://www.openssl.org/docs/HOWTO/keys.txt.38The rest of this text assumes you have a private key in the file privkey.pem.3940413. Creating a certificate request4243To create a certificate, you need to start with a certificate request44(or, as some certificate authorities like to put it, "certificate45signing request", since that's exactly what they do, they sign it and46give you the result back, thus making it authentic according to their47policies). A certificate request is sent to a certificate authority48to get it signed into a certificate. You can also sign the certificate49yourself if you have your own certificate authority or create a50self-signed certificate (typically for testing purposes).5152The certificate request is created like this:5354openssl req -new -key privkey.pem -out cert.csr5556Now, cert.csr can be sent to the certificate authority, if they can57handle files in PEM format. If not, use the extra argument '-outform'58followed by the keyword for the format to use (see another HOWTO59<formats.txt?>). In some cases, -outform does not let you output the60certificate request in the right format and you will have to use one61of the various other commands that are exposed by openssl (or get62creative and use a combination of tools).6364The certificate authority performs various checks (according to their65policies) and usually waits for payment from you. Once that is66complete, they send you your new certificate.6768Section 5 will tell you more on how to handle the certificate you69received.7071724. Creating a self-signed test certificate7374You can create a self-signed certificate if you don't want to deal75with a certificate authority, or if you just want to create a test76certificate for yourself. This is similar to creating a certificate77request, but creates a certificate instead of a certificate request.78This is NOT the recommended way to create a CA certificate, see79https://www.openssl.org/docs/apps/ca.html.8081openssl req -new -x509 -key privkey.pem -out cacert.pem -days 10958283845. What to do with the certificate8586If you created everything yourself, or if the certificate authority87was kind enough, your certificate is a raw DER thing in PEM format.88Your key most definitely is if you have followed the examples above.89However, some (most?) certificate authorities will encode them with90things like PKCS7 or PKCS12, or something else. Depending on your91applications, this may be perfectly OK. It all depends on what they92know how to decode. If not, there are a number of OpenSSL tools to93convert between some (most?) formats.9495So, depending on your application, you may have to convert your96certificate and your key to various formats, most often also putting97them together into one file. The ways to do this is described in98another HOWTO <formats.txt?>, I will just mention the simplest case.99In the case of a raw DER thing in PEM format, and assuming that's all100right for your applications, simply concatenating the certificate and101the key into a new file and using that one should be enough. With102some applications, you don't even have to do that.103104105By now, you have your certificate and your private key and can start106using applications that depend on it.107108--109Richard Levitte110111112