Openssl Certificate Management: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
### certs, crl-dir, and new_certs_dir are generally specified relative to $dir, and should be created with permissions of 0700 as well. You should also create the directory <certs>/private with the same permissions. | ### certs, crl-dir, and new_certs_dir are generally specified relative to $dir, and should be created with permissions of 0700 as well. You should also create the directory <certs>/private with the same permissions. | ||
### database, and serial are generally specified relative to $dir, and are created with the commands below: | ### database, and serial are generally specified relative to $dir, and are created with the commands below: | ||
#### touch <database_specified_in_cnf> ; chmod 0600 <database_specified_in_cnf> | #### <tt>touch <database_specified_in_cnf> ; chmod 0600 <database_specified_in_cnf></tt> | ||
#### echo 01 > <serial_specified_in_cnf> ; chmod 0600 <serial_specified_in_cnf> | #### <tt>echo 01 > <serial_specified_in_cnf> ; chmod 0600 <serial_specified_in_cnf></tt> | ||
### You can edit the other settings in openssl.cnf, but they are not necessary. If you're planning to create or sign a LOT of keys or certs, you could fill out some or all of the *_default settings in the req_distinguished_name section. For any variable name that doesn't already have a _default entry, you can create one. | ### You can edit the other settings in openssl.cnf, but they are not necessary. If you're planning to create or sign a LOT of keys or certs, you could fill out some or all of the *_default settings in the req_distinguished_name section. For any variable name that doesn't already have a _default entry, you can create one. | ||
### Although not required or specified in openssl.cnf, I also create a 0700 mode directory in the "certs" directory called "csr_complete", just for tree neatness. | ### Although not required or specified in openssl.cnf, I also create a 0700 mode directory in the "certs" directory called "csr_complete", just for tree neatness. | ||
## Run the following commands as root, or a user with write permissions to all of the directories and files discussed above: | ## Run the following commands as root, or a user with write permissions to all of the directories and files discussed above: | ||
### openssl req -x509 -new -days <num_days_ca_cert_should_be_valid> -out <certificate_specified_in_cnf> -keyout <private_key_specified_in_cnf> | ### <tt>openssl req -x509 -new -days <num_days_ca_cert_should_be_valid> -out <certificate_specified_in_cnf> -keyout <private_key_specified_in_cnf></tt> | ||
### I use <organization>-ca.pem and <organization>-ca_key.pem as filenames for the cert and key, respectively. | ### I use <tt><organization>-ca.pem</tt> and <tt><organization>-ca_key.pem</tt> as filenames for the cert and key, respectively. | ||
### The passphrase that you specify during this process is extremely important and sensitive. Anyone with your key and that passphrase will be able to perform SSL actions on your behalf, which affects the trustworthiness and security of all communications that rely on any certificates that have ever been signed by your CA. | ### The passphrase that you specify during this process is extremely important and sensitive. Anyone with your key and that passphrase will be able to perform SSL actions on your behalf, which affects the trustworthiness and security of all communications that rely on any certificates that have ever been signed by your CA. | ||
## Verify appropriate permissions are set on all files and subdirectories within the dir that you specified in openssl.cnf. | ## Verify appropriate permissions are set on all files and subdirectories within the dir that you specified in openssl.cnf. | ||
## To renew CA, use: <tt>openssl x509 -in oldcert.pem -out newcert.pem -days <insert_large_number_of_days> -signkey cakey.pem</tt> | |||
# Configure client app(s) to trust all keys signed by the CA | # Configure client app(s) to trust all keys signed by the CA | ||
## TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO | ## TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO | ||
Line 25: | Line 26: | ||
## This step can be accomplished on either the CA system, the system where the certificate will ultimately be used, or any other system, for that matter. However, keep in mind that you will be creating a private key in this step! If it is created on any system other than the one where it will ultimately be used, you'll need a trustworthy, secure means of moving a file to that final system! Using any insecure means will expose the private key material to being viewed and captured by a third party, who would then be able to decrypt any traffic that has been encrypted with that key. | ## This step can be accomplished on either the CA system, the system where the certificate will ultimately be used, or any other system, for that matter. However, keep in mind that you will be creating a private key in this step! If it is created on any system other than the one where it will ultimately be used, you'll need a trustworthy, secure means of moving a file to that final system! Using any insecure means will expose the private key material to being viewed and captured by a third party, who would then be able to decrypt any traffic that has been encrypted with that key. | ||
## Run the following command as root, or more preferably, the user that will be using the key/cert to secure traffic: | ## Run the following command as root, or more preferably, the user that will be using the key/cert to secure traffic: | ||
### openssl genrsa -out <file_for_private_key_material> 2048 | ### <tt>openssl genrsa -out <file_for_private_key_material> 2048</tt> | ||
### Note that the 2048 above specifies the key size for this key, and should be changed to remain in accordance with any local laws or other requirements. | ### Note that the 2048 above specifies the key size for this key, and should be changed to remain in accordance with any local laws or other requirements. | ||
### I generally name the private key file something like <service>-<host>_key.pem file, because it then indicates all relevant information just by the filename. Whether you choose this naming convention or not, decide on one and stick to it. This certainly isn't required, but will greatly simplify management of keys and certificates down the road. | ### I generally name the private key file something like <tt><service>-<host>_key.pem</tt> file, because it then indicates all relevant information just by the filename. Whether you choose this naming convention or not, decide on one and stick to it. This certainly isn't required, but will greatly simplify management of keys and certificates down the road. | ||
# Generate Certificate Signing Request (CSR) for the key | # Generate Certificate Signing Request (CSR) for the key | ||
## As the same user that created the key, run the following command: | ## As the same user that created the key, run the following command: | ||
### openssl req -new -key <file_for_private_key_material_above> -out <file_for_certificate_signing_request> | ### <tt>openssl req -new -key <file_for_private_key_material_above> -out <file_for_certificate_signing_request></tt> | ||
### For CSRs, I use the naming convention <service>-<host>.csr | ### For CSRs, I use the naming convention <tt><service>-<host>.csr</tt> | ||
## Transmit this CSR to the CA, using a secure means. (TODO: I don't think that CSRs are sensitive in and of themselves, but I need to check on that...) | ## Transmit this CSR to the CA, using a secure means. (TODO: I don't think that CSRs are sensitive in and of themselves, but I need to check on that...) | ||
# CA signs key via CSR, creating Public Certificate (cert) | # CA signs key via CSR, creating Public Certificate (cert) | ||
## The CA verifies that the CSR contains valid information, and if comfortable with the truth of that information, signs the CSR. | ## The CA verifies that the CSR contains valid information, and if comfortable with the truth of that information, signs the CSR. | ||
## As root or a user with write permissions to the CA dir tree, run the following command: | ## As root or a user with write permissions to the CA dir tree, run the following command: | ||
### openssl ca -days <num_days_cert_should_be_valid> -in <CSR_received_from_above_step> > <public_key_filename> | ### <tt>openssl ca -days <num_days_cert_should_be_valid> -in <CSR_received_from_above_step> > <public_key_filename></tt> | ||
### I use <service>-<host>.pem as a naming convention. | ### I use <tt><service>-<host>.pem</tt> as a naming convention. | ||
## Transmit the public key certificate file to the requestor. This file is public knowledge, so while secure means may be preferable for a number of reasons, it's not strictly required. | ## Transmit the public key certificate file to the requestor. This file is public knowledge, so while secure means may be preferable for a number of reasons, it's not strictly required. | ||
# Configure server to use key/cert combination | # Configure server to use key/cert combination |
Latest revision as of 21:39, 18 January 2009
NOTE: The information on this page is likely outdated, and is ported forward from an old wiki solely for posterity and future reference/updating.
These steps will allow you to create a Certificate Authority, which esentially signs SSL keys for a particular service, host, site, or combination thereof. I'm assuming that you are using OpenSSL on a Linux box, but the steps are probably pretty similar for other SSL toolkit/operating system combinations.
- Create Certificate Authority (CA)
- Update openssl.cnf to reflect your organization. This file is generally located in /usr/share/ssl, but may be in /usr/local/share/ssl/, or another location, depending on how you installed openssl. You can get creative here, but this will just cover the basics.
- Find the section labeled CA_default. This is where all of the default and system-wide settings will be kept.
- dir should be the root of the location where you will keep all of your files associated with this CA. If specified as a relative directory (i.e. ./my_ca), it will be relative to the directory that holds the openssl.cnf file. Create this directory with permissions of 0700.
- certs, crl-dir, and new_certs_dir are generally specified relative to $dir, and should be created with permissions of 0700 as well. You should also create the directory <certs>/private with the same permissions.
- database, and serial are generally specified relative to $dir, and are created with the commands below:
- touch <database_specified_in_cnf> ; chmod 0600 <database_specified_in_cnf>
- echo 01 > <serial_specified_in_cnf> ; chmod 0600 <serial_specified_in_cnf>
- You can edit the other settings in openssl.cnf, but they are not necessary. If you're planning to create or sign a LOT of keys or certs, you could fill out some or all of the *_default settings in the req_distinguished_name section. For any variable name that doesn't already have a _default entry, you can create one.
- Although not required or specified in openssl.cnf, I also create a 0700 mode directory in the "certs" directory called "csr_complete", just for tree neatness.
- Run the following commands as root, or a user with write permissions to all of the directories and files discussed above:
- openssl req -x509 -new -days <num_days_ca_cert_should_be_valid> -out <certificate_specified_in_cnf> -keyout <private_key_specified_in_cnf>
- I use <organization>-ca.pem and <organization>-ca_key.pem as filenames for the cert and key, respectively.
- The passphrase that you specify during this process is extremely important and sensitive. Anyone with your key and that passphrase will be able to perform SSL actions on your behalf, which affects the trustworthiness and security of all communications that rely on any certificates that have ever been signed by your CA.
- Verify appropriate permissions are set on all files and subdirectories within the dir that you specified in openssl.cnf.
- To renew CA, use: openssl x509 -in oldcert.pem -out newcert.pem -days <insert_large_number_of_days> -signkey cakey.pem
- Update openssl.cnf to reflect your organization. This file is generally located in /usr/share/ssl, but may be in /usr/local/share/ssl/, or another location, depending on how you installed openssl. You can get creative here, but this will just cover the basics.
- Configure client app(s) to trust all keys signed by the CA
- TODO TODO TODO TODO TODO TODO TODO TODO TODO TODO
- Generate SSL key (key) for your service/host/etc
- This step can be accomplished on either the CA system, the system where the certificate will ultimately be used, or any other system, for that matter. However, keep in mind that you will be creating a private key in this step! If it is created on any system other than the one where it will ultimately be used, you'll need a trustworthy, secure means of moving a file to that final system! Using any insecure means will expose the private key material to being viewed and captured by a third party, who would then be able to decrypt any traffic that has been encrypted with that key.
- Run the following command as root, or more preferably, the user that will be using the key/cert to secure traffic:
- openssl genrsa -out <file_for_private_key_material> 2048
- Note that the 2048 above specifies the key size for this key, and should be changed to remain in accordance with any local laws or other requirements.
- I generally name the private key file something like <service>-<host>_key.pem file, because it then indicates all relevant information just by the filename. Whether you choose this naming convention or not, decide on one and stick to it. This certainly isn't required, but will greatly simplify management of keys and certificates down the road.
- Generate Certificate Signing Request (CSR) for the key
- As the same user that created the key, run the following command:
- openssl req -new -key <file_for_private_key_material_above> -out <file_for_certificate_signing_request>
- For CSRs, I use the naming convention <service>-<host>.csr
- Transmit this CSR to the CA, using a secure means. (TODO: I don't think that CSRs are sensitive in and of themselves, but I need to check on that...)
- As the same user that created the key, run the following command:
- CA signs key via CSR, creating Public Certificate (cert)
- The CA verifies that the CSR contains valid information, and if comfortable with the truth of that information, signs the CSR.
- As root or a user with write permissions to the CA dir tree, run the following command:
- openssl ca -days <num_days_cert_should_be_valid> -in <CSR_received_from_above_step> > <public_key_filename>
- I use <service>-<host>.pem as a naming convention.
- Transmit the public key certificate file to the requestor. This file is public knowledge, so while secure means may be preferable for a number of reasons, it's not strictly required.
- Configure server to use key/cert combination