Blame doc/HOWTO/certificates.txt

Packit c4476c
<DRAFT!>
Packit c4476c
			HOWTO certificates
Packit c4476c
Packit c4476c
1. Introduction
Packit c4476c
Packit c4476c
How you handle certificates depends a great deal on what your role is.
Packit c4476c
Your role can be one or several of:
Packit c4476c
Packit c4476c
  - User of some client application
Packit c4476c
  - User of some server application
Packit c4476c
  - Certificate authority
Packit c4476c
Packit c4476c
This file is for users who wish to get a certificate of their own.
Packit c4476c
Certificate authorities should read https://www.openssl.org/docs/apps/ca.html.
Packit c4476c
Packit c4476c
In all the cases shown below, the standard configuration file, as
Packit c4476c
compiled into openssl, will be used.  You may find it in /etc/,
Packit c4476c
/usr/local/ssl/ or somewhere else.  By default the file is named
Packit c4476c
openssl.cnf and is described at https://www.openssl.org/docs/apps/config.html.
Packit c4476c
You can specify a different configuration file using the
Packit c4476c
'-config {file}' argument with the commands shown below.
Packit c4476c
Packit c4476c
Packit c4476c
2. Relationship with keys
Packit c4476c
Packit c4476c
Certificates are related to public key cryptography by containing a
Packit c4476c
public key.  To be useful, there must be a corresponding private key
Packit c4476c
somewhere.  With OpenSSL, public keys are easily derived from private
Packit c4476c
keys, so before you create a certificate or a certificate request, you
Packit c4476c
need to create a private key.
Packit c4476c
Packit c4476c
Private keys are generated with 'openssl genrsa -out privkey.pem' if
Packit c4476c
you want a RSA private key, or if you want a DSA private key:
Packit c4476c
'openssl dsaparam -out dsaparam.pem 2048; openssl gendsa -out privkey.pem dsaparam.pem'.
Packit c4476c
Packit c4476c
The private keys created by these commands are not passphrase protected;
Packit c4476c
it might or might not be the desirable thing.  Further information on how to
Packit c4476c
create private keys can be found at https://www.openssl.org/docs/HOWTO/keys.txt.
Packit c4476c
The rest of this text assumes you have a private key in the file privkey.pem.
Packit c4476c
Packit c4476c
Packit c4476c
3. Creating a certificate request
Packit c4476c
Packit c4476c
To create a certificate, you need to start with a certificate request
Packit c4476c
(or, as some certificate authorities like to put it, "certificate
Packit c4476c
signing request", since that's exactly what they do, they sign it and
Packit c4476c
give you the result back, thus making it authentic according to their
Packit c4476c
policies).  A certificate request is sent to a certificate authority
Packit c4476c
to get it signed into a certificate. You can also sign the certificate
Packit c4476c
yourself if you have your own certificate authority or create a
Packit c4476c
self-signed certificate (typically for testing purpose).
Packit c4476c
Packit c4476c
The certificate request is created like this:
Packit c4476c
Packit c4476c
  openssl req -new -key privkey.pem -out cert.csr
Packit c4476c
Packit c4476c
Now, cert.csr can be sent to the certificate authority, if they can
Packit c4476c
handle files in PEM format.  If not, use the extra argument '-outform'
Packit c4476c
followed by the keyword for the format to use (see another HOWTO
Packit c4476c
<formats.txt?>).  In some cases, -outform does not let you output the
Packit c4476c
certificate request in the right format and you will have to use one
Packit c4476c
of the various other commands that are exposed by openssl (or get
Packit c4476c
creative and use a combination of tools).
Packit c4476c
Packit c4476c
The certificate authority performs various checks (according to their
Packit c4476c
policies) and usually waits for payment from you. Once that is
Packit c4476c
complete, they send you your new certificate.
Packit c4476c
Packit c4476c
Section 5 will tell you more on how to handle the certificate you
Packit c4476c
received.
Packit c4476c
Packit c4476c
Packit c4476c
4. Creating a self-signed test certificate
Packit c4476c
Packit c4476c
You can create a self-signed certificate if you don't want to deal
Packit c4476c
with a certificate authority, or if you just want to create a test
Packit c4476c
certificate for yourself.  This is similar to creating a certificate
Packit c4476c
request, but creates a certificate instead of a certificate request.
Packit c4476c
This is NOT the recommended way to create a CA certificate, see
Packit c4476c
https://www.openssl.org/docs/apps/ca.html.
Packit c4476c
Packit c4476c
  openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
Packit c4476c
Packit c4476c
Packit c4476c
5. What to do with the certificate
Packit c4476c
Packit c4476c
If you created everything yourself, or if the certificate authority
Packit c4476c
was kind enough, your certificate is a raw DER thing in PEM format.
Packit c4476c
Your key most definitely is if you have followed the examples above.
Packit c4476c
However, some (most?) certificate authorities will encode them with
Packit c4476c
things like PKCS7 or PKCS12, or something else.  Depending on your
Packit c4476c
applications, this may be perfectly OK, it all depends on what they
Packit c4476c
know how to decode.  If not, there are a number of OpenSSL tools to
Packit c4476c
convert between some (most?) formats.
Packit c4476c
Packit c4476c
So, depending on your application, you may have to convert your
Packit c4476c
certificate and your key to various formats, most often also putting
Packit c4476c
them together into one file.  The ways to do this is described in
Packit c4476c
another HOWTO <formats.txt?>, I will just mention the simplest case.
Packit c4476c
In the case of a raw DER thing in PEM format, and assuming that's all
Packit c4476c
right for your applications, simply concatenating the certificate and
Packit c4476c
the key into a new file and using that one should be enough.  With
Packit c4476c
some applications, you don't even have to do that.
Packit c4476c
Packit c4476c
Packit c4476c
By now, you have your certificate and your private key and can start
Packit c4476c
using applications that depend on it.
Packit c4476c
Packit c4476c
--
Packit c4476c
Richard Levitte