When it comes to use SSL over apache, OpenSSL is there for us to do everything we want. XAMPP and WAMP both comes with OpenSSL compiled version of Apache, so it becomes quite handy to use it. But how to get SSL certificate for your website?For getting SSL certificate you need to ask your hosting company if you are running on shared server and don't have access to apache installation directory and config files. Most of the hosting companies will do this for you with some amount of fee. Fee/cost depends on the kind of certificate you are requesting and for the period of time. For example www.domain.com certificates will be quite cheaper then *.domain.com.
Now if you are running and managing your own webserver and you have to get certificate(s) for your company/client or your own website then first requirement is to generate "Certificate Signing Request" - CSR file, which you need to send to Certificate Authority to sign and give back to you as CRT file. This tutorial is not meant for Apache expert but for those who have not much experience SSL and Apache stuff.
Generation of CSR files with Apache on OpenSSL is quite simple and it is matter of typing few commands and we are done. You need to follow similar commands on OpenSSL prompt whether you are running Apache over Windows or Linux. Here is the routine which we need to follow to get our .CSR file ready.
If you have your Apache setup ready with OpenSSL then goto BIN directory under your Apache's installation directory. If you are on Windows machine then it could be under D:\Program Files\Apache\bin and if it is Linux you know better where to find it. Open Command Prompt and goto Apache's BIN directory and then type "openssl" over there. You will get OpenSSL prompt immediately. You may need not to goto Apache/Bin directory if that path is set in your system variables, you can just type openssl and you will get the prompt like below.
Now, first of all we need to generate RSA Private key for our server. This key will be Triple-DES encrypted and PEM formatted. Type in following command to get encrypted private key on OpenSSL prompt.
OpenSSL genrsa -des3 -out digitss.key 1024
You can keep it my_server.key or something like that. Once you type in above command it will ask for pass-phrase, please keep a note of that pass-phrase at some secure place. Also, take backup of your private key file at some secure place. Here is the screen-shot(s) visualizing above command over windows command-line.
If you will try to see contents of that file it would look something similar to what I have got here.
To see something which is more readable type in following line and it will ask you pass-phrase which you previously specified.
OpenSSL rsa -noout -text -in digitss.key Enter pass phrase for digitss.key: Private-Key: (1024 bit) modulus: 00:c6:54:39:f5:c5:ae:5a:ef:f5:53:9c:13:c9:86: 27:c5:19:9f:25:ab:a5:96:5a:2e:f3:c0:5b:b0:c5: 02:a6:e0:53:a8:fa:34:e1:8f:55:b4:ee:57:e3:54: 65:70:6a:f0:0c:4d:b1:ed:9f:31:38:51:3c:e1:99: fe:82:6c:0d:3d:a5:d3:6e:01:8c:89:cc:f1:97:c0: 95:0e:80:1a:c7:0a:ac:56:15:27:cd:08:32:e0:2c: 39:00:77:2f:d1:83:4f:2e:ff:ea:50:fb:26:6c:fd: dd:ea:38:3b:ec:c0:f7:d3:c6:c2:23:20:12:40:bf: 1b:94:59:d8:d6:34:8d:7c:dd publicExponent: 65537 (0x10001) privateExponent: 23:5b:b8:c9:9c:68:ad:45:c2:93:19:6c:5d:ad:51: 31:ce:83:95:0f:b9:01:c9:2a:3d:c2:b9:96:16:49: 96:be:bf:ab:8c:90:08:f6:a8:ed:0c:e1:16:62:61: 83:5d:4d:56:a4:33:68:8d:cd:14:a1:47:1d:61:7b: 02:7d:89:0e:77:f9:0b:b9:89:02:a5:e1:0a:ba:66: f2:25:dc:06:7e:74:b2:c7:6a:be:1a:e1:6f:fb:b7: e2:2d:b5:f2:ca:a8:ec:27:9e:81:25:7e:8a:2d:6c: 94:6f:f5:ca:f3:4e:bc:3d:1e:e9:5d:74:47:59:8c: f7:29:d8:8e:9c:d2:e0:01 prime1: 00:f4:85:25:2e:6c:02:79:02:58:c9:ec:29:a8:11: 33:9e:db:bf:84:0a:a2:87:f9:2b:82:f5:a0:04:59: 69:bb:f7:d3:6a:d8:ee:6d:74:0e:bb:62:01:8e:bf: 5f:85:d8:3d:de:e9:12:86:c9:20:de:7c:cf:4c:f2: 6a:1b:40:e2:01 prime2: 00:cf:a3:ea:a4:39:10:6c:4e:3c:58:b1:8e:f0:17: 33:ea:1f:9d:0c:be:0a:bd:3b:d5:80:76:70:e3:e4: 54:4f:1a:8f:8a:ab:00:d5:64:e6:8a:e7:24:12:2b: 3e:97:b9:24:96:b5:f4:31:eb:ae:6d:fa:83:b2:32: 92:8b:06:62:dd exponent1: 00:b4:40:d2:bf:fd:ef:74:b5:3e:2e:dc:61:78:fc: 34:77:9f:16:f7:87:bf:78:ed:3e:1e:34:63:d9:d0: f0:19:19:00:49:6b:d1:97:ee:4e:4d:e4:59:b1:99: 72:19:80:e7:5b:44:05:dc:46:b8:6c:4b:25:a6:5b: ad:cc:99:70:01 exponent2: 00:b8:a7:83:41:ec:65:88:8b:c2:ea:f5:6c:b2:63: 33:98:9f:e8:a0:ae:59:0a:94:ad:78:02:dc:be:2e: 3e:34:12:e0:d8:66:de:e4:e7:48:86:fa:ab:7f:64: e9:d3:30:19:33:d6:38:86:34:9b:f8:be:32:64:44: c9:41:cd:ba:19 coefficient: 7c:9a:fa:80:72:8a:74:11:7b:f0:32:d0:e4:b3:44: cd:d4:2c:4e:6b:37:38:68:9a:6e:cd:ae:f0:9f:54: 31:a5:f6:f7:c8:16:f3:1a:4a:5c:d3:6b:60:a1:7d: f5:a2:6c:b2:ab:12:1d:1c:5c:dd:63:57:d5:c0:be: a3:d1:37:67 OpenSSL
Although it is hardly readable but makes more sense then previous screenshot.
Later on we need to specify path of this file in our httpd-ssl.conf when we get CRT file signed by Authority and we are setting up SSL over our webserver. It is required to have unsecured version of this file as with Windows Apache + OpenSSL setup it's not possible to specify "pass-phrase" (which we have given earlier) and it will give some weired error while setting up SSL and apache will refuse to start and generate errors in log for that.
So to get Unsecured version of this file type following command:
OpenSSL rsa -in digitss.key -out unsecured.digitss.key Enter pass phrase for digitss.key: writing RSA key OpenSSL
Here, digitss.key is the file which we have previously generated and it is encrypted (3-DES), and -out file is the one which will be generated based on our request in non-encrypted form. During this process it will ask for pass-phrase as usual.
Now let's move to final step which is generation of CSR file using RSA private key. Following command will generate Certificate Signing Request file for us which will be PEM formatted. Key in following command:
OpenSSL req -new -key digitss.key -out digitss.csr
If you are running over Windows then probably you will get error which I have faced during this. It would be something similar to following:
OpenSSL req -new -key digitss.key -out digitss.csr
Unable to load config info from /usr/local/ssl/openssl.cnf
In that case we need to specify one more parameter in this command and we are done.
OpenSSL req -new -key digitss.key -out digitss.csr -config openssl.cnf
Here, in this command we are making request for generation of CSR file with our private key generated previously and here we have specified configuration file as "openssl.cnf" as one more parameter. If this file doesn't exist in apache/bin directory then either move it there or specify full path. After keying in above command it will prompt you with few parameters/questions and that's it we are done.
Here is the list of question you need to answer as in you type above command to generate CSR file. Provided for your reference just as an example.
OpenSSL req -new -key digitss.key -out digitss.csr -config openssl.cnf Enter pass phrase for digitss.key: You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:US State or Province Name (full name) [Some-State]:Newyork Locality Name (eg, city) []:Bellrose Organization Name (eg, company) [Internet Widgits Pty Ltd]:DiGiTSS Inc Organizational Unit Name (eg, section) []:DiGiTSS Common Name (eg, YOUR name) []:www.digitss.com Email Address []:dharmavir@digitss.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:password An optional company name []:blogs@DiGiTSS OpenSSL
We are almost done, now we need to send this generated CSR file to a Certifying Authority (CA) for signing, they will send back us Real Certificate CRT file with the help of which we can setup SSL over our webserver running Apache and OpenSSL. We can either send it to Verisign, Thawte Consulting, CertiSign Certificadora Digital Ltd or GoDaddy.
Please note that I have used all commands on Linux server as well and they will work same as they they work on Windows.
For more advance options or more help you can refer to www.modssl.org's FAQ section.
Have your comments on this post.
Similar Posts:
- Generating 2048-bit CSR with OpenSSL
- RSA server certificate CommonName (CN) does NOT match server name!?
- mod_proxy & mod_vhost_alias to host multiple domains on Web-Server and running Apache+IIS together
- PHP – Downloading a File from Secure website (https) using CURL
- Beginner’s Resources for PHP-MySQL Development
#1 by Madhav vyas on August 11, 2008 - 5:15 pm
Quote
Great,
Really very useful to developer…
Thanks
Dharmavir
#2 by sandeep on February 16, 2009 - 3:49 pm
Quote
Hi,
What if i am not having any domain name or Common Name (eg, YOUR name), but still i want to generate CSR for my http://localhost:8080 and test it locally. How can I do this?
thanks
Sandeep
#3 by Dharmavirsinh Jhala on February 18, 2009 - 2:07 am
Quote
Hi Sandeep,
Then it will be called self signed test certificate.
But as far as I know you need SSL for HTTPS:// and default port is 443.
If you are using XAMPP then it comes with self-signed sample Certificates.
You can find "makecert.bat" file under [X]:xamppapache directory which can generate Certificate for you with your own domain.key and domain.csr files.
But in short the answer is YES you can have self-signed SSL certificates for your LOCALHOST.
Let me know if there are any questions, where I can help.
Ref URL: http://www.apachefriends.org/en/xampp.html
#4 by Ex Girlfiend on April 9, 2009 - 6:55 pm
Quote
This is quite a up-to-date information. I think I'll share it on Facebook.
#5 by birco on May 7, 2009 - 2:51 pm
Quote
Hey, i'm having trouble using this command:
req -new -key digitss.key -out digitss.csr -config openssl.cnf
When i do I get the following error:
error on line -1 of openssl.cnf
3900:error:02001002:system library:fopen:no such file or directory:.cryptoioss_file.c:122:fopen('openssl.cnf','rb')
3900:error:2006d080:BIO routines:BIO_new_file:no such file:.cryptoioss_file.c:125:
3900:error:0e078072:configuration file routines:DEF_LOAD:no such file:.cryptoconfconf_def.c:197:
error in req
Any help would be greatly appreciated
Birco
#6 by birco on May 7, 2009 - 2:57 pm
Quote
Nevermind, my mistake… that'll teach me to skim over the instructions, I missed the part where it said to make a copy of openssl.cnf into the bin dir
#7 by Newbie on October 21, 2009 - 2:01 am
Quote
When i run the given below command i get an error
req -new -key digitss.key -out digitss.csr -config openssl.cnf
The error that i got is
"unable to load Private Key
3720:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:.cryptoevpevp_enc.c:461:
3720:error:0906A065:PEM routines:PEM_do_header:bad decrypt:.cryptopempem_lib.c:425:
error in req"
#8 by Brian Jester on October 21, 2009 - 6:42 am
Quote
Thank you for the info on the unsecured version of the server key file on Windows Apache.
Pingback: Generating 2048-bit CSR with OpenSSL | BLOGS@DiGiTSS
#9 by Robert Galea on October 26, 2010 - 12:18 am
Quote
Were is the CSR file located?
#10 by Dharmavirsinh Jhala on October 27, 2010 - 9:18 am
Quote
Robert file will be under your apache/bin directory by default unless we specify different location.
In any command based operation if you don't specify it will refer to current location/directory only.
#11 by Ben Lake on November 18, 2010 - 9:08 pm
Quote
Very nice tutorial, probably the best ive seen.
I have a question that you may be able to help me with.
I have setup a certificate using openssl and i need to generate a new csr however openssl in returning the following:
Warning: Cannot open config file: d: estopenssl1098iopenssl.cnf
I know this is an error meaning the file cannot be found but i have no idea how to administer openssl and the openssl.cnf file does not seem to be located on the server anymore. Further more to root provided above does not exist as i only have a single C: drive, so im not sure where that root has appeared from. Any help would be greatly appreciated
Thanks Ben
#12 by Dharmavirsinh Jhala on November 19, 2010 - 12:08 am
Quote
Hi Ben,
It's highly possible that your setup might not have that file around somehow.
Now you should try downloading XAMPP from following URL and then give it a try. http://www.apachefriends.org/en/xampp-windows.htm…
You can download sample openssl.cnf file from following location and give it a quick try. http://blogs.digitss.com/archives/openssl.cnf
If it does not work just download xampp and follow step you should be through.
Let me know if it does not help.
#13 by Steve Sorell on January 22, 2011 - 10:18 am
Quote
I have used this tutorial to create my csr but I dont understand how I can get the csr submitted or what I need to do to submit is as in thawte and veri sign it has a cut and paste window so what do I need to put here or how do I submit it. also is their anyway I can open and read the csr.
#14 by Dharmavirsinh Jhala on January 22, 2011 - 2:06 pm
Quote
Steve,
You can to submit this CSR file to Certificate Signing Authority like GoDaddy, VeriSign, thawte and many others, if you already have site hosted with some hosting company they can help you out getting SSL Certificate from CSR.
Let me know if this does not help.
#15 by Steve Sorell on January 22, 2011 - 6:55 pm
Quote
So if I am understanding you then it is the file that is submitted rather then pasting the information in.
#16 by Dharmavirsinh Jhala on January 23, 2011 - 10:35 am
Quote
Yes you are correct. We gotta submit CSR file to CSA (Certificate Signing Authority)
#17 by Steve Sorell on January 22, 2011 - 7:20 pm
Quote
This help I have gotten it submitted and received my certificate. Thanks for your comments and help and for an excellent tutorial on where and how to set up the CSR
#18 by Colin on March 27, 2011 - 6:25 am
Quote
Hi im trying to follow this tutorial also and i would like to know if im able to be my own CA perfoming the following here :http://www.davidpashley.com/articles/cert-authority.html
Is this possible?
I keep reciving the following error :
OpenSSL> req -nodes -config c:openssl-w64inopenssl.cnf -days 1825 -x509 -newkey rsa:10
24 -out c:openssl-win64inCApublic
oot.pem -outform PEM
error on line -1 of c:openssl-w64inopenssl.cnf
7932:error:02001003:system library:fopen:No such process:.cryptoioss_file.c:169:fopen
('c:openssl-w64inopenssl.cnf','rb')
7932:error:2006D080:BIO routines:BIO_new_file:no such file:.cryptoioss_file.c:172:
7932:error:0E078072:configuration file routines:DEF_LOAD:no such file:.cryptoconfconf_d
ef.c:197:
error in req
Dose anyone know what i am doing wrong?
#19 by ajay on August 7, 2011 - 4:04 pm
Quote
it is good . good article easy to understand
thanks.
#20 by waqas on November 2, 2011 - 1:08 am
Quote
hi ..
in the last step when i put all the information i get this error …..
1448:error:04075070:rsa routines:RSA_sign:digest too big for rsa key:.crypto
s
a
sa_sign.c:126:
1448:error:0D0C3006:asn1 encoding routines:ASN1_item_sign:EVP lib:.cryptoasn1
a_sign.c:281:
plzz help