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