Cryptography Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.00

'OpenSSL' Signing CSR Generated by 'keytool'

Part:   1  2  3  4  5  6 

(Continued from previous part...)

"keytool" Generating Maria's CSR (Certificate Sign Request)

Maria can not use "keytool" to generate a self-signed public key certificate. But she can use "keytool" to generate CSR (Certificate Sign Request) containing her public and ask me as a CA to sign it for her. To do this, she needs to run one "keytool -certreq" command as shown below:

>keytool -certreq -alias maria_key -keypass keypass 
   -keystore maria.jks -storepass jkspass -file maria.csr

>type maria.csr
-----BEGIN NEW CERTIFICATE REQUEST-----
MIICgTCCAj4CAQAwfDELMAkGA1UEBhMCQVQxFDASBgNVBAgTC01hcmlh...
...
ah8gcsGwrIvlEJCJBra1HzsK
-----END NEW CERTIFICATE REQUEST-----

Notes on what Maria did:

  • "keytool -certreq" command is used to generated a CSR (Certificate Sign Request) based on the given key pair.
  • "-alias maria_key" option specifies the entry in the keystore file where to get the key pair.
  • "-keystore maria.jks" option specifies the keystore file.
  • "-file maria.csr" option specifies the file name where the CSR will be stored.
  • "type maria.csr" command shows the content of "maria.csr"

Normally, the distinguished name of the owner of the key pair should be asked when generating a CSR. But "keytool" has already asked and stored the distinguished name when generting the key pair.

Now Maria send her CSR file, maria.csr, to me now. I will sign her CSR file into a public key certificate as described in the next section.

"OpenSSL" Signing Maria's CSR (Certificate Sign Request)

When I got Maria's CSR (Certificate Sign Request), maria.csr, I can sign it with my CA private key with the "openssl x509 -req" command as shown in the command session below:

>openssl x509 -req -in maria.csr -CA herong.crt 
   -CAkey herong.key -out maria.crt -days 365 
   -CAcreateserial -CAserial herong.seq

Loading 'screen' into random state - done
Signature ok
subject=/C=AT/ST=Maria State/L=Maria City/O=Maria Company
/OU=Maria Unit/CN=Maria Teresa
Getting CA Private Key
Enter pass phrase for herong.key: keypass

>type maria.crt
-----BEGIN CERTIFICATE-----
MIIEGTCCAwECAQIwDQYJKoZIhvcNAQEEBQAwgZMxCzAJBgNVBAYTAkhZ...
...
k7R7Q4bN2eDWX9eiUid6VuJefLx3S1HlyVLwBlR1t4zqUZUeZxVEhqf6...
-----END CERTIFICATE-----

Cool. CSR generated by "keytool" is compatible with "OpenSSL". Here are some notes on what I did:

  • "openssl x509 -req" command signs a CSR (Certificate Sign Request) with my private key and public key certificate.
  • "-req" option specifies the entry in the keystore file where to get the key pair.
  • "-in maria.csr" option specifies the CSR file received from someone else.
  • "-CA herong.crt" option specifies my public key certificate file.
  • "-CAkey herong.key" option specifies my private key file. Password will be prompted.
  • "-days 365" option specifies that the signed certificate is good for 365 days, about 1 year.
  • "-out maria.crt" option specifies the file name to store Maria's public key certificate signed by me.
  • "-CAcreateserial" option tells "OpenSSL" to created a serial number file, if it has not been created. The serial number value will start with 1. It will be inserted into the resulting certificate.
  • "-CAserial herong.seq" option specifies the serial number file name.
  • "type maria.crt" command displays the content of "maria.crt".

Do you want to see some detail information about Maria's public key certificate? Try this command "openssl x509":

>openssl x509 -in maria.crt -noout -text

Certificate:
    Data:
        Version: 1 (0x0)
        Serial Number: 1 (0x1)
        Signature Algorithm: md5WithRSAEncryption
        Issuer: C=HY, ST=HY State, L=HY City, O=HY Company, 
OU=HY Unit, CN=Herong Yang/emailAddress=herongyang.com
        Validity
            Not Before: Apr 1:57:05 2007 GMT
            Not After : Mar 31 17:57:05 2008 GMT
        Subject: C=AT, ST=Maria State, L=Maria City, 
O=Maria Company, OU=Maria Unit, CN=Maria Teresa
        Subject Public Key Info:
            Public Key Algorithm: dsaEncryption
            DSA Public Key:
                pub:
                    0a:aa:91:a7:4e:36:39:4b:95:5e:fb:99:...
                    ... 
                    79:30:3a:fe:40:38:71:71
                P:
                    00:fd:7f:53:81:1d:75:12:29:52:df:4a:...
                    ... 
                    f2:22:03:19:9d:d1:48:01:c7
                Q:
                    00:97:60:50:8f:15:23:0b:cc:b2:92:b9:...
                    84:0b:f0:58:1c:f5
                G:
                    00:f7:e1:a0:85:d6:9b:3d:de:cb:bc:ab:...
                    ... 
                    25:64:01:4c:3b:fe:cf:49:2a
    Signature Algorithm: md5WithRSAEncryption
        00:9e:25:92:ce:33:b1:00:fc:a1:ef:b8:70:d9:97:aa:...
        ...
        fa:c0:68:6c                

The detailed information of the certificate seems to be good. The issuer is me, Herong Yang. The subject is Maria Teresa. The expiration is one year later.

What needs to happen next are:

  • I need to return the signed certificate of Maria's public key back to the Maria. She can give this certificate to other people now and tell them that it is signed by Herong Yang.
  • I need to give a copy of my CA self-signed public key certificate to Maria also. She can use my certificate to verify my signature on ker certificate.
  • Maria needs to import both certificates into her keystore file. See the next section for details.

(Continued on next part...)

Part:   1  2  3  4  5  6 

Dr. Herong Yang, updated in 2007
Cryptography Tutorials - Herong's Tutorial Notes - 'OpenSSL' Signing CSR Generated by 'keytool'