<?xml version="1.0" encoding="utf-8" ?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:tt="http://teletype.in/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"><title>@pineligh</title><author><name>@pineligh</name></author><id>https://teletype.in/atom/pineligh</id><link rel="self" type="application/atom+xml" href="https://teletype.in/atom/pineligh?offset=0"></link><link rel="alternate" type="text/html" href="https://teletype.in/@pineligh?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=pineligh"></link><link rel="next" type="application/rss+xml" href="https://teletype.in/atom/pineligh?offset=10"></link><link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></link><updated>2026-05-30T16:31:22.753Z</updated><entry><id>pineligh:x509</id><link rel="alternate" type="text/html" href="https://teletype.in/@pineligh/x509?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=pineligh"></link><title>x509 certificate for server</title><published>2021-09-21T19:27:54.290Z</published><updated>2021-09-21T19:29:23.641Z</updated><summary type="html">the following describes usage of openssl for issuing CA, mCA and server certificates. </summary><content type="html">
  &lt;p id=&quot;WNrH&quot;&gt;the following describes usage of openssl for issuing CA, mCA and server certificates. &lt;/p&gt;
  &lt;p id=&quot;ASSr&quot;&gt;bin for windows &lt;a href=&quot;https://github.com/shadrunov/openssl/blob/56ec787303060c8e1eefc4541ffe63a2c2424a4a/openssl.exe&quot; target=&quot;_blank&quot;&gt;here (x64)&lt;/a&gt;&lt;/p&gt;
  &lt;h2 id=&quot;0ewb&quot;&gt;config file&lt;/h2&gt;
  &lt;p id=&quot;FpzP&quot;&gt;you need to specify some properties in &lt;u&gt;openssl.conf&lt;/u&gt;:&lt;/p&gt;
  &lt;p id=&quot;zbNm&quot;&gt;CA section:&lt;/p&gt;
  &lt;pre id=&quot;8CR3&quot; data-lang=&quot;shell&quot;&gt;[ ca ]
default_ca = CA_default

[ CA_default ]
# Directory and file locations.
dir               = # directory in double quotes
certs             = $dir
new_certs_dir     = $dir
database          = $dir\\index.txt
serial = ./serial

# The root key and root certificate.
private_key       = $dir\\rootCA.key
certificate       = $dir\\rootCA.crt

default_md        = sha256&lt;/pre&gt;
  &lt;p id=&quot;kSoP&quot;&gt;policy and request section: &lt;/p&gt;
  &lt;pre id=&quot;fyPP&quot; data-lang=&quot;shell&quot;&gt;policy = policy_match

[policy_match]
commonName = supplied

[ req ]
default_bits        = 2048
distinguished_name  = req_distinguished_name
default_md          = sha256

[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
stateOrProvinceName             = State or Province Name
localityName                    = Locality Name
organizationName                = Organization Name
organizationalUnitName          = Organizational Unit Name
commonName                      = Common Name&lt;/pre&gt;
  &lt;p id=&quot;IWVN&quot;&gt;extensions:&lt;/p&gt;
  &lt;pre id=&quot;Ek5R&quot; data-lang=&quot;bash&quot;&gt;[ v3_ca ]
basicConstraints = critical, CA:true, pathlen:1
keyUsage = critical, keyCertSign
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer

[ v3_mca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, keyCertSign
 
[ usr_cert ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = critical, keyCertSign, keyAgreement, keyEncipherment
extendedKeyUsage = clientAuth, serverAuth
subjectAltName = DNS:# domain name&lt;/pre&gt;
  &lt;h2 id=&quot;9Vjq&quot;&gt;openssl&lt;/h2&gt;
  &lt;h3 id=&quot;ihms&quot;&gt;generate root CA certificate: &lt;/h3&gt;
  &lt;pre id=&quot;kqpd&quot;&gt;set OPENSSL_CONF= # path without quotes

openssl req -config openssl.conf -newkey rsa:4096 -x509 -days 365 -passout pass:&amp;quot;qwerty&amp;quot; -extensions v3_ca -multivalue-rdn -subj /C=RU/L=City/O=Organization/OU=OU/CN=&amp;quot;rootCA&amp;quot; -keyout rootCA.key -out rootCA.pem&lt;/pre&gt;
  &lt;h3 id=&quot;XTQo&quot;&gt;generate middle CA certificate: &lt;/h3&gt;
  &lt;pre id=&quot;ET18&quot;&gt;openssl req -config openssl.conf -newkey rsa:4096 -passout pass:&amp;quot;qwerty&amp;quot; -multivalue-rdn -subj /C=RU/L=City/O=Organization/OU=OU/CN=&amp;quot;mCA&amp;quot; -keyout mCA.key -out mCA.csr

type null &amp;gt; &amp;quot;%CD%\index.txt&amp;quot;

echo 22 &amp;gt; &amp;quot;%CD%\serial&amp;quot;

openssl ca -verbose -config openssl.conf -extensions v3_mca -cert rootCA.pem -keyfile rootCA.key -days 365 -passin pass:&amp;quot;qwerty&amp;quot; -multivalue-rdn -in mCA.csr -out mCA.pem -batch &lt;/pre&gt;
  &lt;h3 id=&quot;WNUp&quot;&gt;generate server certificate:&lt;/h3&gt;
  &lt;pre id=&quot;gz6L&quot;&gt;echo 25 &amp;gt; &amp;quot;%CD%\serial&amp;quot;

openssl req -config openssl.conf -newkey rsa:4096 -passout pass:&amp;quot;qwerty&amp;quot; -multivalue-rdn -subj /C=RU/L=City/O=Organization/OU=OU/CN=&amp;quot;domain name&amp;quot; -keyout server.key -out server.csr

openssl ca -verbose -config openssl.conf -extensions usr_cert -cert mCA.pem -keyfile mCA.key -days 365 -passin pass:&amp;quot;qwerty&amp;quot; -multivalue-rdn -in server.csr -out server.p -batch&lt;/pre&gt;
  &lt;h3 id=&quot;8Rwc&quot;&gt;create chain: &lt;/h3&gt;
  &lt;p id=&quot;t9f3&quot;&gt;put server certificate in .pem file, put mCA certificate afterwards and rootCA in the end.&lt;/p&gt;
  &lt;h3 id=&quot;DGa3&quot;&gt;create private key file:&lt;/h3&gt;
  &lt;pre id=&quot;8108&quot;&gt;openssl rsa -in server.key -out plain.key&lt;/pre&gt;
  &lt;h3 id=&quot;0gOz&quot;&gt;upload chain and key to Nginx&lt;/h3&gt;
  &lt;h2 id=&quot;KwuF&quot;&gt;generating .p12 file&lt;/h2&gt;
  &lt;pre id=&quot;2FQD&quot;&gt;openssl pkcs12 -export -passin pass:&amp;quot;qwerty&amp;quot; -in server.crt -inkey server.key -chain -CAfile chain.pem -passout pass:&amp;quot;qwerty&amp;quot; -out packet.p12 &lt;/pre&gt;
  &lt;p id=&quot;fDDD&quot;&gt;chain here contains only mCA and rootCA certificates.&lt;/p&gt;
  &lt;h3 id=&quot;Yild&quot;&gt;convert crt to pem:&lt;/h3&gt;
  &lt;pre id=&quot;6p6W&quot;&gt;openssl x509 -in server.crt -out server.pem -outform PEM&lt;/pre&gt;

</content></entry></feed>