This blog briefly describes theoretically how Public Key Infrastructure (PKI) works. It also introduces the key concepts used in PKI. This is done by describing encryption, decryption, hashing, signing, and authentication using mathematical notations.

PKI in a Nutshell

Intro

Given an asymmetric encryption algorithm E and accompanying Decryption algorithm D. It uses a key pair (Ke, Kd) to encrypt a plain text message x into a cipher text y.

  • encryption: E(Ke, x) = y

  • decyption: D(Kd, y) = x

Alice and Bob

Suppose Alice and Bob want to exchange encrypted messages with each other, and they also want to sign the messages so that they can be sure the messages they receive are from each other indeed, and not from some malignant third party.

Alice owns two key pairs.

  • keyPairA1 ={KA1e, KA1d}

  • keyPairA2 = {KA2e, KA2d}

Alice publishes the keys KA1e and KA2d.

Bob thas two key pairs as well:

  • keyPairB1 = {KB1e, KB1d}

  • keyPairB2 = {KB2e, KB2d}

And he publishes KB1e and KB2d.

The keys that are published are called public keys, the ones you keep for yourself are called private keys.

Key pairs are kept in a keystore. Trusted public keys, or the certificates thereof (see below), are kept in a truststore.

Encryption

Bob can now send an encrypted message to Alice using her public encryption key KA1e with

E(KA1e, x) = y

Which can only be decrypted by Alice with her private decryption key KA1d

D(KA1d, y) = x

And vice versa Alice can send encrypted message to Bob using the public key KB1e from Bob.

Signing

Bob can use his private signing key KB2e to sign his encrypted messages.

Given a hashing algorithm H

h = H(y) = hash of y

Next define

s = S(y) = E(KB2e, H(y)) = signature

Bob sends (y, s) to Alice.

Now Alice can verify the cipher text y is from Bob by applying the verify operation V using Bob’s public verification key KB2d

V(s) = D(KB2d, s) = h

And she can also calculate h herself from the received y. Both hashes must be equal. Since only the owner of KB2e could have sent the signature s encrypted in this way she knows this message is from Bob.

NB The same is true if Bob had signed the plain text x instead of the cipher text y. The choice is somewhat arbitrary. Albeit, that signing the cipher text y is a bit safer. Because when signing x and Alice’s private key has somehow been acquired by a malignant third party Mallory, Mallory can decrypt y and reencrypt it with his own private key and reuse the signature. When y is signed, he cannot reuse the signature.

Vice versa Alice can sign her message to Bob using her signing key KA2e.

Certificates

What if Alice and Bob have no secure channel to exchange their public keys? Well suppose they do both have a secure channel with a third party CA (Certification Authority) whom they trust, which means they trust the CA’s public verification key KCAd. They offer their public keys to CA to have them signed.

For example Alice offers her public encryption key to be signed by CA

SCA(KA1e) = E(KCAe, H(KA1e)) = sA1e

And Alice publishes

cA1e = {KA1e, SCA(KA1e)} = {KA1e, sA1e} = certificate of KA1e signed by CA

Bob can now verify the key is from Alice by calculating

VCA(sA1e) = D(KCAd, sA1e) = hv

and

H(KA1e) = h

The following should be true: hv = h

The same can be done for the other public keys of Alice and Bob. So by publishing certificates of their public keys instead of the keys alone they can safely exchange messages without having a secure channel to exchange their public keys directly.

For convenience CA does not publish its verification key alone, but a self-signed certificate of it

cCAd = {KCAd, SCA(KCAd)}

Chain of Trust

Above is an example of a chain of trust. Alice and Bob trust CA. This a chain of length 2. Longer chains are more common. For example when Alice and Bob use a certificate from CA2, which is signed by CA1, which is signed by a self-signed certificate of CA0=CAroot. They both trust CA0, and Alice has her keys signed by CA2. For example the chain for her public encryption key:

cA1e = {KA1e, sA1e} = {KA1e, SCA2(KA1e)}

cCA2d = {KCA2d, sCA2d} = {KCA2d, SCA1(KCA2d)}

cCA1d = {KCA1d, sCA1d} = {KCA1d, SCA0(KCA1d)}

cCA0d = {KCA0d, sCA0d} = {KCA0d, SCA0(KCA0d)}

So Bob trusts the public encryption key of Alice, KA1e, because it is signed by CA2, which is signed by CA1, which is signed by CA0, which he trusts.

It is common practice to send the entire chain upon publishing/sending of one’s certificate. So usually one keeps the entire chain for each certificate in one’s keystore. Since the public key is part of the certificate a keystore usually contains entries with in it a private key and the associated certificate chain.

The certificates one trusts are kept a so called truststore. The sender’s chain of certificates must end at a certificate in one’s truststore.

shadow-left