Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 . 6 Task 6 : Manually Verifying an X . 5 0 9 Certificate In this task, we will manually verify an X .

3.6 Task 6: Manually Verifying an X.509 Certificate
In this task, we will manually verify an X.509 certificate using our program. An X.509 contains data about
a public key and an issuers signature on the data. We will download a real X.509 certific
ate from a web
server, get its issuers public key, and then use this public key to verify the signature on the certificate.
Step 1: Download a certificate from a real web server. We use the www.example.org server in
this document. Students should choose a different web server that has a different certificate than the
one used in this document (it should be noted that www.example.com share the same certificate with
www.example.org). We can download certificates using browsers or use the following command:
$ openssl s_client-connect www.example.org:443-showcerts
Certificate chain
0 s:/C=US/ST=California/L=Los Angeles/O=Internet Corporation for Assigned
Names and Numbers/OU=Technology/CN=www.example.org
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 High Assurance
Server CA-----BEGIN CERTIFICATE----
MIIF8jCCBNqgAwIBAgIQDmTF+8I2reFLFyrrQceMsDANBgkqhkiG9w0BAQsFADBw
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
......
wDSiIIWIWJiJGbEeIO0TIFwEVWTOnbNl/faPXpk5IRXicapqiII=-----END CERTIFICATE----
1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 High
Assurance Server CA
i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance
EV Root CA-----BEGIN CERTIFICATE----
MIIEsTCCA5mgAwIBAgIQBOHnpNxc8vNtwCtCuF0VnzANBgkqhkiG9w0BAQsFADBs
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
......
cPUeybQ=-----END CERTIFICATE----
The result of the command contains two certificates. The subject field (the entry starting with s:) of
the certificate is www.example.org, i.e., this is www.example.orgs certificate. The issuer field (the
entry starting with i:) provides the issuers information. The subject field of the second certificate is the
same as the issuer field of the first certificate. Basically, the second certificate belongs to an intermediate
CA. In this task, we will use CAs certificate to verify a server certificate.
If you only get one certificate back using the above command, that means the certificate you get is signed
by aroot CA. Root CAs certificates can be obtained from the Firefox browser installed in our pre-built VM.
Gotothe Edit Preferences PrivacyandthenSecurity View Certificates. Search
for the name of the issuer and download its certificate.
Copy and paste each of the certificate (the text between the line containing "Begin CERTIFICATE"
and the line containing "END CERTIFICATE", including these two lines) to a file. Let us call the first one
c0.pem and the second one c1.pem.
Step 2: Extract the public key (e, n) from the issuers certificate. Openssl provides commands to
extract certain attributes from the x509 certificates. We can extract the value of n using-modulus. There
is no specific command to extract e, but we can print out all the fields and can easily find the value of e.
SEEDLabsRSAPublic-KeyEncryptionandSignatureLab 7
Formodulus(n):
$opensslx509-inc1.pem-noout-modulus
Printoutallthefields,find theexponent(e):
$opensslx509-inc1.pem-text-noout
Step3:Extractthesignaturefromtheserverscertificate. Thereisnospecificopensslcommandto
extract thesignaturefield. However,wecanprintoutall thefieldsandthencopyandpastethesignature
blockintoafile(note: ifthesignaturealgorithmusedinthecertificateisnotbasedonRSA,youcanfind
anothercertificate).
$opensslx509-inc0.pem-text-noout
...
SignatureAlgorithm:sha256WithRSAEncryption
84:a8:9a:11:a7:d8:bd:0b:26:7e:52:24:7b:b2:55:9d:ea:30:
89:51:08:87:6f:a9:ed:10:ea:5b:3e:0b:c7:2d:47:04:4e:dd:
......
5c:04:55:64:ce:9d:b3:65:fd:f6:8f:5e:99:39:21:15:e2:71:
aa:6a:88:82
Weneedtoremovethespacesandcolonsfromthedata,sowecangetahex-stringthatwecanfeedinto
ourprogram.Thefollowingcommandcommandscanachievethisgoal.ThetrcommandisaLinuxutility
toolforstringoperations. Inthiscase,the-doptionisusedtodelete":"and"space"fromthedata.
$catsignature|tr-d[:space:]:
84a89a11a7d8bd0b267e52247bb2559dea30895108876fa9ed10ea5b3e0bc7
......
5c045564ce9db365fdf68f5e99392115e271aa6a8882
Step4:Extractthebodyoftheserverscertificate. ACertificateAuthority(CA)generatesthesignature
foraservercertificatebyfirstcomputingthehashof thecertificate,andthensignthehash. Toverifythe
signature,wealsoneedtogenerate thehashfromacertificate. Since thehashisgeneratedbefore the
signatureiscomputed,weneedtoexcludethesignatureblockofacertificatewhencomputingthehash.
Findingoutwhatpartof thecertificateisusedtogeneratethehashisquitechallengingwithoutagood
understandingoftheformatofthecertificate.
X.509certificatesareencodedusingtheASN.1(AbstractSyntaxNotation.One)standard,soifwecan
parsetheASN.1structure,wecaneasilyextractanyfieldfromacertificate.Opensslhasacommandcalled

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions

Question

=+2. Are you happy to pay a price premium for CSR products?

Answered: 1 week ago