├── LICENSE ├── README.md ├── certs.sh └── load-trusted-root.ps1 /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SelfSigned-Cert-Creator 2 | A short script to make it easy to create a viable, trusted self-signed certificate that can be used for SSL/TLS in particular. 3 | 4 | # UPDATE 2019-01-12 5 | 6 | I've discovered another repository that has some much better functions than mine and is more up-to-date. 7 | 8 | Please try out [FiloSottile/mkcert](https://github.com/FiloSottile/mkcert) before trying this. 9 | 10 | # UPDATE 2017-12-09 11 | 12 | I've finally managed to update this script to correctly add Subject Alternate Names so that the resulting certificates 13 | work correctly with Chrome and other modern browsers. 14 | 15 | # Quickstart 16 | 17 | 1. Run the script giving the web server's IP address/domain the parameter (e.g. 192.168.1.10, myweb.mydomain.com, *.mydomain.com). 18 | 2. Move the files in the `server` folder to a convenient location 19 | 3. Adjust your web server configuration to use the `privkey.pem` & `fullchain.pem` files 20 | 4. Upload the `client/my-private-root-ca.crt` to the certificate store on any device needing access to the server to get rid of untrusted root CA warnings. 21 | 22 | # Background 23 | The correct use of public key cryptography is a difficult and complex subject. And yet we are encouraged to ensure that **all** websites use HTTPS (TLS) to ensure that the transport between the server and clients is encrypted. 24 | 25 | Certificates for HTTPS are also often very expensive to buy and update. Although there are a few low-cost certificate providers such as StartSSL and Lets Encrypt, you are trading the low cost for higher maintenance since the certificate lifetimes are short. 26 | 27 | It is possible however to create your own certificates, so called self-signed. But the process is arcane even in 2016. Also, all browsers are gradually moving to a model that automatically rejects self-signed certificates, assuming that they are some kind of attack - which of course they can be - but generally are not. They are merely an attempt to develop new services or to keep down costs. 28 | 29 | To use certificates to encrypt traffic from your server to clients, you need to provide two things. A *certificate* and a *private key*. The certificate can be freely published and you can let anyone have it. The private key, on the other hand, **must** be kept safe at all times, if someone gets a copy, it is worthless and you need to generate a new certificate & key. 30 | 31 | # The script 32 | The script offered here contains all the arcane wizardry to create not only a server certificate that will let you secure communications to client devices but also a stand-alone Certificate Authority (CA) that can be used for signing as many certificates as you like. 33 | 34 | If you don't do anything on devices accessing your server, you will still get warnings saying that the certificate is untrusted. That is because all client devices using HTTPS contain a list of trusted root certificates. Any server certificate cross-signed by a trusted root CA will be trusted by the browser (a much bigger risk than using self-signed certs!). As your CA cert is not in the list, the device doesn't trust your servers certificate. This is easily fixed though, see the how-to-use section. 35 | 36 | You only need to run the full script once. Thereafter, you don't need the CA lines because you already have a CA certificate and key. 37 | 38 | The script will create a number of folders relative to the location of the script file: 39 | - `tmp` - deleted at the end of the script 40 | - `ca` - contains the CA related files - **must be kept secure**, best kept offline until needed next time 41 | - `server` - the certificate and key files required by the server to work over HTTPS, move to a convenient location 42 | - `client` - files to help clients trust your self-signed certificate, see the how-to-use section 43 | 44 | The script is a BASH command line script so only works on a Linux command prompt and requires OpenSSL which virtually all current versions of Linux already have installed. The script also works on the Windows 10 Ubuntu subsystem. 45 | 46 | ## Running 47 | To run the script, you need to be at a BASH command prompt and you need to supply either a domain specification or an IP address. That address will be baked into the certificate and the certificate will only be valid when used on that address: 48 | 49 | ./certs.sh 192.168.1.10 50 | 51 | This example creates a server certificate (and corresponding CA) that is valid for a server access on IP address `192.168.1.10`, the certificate would not be valid if used on `myserver.mydomain.com` for example. 52 | 53 | # How to use the output 54 | The server certificate and key can be used with any software that provides a web server. That includes Apache, NGINX, Node.JS, Python, etc. 55 | 56 | The important files are put into the `server` folder and are: 57 | 58 | - `privkey.pem` - This is the servers private key file. It **must** be kept secure on the server. 59 | - `fullchain.pem` - This is the servers certificate file. It will be sent to any connected client and does not need to be kept particularly secure. It not only contains the server certificate but also the CA certificate so that the browser is able to validate the chain. Note that the browser will still dislike the certificate until you add the CA cert to the appropriate trusted root CA store (see below). 60 | 61 | ## Using with [Node.JS](https://nodejs.org) 62 | Here is an example of the options to need to pass to the [HTTPS create server function](https://nodejs.org/dist/latest-v6.x/docs/api/https.html#https_https_createserver_options_requestlistener). Adjust according to wherever you put the server key and certificate files. 63 | 64 | const options = { 65 | key: fs.readFileSync( path.join('.', '.data', 'certs', 'server', 'privkey.pem') ), 66 | cert: fs.readFileSync( path.join('.', '.data', 'certs', 'server', 'fullchain.pem') ) 67 | }; 68 | 69 | Note that you do not need the `ca` option and that you need to use the `server/fullchain.pem` file not just the `server/cert.pem` file otherwise the certificate will not be valid. 70 | 71 | ## Using with [Node-RED](https://nodered.org) 72 | Here is an example of the code that you will need to add to your settings.js file for Node-RED. Take note of the joined paths and adjust according to where you moved the server key and certificate files to. 73 | 74 | module.exports = { 75 | ... 76 | https: { 77 | key: fs.readFileSync( path.join('.', '.data', 'certs', 'server', 'privkey.pem') ), 78 | cert: fs.readFileSync( path.join('.', '.data', 'certs', 'server', 'fullchain.pem') ) 79 | }, 80 | .... 81 | } 82 | 83 | ## Using on a Windows client 84 | To get rid of any browser warnings, you must load the CA certificate into a position of trust. 85 | 86 | Copy the file `client/my-private-root-ca.crt` to the Windows PC. Right-click and choose `Install Certificate`. Choose whether you want this for just the current user or for all users of this PC (Local Machine, You will need local admin rights for this). On the next stage, choose "Place all certificates in the following store" and click the browse button. Choose "Trusted Root Certification Authorities" and click OK. Continuing should result in a message that the certificate as been successfully installed. 87 | 88 | Restart your browser and any certificate errors when connecting to your server should now have gone away. This works for Edge, Internet Explorer and Chrome. 89 | 90 | Firefox has its own certificate store. It is also the only browser where you can add a permanent exception to certificate warnings. But if you want to fix it properly, Go to Options, Advanced, Certificates. Click on View Certificates, Import. Select "Trust this CA to identify web sites". You will at least need to open a new tab if you already had the site open. 91 | 92 | ## Using on mobile client devices 93 | Firstly, you will need to make the root CA certificate available. You can either drop it in an email to yourself or serve it via a convenient web server, or put it in cloud storage. As you are only making the certificate available (which can be public), it doesn't matter if someone else gets hold of it. 94 | 95 | ...tbc... 96 | 97 | ## Other uses 98 | Although this has focused on using the certificate/key for HTTPS. It is possible to use the same details for other purposes such as encrypting emails or files and signing code. 99 | 100 | For example, there is a server public key file in the `client` folder. This can be used with appropriate software (*need ref*) to encrypt data that the server could decrypt or visa versa. 101 | 102 | ## Reusing the CA 103 | If you keep the CA folder and contents safe, you can reuse the files when creating new server certificates in the future. Simply put the folder and contents back under the script files location and comment out the lines that relate to creating the CA details. 104 | 105 | # Security 106 | It is very important that the files in the CA folder are kept totally secure. If they are compromised, all of the certificates that have been signed by the CA cert will be suspect and will have to be replaced. 107 | 108 | Similarly, any private key file absolutely must be kept secure or will be considered compromised. 109 | 110 | # License 111 | This code is Open Source under an Apache 2 License. Please see the LICENSE file for details. 112 | 113 | You may not use this code except in compliance with the License. You may obtain an original copy of the License at 114 | 115 | http://www.apache.org/licenses/LICENSE-2.0 116 | 117 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Please see the License for the specific language governing permissions and limitations under the License. 118 | 119 | # Author 120 | [Julian Knight](https://uk.linkedin.com/in/julianknight2/) ([Totally Information](https://www.totallyinformation.com)), https://github.com/totallyinformation 121 | 122 | # Feedback and Support 123 | Please report any issues or suggestions via the [Github Issues list for this repository](https://github.com/TotallyInformation/SelfSigned-Cert-Creator/issues). 124 | -------------------------------------------------------------------------------- /certs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Create self-signed certificates and keys for a CA and a server 4 | # Primarily for using with SSL/TLS to secure communications 5 | # between local servers and clients NOT ON THE INTERNET! 6 | # 7 | # Inspired by: https://github.com/Daplie/nodejs-self-signed-certificate-example/blob/master/make-root-ca-and-certificates.sh 8 | # 9 | # Use as: bash make-certs.sh 'localhost.daplie.com' 10 | # 11 | # Author: Julian Knight, Totally Information, 2016-11-05 12 | # Updates: 13 | # v1.1 2017-12-08: JK change to add SAN as now required by Chrome 14 | # License: MIT, may be freely reused. 15 | 16 | function create_ca { 17 | # ------------------- CA -------------------- # 18 | # You can reuse CA certs, no need to recreate # 19 | # unless they are compromised # 20 | # ------------------------------------------- # 21 | 22 | # Create/update the ca/ca.cnf file 23 | create_ca_cnf 24 | 25 | # We need the ca.cnf file in order to create the CA cert 26 | if [ ! -f ca/ca.cnf ]; then 27 | echo " " 28 | echo "ERROR in create_ca() - STOPPING" 29 | echo " The ca/ca.cnf file does not exist." 30 | echo " Please ensure the cnf setup function has been run." 31 | echo " " 32 | exit 1 33 | fi 34 | 35 | echo " " 36 | echo "Creating Root Certificate Authority private key" 37 | openssl genrsa \ 38 | -out ca/my-private-root-ca.privkey.pem \ 39 | 2048 40 | 41 | echo " " 42 | echo "Creating the Self-signed Root Certificate Authority certificate" 43 | # Since this is private, the details can be as bogus as you like 44 | openssl req \ 45 | -x509 \ 46 | -new \ 47 | -nodes \ 48 | -days 9999 \ 49 | -outform PEM \ 50 | -key ca/my-private-root-ca.privkey.pem \ 51 | -out ca/my-private-root-ca.cert.pem \ 52 | -config ca/ca.cnf 53 | 54 | # Create CRT format copy for Windows use if needed 55 | openssl x509 -in ca/my-private-root-ca.cert.pem -out ca/my-private-root-ca.cert.crt 56 | 57 | echo " " 58 | echo "Import ca/my-private-root-ca.cert.crt to Windows Trusted Root store if required" 59 | echo " or use load-trusted-root.ps1" 60 | } 61 | 62 | function create_srv { 63 | # ------------- Server ------------- # 64 | # Need one of these for each server # 65 | # where you want different certs # 66 | # ---------------------------------- # 67 | 68 | # Create/update the ./ssl.cnf file 69 | create_ssl_cnf 70 | 71 | # We need the ./ssl.cnf file in order to create the CA cert 72 | if [ ! -f ./ssl.cnf ]; then 73 | echo " " 74 | echo "ERROR in create_srv() - STOPPING" 75 | echo " The ./ssl.cnf file does not exist." 76 | echo " Please ensure the create_cnf function has been run." 77 | echo " " 78 | exit 1 79 | fi 80 | 81 | # We need the ca/ca.cnf file in order to sign the server cert request 82 | if [ ! -f ca/ca.cnf ]; then 83 | echo " " 84 | echo "ERROR in create_srv() - STOPPING" 85 | echo " The ca/ca.cnf file does not exist." 86 | echo " Please ensure the create_cnf function has been run." 87 | echo " " 88 | exit 1 89 | fi 90 | 91 | # We need the CA private key and certificate files in order to create a server certificate 92 | if [ ! \( -f ca/my-private-root-ca.cert.pem -a -f ca/my-private-root-ca.privkey.pem \) ]; then 93 | echo " " 94 | echo "ERROR in create_srv() - STOPPING" 95 | echo " The CA private key and/or certificate files are missing." 96 | echo " Please ensure the create_ca function has been run." 97 | echo " " 98 | exit 1 99 | fi 100 | 101 | echo " " 102 | echo "Creating a Server Private Key - KEEP THIS SECURE ON THE SERVER!" 103 | echo " It is required for the server to use SSL or TLS." 104 | openssl genrsa \ 105 | -out server/privkey.pem \ 106 | 2048 107 | 108 | echo " " 109 | echo "Creating a temp request (CSR) from your Server, which your Root CA will sign" 110 | # 1 for each domain such as 192.168.1.167, example.com, *.example.com, awesome.example.com 111 | # NOTE: You MUST match CN to the domain name or ip address you want to use 112 | # Multi-domain certs require the use of a configuration file and SubjectAltName 113 | openssl req -new -sha256 \ 114 | -key server/privkey.pem \ 115 | -out tmp/csr.pem \ 116 | -config ./ssl.cnf 117 | 118 | echo " " 119 | echo "Signing the server request with your Root CA, creates the actual server cert" 120 | openssl x509 \ 121 | -CAcreateserial -req \ 122 | -extfile v3ext.cnf \ 123 | -in tmp/csr.pem \ 124 | -CA ca/my-private-root-ca.cert.pem \ 125 | -CAkey ca/my-private-root-ca.privkey.pem \ 126 | -out server/cert.pem \ 127 | -outform PEM \ 128 | -days 9999 129 | #openssl ca -config ./ssl.cnf \ 130 | # -extensions server_cert -days 9999 -notext -md sha256 \ 131 | # -in tmp/csr.pem \ 132 | # -out server/cert.pem 133 | # NOTE use of -extfile here, it appears to be the only successful 134 | # way to pass in the x509 extension parameters without using 135 | # the ca function instead of the x509 one. 136 | 137 | echo " " 138 | echo "Creating a combined pfx file for convenience" 139 | openssl pkcs12 -export \ 140 | -certfile ca/my-private-root-ca.cert.pem \ 141 | -inkey server/privkey.pem \ 142 | -in server/cert.pem \ 143 | -out server/cert.pfx \ 144 | -name "Self-Signed Server Certificate" 145 | 146 | #echo " " 147 | #echo "Copying root ca cert to server as chain.pem" 148 | #echo " This is only required if NOT using the fullchain certificate." 149 | #rsync -a ca/my-private-root-ca.cert.pem server/chain.pem 150 | 151 | echo " " 152 | echo "Creating a server full chain cert for SSL/TLS use" 153 | echo " Using fullchain removes the need to include the ca parameter in server settings." 154 | cat server/cert.pem ca/my-private-root-ca.cert.pem > server/fullchain.pem 155 | 156 | echo " " 157 | echo "Use in Node.JS as: sslOpts = { key: 'server/privkey.pem', cert: 'server/fullchain.pem' }" 158 | echo " as this is self-signed, use of ca opt isn't required as it is included in the chain" 159 | 160 | } 161 | 162 | function create_client { 163 | # -------------- Client -------------- # 164 | # Need one of these for each client # 165 | # you want to authenticate to a server # 166 | # ------------------------------------ # 167 | 168 | # We need the ./ssl.cnf file in order to create the CA cert 169 | if [ ! -f ./ssl.cnf ]; then 170 | echo " " 171 | echo "ERROR - STOPPING" 172 | echo " The ./ssl.cnf file does not exist." 173 | echo " Please ensure the create_cnf function has been run." 174 | echo " " 175 | exit 1 176 | fi 177 | 178 | # We need the CA certificate 179 | if [ ! -f ca/my-private-root-ca.cert.pem ]; then 180 | echo " " 181 | echo "ERROR - STOPPING" 182 | echo " The CA certificate file is missing." 183 | echo " Please ensure the create_ca function has been run." 184 | echo " " 185 | exit 1 186 | fi 187 | 188 | # We need the SERVER private key 189 | if [ ! -f server/privkey.pem ]; then 190 | echo " " 191 | echo "ERROR - STOPPING" 192 | echo " A SERVER private key is needed." 193 | echo " Please ensure the create_srv function has been run." 194 | echo " " 195 | exit 1 196 | fi 197 | 198 | #echo " " 199 | #echo "Copying root ca cert to client folder as chain.pem" 200 | #echo " This is only required if NOT using the fullchain certificate." 201 | #rsync -a ca/my-private-root-ca.cert.pem client/chain.pem 202 | 203 | echo " " 204 | echo "Create a public key to match an existing server." 205 | echo " In case you want a client to be able to encrypt messages to this server." 206 | echo " Not required for simply accessing SSL/TLS web pages" 207 | openssl rsa -pubout \ 208 | -in server/privkey.pem \ 209 | -out client/server-pubkey.pem 210 | 211 | echo " " 212 | echo "Create DER format crt file for iOS Mobile Safari, etc" 213 | openssl x509 \ 214 | -outform der \ 215 | -in ca/my-private-root-ca.cert.pem \ 216 | -out client/my-private-root-ca.crt 217 | } 218 | 219 | function create_ca_cnf { 220 | # This is the configuration file for creatin a CA root certificate 221 | 222 | echo " " 223 | echo "Creating CA OpenSSL configuration file for certificate creation" 224 | 225 | # Required as this is the only way to add SubjectAltName fields which are now required 226 | # by Chrome. 227 | cat >ca/ca.cnf <./ssl.cnf <./v3ext.cnf <