<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.saruman.biz/saruwiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=217.128.70.0%2F24</id>
	<title>SaruWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.saruman.biz/saruwiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=217.128.70.0%2F24"/>
	<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Special:Contributions/217.128.70.0/24"/>
	<updated>2026-09-08T20:56:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://www.saruman.biz/saruwiki/index.php?title=Creating_digital_certificates_with_our_root_certificate&amp;diff=2395</id>
		<title>Creating digital certificates with our root certificate</title>
		<link rel="alternate" type="text/html" href="https://www.saruman.biz/saruwiki/index.php?title=Creating_digital_certificates_with_our_root_certificate&amp;diff=2395"/>
		<updated>2009-04-29T15:17:28Z</updated>

		<summary type="html">&lt;p&gt;217.128.70.172: /* CA.sh - certificate creation made easy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Preparing for certificate creation==&lt;br /&gt;
When we&#039;re going to create certificates, we&#039;re going to use the &#039;&#039;openssl&#039;&#039; command twice:&lt;br /&gt;
* once to create a &amp;quot;certificate signing request&amp;quot;, in which we define all information to be included in the certificate, and actually generate the public and private key parts of the key pair, and&lt;br /&gt;
* once to instruct the OpenSSL package to sign the certificate with our CA root certificate.&lt;br /&gt;
The first step thus &#039;&#039;&#039;creates&#039;&#039;&#039; the actual keypair, and the second step &#039;&#039;&#039;signs&#039;&#039;&#039; the public key.&lt;br /&gt;
&lt;br /&gt;
However, we&#039;re going to need to input a lot of parameters on the &#039;&#039;openssl&#039;&#039; command line. We can make things a bit easier for us by specifying these in the &#039;&#039;openssl.cnf&#039;&#039; file, just as we have added some values when creating the CA itself. To be precise, we&#039;re going to add &#039;&#039;&#039;X.509 V3 extensions&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
By default OpenSSL generates V1 certificates, but if we&#039;re not extremely worried about offending certain ancient web browsers, we can add V3 extensions, and even make &#039;&#039;openssl&#039;&#039; do that by default. To do this, we find in &#039;&#039;openssl.cnf&#039;&#039; the following line in the section &#039;&#039;[ req ]&#039;&#039;, which is likely present but commented out:&lt;br /&gt;
 req_extensions = v3_req # The extensions to add to a certificate request&lt;br /&gt;
Simply remove the # sign in front of it, so that it appears as given above. This by default enables V3 extensions.&lt;br /&gt;
&lt;br /&gt;
Furthermore, check the section &#039;&#039;[ v3_req ]&#039;&#039;. It should look like this:&lt;br /&gt;
 [ v3_req ]&lt;br /&gt;
 &lt;br /&gt;
 # Extensions to add to a certificate request&lt;br /&gt;
 &lt;br /&gt;
 basicConstraints = CA:FALSE&lt;br /&gt;
 keyUsage = nonRepudiation, digitalSignature, keyEncipherment&lt;br /&gt;
 subjectKeyIdentifier = hash&lt;br /&gt;
What is added is the last line, with &#039;&#039;subjectKeyIdentifier&#039;&#039;; this line specifies how to identify the public key being certified, so that distinct keys used by the same subject can be differentiated (e.g. as key updating occurs, for example). Four values are possible, but the IETF Public Key Infrastructure (PKIX) working group recommends the setting &#039;&#039;subjectKeyIdentifier=hash&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Creating an SSL certificate==&lt;br /&gt;
Now we can create an SSL certificate for a web server. For the Common Name of the certificate, we need the &#039;&#039;&#039;exact&#039;&#039;&#039; name of the web server that&#039;ll offer the SSL connections. However, some servers run different websites as Virtual Hosts, so they could be running, for example, www.saruman.biz, as well as shop.saruman.biz. That might present a problem, because if the certificate is issued for www.saruman.biz, then each visitor of shop.saruman.biz will get a warning along the lines of &amp;quot;Warning: The website you&#039;re trying to visit is shop.saruman.biz, but the certificate offered is for www.saruman.biz&amp;quot;. To prevent that, we could use the wildcard character in the name of the certificate, so as to generate a certificate for *.saruman.biz.&lt;br /&gt;
&lt;br /&gt;
=== CA.sh - certificate creation made easy===&lt;br /&gt;
Since we have the &#039;&#039;openssl.cnf&#039;&#039; set up just right, and the &#039;&#039;CA.sh&#039;&#039; script primed, generating an SSL certificate is not very hard. From any old directory, run as root&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -newreq&lt;br /&gt;
This will create the signing request. The questions it&#039;ll ask, are&lt;br /&gt;
* a PEM passphrase, with which to protect the private key of the key pair. Note: you cannot generate a signing request without passphrase, so the private key you&#039;ll generate will &#039;&#039;always&#039;&#039; have a passphrase. If this is not what you want, do not despair: you can easily remove the passphrase from the private key after it&#039;s been generated (see further down). So just use a passphrase, even if you don&#039;t need one.&lt;br /&gt;
* Country/State/Locality/Organization/Organizational Unit; just as with the CA root certificate creation, these have your preprogrammed defaults that you may or may not change.&lt;br /&gt;
* Common Name; here we MUST give the DNS name of the host that is going to use the certificate, e.g. &#039;&#039;shop.saruman.biz&#039;&#039;, or &#039;&#039;*.saruman.biz&#039;&#039;.&lt;br /&gt;
* Challenge password; leave it blank, it&#039;s just to protect your signing request while en-route to the CA - but that&#039;s you anyway :-)&lt;br /&gt;
* Optional company name; leave that blank too, it&#039;s also extra information for the CA.&lt;br /&gt;
&lt;br /&gt;
Now your private key and your certificate signing request (CSR) are ready; they&#039;re called &#039;&#039;newkey.pem&#039;&#039; and &#039;&#039;newreq.pem&#039;&#039; by default, and are located in your working directory. Time to do some signing! From that same working directory, run&lt;br /&gt;
 /usr/lib/ssl/misc/CA.sh -sign&lt;br /&gt;
The script will show that it&#039;s using the config file &#039;&#039;/usr/lib/ssl/openssl.cnf&#039;&#039; (as we indeed wish), and then ask for the super-duper-secret passphrase to the CA private key (provided you&#039;ve left that in directory &#039;&#039;/etc/ssl/ca/private&#039;&#039;). Feed the script the passphrase, and it&#039;ll get to work. It&#039;ll check the request, then show you the details of the certificate you&#039;re about to sign. An example would be&lt;br /&gt;
 Certificate Details:&lt;br /&gt;
         Serial Number: 1 (0x1)&lt;br /&gt;
         Validity&lt;br /&gt;
             Not Before: Oct 27 09:34:00 2008 GMT&lt;br /&gt;
             Not After : Nov  1 09:34:00 2009 GMT&lt;br /&gt;
         Subject:&lt;br /&gt;
             countryName               = NL&lt;br /&gt;
             stateOrProvinceName       = Utrecht&lt;br /&gt;
             organizationName          = Saruman.biz&lt;br /&gt;
             organizationalUnitName    = Internet Dept.&lt;br /&gt;
             commonName                = shop.saruman.biz&lt;br /&gt;
             emailAddress              = webmaster@saruman.biz&lt;br /&gt;
         X509v3 extensions:&lt;br /&gt;
             X509v3 Basic Constraints:&lt;br /&gt;
                 CA:FALSE&lt;br /&gt;
             Netscape Comment:&lt;br /&gt;
                 OpenSSL Generated Certificate&lt;br /&gt;
             X509v3 Subject Key Identifier:&lt;br /&gt;
                 30:F2:61:80:AA:CF:1B:F0:3E:44:41:D6:38:CC:31:F0:94:28:BD:2B&lt;br /&gt;
             X509v3 Authority Key Identifier:&lt;br /&gt;
                 keyid:80:41:F8:A5:1F:C2:27:6E:CF:A9:28:8E:8A:EF:83:E7:FD:8A:D5:26&lt;br /&gt;
 &lt;br /&gt;
 Certificate is to be certified until Nov  1 09:34:00 2009 GMT (370 days)&lt;br /&gt;
 Sign the certificate? [y/n]:&lt;br /&gt;
After doing your CA duty and diligently checking all the data, just press &#039;&#039;y&#039;&#039;. The script certifies the request, and asks if it is to commit the request. This means it&#039;ll update it&#039;s own database, by saving a copy of the signed certificate in &#039;&#039;/etc/ssl/ca/newcerts&#039;&#039; named after its serial number (&#039;&#039;01.pem&#039;&#039; for this example). Furthermore the script will record the serial and ID&#039;s of the generated certificate so that the next certificate will have a new serial number. And now: hey presto! We have a &#039;&#039;newcert.pem&#039;&#039; in our working directory!&lt;br /&gt;
&lt;br /&gt;
For good measure:&lt;br /&gt;
* delete &#039;&#039;newreq.pem&#039;&#039;&lt;br /&gt;
* rename the generated private key &#039;&#039;newkey.pem&#039;&#039; to &#039;&#039;shop.saruman.biz.seckey.pem&#039;&#039;&lt;br /&gt;
* rename the generated public certificate &#039;&#039;newcert.pem&#039;&#039; to &#039;&#039;shop.saruman.biz.pem&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To remove the passphrase from the private key, use a command like this:&lt;br /&gt;
 openssl rsa -in shop.saruman.biz.seckey.key -out shop.saruman.biz.key.key&lt;br /&gt;
This will make &#039;&#039;openssl&#039;&#039; ask for your passphrase, and then create the unsecured &#039;&#039;shop.saruman.biz.key.pem&#039;&#039; key file. Best practice: ALWAYS use a passphrase-protected key, unless the application cannot support it (e.g. Postfix).&lt;br /&gt;
&lt;br /&gt;
Save the secure private key and its PEM passphrase in a safe place (e.g. Keepass database). And if you removed the passphrase from the private key, then store it in an even safer place!&lt;br /&gt;
&lt;br /&gt;
Now you can deploy your certificate. (more on that in another section).&lt;br /&gt;
&lt;br /&gt;
=== openssl - the hard way to certificate creation===&lt;br /&gt;
We don&#039;t actually need to use the &#039;&#039;CA.sh&#039;&#039; script, because we can do manually what the &#039;&#039;CA.sh&#039;&#039; script does. That gives us more control, but also more work. Let&#039;s see what we&#039;ve got to do.&lt;br /&gt;
&lt;br /&gt;
We will now perform the first step in our &amp;quot;manual&amp;quot; certificate generation: we create a signing request with all the information that we want in our SSL certificate. We run the magic incantation - note how we already&lt;br /&gt;
 openssl req -new -nodes -keyout webmail.saruman.biz.key.pem -out webmail.saruman.biz.req.pem&lt;br /&gt;
This generates a new private key (named &#039;&#039;webmail.saruman.biz.key.pem&#039;&#039;), and a new, non-encrypted (because of &#039;&#039;-nodes&#039;&#039;), key signing request named &#039;&#039;webmail.saruman.biz.req.pem&#039;&#039;. We can leave out terms like &#039;&#039;-newkey rsa:2048&#039;&#039; and &#039;&#039;-days 370&#039;&#039; since we&#039;ve put that in the configuration file. And naturally you&#039;re free to choose your own names for the keys.&lt;br /&gt;
&lt;br /&gt;
FIXME - need the full process here&lt;br /&gt;
&lt;br /&gt;
=== Validating the generated certificates===&lt;br /&gt;
Again, we can use the &#039;&#039;openssl&#039;&#039; command to validate the keys we&#039;ve generated. For instance, the &#039;&#039;CA.sh&#039;&#039; generated certificate, after renaming, is verified with&lt;br /&gt;
 openssl x509 -in shop.saruman.biz.pem -noout -purpose&lt;br /&gt;
 Certificate purposes:&lt;br /&gt;
 SSL client : Yes&lt;br /&gt;
 SSL client CA : No&lt;br /&gt;
 SSL server : Yes&lt;br /&gt;
 SSL server CA : No&lt;br /&gt;
 Netscape SSL server : Yes&lt;br /&gt;
 Netscape SSL server CA : No&lt;br /&gt;
 S/MIME signing : Yes&lt;br /&gt;
 S/MIME signing CA : No&lt;br /&gt;
 S/MIME encryption : Yes&lt;br /&gt;
 S/MIME encryption CA : No&lt;br /&gt;
 CRL signing : Yes&lt;br /&gt;
 CRL signing CA : No&lt;br /&gt;
 Any Purpose : Yes&lt;br /&gt;
 Any Purpose CA : Yes&lt;br /&gt;
 OCSP helper : Yes&lt;br /&gt;
 OCSP helper CA : No&lt;br /&gt;
Notice that the certificate is valid for everything except CA tasks.&lt;br /&gt;
&lt;br /&gt;
Likewise, using &#039;&#039;-dates&#039;&#039; instead of &#039;&#039;-purpose&#039;&#039; lets you see the validity time period, and &#039;&#039;-text&#039;&#039; gives the whole text of the certificate. Note the line marked &amp;quot;issuer&amp;quot;, and see how your own CA is referenced there.&lt;/div&gt;</summary>
		<author><name>217.128.70.172</name></author>
	</entry>
</feed>