go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Create Your Own Root CA (Certificate Authority)
 
Subject: Create Your Own Root CA (Certificate Authority)
Author: authen
In response to: Modify Configuration File Openssl.cnf Accordingly
Posted on: 03/07/2008 03:42:35 PM

Create your CA's private key:

C:\OpenSSL\myCA>openssl genrsa -des3 -out cakey.pem 2048

Loading 'screen' into random state - done
Generating RSA private key, 2048 bit long modulus
..........+++
...................................................................+++
e is 65537 (0x10001)
Enter pass phrase for cakey.pem:<passphrase>
Verifying - Enter pass phrase for cakey.pem:<passphrase>


The private key is in 2048 bits and placed in file 'cakey.pem' which is encrypted in des3 with your input passphrase. Keep this file in a safe place like a floppy disk. Here is what the key looks like:
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,53AEF89F96AEF2DC

ry0oa6dR/5S2wXnwhJUJvNzDEywbyW5M+qE59aMHiItp6zJqVVqQ/qzL/zZKkT89
KkNm9IE6mMGniJg9gcJJGgu+8rOEEP2Iptt91WrQfKPNMk4l877RXhOhOrTR3e7A
1SGINbC5fmC2QUDVWnw9WDRFxajkMmc2Q5bftFXcAoMjzFbSHdxEi5Zo44WZnD16
tx+r30dqljNmAvlXA47LERy2wjCZrXvdfVP2fEScTg1XJi+lf5FX9AfPyzXSYrfd
1/egRAJ50vy0Pf7Wz5p3TmWgXHsDgUGt23VrPlEU5y1gjw4/3e8biJWwmNMesSVC
x/tJRsb9g1m9JXrK8evFS6zlBC1kfXz5DjerCA8Q5hXyOAVJO2bN+VTiu00xaYIU
SzEOLBWCa/XA82cXFLUpNhN1lxbWzT3IByyFLJ7QXXWVcPNIPzQqxblczYOYBapS
qiao71xdAhKPbMYQwl/oTTudBf9tyxlkPWsQcrSLMRaocQzJzn+9ZOqXzIfBWAD6
ovYcjGsQZTp+jiWkxdoyOQ1JSZfw0L7NpLerRkB5UuRlpqUHvh+duhuXNXQC2rIU
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, owha?


Generate your CA's certificate (public key):

Since A root CA's certificate is always a self-signed certificate, you can sign the CSR (certificate Sign Request) with the CA's private key.
C:\OpenSSL\myCA>openssl req -new -x509 -key cakey.pem \
-out cacert.pem -days 3650

Enter pass phrase for cakey.pem:<passphrase>
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]:California
Locality Name (eg, city) []:San Francisco
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Open CA
Organizational Unit Name (eg, section) []:Open CA
Common Name (eg, YOUR name) []:My Root CA
Email Address []:


Your root CA's certificate is valid for 3650 days and is placed in file 'cacert.pem'. The certificate looks like this (in file):
-----BEGIN CERTIFICATE-----
MIIEQjCCAyqgAwIBAgIJAPZFB8IV4uO/MA0GCSqGSIb3DQEBBQUAMHMxCzAJBgNV
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
c2NvMRAwDgYDVQQKEwdPcGVuIENBMRAwDgYDVQQLEwdPcGVuIENBMRMwEQYDVQQD
EwpNeSBSb290IENBMB4XDTA4MDMwNjAyMjMyMloXDTE4MDMwNDAyMjMyMlowczEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xEDAOBgNVBAoTB09wZW4gQ0ExEDAOBgNVBAsTB09wZW4gQ0ExEzAR
BgNVBAMTCk15IFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
AQC0ZkgO33sedYRMyXlbQf6HNVN5QPceR1hO0EfrRFgjUSENVH815EjnpsVAALzr
uDx6b+IP0+Z4PUQQrn0Cr9HS+3aS4c3Wfa+c+706bNDRzuxcFpUUXTEkAZ+5mKrk
UkSzUMROVz57Wk+SpHSuN/lNuuqBD30WrmuS5lB2YB5vsaySaXynbT7aDiELqwU1
37+kaS/86KQZo1k7VafyQk/Qs5ymhj1rO33++AgstGcZ2HxmM+anT7ekAPCpp+7A
/qa/zVLVBu5ItP4o9rAsFW8Wg0MVsUW7p4WqLB5pUfC0Op9fgFYcbGyGof3HHrjh
WHBtz4T0LwGA95lPImL/oLuBAgMBAAGjgdgwgdUwHQYDVR0OBBYEFBjex/BEYHmd
tDfc7C10VJ8ylkS4MIGlBgNVHSMEgZ0wgZqAFBjex/BEYHmdtDfc7C10VJ8ylkS4
oXekdTBzMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UE
BxMNU2FuIEZyYW5jaXNjbzEQMA4GA1UEChMHT3BlbiBDQTEQMA4GA1UECxMHT3Bl
biBDQTETMBEGA1UEAxMKTXkgUm9vdCBDQYIJAPZFB8IV4uO/MAwGA1UdEwQFMAMB
Af8wDQYJKoZIhvcNAQEFBQADggEBABl87rPX4IZ4ccXQUhnjohyphhY8pr7Ij///
3IYfIE+lSMSehED8jgiFrxwIeY4RMZY3emhvc5XJ6AfetAPljMC4FFxL4kGPM21Q
hDdgJumpWxIV12gsN7Clt1f2ZhP4xuDMCVq8igccQzkorgocX4AszvBnv0PIDRT8
5GL8T3cojI0bEdU4oZr/GKn5Sx2a5gy89SiruAxNZXf9XoyH2IszKmTOq3mDC5Dw
dQAqiA8FYE6abXGCHd4HOB/MZBkLIlNHB+lAW9XxUKo6x44P70TaMmzLFkneyJCj
/o1UbYI1WOU41PeFTjucnwVMjyutbbsH/ZJK5Lf5oxjDcip+zJ0=
-----END CERTIFICATE-----


Still very cute. If you are really wondering what's inside anyway, you can display it using x509 utility.

Display a certificate
C:\OpenSSL\myCA>openssl x509 -in cacert.pem -noout -text

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            f6:45:07:c2:15:e2:e3:bf
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=US, ST=California, L=San Francisco, O=Open CA, OU=Open CA, CN=
My Root CA
        Validity
            Not Before: Mar  6 02:23:22 2008 GMT
            Not After : Mar  4 02:23:22 2018 GMT
        Subject: C=US, ST=California, L=San Francisco, O=Open CA, OU=Open CA, CN
=My Root CA
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (2048 bit)
                Modulus (2048 bit):
                    00:b4:66:48:0e:df:7b:1e:75:84:4c:c9:79:5b:41:
                    fe:87:35:53:79:40:f7:1e:47:58:4e:d0:47:eb:44:
                    58:23:51:21:0d:54:7f:35:e4:48:e7:a6:c5:40:00:
                    bc:eb:b8:3c:7a:6f:e2:0f:d3:e6:78:3d:44:10:ae:
                    7d:02:af:d1:d2:fb:76:92:e1:cd:d6:7d:af:9c:fb:
                    bd:3a:6c:d0:d1:ce:ec:5c:16:95:14:5d:31:24:01:
                    9f:b9:98:aa:e4:52:44:b3:50:c4:4e:57:3e:7b:5a:
                    4f:92:a4:74:ae:37:f9:4d:ba:ea:81:0f:7d:16:ae:
                    6b:92:e6:50:76:60:1e:6f:b1:ac:92:69:7c:a7:6d:
                    3e:da:0e:21:0b:ab:05:35:df:bf:a4:69:2f:fc:e8:
                    a4:19:a3:59:3b:55:a7:f2:42:4f:d0:b3:9c:a6:86:
                    3d:6b:3b:7d:fe:f8:08:2c:b4:67:19:d8:7c:66:33:
                    e6:a7:4f:b7:a4:00:f0:a9:a7:ee:c0:fe:a6:bf:cd:
                    52:d5:06:ee:48:b4:fe:28:f6:b0:2c:15:6f:16:83:
                    43:15:b1:45:bb:a7:85:aa:2c:1e:69:51:f0:b4:3a:
                    9f:5f:80:56:1c:6c:6c:86:a1:fd:c7:1e:b8:e1:58:
                    70:6d:cf:84:f4:2f:01:80:f7:99:4f:22:62:ff:a0:
                    bb:81
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Subject Key Identifier:
                18:DE:C7:F0:44:60:79:9D:B4:37:DC:EC:2D:74:54:9F:32:96:44:B8
            X509v3 Authority Key Identifier:
                keyid:18:DE:C7:F0:44:60:79:9D:B4:37:DC:EC:2D:74:54:9F:32:96:44:B
8
                DirName:/C=US/ST=California/L=San Francisco/O=Open CA/OU=Open CA
/CN=My Root CA
                serial:F6:45:07:C2:15:E2:E3:BF

            X509v3 Basic Constraints:
                CA:TRUE
    Signature Algorithm: sha1WithRSAEncryption
        19:7c:ee:b3:d7:e0:86:78:71:c5:d0:52:19:e3:a2:1c:a9:86:
        16:3c:a6:be:c8:8f:ff:ff:dc:86:1f:20:4f:a5:48:c4:9e:84:
        40:fc:8e:08:85:af:1c:08:79:8e:11:31:96:37:7a:68:6f:73:
        95:c9:e8:07:de:b4:03:e5:8c:c0:b8:14:5c:4b:e2:41:8f:33:
        6d:50:84:37:60:26:e9:a9:5b:12:15:d7:68:2c:37:b0:a5:b7:
        57:f6:66:13:f8:c6:e0:cc:09:5a:bc:8a:07:1c:43:39:28:ae:
        0a:1c:5f:80:2c:ce:f0:67:bf:43:c8:0d:14:fc:e4:62:fc:4f:
        77:28:8c:8d:1b:11:d5:38:a1:9a:ff:18:a9:f9:4b:1d:9a:e6:
        0c:bc:f5:28:ab:b8:0c:4d:65:77:fd:5e:8c:87:d8:8b:33:2a:
        64:ce:ab:79:83:0b:90:f0:75:00:2a:88:0f:05:60:4e:9a:6d:
        71:82:1d:de:07:38:1f:cc:64:19:0b:22:53:47:07:e9:40:5b:
        d5:f1:50:aa:3a:c7:8e:0f:ef:44:da:32:6c:cb:16:49:de:c8:
        90:a3:fe:8d:54:6d:82:35:58:e5:38:d4:f7:85:4e:3b:9c:9f:
        05:4c:8f:2b:ad:6d:bb:07:fd:92:4a:e4:b7:f9:a3:18:c3:72:
        2a:7e:cc:9d


Now you have a root Certification Authority. You can sign any certificate requests and maintain a database of all certificates you have issued. Also, you can revoke any certificates and publish a Certificate Revocation List (CRL).

The big challenge left is how to make your CA, essentially your root CA's certificate, publicly aware. Before you release your certificate to public, you probably want to strip the certificate from all its text to keep only the -CERTIFICATE- section and change the file type from .pem to .cer -- just to make your certificate easier to be identified and imported on the client side.

Trim a certificate
C:\OpenSSL\myCA>openssl x509 -in cacert.pem -out cacert.cer



 

> On 03/07/2008 03:35:50 PM authen wrote:


#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#

# This definition stops the following lines choking if HOME isn't
# defined.
HOME			= .
RANDFILE		= $ENV::HOME/.rnd

# Extra OBJECT IDENTIFIER info:
#oid_file		= $ENV::HOME/.oid
oid_section		= new_oids

# To use this configuration file with the "-extfile" option of the
# "openssl x509" utility, name here the section containing the
# X.509v3 extensions to use:
# extensions		= 
# (Alternatively, use a configuration file that has only
# X.509v3 extensions in its main [= default] section.)

[ new_oids ]

# We can add new OIDs in here for use by 'ca' and 'req'.
# Add a simple OID like this:
# testoid1=1.2.3.4
# Or use config file substitution like this:
# testoid2=${testoid1}.5.6

####################################################################
[ ca ]
default_ca	= CA_default		# The default ca section

####################################################################
[ CA_default ]

dir		= ./demoCA		# Where everything is kept
certs		= $dir/certs		# Where the issued certs are kept
crl_dir		= $dir/crl		# Where the issued crl are kept
database	= $dir/index.txt	# database index file.
#unique_subject	= no			# Set to 'no' to allow creation of
					# several ctificates with same subject.
new_certs_dir	= $dir/newcerts		# default place for new certs.

certificate	= $dir/cacert.pem 	# The CA certificate
serial		= $dir/serial 		# The current serial number
crlnumber	= $dir/crlnumber	# the current crl number
					# must be commented out to leave a V1 CRL
crl		= $dir/crl.pem 		# The current CRL
private_key	= $dir/private/cakey.pem# The private key
RANDFILE	= $dir/private/.rand	# private random number file

x509_extensions	= usr_cert		# The extentions to add to the cert

# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt 	= ca_default		# Subject Name options
cert_opt 	= ca_default		# Certificate field options

# Extension copying option: use with caution.
# copy_extensions = copy

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions	= crl_ext

default_days	= 365			# how long to certify for
default_crl_days= 30			# how long before next CRL
default_md	= sha1			# which md to use.
preserve	= no			# keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy		= policy_match

# For the CA policy
[ policy_match ]
countryName		= match
stateOrProvinceName	= match
organizationName	= match
organizationalUnitName	= optional
commonName		= supplied
emailAddress		= optional

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName		= optional
stateOrProvinceName	= optional
localityName		= optional
organizationName	= optional
organizationalUnitName	= optional
commonName		= supplied
emailAddress		= optional

####################################################################
[ req ]
default_bits		= 1024
default_keyfile 	= privkey.pem
distinguished_name	= req_distinguished_name
attributes		= req_attributes
x509_extensions	= v3_ca	# The extentions to add to the self signed cert

# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret

# This sets a mask for permitted string types. There are several options. 
# default: PrintableString, T61String, BMPString.
# pkix	 : PrintableString, BMPString.
# utf8only: only UTF8Strings.
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
# WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
# so use this option with caution!
string_mask = nombstr

# req_extensions = v3_req # The extensions to add to a certificate request

[ req_distinguished_name ]
countryName			= Country Name (2 letter code)
countryName_default		= AU
countryName_min			= 2
countryName_max			= 2

stateOrProvinceName		= State or Province Name (full name)
stateOrProvinceName_default	= Some-State

localityName			= Locality Name (eg, city)

0.organizationName		= Organization Name (eg, company)
0.organizationName_default	= Internet Widgits Pty Ltd

# we can do this but it is not needed normally :-)
#1.organizationName		= Second Organization Name (eg, company)
#1.organizationName_default	= World Wide Web Pty Ltd

organizationalUnitName		= Organizational Unit Name (eg, section)
#organizationalUnitName_default	=

commonName			= Common Name (eg, YOUR name)
commonName_max			= 64

emailAddress			= Email Address
emailAddress_max		= 64

# SET-ex3			= SET extension number 3

[ req_attributes ]
challengePassword		= A challenge password
challengePassword_min		= 4
challengePassword_max		= 20

unstructuredName		= An optional company name

[ usr_cert ]

# These extensions are added when 'ca' signs a request.

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType			= server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
nsComment			= "OpenSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl		= http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

[ v3_req ]

# Extensions to add to a certificate request

basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment

[ v3_ca ]


# Extensions for a typical CA


# PKIX recommendation.

subjectKeyIdentifier=hash

authorityKeyIdentifier=keyid:always,issuer:always

# This is what PKIX recommends but some broken software chokes on critical
# extensions.
#basicConstraints = critical,CA:true
# So we do this instead.
basicConstraints = CA:true

# Key usage: this is typical for a CA certificate. However since it will
# prevent it being used as an test self-signed certificate it is best
# left out by default.
# keyUsage = cRLSign, keyCertSign

# Some might want this also
# nsCertType = sslCA, emailCA

# Include email address in subject alt name: another PKIX recommendation
# subjectAltName=email:copy
# Copy issuer details
# issuerAltName=issuer:copy

# DER hex encoding of an extension: beware experts only!
# obj=DER:02:03
# Where 'obj' is a standard or added object
# You can even override a supported extension:
# basicConstraints= critical, DER:30:03:01:01:FF

[ crl_ext ]

# CRL extensions.
# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.

# issuerAltName=issuer:copy
authorityKeyIdentifier=keyid:always,issuer:always

[ proxy_cert_ext ]
# These extensions should be added when creating a proxy certificate

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType			= server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
nsComment			= "OpenSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer:always

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl		= http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

# This really needs to be in place for it to be a proxy certificate.
proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo






References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.