Citizen Card Middleware

The Portuguese Citizen Card is more than an identity document. Since its introduction, it has become the cornerstone of Portugal’s digital public infrastructure. As a result, citizens can now authenticate themselves online, sign documents with legal validity and access healthcare and tax services without ever appearing in person. Behind every one of these interactions, running silently, is the Citizen Card Middleware developed by Caixa Mágica Software.

Since 2011, Caixa Mágica Software has been the primary developer and maintainer of this open-source, cross-platform middleware. This software connects the physical smart card to the digital world. Importantly, it is not a niche technical tool, every citizen and business in Portugal uses it, directly or indirectly, every single day. Furthermore, it continues to evolve through active collaboration with the National Printing House (INCM), the Agency for Administrative Modernization (AMA) and the Institute of Registries and Notaries (IRN).

The Citizen Card Middleware Challenge

In 2011, Portugal’s digital transformation agenda required a fundamental upgrade to how citizens interacted with the state online. The Portuguese Citizen Card had been in circulation since 2007, consolidating five separate identity documents into a single smart card with an embedded cryptographic chip. Those documents were: the identity card, taxpayer card, social security card, national health service card and voter registration card.

Why the Middleware Was Essential

The chip held qualified digital certificates that could allow citizens to sign documents with the same legal force as a handwritten signature. However, for all of this to work in practice, there needed to be a reliable, cross-platform software layer between the card and the applications that wanted to use it. Without that layer, the Citizen Card Middleware, the cryptographic capabilities of the card were inaccessible to ordinary citizens and developers alike.

However, the challenge was formidable for several reasons. First, the middleware had to work across multiple operating systems, Windows, Linux, and macOS, each with its own security model and application integration requirements. Second, it had to support multiple browser environments. Third, and most importantly, it had to be maintainable over the long term, given that the card itself would be in use for decades. Crucially, it also had to be open source, transparent to security researchers, auditable by government bodies and freely available to any developer.

Balancing Simplicity and Reliability

Beyond the technical requirements, there was a significant human dimension. The Citizen Card Middleware would ultimately be used by millions of citizens with no technical background. Therefore, it had to be simple enough for a retired pensioner filing a tax return to use without assistance. At the same time, it needed to be sophisticated enough for a legal professional signing a notarial document to trust completely. These two requirements, extreme simplicity for end users and extreme reliability for professionals, had to coexist in a single piece of software. Caixa Mágica Software accepted this challenge and began a collaboration with the Portuguese government that continues to this day.

The Citizen Card Middleware Solution

Technology Choices

Caixa Mágica Software chose to build the middleware using the Qt Framework and the C/C++ programming language. In addition, the team incorporated established open-source libraries including OpenSSL for cryptographic operations and Poppler for PDF handling. These choices were deliberate and strategic.

Qt provided a cross-platform foundation that allowed the same codebase to run on Windows, Linux and macOS. As a result, separate development teams for each operating system were not required. C/C++ provided the performance and low-level hardware access required for smart card operations. Furthermore, OpenSSL, the world’s most widely audited cryptographic library, provided the security foundations that a national identity system demands.

The project is licensed under the EUPL — European Union Public Licence 1.2. This licence was specifically designed for European public sector software, ensuring transparency, openness and legal compatibility across EU member states. The complete source code is publicly available on GitHub, where it continues to receive regular commits and community contributions.

Development follows agile methodologies, with regular update cycles. Consequently, the middleware keeps pace with operating system updates, new browser versions and evolving security requirements. Over fifteen years, Windows, macOS and the major Linux distributions have each gone through multiple major versions. Nevertheless, the middleware has tracked all of these changes without interruption to the millions of citizens depending on it.

Core Citizen Card Middleware Capabilities

Digital Certificate Management

The Portuguese Citizen Card contains multiple digital certificates, each serving a different purpose. The middleware manages these certificates, ensuring they are current and available for use in both authentication and signature operations. Moreover, it handles certificate discovery, validation against Portuguese government trust anchors, and presentation to the operating system’s certificate store. As a result, any certificate-aware application can use the card without requiring dedicated integration work.

Personal Data Access

For applications that need to verify citizen identity, government portals, banking applications, healthcare systems, the middleware provides controlled access to personal data stored on the card. This includes name, identification number, photograph and official address. However, access is always subject to the cardholder’s consent and the permissions established by the application’s authorisation. Therefore, no application can access card data without the appropriate permissions.

Digital Signature

One of the most consequential capabilities of the Citizen Card Middleware is its support for qualified digital signatures. Through the middleware, citizens can sign PDF documents, contracts, tax declarations and legal submissions. Importantly, these signatures carry the same legal weight as handwritten signatures under Portuguese and European law. The middleware handles the complete signature workflow, from presenting the document to the citizen for review, through PIN verification, to the cryptographic signing operation.

This capability has transformed numerous professional and administrative workflows in Portugal. Notarial documents, legal filings and property transactions that once required physical presence now flow digitally. Furthermore, tax submissions that previously required in-person visits are now completed entirely online.

Authentication

Beyond document signing, the middleware enables citizens to use their Citizen Card as a strong authentication credential for online services. Rather than relying on passwords which can be forgotten, stolen or guessed, services can instead require Citizen Card authentication. This provides a level of identity assurance that password-based systems cannot match. The middleware implements this through standard PKCS#11 and CSP/KSP interfaces. Consequently, any application supporting these standard protocols can integrate Citizen Card authentication without bespoke development.

Mobile Digital Key Integration

Recognising that not all citizens have smart card readers, the Portuguese government developed the Mobile Digital Key (Chave Móvel Digital or CMD). This is an authentication and signature system linked to a citizen’s mobile phone number rather than a physical card. Caixa Mágica Software integrated CMD support directly into the Citizen Card Middleware. As a result, the same software that manages physical card operations also supports CMD signatures within its own graphical application and other system applications. Therefore, citizens can choose the authentication method that suits their situation — card or mobile — while using the same familiar software interface.

SCAP — Professional Attribute Certification

The System of Certification of Professional Attributes (SCAP) extends the Citizen Card Middleware’s capabilities into professional contexts. Through SCAP integration, citizens can sign documents in their professional capacity, as a doctor, lawyer, engineer or company administrator. In addition, these signatures carry verified professional credentials, not just personal identity. The middleware’s SCAP integration connects to the official professional certification infrastructure, ensuring these signatures are legally valid and verifiable.

Integration with Digital Services

Connecting the Citizen Card to tax declaration services (Portal das Finanças), healthcare platforms (SNS) and social security systems was another key milestone. Judicial portals, commercial registry services, and private sector applications including banking and insurance followed. Each new integration makes the card more valuable to citizens and reduces the cost of identity verification for organisations.

Citizen Card Middleware Impact

National Scale

Beyond the technical achievements, the Citizen Card Middleware has had a profound societal impact. It has fundamentally changed the relationship between Portuguese citizens and the state.

Every citizen and business in Portugal interacts with the middleware, directly or indirectly. For example, when a Portuguese citizen files their tax return online, they are using the middleware. Similarly, when a lawyer signs a court submission electronically, they are using the middleware. When a company administrator signs documents with the Commercial Registry, they are also using the middleware. In addition, when a citizen authenticates to access their health records on SNS, the middleware is working in the background.

Open Source as a Strength

The open-source nature of the project has proven to be one of its greatest strengths. By publishing the source code and adopting an open licence, Caixa Mágica Software and its government partners created a system with significant long-term advantages. First, the security research community can scrutinise the code at any time. Second, developers can build on it without licensing costs. Third, and most importantly, it will outlast any single organisation’s involvement.
Furthermore, the middleware has become the exclusive solution for signatures on government documents and public tenders. This has established a standard for reliable digital authentication in public procurement. Private usage continues to expand as well, with citizens increasingly turning to digital signatures for personal transactions that previously required notarial involvement. Meanwhile, integration with the Commercial Registry Authority allows citizens to sign as company administrators with verified credentials. Qualified professionals, architects, engineers, doctors and lawyers can additionally sign documents in their professional capacity through SCAP.

Collaboration and Continuity of the Citizen Card Middleware

The Citizen Card Middleware is not a completed project. Instead, it is a living infrastructure that Caixa Mágica Software continues to develop and maintain. This ongoing work happens in close collaboration with three government partners: the National Printing House (INCM), the Agency for Administrative Modernization (AMA) and the Institute of Registries and Notaries (IRN).

A Public-Private Partnership Model

This collaboration model, a private software company working alongside multiple government agencies on a shared open-source codebase has proven highly effective. On one hand, government partners provide domain expertise, security requirements and access to the card and certification infrastructure. On the other hand, Caixa Mágica Software provides software engineering leadership, cross-platform expertise, and the agile development capability needed to keep pace with a rapidly evolving technology landscape.

Government funding ensures the project’s long-term financial sustainability. In addition, community participation and Caixa Mágica’s technical stewardship ensure its ongoing technical vitality. Ultimately, this combination has produced a piece of national infrastructure that has served Portugal reliably for over fifteen years. Therefore, it is well positioned to continue doing so for many more.

Finally, the complete source code remains available on GitHub.