Skip to content

Commit 88b05b3

Browse files
committed
Enable support for keys obtained through PKCS#11
This allows signing using a HSM or a Smartcard (ex. Yubikey) Look at PKCS11.md for help on getting started. Sponsered by: @ZonD80
1 parent f38a095 commit 88b05b3

File tree

6 files changed

+224
-44
lines changed

6 files changed

+224
-44
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ LIBCRYPTO_INCLUDES ?= $(shell pkg-config --cflags libcrypto)
3131
LIBCRYPTO_LIBS ?= $(shell pkg-config --libs libcrypto)
3232
endif
3333

34+
ifeq ($(SMARTCARD),1)
35+
CPPFLAGS += -DSMARTCARD
36+
endif
37+
3438
MANPAGE_LANGS := zh_TW zh_CN
3539

3640
EXT ?=

PKCS11.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Setup
2+
1. Build with `make SMARTCARD=1`
3+
2. Install the OpenSSL engine for PKCS#11 (`libengine-pkcs11-openssl` on Debian, part of `libp11`)
4+
5+
## Load Key Into Smartcard
6+
It is recommend that you generate the key on the card itself, but you can import it if needed.
7+
8+
For yubikeys:
9+
1. Extract Cert and Key from p12
10+
```
11+
openssl pkcs12 -in Certificates.p12 -out cert.crt.pem -clcerts -nokeys -legacy
12+
openssl pkcs12 -in Certificates.p12 -out key.pem -nocerts -nodes -legacy
13+
```
14+
2. Import into Key
15+
```
16+
yubico-piv-tool -s 9c -a import-certificate -i cert.crt.pem
17+
yubico-piv-tool -s 9c -a import-key -i key.pem
18+
yubico-piv-tool -s 9c -a set-chuid
19+
```
20+
3. You can use `p11tool --list-privkeys --login` to identify the URI for the slot (make sure that `type` is not in the URI, as seperate URIs for the cert and private key are not currently supported from the command line)
21+
22+
## Sign
23+
1. `ldid -K'pkcs11:model=YubiKey%20YK5;id=%02' -Sents.xml ls.bin`
24+
2. If the correct PKCS#11 module is not being loaded, try setting `PKCS11_MODULE_PATH` in your environment (ex. `export PKCS11_MODULE_PATH="/usr/local/lib/p11-kit-proxy.so"` or `PKCS11_MODULE_PATH="/usr/local/lib/libykcs11.so"`)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Changes from https://git.saurik.com/ldid.git:
66
- Allow p12 keys to have a password (@sunflsks)
77
- Add a `-arch arch_type` flag so that typing the raw CPU type is not needed
88
- Proper error messages
9+
- Load key using PKCS#11

docs/ldid.1

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
.Op Fl H Ns Op Ar sha1 | Ar sha256
2121
.Op Fl h
2222
.Op Fl I Ns Ar name
23-
.Op Fl K Ns Ar key.p12 Op Fl U Ns Ar password
23+
.Op Fl K Ns Ar file Op Fl U Ns Ar password
2424
.Op Fl M
2525
.Op Fl P Ns Op Ar num
2626
.Op Fl Q Ns Ar requirements
@@ -93,14 +93,19 @@ hash types, flags, CDHash, and CodeDirectory version to
9393
Set the identifier used in the binaries signature to
9494
.Ar name .
9595
If not specified, the basename of the binary is used.
96-
.It Fl K Ns Ar key.p12
96+
.It Fl K Ns Ar file
9797
Sign using the identity in
98-
.Ar key.p12 .
98+
.Ar file .
99+
Must be either a
100+
.Ar p12
101+
or
102+
.Ar pkcs11:
103+
URI.
99104
This will give the binary a valid signature so that it can be run
100105
on a system with signature validation.
101-
If
102-
.Ar key.p12
103-
has a password you will be prompted for it,
106+
If the
107+
.Ar p12
108+
has a password, you will be prompted for it,
104109
or you can specify from the command line with
105110
.Fl U .
106111
.It Fl M

0 commit comments

Comments
 (0)