Speed

The CA Signs the Request

The signing command takes a request, the CA certificate and the CA key and builds a certificate whose issuer is the CA; the extensions come from a file the CA writes, and extensions that the request asks for are added only if the command is told to copy them.

The question

A request holds a subject and a public key. A certificate holds that, and also an issuer, a serial number, two dates, extensions and the issuer's signature. Which of these does the CA take from the request, which does it write itself, and what happens to extensions that the request asks for?

The keys of this book are test material, 512-bit RSA, a toy size far too small to use.

Work it by hand

From the request the CA takes two things: the subject name and the public key. It does not take the requester's word for anything else. The issuer name is the subject of the CA certificate. The serial number and the two dates come from the CA's command. The extensions come from a file the CA writes. The CA signs the whole first part with its own key.

The extension file of the demo is the one that made the intermediate of the example chain: the CA flag with a path length limit of 0, key usage for signing certificates, a subject key identifier and an authority key identifier. The authority key identifier is the key identifier of the CA's key, here the SHA-1 hash of its public key, so a verifier can find the issuer.

A request can ask for extensions too. Whether the CA grants them is its choice: the command ignores them unless it is run with -copy_extensions copy.

Run it

The demo is one command (lines 3 to 5): x509 -req reads the request of the intermediate in in/csr.txt, the root in in/ca.txt and the root's key in in/ca_key.txt. It sets serial number 2 and the two dates, signs with SHA-256 and takes the extensions from in/ext.txt. The file out.pem is the same, byte for byte, as the committed intermediate certificate; this was measured.

The 4 lines of the extension file: basic constraints with CA true and path length 0, key usage, subject key identifier and authority key identifier; the first 16 bytes of out.pem, which are the characters of the BEGIN line, and the number of bytes the command wrote.

Public test material, generated for this lesson. Never use it for anything real.

# Writes the signed certificate to out.pem.
# Check runs it with other requests in in/csr.txt.
openssl x509 -req -in in/csr.txt -CA in/ca.txt -CAkey in/ca_key.txt \
  -set_serial 2 -not_before 20260101000000Z -not_after 20360101000000Z \
  -sha256 -extfile in/ext.txt -out out.pem
{
  "answer": "2d2d2d2d2d424547494e2043455254494649434154452d2d2d2d2d0a4d494942307a4343415832674177494241674942416a414e42676b71686b69473977304241517346414441364d526b77467759445651514b44424246654746740a6347786c4946526c63335167544746694d523077477759445651514444425246654746746347786c4946526c63335167556d39766443424451544165467730790a4e6a41784d4445774d4441774d4442614677307a4e6a41784d4445774d4441774d4442614d4549784754415842674e5642416f4d4545563459573177624755670a5647567a6443424d595749784a54416a42674e5642414d4d4845563459573177624755675647567a6443424a626e526c636d316c5a476c6864475567513045770a5844414e42676b71686b6947397730424151454641414e4c41444249416b4541747a4f58637a507234684b37676a654b575a37706c786b6d554f585761354a2b0a596557316d70693668534d69347669634248526d447a726976356b30584b366b4e396f494c6530454777444e673679503145756d73774944415141426f3259770a5a44415342674e5648524d4241663845434441474151482f416745414d41344741315564447745422f77514541774942426a416442674e5648513445466751550a59746a785a73535756634c59537135785a4276504435364c4b4a5177487759445652306a42426777466f4155376330426e756e706e42346c77753061692b35550a4f2b3339764838774451594a4b6f5a496876634e4151454c4251414451514134303772724e58354e4f673764376353493941304a535251665554574f6575566c0a743046704850374270634c4f55615762352b77564e695a466b466577614d6d4c42356d356e66644a674f4b62726b664d2b7534710a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a",
  "file": "out.pem",
  "bytes": 692
}

You can change the serial number, the dates and the file of extensions. Measured: without -set_serial the serial is random, and without -extfile the certificate has only a subject key identifier and an authority key identifier, which this command adds by itself, so the other extensions of a file are lost.

Your turn

Write one command that signs the request in in/csr.txt with the CA certificate in in/ca.txt and the CA key in in/ca_key.txt: serial number 3, notBefore 20260101000000Z, notAfter 20360101000000Z, SHA-256, with the extensions of the file in/ext.txt and no others. The command below is a starting point. Check runs it with other requests in in/csr.txt and on four others.

The 3 lines of the extension file: subject key identifier, authority key identifier and extended key usage; the first 16 bytes of out.pem and the number of bytes that the starting command wrote.

Public test material, generated for this lesson. Never use it for anything real.

# Writes the signed certificate to out.pem.
# Check runs it with other requests in in/csr.txt.
openssl x509 -req -in in/csr.txt -CA in/ca.txt -CAkey in/ca_key.txt \
  -set_serial 1 -not_before 20260101000000Z -not_after 20360101000000Z \
  -sha256 -extfile in/ext.txt -out out.pem
{
  "answer": "2d2d2d2d2d424547494e2043455254494649434154452d2d2d2d2d0a4d4949427054434341552b6741774942416749424154414e42676b71686b69473977304241517346414442434d526b77467759445651514b44424246654746740a6347786c4946526c63335167544746694d535577497759445651514444427846654746746347786c4946526c63335167535735305a584a745a5752705958526c0a49454e424d423458445449324d4445774d5441774d4441774d466f5844544d324d4445774d5441774d4441774d466f77477a455a4d42634741315545417777510a643364334c6d563459573177624755756447567a644442634d41304743537147534962334451454241515541413073414d45674351514336584b6551626677730a74556e506a6e3031317966504d546f46657463596177694e75792f63462f2b4655676a71372f533237692f77426f6d2b4e41784b6178673348563063516361510a39634654384d3350724d384441674d424141476a567a42564d423047413155644467515742425338454c4a4b374b37514f687937694c6d6f356665546e52354f0a4a54416642674e5648534d4547444157674252693250466d784a5a567774684b726e466b473838506e6f736f6c44415442674e56485355454444414b426767720a42674546425163444154414e42676b71686b6947397730424151734641414e4241486773496a6d4d6472372f466f525551726a4654692f62452b324b502f4e700a6162757663795a2b5233724d2f624d666a785a633247643968756e5130524b4a584157636345364e622b475573454d64496e787551336f3d0a2d2d2d2d2d454e442043455254494649434154452d2d2d2d2d0a",
  "file": "out.pem",
  "bytes": 631
}

Write one openssl command that signs the request in in/csr.txt with the CA certificate in in/ca.txt and the CA key in in/ca_key.txt, with serial number 3, notBefore 20260101000000Z, notAfter 20360101000000Z and SHA-256, takes its extensions only from the file in/ext.txt, and writes the certificate to out.pem in PEM form. Check runs your command with other requests in in/csr.txt.

Read the result carefully

The trap is -copy_extensions copy. Measured with a file that holds a subject key identifier, an authority key identifier and the extended key usage for TLS server authentication: a request that asks for CA:TRUE gets a certificate with Basic Constraints: critical CA:TRUE, and a request that asks for key usage Certificate Sign gets Key Usage: critical Certificate Sign. A request asked for a CA, and the CA gave it. Measured on a file that already has key usage: the file's one is kept and the request's is not used.

So a command that copies is not wrong in every case, only unsafe when the requester is not trusted. This page measures what the command does and gives no rule for a real authority. The fields of the certificate it makes are read in A Certificate, Field by Field.

Recap

  • The CA takes the subject and the public key from the request and writes everything else.
  • The issuer is the CA certificate's subject; the authority key identifier names the CA's key.
  • Serial number and dates must be fixed in the command to make the same output.
  • Requested extensions are ignored unless the command is told to copy them, and then they can add a CA flag the CA never meant to give.