Blog ·Guides

How do you check the validity of certificates and electronic signatures with CRL and OCSP?

· 12 min read

Introduction

We have already answered the questions “What is an electronic signature?”, “Who can issue one?” (in Bulgarian) and “Why is it better to sign electronically?” in separate blog articles.

We also know that every advanced or qualified signature has its own validity period, which is set when the signature is created.

But what happens if the security of your signature is compromised? For example, if you lose your smart card (USB token)?

The industry has created two main mechanisms for checking whether a certificate is valid:

  • List of revoked certificates
    Certificate Revocation List (CRL)
  • Protocol for checking certificate status online
    Online Certificate Status Protocol (OCSP)

In this post we look at how these technologies work and why they are so important for managing electronic signatures and certificates.

An electronic signature is the digital equivalent of a handwritten signature, used in electronic documents to confirm 1) the authenticity and 2) the integrity of the document. It is based on digital certificates, which identify the signatory and guarantee that the data has not been changed after signing.

For the whole concept of electronic document signing to work correctly, it is essential that certificates are valid and up to date at all times. This calls for the methods of checking them that we write about here.

Why checking the certificate of an electronic signature matters

The validity of an electronic signature depends entirely on the status of the certificate used for it. If the certificate is revoked or has expired, the signature can no longer be used or considered valid. This does not mean that documents signed before then become invalid.

Checking certificates guarantees that all transactions or documents signed with them are valid.

Why are certificates revoked or blocked?

Certificates can be revoked for a number of reasons:

  • Key compromise: If the certificate’s private key is stolen or put at risk, the security of the certificate is seriously threatened. For example, if you lose the smart card (USB token) that stores your private key.
  • Change of information: Changes in the information about the signature holder, such as their name or e-mail address, may require a new certificate to be issued.
  • Cessation of operations: In the case of a professional electronic signature that links an individual to a legal entity which ceases its activity.
  • Expiry: Certificates have a set period of validity, after which they must be renewed or revoked.

How do you end the validity of a compromised electronic signature?

If your electronic signature is stolen or lost, you must contact its issuer immediately to have it suspended.

For B-Trust, call 0700 199 10 or *9910. To revoke the certificate, you have to submit a certificate management request at an office.

With Evrotrust, the certificate is revoked through the mobile app.

What happens after you report it?

Whatever the reason you want to end the validity of a certificate, once you report it, the issuer first updates the status of the certificate in its database and then adds the certificate’s serial number to its Certificate Revocation List (CRL).

What is a Certificate Revocation List (CRL)?

A Certificate Revocation List (CRL) is a list published by certificate issuers that contains the serial numbers of certificates that have been revoked and are no longer valid. CRLs are used by various applications and services to check the status of certificates and make sure they have not been compromised or withdrawn from use.

How is a CRL updated and maintained?

Certificate issuers are responsible for maintaining and updating the CRL. They publish CRL updates periodically, which keeps the information in the list up to date. This allows client applications (such as Adobe Acrobat) to check in real time whether a certificate is valid or has been revoked. Revoked certificates whose validity period has already expired can be removed from the CRL.

Challenges with CRLs

Using CRLs is not without its challenges:

  • Scalability: As the internet grows, the number of certificates that have to be managed grows exponentially. This can lead to huge CRL files that are hard to manage and distribute.
  • Slower performance: A CRL file can become very large, especially for organisations with many certificates. Checking the CRL can therefore slow down authentication, because client systems have to download and check large lists.
  • Timeliness: Although CRLs are updated regularly, there is always a window of time in which a revoked certificate may not yet be included in the latest version of the list. This means a certificate may have been revoked but not yet be included in the CRL.

An example of using a CRL

If you need to check a certificate against a CRL, go through the following steps:

  1. Download the CRL - First, download the CRL from the issuer of the certificate you want to check. A CRL is usually provided as a file with the .crl extension. Here are sample addresses of the two main electronic signature providers in Bulgaria:

    Information about the addresses of these servers is contained in the certificates themselves. CRL files do not contain plain text, i.e. they are not human-readable. They are encoded in a special DER (Distinguished Encoding Rules) format. DER is a binary format used to encode ASN.1 (Abstract Syntax Notation One) data. ASN.1 is a data description language used to define the structure of certificates and CRLs.

  2. Install specialised software - One of the most popular tools for working with certificates is the OpenSSL library – an open-source cryptographic library that includes tools for managing and analysing certificates.

  3. Read the information - Open a terminal on your operating system and go to the directory where you saved the CRL file (for example: cd /…/downloads). Enter the command: openssl crl -inform DER -in crl_file.crl -noout -text (replacing crl_file.crl with the name of the file you downloaded in step 1; if the file is in the PEM text format, leave out -inform DER). The screen will show information about:

    • The issuer of the certificates
    • The date of the last and the next update
    • A list of revoked certificates with their serial number, revocation date and possibly the reason for revocation

    It is important to note that the steps above will help you understand the contents of a CRL file, but you do not need to do this by hand. Most applications (again, we have to mention Adobe Acrobat Reader) do these checks automatically. And if you are developing software, it is best to use ready-made specialised libraries instead of writing code from scratch.

Alternatives to CRL

Because of some of the challenges listed above, the industry has developed an alternative to CRL: the Online Certificate Status Protocol (OCSP). OCSP lets applications get a faster answer about a certificate’s status by sending a request to the OCSP server and quickly receiving a reply on whether the specific certificate is valid or revoked.

Online Certificate Status Protocol (OCSP): The modern approach to checking certificate status

The Online Certificate Status Protocol (OCSP) is an internet-based protocol for checking the status of a digital certificate. It was introduced to provide a faster and more efficient way of checking certificate validity than traditional Certificate Revocation Lists (CRLs). OCSP allows systems to send a query to an OCSP server, which can confirm whether a certificate is still valid or has been revoked.

Why is OCSP preferred over CRL?

  1. Speed and efficiency - OCSP makes it possible to check the status of a certificate instantly, which is much faster than downloading and checking large CRL files.
  2. Lower network load - Because OCSP only requires sending small queries and receiving short replies, it greatly reduces network load compared with downloading bulky certificate revocation lists.
  3. Real-time updates - OCSP offers almost instant information about a certificate’s status, which is especially important in the dynamic environment of the internet.

How does OCSP work?

The OCSP process starts when a client (for example Adobe Acrobat Reader) sends a query to the OCSP server. The query contains the identifier of the certificate whose status is being checked. The signature provider checks the status of that certificate in its database and returns a reply stating whether the certificate is valid, revoked, or of unknown status.

Example of a request to an OCSP server

If you want to use the OCSP protocol to check the validity of a certificate, follow these steps:

  1. Create an OCSP request - First, you need to create an OCSP request. It must contain the following information:
    • The address of the OCSP server: The issuer gives it in the certificate itself, in the Authority Information Access (AIA) extension. The request is sent to this address.
    • The certificate identifier: The serial number of the certificate you want to check, together with hashes of its issuer’s name and public key.
    • The request signature (optional): The request can be signed with the client’s private key, but most OCSP servers do not require it.
  2. Send the request - Once you have created the OCSP request, send it to the OCSP server. You can do this over HTTP or HTTPS.
  3. OCSP response - The OCSP server will check the validity of the certificate and send a response. The OCSP response will contain the following information:
    • Certificate status: “good” (the certificate has not been revoked), “revoked” or “unknown” (the server does not recognise the certificate). If the server cannot process the request, it returns an error code instead of a status.
    • Response signature: The server signs its response, so the client can make sure it comes from the issuer or a server the issuer has authorised.
    • Revocation date: If the certificate has been revoked, the OCSP response will contain the date and time it was revoked.
    • Reason for revocation: If the certificate has been revoked, the OCSP response may contain the reason for revocation.
  4. Process the OCSP response - Once you receive a response from the OCSP server, you need to process it. If the certificate status is “good”, you can accept the electronic signature. If the certificate status is “revoked”, you must reject the electronic signature. If the status is “unknown” or the server returns an error, you cannot rely on the signature until you have checked the certificate another way, for example with the CRL.

Sample code

The example is in Python and uses the cryptography and requests libraries. You need the certificate you are checking and the certificate of its issuer, in PEM format.

import requests
from cryptography import x509
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.x509 import ocsp
from cryptography.x509.oid import AuthorityInformationAccessOID, ExtensionOID
# The certificate we are checking and the certificate of its issuer
cert = x509.load_pem_x509_certificate(open("certificate.pem", "rb").read())
issuer = x509.load_pem_x509_certificate(open("issuer.pem", "rb").read())
# The OCSP server address is written in the certificate itself (Authority Information Access)
aia = cert.extensions.get_extension_for_oid(ExtensionOID.AUTHORITY_INFORMATION_ACCESS).value
ocsp_url = next(d.access_location.value for d in aia if d.access_method == AuthorityInformationAccessOID.OCSP)
# The request identifies the certificate by its serial number and hashes of the issuer's name and key
request = ocsp.OCSPRequestBuilder().add_certificate(cert, issuer, hashes.SHA1()).build()
reply = requests.post(
ocsp_url,
data=request.public_bytes(serialization.Encoding.DER),
headers={"Content-Type": "application/ocsp-request"},
timeout=10,
)
response = ocsp.load_der_ocsp_response(reply.content)
# Process the response
if response.response_status != ocsp.OCSPResponseStatus.SUCCESSFUL:
print("The OCSP server could not answer:", response.response_status.name)
elif response.certificate_status == ocsp.OCSPCertStatus.GOOD:
print("The certificate has not been revoked.")
elif response.certificate_status == ocsp.OCSPCertStatus.REVOKED:
print("The certificate was revoked on", response.revocation_time_utc)
else:
print("The OCSP server does not know this certificate.")

OCSP does not rely on the CRL. Both methods serve the same purpose, but they work independently of each other. Providers first update their databases and then periodically generate the CRL and publish it, whereas an OCSP check is made directly against the issuer’s database.

Final words

An electronic signature is the digital equivalent of a handwritten signature. It serves to confirm the authenticity and integrity of an electronic document. An electronic signature is based on a digital certificate, which identifies the signatory and guarantees that the data has not been changed after signing.

An important aspect is checking the validity of certificates, to make sure that electronic signatures can be relied on. Two main methods are used for this:

  • Certificate Revocation List (CRL): A CRL is a list published by certificate issuers that contains the serial numbers of certificates that have been revoked and are no longer valid. CRLs are updated periodically, but they have limitations such as size and delay.
  • Online Certificate Status Protocol (OCSP): OCSP is a protocol that lets applications get a faster answer about a certificate’s status by sending a request to the OCSP server. OCSP is more efficient than CRL, but it may not be available from all certificate issuers.

The choice between CRL and OCSP depends on your needs:

  • CRL: Suitable for offline scenarios and systems with limited resources.
  • OCSP: Suitable for real-time checks and systems with internet access.

Ideally, a combination of CRL and OCSP can be used for extra security.

What to remember:

  1. Electronic signatures are based on valid digital certificates.
  2. CRL and OCSP are two methods of checking certificate validity.
  3. OCSP is more efficient than CRL, but CRL is more widely available.
  4. The choice between CRL and OCSP depends on your needs.
  5. Combining CRL and OCSP can provide the highest level of security.

Signing can be easier

DigiSign works with every type of electronic signature and lets you combine several signing methods in one document.

Learn more

From the blog

All articles

See DigiSign in action

Send yourself a sample document and sign it, or book a demo with our team.

Try