ARMOR: A Formally Verified Implementation of X.509 Certificate Chain Validation

Joyanta Debnath, Christa Jenkins, Yuteng SUN, Sze Yiu Chau, Omar Chowdhury

IEEE Symposium on Security and Privacy 2024 · Day 1 · Continental Ballroom 6

Overview

The talk "ARMOR: A Formally Verified Implementation of X.509 Certificate Chain Validation" introduces a groundbreaking project aimed at developing a robust, formally verified implementation for the critical process of validating X.509 certificate chains. Presented by Joyanta Debnath from Stony Brook University, this work addresses a long-standing vulnerability in network security: the often-flawed and error-prone implementations of X.509 Public Key Infrastructure (PKI) certificate validation. Despite its foundational role in securing protocols like TLS, the complexity of the X.509 standard, primarily defined in RFC 5280, frequently leads to logical bugs and inconsistencies across different libraries.

Watch on YouTube

Visual summary for ARMOR: A Formally Verified Implementation of X.509 Certificate Chain Validation by Joyanta Debnath, Christa Jenkins, Yuteng SUN, Sze Yiu Chau, Omar Chowdhury
Visual summary for ARMOR: A Formally Verified Implementation of X.509 Certificate Chain Validation by Joyanta Debnath, Christa Jenkins, Yuteng SUN, Sze Yiu Chau, Omar Chowdhury

Key moments

  1. 0:00 ARMOR: Formally Verified X.509 Certificate Chain Validation
  2. 2:15 Why X.509 validation is "most dangerous code"
  3. 3:00 Explaining the necessity of formal verification over testing
  4. 4:15 Key contributions of the ARMOR project
  5. 5:50 ARMOR's modular decomposition for certificate chain validation
  6. 8:00 Design philosophy: implementation-independent relational specifications

ARMOR: A Formally Verified Implementation of X.509 Certificate Chain Validation

Speakers: Joyanta Debnath, PhD Student, Stony Brook University; Christa Jenkins, Postdoctoral Researcher, Stony Brook University; Yuteng SUN, PhD Student, Chinese University of Hong Kong; Sze Yiu Chau, Professor, Chinese University of Hong Kong; Omar Chowdhury, Assistant Professor, Stony Brook University

Conference: IEEE S&P

YouTube: https://www.youtube.com/watch?v=ENRNG6BeMzQ

Overview

The talk "ARMOR: A Formally Verified Implementation of X.509 Certificate Chain Validation" introduces a groundbreaking project aimed at developing a robust, formally verified implementation for the critical process of validating X.509 certificate chains. Presented by Joyanta Debnath from Stony Brook University, this work addresses a long-standing vulnerability in network security: the often-flawed and error-prone implementations of X.509 Public Key Infrastructure (PKI) certificate validation. Despite its foundational role in securing protocols like TLS, the complexity of the X.509 standard, primarily defined in RFC 5280, frequently leads to logical bugs and inconsistencies across different libraries.

The significance of ARMOR cannot be overstated. Incorrect certificate chain validation can enable sophisticated man-in-the-middle (MITM) attacks, allowing adversaries to intercept and decrypt sensitive communications, thereby undermining the very security guarantees that protocols like TLS are designed to provide. As one researcher highlighted, these implementations are "the most dangerous code in the world." ARMOR aims to provide an unimpeachable "ground truth" implementation, offering a reference for testing other libraries and guiding application developers. This initiative aligns with recent cybersecurity agendas emphasizing the need for formally verified software, as even TLS 1.2 and 1.3 implementations often implicitly trust the correctness of underlying certificate validation.

Background

▶ Watch: ARMOR: Formally Verified X.509 Certificate Chain Validation (0:00)

X.509 PKI forms the backbone of authentication and key distribution in countless network applications and services. At its core, it establishes a verifiable link between an identity and its public key through digital certificates. When a client connects to a server, especially in protocols like TLS, the server presents a certificate or, more commonly, a chain of certificates. The client's TLS library is then tasked with validating this chain, verifying that trust can be extended from a trusted root Certificate Authority (CA) to intermediate CAs, and finally to the end-entity server certificate. This validation is a prerequisite for establishing the end-to-end security guarantees of TLS, such as confidentiality and data integrity.

The intricate logic for this validation is primarily detailed in RFC 5280. However, the natural language specification of RFC 5280, coupled with the inherent complexity of certificate parsing and chain building, has historically led to numerous implementation errors. Developers often struggle to interpret the standard precisely, leading to logical bugs frequently reported in vulnerability databases. Previous research, including the speakers' own work on simers, has exposed these vulnerabilities, with one library developer reportedly calling X.509 validation "one of the most error prone code blotting and compatibility nightmare." These errors are not theoretical; they represent critical attack vectors for MITM exploits.

Traditional software testing, while valuable, is insufficient for guaranteeing the absence of bugs, as famously stated by Edsger Dijkstra: "Program testing can be used to show the presence of bugs, but never to show their absence." This limitation is particularly dangerous for security-critical components like certificate validation. In contrast, formal verification provides mathematical proof of correctness, significantly reducing the likelihood of bugs. While prior efforts have achieved formal verification for recent TLS versions (e.g., TLS 1.2 and 1.3), these implementations often make the critical assumption that the underlying certificate chain validation is already correct. ARMOR directly addresses this implicit assumption, aiming to remove this critical blind spot in the security chain.

Key Findings

▶ Watch: Explaining the necessity of formal verification over testing (3:00)

ARMOR introduces several novel contributions to the field of formally verified security software:

  1. First Comprehensive Formal Verification of Certificate Chain Validation: Unlike prior work that focused primarily on certificate parsing (e.g., ASN.1), ARMOR is the first effort to formally verify the entire X.509 certificate chain validation process. This includes not just parsing individual certificates but also the complex logic of building and validating trust paths.
  2. Implementation-Independent Relational Specifications: The project developed unique relational specifications for various stages of certificate chain validation. These specifications define the expected properties of the validation process without tying them to a particular implementation algorithm. This approach allows for a clear definition of correctness properties for both specification and implementation, serving as a robust alternative to ambiguous natural language standards.
  3. Explicit Proofs of Soundness, Completeness, and Termination: For a significant subset of the validation process, ARMOR provides explicit proofs demonstrating soundness, completeness, and termination guarantees. Soundness ensures that if the parser accepts an input, that input is indeed valid according to the language specification. Completeness ensures that all valid inputs are accepted. Termination guarantees that all recursive functions within the implementation will always halt.
  4. Identification of Non-Compliance in Widely Used Libraries: Through extensive evaluation against 11 open-source X.509 libraries, ARMOR revealed significant instances of non-compliance with RFC 5280. Libraries such as OpenSSL, GnuTLS, and mbed TLS were found to deviate from the standard in critical areas, including enforcement of string length restrictions in subject and issuer names and the proper handling of critical extensions. These findings underscore the necessity of a formally verified reference implementation like ARMOR.

Technical Deep Dive

▶ Watch: Key contributions of the ARMOR project (4:15)

Achieving the goal of a formally verified X.509 implementation presents substantial challenges. The primary hurdles include correctly interpreting the often ambiguous and underspecified natural language of RFC 5280, handling the context-sensitive grammar of DER-encoded certificates, and devising rigorous formal correctness guarantees with accompanying proofs.

ARMOR tackles this complexity through a modular decomposition of the entire certificate chain validation process. The system's architecture comprises several distinct modules:

  • PM Parser: Extracts individual Base64-encoded certificates from a given PEM-formatted file.
  • Base64 Decoder: Decodes each certificate into its DER byte string format.
  • X.690 DER and X.509 Parsers: Parse the DER byte string to extract certificate fields according to X.690 and X.509 standards.
  • String Canonicalizer: Normalizes subject and issuer names, which is crucial for consistent chain building.
  • Chain Builder: Generates all potential candidate certificate chains based on the parsed certificates.
  • Semantic Validator: Applies the core RFC 5280 validation logic to check if at least one candidate chain is valid.
  • Driver Module: Manages inputs, outputs, and coordinates the flow between all other modules.

This modular design is inspired by prior work in X.509 and TLS (including the Simers project) and is fundamental to ARMOR's verification philosophy. It allows for individual specification and proof of soundness and completeness for each component.

A core tenet of ARMOR's verification approach is the development of implementation-independent relational specifications. Unlike executable specifications, which detail a specific algorithm (e.g., C code for selection sort), relational specifications define the expected properties without constraining the implementation details. For example, a relational specification for sorting would simply state that the output is sorted and contains the same elements as the input, regardless of whether selection sort, merge sort, or another algorithm is used. This approach enables a clear definition of correctness properties for both the specification and the implementation, and can serve as an unambiguous alternative to natural language specifications.

For the formal verification, ARMOR utilizes Agda, a powerful functional programming language and interactive theorem prover. While significant progress has been made, the current version of ARMOR has certain limitations. Properties for the String Canonicalizer and Driver modules have not yet been formally proven, meaning that full end-to-end correctness guarantees combining all modules are not yet established. Furthermore, the current implementation does not support hostname verification or certificate revocation checking, both of which are critical components of a complete X.509 validation system and are planned for future work. Despite these limitations, ARMOR represents the most comprehensive effort to date for the formal verification of certificate chain validation.

The correctness properties for the X.509 parser and its specification are defined rigorously:

  • Soundness: States that "if any prefix of the input is accepted by the parser, the prefix is in the language."
  • Completeness: States that "if the prefix is in the language, the parser accepts the prefix of the input," which is the reverse of soundness.
  • Termination: Ensures that any recursive functions within the parser are well-founded and will always terminate.

These three properties together provide total correctness. However, for X.509 parsing, simple completeness is not enough to rule out all security-threatening behaviors. The parser's freedom over which prefix it consumes or how internal data structures are constructed must be constrained. To achieve strong completeness, ARMOR introduces two additional lemmas:

  • Unambiguity: Ensures that "one input cannot be the encoding of two distinct data."
  • Unique Prefixes: States that "at most one prefix can be in the language."

These two lemmas, combined with the core properties, guarantee that "if a prefix is in the language and encodes value V, the parser consumes exactly that prefix and produces V."

ARMOR also formalizes various semantic checks mandated by RFC 5280. For instance, a basic check for any individual certificate requires that the signature algorithm field contains the same algorithm identifier as the signature field of the TBS (To Be Signed) certificate field. In Agda, this property is expressed as a predicate (Capital R1) and its decidability proof (small R1). The proof involves proving equality for both the Object Identifier (OID) and the optional parameters whose type depends on the OID.

A more complex semantic check involves the entire certificate chain: all issuer certificates in a valid chain must be CA certificates. This means the Basic Constraints extension must be present, and its cA boolean field must be set to TRUE. Since extensions are only permitted in Version 3 certificates, ARMOR consults RFC 5280, which allows implementations to reject Version 1 and Version 2 intermediate CA certificates. ARMOR defines a predicate is_confirmed_CA to check these conditions and uses Capital R23 to extend this property to all issuer certificates in a chain, with small R23 as its sound-by-construction checker.

Demo / Proof of Concept

▶ Watch: ARMOR's modular decomposition for certificate chain validation (5:50)

While the talk did not feature a live, interactive demo of ARMOR in action, it presented a comprehensive evaluation demonstrating ARMOR's capabilities and highlighting non-compliance in existing libraries. This evaluation effectively served as a proof of concept for ARMOR's strict adherence to RFC 5280 and its potential as a "ground truth" reference.

The ARMOR team rigorously tested 11 open-source X.509 libraries, including widely used implementations like OpenSSL, GnuTLS, mbed TLS, and old SSL. The evaluation measured execution time and memory overhead for each test run. The dataset for this evaluation was substantial, comprising over 4 million certificate chains, a mix of real-world and synthetically generated chains, ensuring broad coverage of validation scenarios. Furthermore, ARMOR was integrated with BoringSSL to assess its performance and behavior while visiting Alexa's top 100 websites using the curl application.

The evaluation yielded critical findings regarding the accuracy of ARMOR's interpretation of specifications and the compliance of other libraries:

  • Strict RFC 5280 Adherence: ARMOR was found to follow RFC 5280 more strictly than all tested implementations.
  • Length Restrictions: OpenSSL, GnuTLS, and mbed TLS, for example, do not enforce the minimum length restrictions on strings in subject and issuer names, accepting certificates with zero-length strings where RFC 5280 requires a minimum size of one. ARMOR correctly rejects such non-compliant certificates.
  • Critical Extensions Handling: OpenSSL, GnuTLS, and old SSL were observed not to reject certain certificates even when they failed to parse or process critical extensions (e.g., the certificate policy extension). RFC 5280 explicitly mandates that an implementation must reject a certificate if it cannot recognize or process a critical extension. ARMOR correctly enforces this rule.

On the negative side, ARMOR currently incurs a significant performance overhead. It takes approximately 2.5 seconds to validate a certificate chain, whereas other libraries average at most 0.5 seconds. In terms of memory consumption, ARMOR requires about 1,000 megabytes during runtime. The speakers acknowledged that identifying the exact reasons for this high overhead and implementing optimization strategies are key parts of their future work plan.

Defensive Implications

▶ Watch: Design philosophy: implementation-independent relational specifications (8:00)

The development and evaluation of ARMOR carry profound defensive implications for anyone involved in building, deploying, or securing systems that rely on X.509 PKI.

Firstly, developers of TLS libraries and applications should consider ARMOR as a ground truth for testing their own implementations. Its formally verified nature provides an unparalleled benchmark for correctness and RFC 5280 compliance. Using ARMOR as a reference can help identify subtle bugs and deviations from the standard that might otherwise go unnoticed, potentially preventing future vulnerabilities.

Secondly, the findings reveal that many widely used open-source X.509 libraries do not strictly adhere to RFC 5280. This exposes applications relying on these libraries to potential risks, as non-compliant certificate validation can be exploited to bypass authentication checks. Defenders must be aware that the "trusted" underlying certificate validation in their systems might have critical flaws. This necessitates a re-evaluation of assumptions about the security posture of existing TLS and PKI implementations.

Specifically, security teams and developers should pay close attention to:

  • String Length Restrictions: Ensure that their validation logic properly enforces minimum length requirements for subject and issuer names, rejecting certificates with zero-length attributes.
  • Critical Extensions: Verify that their systems correctly handle critical extensions. Any certificate containing a critical extension that cannot be parsed or processed must be rejected, as per RFC 5280. Failure to do so, as observed in some popular libraries, creates a critical bypass opportunity.
  • Consistent Interpretation: The ambiguities in RFC 5280 highlight the need for a consistent and formally verified interpretation. ARMOR provides a blueprint for such an interpretation, which can inform future development and auditing efforts.

Ultimately, ARMOR underscores the importance of strict adherence to standards in security-critical code. While performance and legacy compatibility often lead to compromises, the security implications of such compromises in certificate validation are severe. Organizations should advocate for, and contribute to, the adoption of formally verified components in their security infrastructure to mitigate the risks of man-in-the-middle attacks and ensure the integrity of their communications.

Key Takeaways

  • X.509 certificate chain validation is a highly complex and error-prone process, frequently leading to critical bugs and man-in-the-middle attack vulnerabilities in widely used software.
  • ARMOR is the first project to achieve formal verification for the entire X.509 certificate chain validation process, going beyond just parsing, thereby addressing a critical gap in existing formally verified TLS implementations.
  • The project utilizes a modular design, implementation-independent relational specifications, and the Agda interactive theorem prover to provide explicit proofs of soundness, completeness, and termination for a large subset of the validation logic.
  • Evaluations demonstrated that ARMOR adheres more strictly to RFC 5280 than 11 popular open-source X.509 libraries (including OpenSSL and GnuTLS), which were found to deviate in critical areas like string length enforcement and handling of critical extensions.
  • While ARMOR currently incurs significant performance and memory overhead (2.5 seconds validation time, 1000MB memory), these are acknowledged limitations targeted for future optimization.
  • ARMOR serves as a vital "ground truth" and reference implementation for testing existing libraries, guiding future development, and raising awareness about the inherent vulnerabilities in current X.509 validation practices.

About the Speaker(s)

The ARMOR project is a collaborative effort involving researchers from Stony Brook University and the Chinese University of Hong Kong. Joyanta Debnath, a PhD student from Stony Brook University, presented this work. He is a key contributor to the formal verification efforts within the ARMOR project. Christa Jenkins, a postdoctoral researcher at Stony Brook University, also played a significant role in this research. The project was advised by Omar Chowdhury, an Assistant Professor at Stony Brook University, whose expertise guided the overall research direction. From the Chinese University of Hong Kong, Sze Yiu Chau, a Professor, and Yuteng SUN, a PhD student, contributed to this joint work, bringing their specialized knowledge to the comprehensive formal verification of X.509 certificate chain validation.

Reviews

Dr. Zero (Offensive Security Researcher) — MUST SEE

A formally verified X.509 chain validation is a critical, foundational piece of work. The team's rigorous application of Agda to such a complex, error-prone standard, exposing real flaws in widely used libraries, is a significant contribution that defines a new "ground truth." This is the kind of deep, uncomfortable research we need, and it directly addresses a critical blind spot in global network security.

Heather Calloway (CISO) — STRONG ACCEPT

This work identifies a critical, systemic flaw in X.509 certificate validation across widely used libraries, a foundational element of secure communications. ARMOR provides a formally verified 'ground truth' that exposes these vulnerabilities and offers a benchmark for developers. While not yet production-ready, it provides crucial insights for security leaders and architects to re-evaluate their trust assumptions and advocate for stronger standards.

→ Top-rated talks at IEEE Symposium on Security and Privacy 2024

All talks from IEEE Symposium on Security and Privacy 2024