Skip to content

Architecture

What a payment terminal does, how a7pay divides that work, and how one contactless payment travels through the pieces. Terms in bold are in the glossary.

When a card is tapped, the terminal has to answer one question: may this payment go through? To answer it, it:

  1. talks to the card over the contactless field, finds which payment application to use, and reads its data (Level 1 and Level 2);
  2. checks the card and the transaction: is the card genuine (ODA), expired, allowed in this country, under which limits; does the cardholder need to be verified (CVM: PIN, phone unlock, nothing);
  3. gets a decision: the card and the terminal can approve or decline on the spot (offline), or the card produces a cryptogram for its issuer and the terminal sends the payment to its acquirer, which gets the issuer’s answer (online);
  4. finishes: shows the result, prints or sends a receipt, records the transaction and confirms it to the acquirer (Level 3).

Steps 1 to 3, up to the decision to go online, are what EMV standardises as Level 2: Entry Point (EMVCo Book B) and one kernel per card family (Books C-2 to C-8). They are the hardest part to get right and the part certified most strictly, which is why they are usually bought rather than written.

The rest (the payment application, the messages to the acquirer, the terminal’s configuration) is Level 3. Terminals in Europe often build it on the nexo standards, which a7pay implements too.

a7pay models a terminal as a stack. The payment application is on top. The card and host protocols are in the middle. The device is underneath, and the layers above only reach it through four interfaces (traits, in Rust).

The layers of a terminal built on a7pay The layers of a terminal built on a7pay

Dashed boxes are planned.

Layer In a7pay Page
Payment application nexo::fast: nexo FAST, the card services (payment, refund, cancellation) and their host exchanges nexo
Host protocols nexo: the acquirer, terminal management and sale system protocols, and their security nexo
EMV Level 2 emvco::l2: Entry Point and Kernels 2, 3, 4, 6 and 8 Entry Point, Kernels
Platform interfaces platform: card reader, cryptography, security module, PIN pad Platform
Device Your hardware, or the software implementations used for tests Platform

A test platform drives the same stack with simulated cards and hosts: see Level 3 test platform and Test environment.

What happens when the cash register asks for 12.50 and a Mastercard is tapped, with the part of a7pay doing each step:

  1. The cash register sends a payment request to the terminal (nexo::retailer).
  2. The payment application starts a transaction (nexo::fast::card_service).
  3. Pre-Processing: Entry Point compares the amount with each Combination’s limits, e.g. whether a verification will be needed (emvco::l2::ep).
  4. Protocol Activation: Entry Point asks the reader to poll for a card and shows “Present card” (platform::Reader).
  5. Combination Selection: Entry Point reads the card’s PPSE directory, matches its applications with the reader’s Combinations, and selects one: Mastercard’s AID, on Kernel 2.
  6. Kernel Activation: Entry Point hands over to Kernel 2 (emvco::l2::k::c2). Kernel 2:
    • gets the card’s processing options and reads its records;
    • checks the card’s certificates (ODA, through platform::Crypto);
    • applies the processing restrictions;
    • chooses the verification method;
    • asks the card for a cryptogram;
    • ends with an Outcome: here Online Request, with the Data Record to send.
  7. Outcome Processing: Entry Point shows “Authorising, please wait” and returns the Outcome.
  8. The payment application builds the authorisation request from the Data Record, protects it with a MAC (nexo::security, through platform::SecurityModule), and sends it to the acquirer (nexo::acquirer).
  9. The acquirer answers with the issuer’s decision. If the kernel asked for it, the terminal hands the answer back to the kernel (a second tap for some kernels).
  10. The terminal shows “Approved”, answers the cash register, records the transaction, and sends the acquirer a completion advice confirming it.

A Kernel 8 payment follows the same path, with a secure channel between the kernel and the card:

A Kernel 8 payment A Kernel 8 payment

No I/O in the protocol code. The kernels and the host protocols take plain data and return plain data (“sans-IO”). They never open a socket or touch a device:

  • a kernel says “send this command to the card”, and its session loop does it through the Reader trait;
  • a host protocol builds the message, and the application sends it.

This is what lets the same code run on a countertop terminal, an unattended reader, a phone (SoftPOS) or a test bench, and it is what makes every step testable without hardware.

One cryptography provider. The protocol code holds no keys and implements no cryptographic algorithm. Every key operation goes through the platform’s provider (the Crypto and SecurityModule traits). On a real terminal that provider is its secure element or HSM; on a phone, the MPoC solution’s protected cryptography. A certifier only has to look at one place.

The specification, line by line. Each numbered requirement of an EMVCo Book is one function, carrying its reference (book, section, symbol of the flow diagram), with its own test. A reviewer can read the code beside the specification’s diagrams. Where a specification is ambiguous, the reading chosen is commented where it is implemented and listed in todo.md.

Small and portable. Everything in emvco::l2 is no_std Rust (it runs without an operating system) with no unsafe code, and depends on two small crates (hex, log). A build carries only the kernels it needs: see Building.

The public specification first. The kernels follow EMVCo’s public Books. Where a scheme’s certification expects something else, that behaviour sits behind a brand feature, off by default and documented with the test that needs it (see Kernels).

Projects depend on one crate, a7pay, which re-exports the parts their features choose (see Building). Each part is a crate of its own:

Module Crate What it is
a7pay::emvco a7pay-emvco EMV Level 2 (emvco::l2: Entry Point, kernels, the EMV functions they share, the reader’s transaction around them), no_std; the Level 3 test platform (emvco::l3, feature l3)
a7pay::platform a7pay-platform The platform interfaces (Reader, Crypto, SecurityModule, PinPad), no_std, their software implementations (for tests, and swcrypto for devices), a PC/SC reader
a7pay::nexo a7pay-nexo The nexo protocols and nexo FAST; nexo over TCP for the test environment

Outside the library: the test environment’s programs (apps/nexo/: vpoi, acqsim, tmssim, salesim), the Level 2 test agent and its protocol (apps/emvco/, see Level 2 test agent), and nexo-codegen, a development tool generating nexo’s message types from the ISO 20022 schemas.

Dependencies go one way. The protocol crates never depend on a platform implementation, and the open crates never depend on the private ones.

How the crates depend on each other How the crates depend on each other