• Stars
    star
    178
  • Rank 214,989 (Top 5 %)
  • Language
    Java
  • License
    GNU General Publi...
  • Created about 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SmartPGP is a JavaCard implementation of the OpenPGP card specifications

SmartPGP applet

SmartPGP is a free and open source implementation of the OpenPGP card 3.4 specification in JavaCard.

The main improvement introduced in OpenPGP card 3.x specification from previous version is the support of elliptic curve cryptography with several existing curves (NIST P-256, NIST P-384, NIST P-521, brainpool p256r1, brainpool p384r1 and brainpool p512r1).

Features

The following features are implemented at the applet level, but some of them depend on underlying hardware support and available (non-)volatile memory resources:

  • RSA (>= 2048 bits modulus, 17 bits exponent) and ECC (NIST P-256, NIST P-384, NIST P-521, brainpool p256r1, brainpool p384r1 and brainpool p512r1) for signature, encryption and authentication;

  • On-board key generation and external private key import;

  • PIN codes (user, admin and resetting code) up to 127 characters;

  • Certificate up to 1 kB (DER encoded) for each key;

  • Login, URL, and private DOs up to 256 bytes;

  • Command and response chaining;

  • AES 128/256 bits deciphering primitive;

  • Secure messaging (see below).

Default values

The SmartPGP applet is configured with the following default values:

  • Admin PIN is 12345678;

  • User PIN is 123456;

  • No PUK (a.k.a. resetting code) is defined;

  • RSA 2048 bits for PGP keys;

  • NIST P-256 for the secure messaging key.

These values can be changed by modifying default values in the code (see the Constants class).

When the applet is installed, one can use the smartpgp-cli utility given in the bin directory to change these values. Keep in mind that when you change the algorithm attributes of a PGP key or of the secure messaging key, the key and the corresponding certificate are erased. Also note that hard coded default values will be restored upon a factory reset.

Compliance with OpenPGP card 3.4 specification

The SmartPGP applet implements the complete OpenPGP card 3.4 specification, except the secure messaging related features:

  • Commands and responses protection is not implemented as described in the specification. Motivation and implementation details are explained in the secure messaging document;

  • A command protected by secure messaging is not granted admin rights. Secure messaging can thus be used to protect communications only, especially when the token is used contactless;

  • If and only if secure messaging static key and certificate have been provisioned, all commands containing sensitive data (e.g. PIN code, decrypted data, private key, ...) emitted through a contactless interface must be protected by secure messaging or they will be refused;

  • The ACTIVATE FILE with P1 = P2 = 0, as described in the specification, resets everything except the secure messaging static key and certificate. Complete reset, including these elements, can be performed with ACTIVATE FILE with P1 = 0 and P2 = 1.

Application support

Tokens following the OpenPGP card 3.4 specification are not yet fully supported by most PGP applications.

GnuPG

OpenPGP card 3.x is supported by GnuPG starting from version 2.1.16.

The specific secure messaging of the SmartPGP applet is not supported at is not part of the OpenPGP card specification.

OpenKeychain

OpenPGP card 3.x is supported by OpenKeychain starting from version 4.2.

The secure messaging of the SmartPGP applet is fully supported in OpenKeychain. See the section below for more information on the setup process.

Content of the repository

The repository contains several directories:

  • bin contains a Python library and command line tool called smartpgp-cli to interact with an OpenPGP card 3.x but also to deal with the specific secure messaging feature of the SmartPGP applet;

  • secure_messaging contains documentation and example scripts to play with the secure messaging feature of SmartPGP;

  • src contains the JavaCard source code of the SmartPGP applet;

  • videos contains sample videos demonstrating smartcard interactions with OpenKeychain and K9 mail on Android Nexus 5.

Build and installation instructions

Prerequisites

  • JavaCard Development Kit 3.0.4 (or above) from Oracle website;

  • A device compliant with JavaCard 3.0.4 (or above) with enough available resources to hold the code (approximately 23 kB of non-volatile memory), persistent data (approximately 10 kB of non-volatile memory) and volatile data (approximately 2 kB of RAM).

  • The pyscard and pyasn1 Python libraries for smartcard-cli.

Importing RSA keys above 2048 bits (3072 or 4096 bits)

The size of the internal buffer is set by default to a value that permits to import RSA 2048 bits. If your card is able to deal with RSA keys of 3072 or 4096 bits and you want to be able to import such keys, then you need to adjust the size of this buffer:

  • for RSA 2048 bits, Constants.INTERNAL_BUFFER_MAX_LENGTH must be at least (short)0x3b0;

  • for RSA 3072 bits, Constants.INTERNAL_BUFFER_MAX_LENGTH must be at least (short)0x570;

  • for RSA 4096 bits, Constants.INTERNAL_BUFFER_MAX_LENGTH must be at least (short)0x730.

Reducing flash and/or RAM consumption

The applet allocates all its data structures to their maximal size at installation to avoid as much as possible runtime errors caused by memory allocation failure. If your device does not have enough flash and/or RAM available, or if you plan not to use some features (e.g. stored certificates), you can adjust the applet to reduce its resource consumption by tweaking the following variables:

  • Constants.INTERNAL_BUFFER_MAX_LENGTH: the size in bytes of the internal RAM buffer used for input/output chaining. Chaining is especially used in case of long commands and responses such as those involved in private key import and certificate import/export;

  • Constants.EXTENDED_CAPABILITIES, bytes 5 and 6: the maximal size in bytes of a certificate associated to a key. Following the OpenPGP card specification, a certificate can be stored for each of the three keys. In SmartPGP, a fourth certificate is stored for secure messaging.

Building the CAP file

  • Set path to the JavaCard Development Kit: export JC_HOME="your/path/to/javacardkit"

  • (Optional) Edit the build.xml file and replace the 0xAF:0xAF bytes in the APPLET_AID with your own manufacturer identifier (see section 4.2.1 of OpenPGP card specification). Alternatively, set the right AID instance bytes during applet installation.

  • Execute ant with no parameter will produce the CAP file in SmartPGPApplet.cap.

Installing the CAP file

The CAP file installation depends on your device, so you have to refer to the instructions given by your device manufacturer. Most open cards relying on Global Platform with default keys are supported by GlobalPlatformPro.

Be careful to use a valid AID according to the OpenPGP card specification (see section 4.2.1) for each card (-create <AID> with GlobalPlatformPro)

Setting up secure messaging with OpenKeychain

Secure messaging without token authentication

Without token authentication, you are not protected against man-in-the-middle attack as your device cannot ensure it is communicating directly with a trusted token. Nevertheless, the communications with the token are still protected in confidentiality against passive attacks (i.e. trafic capture).

If you want to test secure messaging without token authentication, you can use the following command to order the token to generate its secure messaging key on-board.

./smartpgp-cli -r X -I generate-sm-key -o pubkey.raw

In this case, you have to deactivate the certificate verification in OpenKeychain: go to "Parameters" > "Experimental features" and deactivate the option called "SmartPGP verify certificate".

Secure messaging with token authentication

The secure_messaging directory contains a subdirectory called pki which contains two sample scripts to generate a certificate authority and token certificates.

The sample scripts are given only for test purposes of the secure messaging feature with certificate verification. They require openssl to be installed on your system.

If you want to use your own PKI, you have to generate a specific intermediate certificate authority to sign the certificates of your token(s). Then, you have to provision the complete certificate chain from this new intermediate CA to your root CA in OpenKeychain because the certificate verification implemented in the given patch does not rely on the system keystore.

Generate a sample CA key and certificate

Change your current directory to the pki directory and execute the script ./generate_ca.sh. It will produce a sample CA key in PKI/private/ca.key.pem and the corresponding certificate in PKI/certs/ca.cert.pem.

Generate a sample token key and certificate

Change your current directory to the pki directory and execute the script

./generate_token.sh mycard1

where mycard1 is some unique identifier for the token. It will produce a sample token key in PKI/private/mycard1.key.pem and the corresponding certificate in PKI/certs/mycard1.cert.pem.

Provision the token with its sample key and certificate

Change your current directory to the bin directory and execute the following commands after replacing the reader number X by the number of the reader that contains your token, and the path to the pki directory used in previous sections.

The following command imports the token key in the token.

./smartpgp-cli -r X -I -i path_to_the_pki_dir/PKI/private/mycard1.key.der put-sm-key

The following command imports the token certificate in the token.

./smartpgp-cli -r X -I -i path_to_the_pki_dir/PKI/certs/mycard1.cert.der put-sm-certificate

These commands have to be executed in this order because the key import clears any previously stored certificate.

Once the token key is imported, you should remove the token private key from you system as there is no need to keep it outside of your token.

Install the CA in OpenKeychain

  • Upload the CA certificate PKI/certs/ca.cert.pem to your phone;

  • Go to "Parameters" > "Experimental features" and activate the option called "SmartPGP verify certificate`;

  • Click on "SmartPGP trusted authorities", and then on "+" at the top left;

  • Set a name for this authority and select the file you uploaded.

More Repositories

1

AD-control-paths

Active Directory Control Paths auditing and graphing tools
C
650
star
2

rust-guide

Recommendations for secure applications development with Rust
Shell
591
star
3

ADTimeline

Timeline of Active Directory changes with replication metadata
PowerShell
466
star
4

bmc-tools

RDP Bitmap Cache parser
Python
465
star
5

polichombr

Collaborative malware analysis framework
Python
373
star
6

MLA

Multi Layer Archive - A pure rust encrypted and compressed archive file format
Rust
322
star
7

SecuML

Machine Learning for Computer Security
Python
271
star
8

libecc

Library for elliptic curves cryptography
C
258
star
9

DFIR-O365RC

PowerShell module for Office 365 and Azure log collection
PowerShell
240
star
10

ORADAD

Outil de récupération automatique des données de l'Active Directory / Automated tool for dumping Active Directory data
C++
215
star
11

ASCAD

Side Channels Analysis and Deep Learning
Python
174
star
12

cry-me

CRY.ME (CRYptographic MEssaging application)
Kotlin
168
star
13

ultrablue

User-friendly Lightweight TPM Remote Attestation over Bluetooth
Kotlin
163
star
14

ctf

Epreuves de sélection de la TeamFR pour l'ECSC 2019.
Python
156
star
15

AD-permissions

Active Directory permissions (ACL/ACE) auditing tools
PHP
144
star
16

DFIR4vSphere

Powershell module for VMWare vSphere forensics
PowerShell
138
star
17

tabi

BGP Hijack Detection
Python
109
star
18

bootcode_parser

A boot record parser that identifies known good signatures for MBR, VBR and IPL.
Python
97
star
19

SysvolExplorer

Active Directory Group Policy analyzer
C++
94
star
20

Binacle

Full-bin indexation of binary files
Rust
92
star
21

audit-radius

A RADIUS authentication server audit tool
Python
79
star
22

AnoMark

Algorithme d'apprentissage statistique permettant de créer un modèle sur les lignes de commandes des évènements "Création de Processus", afin de détecter des anomalies dans les évènements futurs
Python
78
star
23

bits_parser

Extract BITS jobs from QMGR queue and store them as CSV records
Python
73
star
24

route_leaks

BGP Route Leaks Detection
Python
69
star
25

transdep

Discover SPOF in DNS dependency graphs
Go
67
star
26

SecAESSTM32

Bibliothèque C et assembleur permettant le chiffrement/déchiffrement AES-128 de messages pour des composants grand public (famille STM32F3/STM32F4)
C
67
star
27

x509-parser

a RTE-free X.509 parser
C
58
star
28

guide-journalisation-microsoft

Guide journalisation Microsoft
PowerShell
56
star
29

mabo

MRT Parser
OCaml
46
star
30

chipsec-check

Tools to generate a Debian Linux distribution with chipsec to test hardware requirements
Shell
45
star
31

lidi

Transfer a raw TCP or Unix stream or files through a unidirectional link with forward error correction
Rust
44
star
32

shovel

Web interface to explore Suricata EVE outputs
JavaScript
38
star
33

picon

Picon
C
38
star
34

nogaxeh

Tools for analyzing hexagon code
C++
38
star
35

secAES-ATmega8515

Secure AES128 Encryption Implementation for ATmega8515
Assembly
34
star
36

OVALI

Generic graph exploration, manipulation and visualization tool (Outil de Visualisation et Analyse de Liens Inter-objets)
JavaScript
34
star
37

Open-ISO7816-Stack

This project aims to provide an open-source implementation of the ISO7816-3 communication protocol from the reader side. This protocol is ruling the interactions between a smartcard and a card-reader when using its contacts to communicate
C
33
star
38

packetweaver

A Python framework for script filing and task sequencing
Python
26
star
39

IPECC

A VHDL IP for ECC (Elliptic Curve Cryptography) hardware acceleration
VHDL
26
star
40

ADCP-DirectoryCrawler

AD-control-paths LDAP submodule
C
18
star
41

WAAD

Détection d'anomalie à partir des journaux d'authentification Windows
Python
17
star
42

cardstalker

CardStalker provides a UART-driven smartcard reader at the T=1 (see ISO7816-3) level (link and physical layer), where most of the smartcard reader devices on the market are only providing an APDU interface (application layer).
C
17
star
43

sftp2misp

Automation script to download JSON MISP files from a SFTP server and import them via API to a MISP instance.
Python
15
star
44

mdbook-checklist

mdbook preprocessor for generating checklists and indexes
Rust
13
star
45

cornetto

Outil de gestion de version statique de site web
JavaScript
10
star
46

pciemem

Linux kernel module for driving an USB3380 board, exposing a /dev/pciemem device node on the analysis machine representing the physical memory of the machine under test
C
10
star
47

ORADAZ

Outil de récupération automatique des données AZure / Automated tool for dumping Azure configuration data
Rust
10
star
48

xsvgen

XML Schema Validator Generator
OCaml
10
star
49

ProTIP

ProTIP permet de caractériser la connectivité réelle entre composants d'une architecture PCI Express
Prolog
9
star
50

coq-prelude

General-purpose monad typeclass hierarchy for Coq
Coq
8
star
51

scep

Security Contexts for Enhanced Protection Linux Security Module
C
7
star
52

libdrbg

A portable library implementing NIST SP 800-90A DRBGs
C
7
star
53

Faults_analyzer

Logiciel d'analyse de campagnes de perturbations sur composants
Python
6
star
54

hackropole-hugo

A Hugo theme to host Capture-The-Flag (CTF) challenges as a static website like hackropole.fr.
HTML
6
star
55

caradoc

A PDF parser and validator
6
star
56

WSUS_Audit

Auditing scripts for WSUS infrastructures
6
star
57

DroidWorks

Rust
5
star
58

libapn

libapn is a header-based C++ library developed to study vectorial Boolean functions, including but not limited to APN functions.
C++
5
star
59

pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
5
star
60

ADCP-libdev

AD-control-paths libraries submodule
C
5
star
61

caml-crush

Caml Crush: an OCaml PKCS#11 filtering proxy
3
star
62

Faults_experiments

Résultats bruts de campagnes de perturbation de composants réalisées par le laboratoire de sécurité des composants de l'ANSSI
Python
2
star
63

eurydice

A user-friendly solution to transfer files through a physical diode using the Lidi utility, complete with data retention, file history, user accounts and admin management. Provides a scriptable API and a web interface.
2
star
64

DECODE

Malware detection tool for Windows PE files based on DFIR ORC data
Python
2
star
65

scantru

Non-Profiled Side Channel Analysis on NTRU
Jupyter Notebook
1
star
66

concerto

Toolset to analyse TLS datasets
1
star
67

opkcs11-tool

opkcs11-tool: managing and operating PKCS #11 security tokens in OCaml
1
star