2016-10-21 12:56:47 +00:00
# SmartPGP applet
SmartPGP is a free and open source implementation of the [OpenPGP card
2019-07-02 08:05:54 +00:00
3.4 specification](https://gnupg.org/ftp/specs/OpenPGP-smart-card-application-3.4.pdf) in JavaCard.
2016-10-21 12:56:47 +00:00
## 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:
2023-10-04 19:25:34 +00:00
- RSA (>= 2048 bits modulus, 17 bits exponent) 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 each
- 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
2016-10-21 12:56:47 +00:00
## Default values
The SmartPGP applet is configured with the following default values:
2023-10-04 19:25:34 +00:00
- Admin PIN is 12345678
- User PIN is 123456
- No PUK (a.k.a. resetting code) is defined
- RSA 2048 bits for PGP keys
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
These values can be changed by modifying the [Constants ](src/dev/c0de/smartpgp/Constants.java ) class.
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
After the applet has been installed, the [smartpgp-cli ](bin/smartpgp-cli ) utility
will be able to change the above values.
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
_Note: These settings are restored if you factory reset the applet._
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
__Note: If you change algorithm attributes, the key and corresponding certificate will be erased.__
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
## Build and Install instructions
2016-10-21 12:56:47 +00:00
2023-10-04 18:38:28 +00:00
### Prerequisites
2016-10-21 12:56:47 +00:00
2023-10-04 18:38:28 +00:00
- A Java compiler (No higher than OpenJDK 11 or equivalent)
- A device compliant with JavaCard 3.0.1 (or above) with enough available resources
- Applet: ~23 KiB of non-volatile (eeprom/flash) memory
- Persistant Data: ~10 KiB of non-volatile (eeprom/flash) memory
- Transient Data: ~2 KiB of volatile (RAM) memory
2016-10-21 12:56:47 +00:00
2023-10-04 18:38:28 +00:00
<!-- - The [pyscard ](https://pypi.org/project/pyscard/ ) and [pyasn1 ](https://pypi.org/project/pyasn1/ )
Python libraries for `smartcard-cli` . -->
2016-10-21 12:56:47 +00:00
2023-10-04 18:38:28 +00:00
### Importing RSA keys above 2048 bits
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
The internal buffer that stores keys is configured with a default value that is only large enough for RSA 2048 bit keys.
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
If your card is able to handle larger RSA key bit-lengths (3072 or 4096), and you want to import those keys, you will need to increase the buffer size.
2021-06-19 00:34:45 +00:00
2023-10-04 18:38:28 +00:00
This can be accomplished by modifying `Constants.INTERNAL_BUFFER_MAX_LENGTH` in [Constants.java ](src/dev/c0de/smartpgp/Constants.java )
2020-01-15 10:39:08 +00:00
2023-10-04 18:38:28 +00:00
#### RSA 2048 bit keys
2020-01-15 10:39:08 +00:00
2023-10-04 18:38:28 +00:00
When produced by OpenPGP, these keys are 949 Bytes in length.
`Constants.INTERNAL_BUFFER_MAX_LENGTH` may not be smaller than `(short)0x3b6` (decimal: 950)
2020-01-15 10:39:08 +00:00
2023-10-04 18:38:28 +00:00
#### RSA 3072 bit keys
2020-01-15 10:39:08 +00:00
2023-10-04 18:38:28 +00:00
When produced by OpenPGP, these keys are 1294 Bytes in length.
`Constants.INTERNAL_BUFFER_MAX_LENGTH` may not be smaller than `(short)0x50f` (decimal: 1295)
2020-01-15 10:39:08 +00:00
2023-10-04 18:38:28 +00:00
#### RSA 4096 bit keys
2020-01-15 10:39:08 +00:00
2023-10-04 18:38:28 +00:00
When produced by OpenPGP, these keys are 1644 Bytes in length.
`Constants.INTERNAL_BUFFER_MAX_LENGTH` may not be smaller than `(short)0x66d` (decimal: 1645)
2020-01-15 10:39:08 +00:00
2023-10-04 19:25:34 +00:00
### Reducing flash and/or RAM consumption
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
When the applet is installed, all data structures will be allocated
to their maximum size. This is a standard practice for JavaCard applets
to ensure that there will not be a memory allocation failure at runtime.
A consequence of this is that, if you configure a large rsa key and
use a small key, that extra space can not be used for anything else.
If your device does not have enough flash memory and/or RAM, or you plan
to not use some features (eg. on-device certificates), you can modify
the following variables in [Constants.java ](src/dev/c0de/smartpgp/Constants.java )
2016-10-21 12:56:47 +00:00
- `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
2020-01-15 10:39:08 +00:00
involved in private key import and certificate import/export;
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
- `Constants.EXTENDED_CAPABILITIES` , bytes 5 and 6: the maximum size
in bytes of a certificate associated to a key. The default is 1152 Bytes.
A certificate can be stored for each of the three keys.
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
### Building the CAP file
2016-10-21 12:56:47 +00:00
2023-08-26 21:02:53 +00:00
- (Optional) Edit the `build.xml` file and replace the `APPLET_AID`
with your a unique value. Alternatively, set the
2018-07-02 11:36:32 +00:00
right AID instance bytes during applet installation.
2023-08-26 21:02:53 +00:00
Generate the AID using [this tool ](https://c0de.dev/c0de/SmartPGP-AID-Generator )
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
- Execute `ant` to build `SmartPGPApplet.cap`
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
### Installing the CAP file
2016-10-21 12:56:47 +00:00
The CAP file installation depends on your device, so you have to refer
2018-07-02 11:36:32 +00:00
to the instructions given by your device manufacturer. Most open cards
relying on Global Platform with default keys are supported by
[GlobalPlatformPro ](https://github.com/martinpaljak/GlobalPlatformPro ).
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
You must use a valid, unique AID that matches the OpenPGP card specification (see section 4.2.1)
for each card (`-create < AID > ` with GlobalPlatformPro)
2016-10-21 12:56:47 +00:00
2023-10-04 19:25:34 +00:00
Example Installation commands:
2023-08-26 21:02:53 +00:00
- `gp --install SmartPGPApplet.cap --default`
- `gp --install SmartPGPApplet.cap --create <AID>`