{"id":864,"date":"2012-08-02T14:40:18","date_gmt":"2012-08-02T06:40:18","guid":{"rendered":"http:\/\/rmohan.com\/?p=864"},"modified":"2012-08-02T14:40:18","modified_gmt":"2012-08-02T06:40:18","slug":"converting-apache-ssl-certs-to-qmail","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=864","title":{"rendered":"Converting apache ssl certs to qmail"},"content":{"rendered":"<p>This is a document to help you convert your apache certs to qmail.<\/p>\n<p>Please note that the common name you used needs to match the server name in order for your clients not to get the nag screen when they send emails via SSL or TLS.<\/p>\n<p>In order to convert your apache cert, it is important to create the cert correctly. Here is how to do it:<\/p>\n<p>First, We create the key:<\/p>\n<p># openssl genrsa -out domain.xxx.key 2048<\/p>\n<p>You can substitute 2048 with 4096 for stronger encryption and make sure you replace YOURDOMAIN with your actual domain name.<\/p>\n<p>Next, We need to add a password. Go ahead and type it and confirm.<\/p>\n<p>Now create a csr:<\/p>\n<p># openssl req -new -key YOURDOMAIN.key -out YOURDOMAIN.csr<\/p>\n<p>It is important to note here to type in all information for your company. When it asks for Common Name (eg, YOUR name) []: it is VERY IMPORTANT this field matches what your users are going to use for their mailserver name. If you are buying a cert for multiple domains, this will be the domain users use the most. When viewing a cert for multiple domains, the common will appear first and the others will show on the cert.<\/p>\n<p>This is the csr you can you to generate your cert when asked by the domain you buy your cert from.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>First lets backup the current \/var\/qmail\/control folder first:<\/p>\n<p># mkdir \/var\/qmail\/backup_control<br \/>\n# cp -Rp \/var\/qmail\/control\/* \/var\/qmail\/backup_control<\/p>\n<p>Please copy the .crt, .csr and the .key to the root folder. Then run the following to make a signed cert:<\/p>\n<p># cat \/root\/cert.key &gt; \/var\/qmail\/control\/servercert.pem<br \/>\n# cat \/root\/cert.crt &gt;&gt; \/var\/qmail\/control\/servercert.pem<br \/>\n# cat \/root\/intermediate.crt &gt;&gt; \/var\/qmail\/control\/servercert.pem<\/p>\n<p>And now lets set the permissions on the servercert.pem:<\/p>\n<p># chown root:qnofiles \/var\/qmail\/control\/servercert.pem<br \/>\n# chmod 640 \/var\/qmail\/control\/servercert.pem<\/p>\n<p>Now lets create the clientcert.pem file and the permissions:<\/p>\n<p># cp \/var\/qmail\/control\/servercert.pem \/var\/qmail\/control\/clientcert.pem<br \/>\n# chown root:qmail \/var\/qmail\/control\/clientcert.pem<br \/>\n# chmod 640 \/var\/qmail\/control\/clientcert.pem<\/p>\n<p>Now restart qmail in order to make the changes take effect:<\/p>\n<p># qmailctl restart<\/p>\n<p>If you have any other services that reference the servercert.pem, you will want to restart those services as well. Such services could include smtpd-ssl and smtpd-tls (Just as an example)<\/p>\n<p>Now if you decided to run imap, You can use the following to create imap certs as well.<\/p>\n<p># cp \/var\/qmail\/control\/servercert.pem \/usr\/local\/share\/courier-imap\/imapd.pem<br \/>\n# cp \/var\/qmail\/control\/servercert.pem \/usr\/local\/share\/courier-imap\/pop3d.pem<\/p>\n<p>Now to restart the service(s)<\/p>\n<p># svc -t \/service\/courier-*<\/p>\n<p>That will restart ALL the courier- services.<\/p>\n<p>Now your customers will not get the annoying nag screen when people send mail via smtp-ssl, smtp-tls or via imap!<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>rom Qmailtoaster<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Security Certificate<\/strong><\/span><\/p>\n<p>To configure a SSL certificate for TLS and\/or SSL over SMTP:<br \/>\n1) Create a private key using the triple des encryption standard (recommended):<\/p>\n<pre># openssl genrsa -des3 -out servercert.key.enc 1024<\/pre>\n<p>2) Remove the pass phrase from the private key:<\/p>\n<pre># openssl rsa -in servercert.key.enc -out servercert.key<\/pre>\n<p>3) Generate Certificate Request<\/p>\n<pre># openssl req -new -key servercert.key -out servercert.csr<\/pre>\n<p>4) Go to <a href=\"http:\/\/www.discountwebcerts.com\/idev\/idevaffiliate.php?id=135\" rel=\"nofollow\">DiscountWebCerts<\/a> and submit servercert.csr for a trusted certificate ($19.95). You will then receive a servercert.crt. Now just do the following.<\/p>\n<p>5) Create standard .pem in \/var\/qmail\/control\/servercert.pem<\/p>\n<pre># cat servercert.key servercert.crt &gt; \/var\/qmail\/control\/servercert.pem<\/pre>\n<hr \/>\n<ul>\n<li>NOTE &#8211; For reference, here is the command to sign the request for a self signed certificate:<\/li>\n<\/ul>\n<ol>\n<li>openssl x509 -req -days 365 -in servercert.csr -signkey servercert.key -out servercert.crt<\/li>\n<\/ol>\n<p>Here is an additional resource with some good examples.<\/p>\n<p><a href=\"http:\/\/www.madboa.com\/geek\/openssl\/#cert-self\" rel=\"nofollow\">http:\/\/www.madboa.com\/geek\/openssl\/#cert-self<\/a><\/p>\n<hr \/>\n<hr \/>\n<ul>\n<li>\n<ul>\n<li>NOTE &#8211; Some certificate providers, like GoDaddy for example, will also give you a chain file (also sometimes called intermediate file), dump it into the same servercert.pem like so:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>cat \/etc\/pki\/tls\/private\/localhost.key \/etc\/pki\/tls\/certs\/localhost.crt \/etc\/pki\/tls\/certs\/intermediate.crt &gt; \/var\/qmail\/control\/servercert.pem<\/p>\n<p>This will join all three of them: The key, signed certificate and the intermediate certificate. You can use the same certificate you have obtained for your Apache website.<\/p>\n<hr \/>\n<pre># chown root:vchkpw \/var\/qmail\/control\/servercert.pem\r\n# chmod 640 \/var\/qmail\/control\/servercert.pem<\/pre>\n<p>Note, in order to avoid verification errors in email clients (i.e. Outlook, Thunderbird, etc), you need to use the same server name (FQDN) in your client configuration(s) for both incoming (pop\/imap) and outgoing (smtp) servers that was entered as the hostname when the certificate request was created. This should also be the same name that is used on the DNS MX record.<\/p>\n<p>That&#8217;s all there is to it. There is no need to restart qmail.<br \/>\nYou can also use this signed certificate for apache by putting:<\/p>\n<ul>\n<li><strong>servercert.key<\/strong> in <strong>\/etc\/pki\/tls\/private\/localhost.key<\/strong><\/li>\n<li><strong>servercert.crt<\/strong> in <strong>\/etc\/pki\/tls\/certs\/localhost.crt<\/strong><\/li>\n<\/ul>\n<p>Be sure to check your \/etc\/httpd\/conf.d\/ssl.conf file to be certain that the correct file names are specified, and that the corresponding parameters are not commented out.<\/p>\n<p>You need to restart apache to activate the modified certificate configuration.<br \/>\nSee <a href=\"http:\/\/tldp.org\/HOWTO\/SSL-RedHat-HOWTO.html\" rel=\"nofollow\">Building a Secure Redhat Apache Server HOWTO<\/a> for guidance with securing your Apache Server.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Self-signed ssl cert<\/strong> gleaned from the archives<br \/>\nQuick-n-dirty how-to for ssl certs<\/p>\n<pre># cd \/usr\/share\/ssl\/certs<\/pre>\n<pre># make stunnel.pem\r\n\r\n# mv stunnel.pem \/var\/qmail\/control\/servercert.pem<\/pre>\n<p>Then run these commands to finish:<\/p>\n<pre># cd \/var\/qmail\/control<\/pre>\n<pre># chown root:qmail \/var\/qmail\/control\/servercert.pem<\/pre>\n<pre># chmod 644 \/var\/qmail\/control\/servercert.pem<\/pre>\n<pre># ln -s \/var\/qmail\/control\/servercert.pem \/var\/qmail\/control\/clientcert.pem<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a document to help you convert your apache certs to qmail.<\/p>\n<p>Please note that the common name you used needs to match the server name in order for your clients not to get the nag screen when they send emails via SSL or TLS.<\/p>\n<p>In order to convert your apache cert, it is [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/864"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=864"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/864\/revisions"}],"predecessor-version":[{"id":865,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/864\/revisions\/865"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}