Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
technical:openssl_usage_notes [2018/12/04 14:00] – [Notes] bob | technical:openssl_usage_notes [2021/10/14 19:46] (current) – bob | ||
---|---|---|---|
Line 7: | Line 7: | ||
* SSL is based on RSA asymmetrical encryption (aka public key encryption) | * SSL is based on RSA asymmetrical encryption (aka public key encryption) | ||
* Two files are created; a certificate (the " | * Two files are created; a certificate (the " | ||
- | * The cert is public. It contains information about the cert user (i.e. the " | + | * The cert is public. It contains information about the cert user (i.e. the " |
* " | * " | ||
* Check the integrity of the cert by calculating the secure hash of the cert and comparing it with the decrypted signature. | * Check the integrity of the cert by calculating the secure hash of the cert and comparing it with the decrypted signature. | ||
Line 20: | Line 20: | ||
| key | Subject' | | key | Subject' | ||
| PEM | Straight ASCII (BASE64) format of a binary cert or key | | | PEM | Straight ASCII (BASE64) format of a binary cert or key | | ||
- | | sign | Calculate a secure hash and encrypt hash with issuer' | + | | sign | Calculate a secure hash and encrypt hash with issuer' |
| subject | The entity (person or organization) described in the cert | | | subject | The entity (person or organization) described in the cert | | ||
+ | |||
+ | ==== File Types ==== | ||
+ | |||
+ | | .pem | Stands for PEM, Privacy Enhanced Mail; it simply indicates a base64 encoding with header and footer lines. Mail traditionally only handles text, not binary which most cryptographic data is, so some kind of encoding is required to make the contents part of a mail message itself (rather than an encoded attachment). The contents of the PEM are detailed in the header and footer line - .pem itself doesn' | ||
+ | | .key | Can be any kind of key, but usually it is the private key - OpenSSL can wrap private keys for all algorithms (RSA, DSA, EC) in a generic and standard PKCS#8 structure, but it also supports a separate ' | ||
+ | | .crt or .cer | Stands simply for certificate, | ||
+ | | .csr or .req | Stands for Certificate Signing Request as defined in PKCS#10; it contains information such as the public key and common name required by a Certificate Authority to create and sign a certificate for the requester, the encoding could be PEM or DER (which is a binary encoding of an ASN.1 specified structure) | | ||
+ | |||
===== Important OpenSSL Commands and Options ===== | ===== Important OpenSSL Commands and Options ===== | ||
Line 63: | Line 71: | ||
| -text | Text form of request | | | -text | Text form of request | | ||
| -noout | | -noout | ||
+ | |||
+ | ===== Generate a public / private RSA key pair ===== | ||
+ | |||
+ | This just generates a matched pair of public and private keys using the RSA algorithm. Once generated these keys can be used for other SSL activities such as encryption certificate signing. | ||
+ | |||
+ | < | ||
+ | openssl genrsa -out my_key_name.key 2048 | ||
+ | </ | ||
+ | |||
+ | Both the public and private keys reside in the key file. Hold this file near and dear, especially if it isn't password protected. Extract the public key portion of this with RSA command. | ||
+ | |||
+ | < | ||
+ | openssl rsa -in my_key_name.key -outform PEM -pubout -out my_public_key_name.pem | ||
+ | </ | ||
===== Build a " | ===== Build a " | ||
Line 71: | Line 93: | ||
===== Build a Certificate Signing Request (CSR) ===== | ===== Build a Certificate Signing Request (CSR) ===== | ||
+ | |||
+ | Here is a basic version of CSR generation | ||
< | < | ||
Line 76: | Line 100: | ||
</ | </ | ||
- | ===== Sign a Certificate Signing Request (CSR) ===== | + | Cheap SSL Security has a guide to [[https:// |
+ | |||
+ | < | ||
+ | openssl req -new -newkeys rsa:2048 -nodes -keyout baggerman.org.key -out baggerman.org.crt | ||
+ | </ | ||
+ | |||
+ | This makes new RSA keys. To use an existing key use this form: | ||
+ | |||
+ | < | ||
+ | openssl req -new -key key_file_name.pem -out baggerman.org.csr | ||
+ | </ | ||
+ | |||
+ | This doesn' | ||
+ | |||
+ | [ req ] | ||
+ | req_extensions | ||
+ | |||
+ | [ v3_req ] | ||
+ | subjectAltName | ||
+ | |||
+ | [alt_names] | ||
+ | DNS.1 = www.baggerman.org | ||
+ | DNS.2 = baggerman.org | ||
+ | IP.1 = 198.89.126.181 | ||
+ | |||
+ | Check the CSR with the following command: | ||
+ | |||
+ | < | ||
+ | openssl req -text -noout -in baggerman.org.csr | ||
+ | </ | ||
+ | |||
+ | There is also a good CSR decoder at [[https:// | ||
+ | |||
+ | ===== Submit a Certificate Signing Request (CSR) ===== | ||
+ | |||
+ | Use the .csr file to submit a signing request to a certificate provider like CheapSSL. | ||
+ | Save the returned certificate into to a certificate file (.cer) | ||
+ | Also save the intermediate certificate advisory file if necessary. | ||
+ | |||
+ | |||
+ | ===== Or self-sign | ||
< | < | ||
Line 87: | Line 151: | ||
openssl x509 -in certificate.crt -text -noout | openssl x509 -in certificate.crt -text -noout | ||
</ | </ | ||
+ | |||
+ | ===== Convert a Certificate to PEM format ===== | ||
+ | |||
+ | < | ||
+ | openssl x509 -inform der -in certificate.cer -out certificate.pem | ||
+ | </ | ||
+ | |||
+ | If you get an error it probably means the certificate is already in PEM format | ||
===== Self-sign a Certificate ===== | ===== Self-sign a Certificate ===== | ||
Line 93: | Line 165: | ||
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mysitename.key -out mysitename.crt | openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mysitename.key -out mysitename.crt | ||
</ | </ | ||
+ | |||
+ | ===== Configure Apache ===== | ||
+ | |||
+ | Good notes at | ||
+ | |||
+ | Setup default SSL settings outside of a virtual host. Current recommended config (from [[https:// | ||
+ | |||
+ | SSLCipherSuite EECDH+AESGCM: | ||
+ | SSLProtocol All -SSLv2 -SSLv3 | ||
+ | SSLHonorCipherOrder On | ||
+ | |||
+ | Be sure to set: | ||
+ | |||
+ | SSLCertificateKeyFile | ||
+ | SSLCertificateFile | ||
+ | SSLCertificateChainFile "/ | ||