1 Gnuk - An Implementation of USB Cryptographic Token for GnuPG
6 Free Software Initiative of Japan
11 This is the release of Gnuk, version 1.2.11, which has major
12 incompatible changes to Gnuk 1.0.x. Specifically, it now supports
13 overriding key import, but importing keys (or generating keys) results
14 password reset. Also, you need to import private keys before changing
15 your password. Please update your documentation for Gnuk Token, so
16 that the instruction of importing keys won't cause any confusion.
18 It has supports of EdDSA, ECDSA (with NIST P256 and secp256k1), and
19 ECDH (with X25519, NIST P256 and secp256k1), but this ECC feature is
20 somehow experimental, and it requires modern GnuPG 2.2 with libgcrypt
23 It also supports RSA-4096, but users should know that it takes more
24 than 8 seconds to sign/decrypt. Key generation of RSA-4096 just fails,
25 because the device doesn't have enough memory.
27 It supports new KDF-DO feature. Please note that this is
28 experimental. To use the feature, you need to use newer GnuPG (2.2.6
29 or later). You need to prepare the KDF-DO on your token by the
30 card-edit/kdf-setup command.
32 With FST-01SZ, experimental ack button support is available for test.
38 Gnuk is an implementation of USB cryptographic token for GNU Privacy
39 Guard. Gnuk supports OpenPGP card protocol version 3, and it runs on
40 STM32F103 processor (and its compatible).
42 I wish that Gnuk will be a developer's soother who uses GnuPG. I have
43 been nervous of storing secret key(s) on usual secondary storage.
44 There is a solution with OpenPGP card, but it is not the choice for
45 me, as card reader is not common device. With Gnuk, this issue will
46 be solved by a USB token.
48 Please look at the graphics of "gnuk.svg" for the software name. My
49 son used to be with his NUK(R), always, everywhere. Now, I am with a
50 USB Cryptographic Token by "Gnuk", always, everywhere.
56 Q0: How Gnuk USB Token is superior than other solutions (OpenPGP
57 card 2.0, YubiKey, etc.) ?
58 https://www.g10code.de/p-card.html
59 https://www.yubico.com/
60 A0: Good points of Gnuk are:
61 * If you have skill of electronics and like DIY, you can build
62 Gnuk Token cheaper (see Q8-A8).
63 * You can study Gnuk to modify and to enhance. For example, you
64 can implement your own authentication method with some sensor
65 such as an acceleration sensor.
66 * It is "of Free Software"; Gnuk is distributed under GPLv3+,
67 "by Free Software"; Gnuk development requires only Free Software
68 (GNU Toolchain, Python, etc.),
69 "for Free Software"; Gnuk supports GnuPG.
71 Q1: What kind of key algorithm is supported?
72 A1: Gnuk version 1.0 only supports RSA-2048.
73 Gnuk version 1.2.x supports 255-bit EdDSA, as well as RSA-4096.
74 (Note that it takes long time to sign with RSA-4096.)
76 Q2: How long does it take for digital signing?
77 A2: It takes a second and a half or so for RSA-2048.
78 It takes more than 8 secondd for RSA-4096.
80 Q3: What's your recommendation for target board?
81 A3: Orthodox choice is Olimex STM32-H103.
82 FST-01 (Flying Stone Tiny 01) is available for sale, and it is a
83 kind of the best choice, hopefully.
84 If you have a skill of electronics, STM32 Nucleo F103 is the best
85 choice for experiment.
87 Q4: What's version of GnuPG are you using?
88 A4: In Debian GNU/Linux system, I use GnuPG modern 2.1.18.
90 Q5: What's version of pcscd and libccid are you using?
91 A5: I don't use them, pcscd and libccid are optional, you can use Gnuk
93 I tested pcscd 1.5.5-4 and libccid 1.3.11-2 which were in Debian
96 Q6: What kinds of hardware is required for development?
97 A6: You need a target board plus a JTAG/SWD debugger. If you just
98 want to test Gnuk for target boards with DfuSe, JTAG debugger is
99 not the requirement. Note that for real use, you need JTAG/SWD
100 debugger to enable flash ROM protection.
102 Q7: How much does it cost?
103 A7: Olimex STM32-H103 plus ARM-USB-TINY-H cost 70 Euro or so.
105 Q8: How much does it cost for DIY version?
106 A8: STM32 Nucleo F103 costs about $10 USD.
108 Q9: I got an error like "gpg: selecting openpgp failed: ec=6.108", what's up?
109 A9: Older GnuPG's SCDaemon has problems for handling insertion/removal of
110 card/reader. When your newly inserted token is not found by
111 GnuPG, try killing scdaemon and let it to be invoked again. I do:
113 $ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
115 and confirm scdaemon doesn't exist, then,
117 $ gpg-connect-agent learn /bye
119 Qa: With GNOME 2, I can't use Gnuk Token for SSH. How can we use it for SSH?
120 Aa: You need to deactivate seahorse-agent and gnome-keyring, but use
121 gpg-agant for the role of ssh-agent. For gnome-keyring please do:
123 $ gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
125 Qb: With GNOME 3.0, I can't use Gnuk Token at all. Why?
126 Ab: That's because gnome-keyring-daemon interferes GnuPG. Type:
128 $ gnome-session-properties
130 and at the tab of "Startup Programs", disable check buttons for
131 "GPG Password Agent" and "SSH Key Agent".
133 Qc: With GNOME 3.x (x >= 8?), I can't use Gnuk Token at all. Why?
134 Ac: That's because gnome-keyring-daemon interferes GnuPG. Please
135 disable the invocation of gnome-keyring-daemon. In Debian
136 wheezy, it's in the files /etc/xdg/autostart/gnome-keyring-ssh.desktop
137 and /etc/xdg/autostart/gnome-keyring-gpg.desktop.
138 We have a line something like:
140 OnlyShowIn=GNOME;Unity;MATE;
142 Please edit this line to:
146 Qd: Do you know a good SWD debugger to connect FST-01 or something?
147 Ad: ST-Link/V2 is cheap one. We have a tool/stlinkv2.py as flash ROM
148 writer program. STM32 Nucleo F103 comes with the valiant of
149 ST-Link/V2. However, the firmware of ST-Link/V2 is proprietary.
150 Now, I develop BBG-SWD, SWD debugger by BeagleBone Green.
156 Gnuk is tested by test suite. Please see the test directory.
158 * Personalization of the card
159 * Changing Login name, URL, Name, Sex, Language, etc.
160 * Password handling (PW1, RC, PW3)
161 * Key import for three types:
162 * key for digital signing
164 * key for authentication
165 * PSO: Digital Signature
167 * INTERNAL AUTHENTICATE
168 * Changing value of password status bytes (0x00C4): forcesig
169 * Verify with pin pad
170 * Modify with pin pad
171 * Card holder certificate (read)
173 * Key generation on device side for RSA-2048
174 * Overriding key import
176 Original features of Gnuk, tested manually lightly:
178 * OpenPGP card serial number setup
179 * Card holder certificate (write by UPDATE BINARY)
180 * Upgrading with "EXTERNAL AUTHENTICATE" by reGNUal
186 We use Olimex STM32-H103 board and Flying Stone Tiny 01 (FST-01).
188 With DfuSe support, STBee is also our targets. But this target with
189 DfuSe is for experiment only, because it is impossible for DfuSe to
190 disable read from flash. For real use, please consider killing DfuSe
191 and enabling read protection using JTAG debugger.
193 For experimental PIN-pad support, I connect a consumer IR receive
194 module to FST-01, and use controller for TV. PIN verification is
195 supported by this configuration. Yes, it is not secure at all, since
196 it is very easy to monitor IR output of the controllers. It is just
197 an experiment. Note that hardware needed for this experiment is only
198 a consumer IR receive module which is as cheap as 50 JPY.
200 Note that you need pinpad support for GnuPG to use PIN-pad enabled
201 Gnuk. The pinpad support for GnuPG is only available in version 2.
204 Build system and Host system
205 ============================
207 Makefile is written for GNU make. You need Bash 4.x for configure.
209 If your bash is not installed as /bin/bash, you need to run configure
210 script prepending 'bash' before './configure'.
212 Some tools are written in Python. If your Python is not installed as
213 /usr/bin/python, please prepend 'python' for your command invocation.
214 Python 2.7 and PyUSB 0.4.3 is assumed. I also use Python 3.5 and
221 Gnuk source code is under src/ directory.
223 Note that SHA-2 hash function implementation, src/sha256.c, is based
224 on the original implementation by Dr. Brian Gladman. See:
226 http://brg.a2hosted.com//oldsite/cryptography_technology/sha/index.php
228 http://gladman.plushost.co.uk/oldsite/cryptography_technology/sha/index.php)
234 It is distributed under GNU General Public Licence version 3 or later
235 (GPLv3+). Please see src/COPYING.
237 Please note that it is distributed with external source code too.
238 Please read relevant licenses for external source code as well.
240 The author(s) of Gnuk expect users of Gnuk will be able to access the
241 source code of Gnuk, so that users can study the code and can modify
242 if needed. This doesn't mean person who has a Gnuk Token should be
243 able to access everything on the Token, regardless of its protections.
244 Private keys, and other information should be protected properly.
250 Gnuk is distributed with external source code.
252 * chopstx/ -- Chopstx 1.11
254 We use Chopstx as the kernel for Gnuk.
256 Chopstx is distributed under GPLv3+ (with a special exception).
259 * polarssl/ -- based on PolarSSL 1.2.10 (now mbedTLS)
261 Souce code taken from: http://polarssl.org/
263 We use PolarSSL for RSA computation, and AES encryption/decryption.
265 PolarSSL is distributed under GPLv2+. We use PolarSSL under GPLv3
268 The file include/polarssl/bn_mul.h is heavily modified for ARM
271 The function rsa_private in polarssl/library/rsa.c is modified so
272 that it doesn't check T against N. The function rsa_pkcs1_sign is
273 modified to avoid warnings in case of !POLARSSL_PKCS1_V21.
275 The functions rsa_pkcs1_verify and rsa_rsassa_pkcs1_v15_verify in
276 include/polarssl/rsa.h and polarssl/library/rsa.c are modified
277 (fixed) for last argument SIG, as the memory at SIG aren't modified
280 The constant POLARSSL_MPI_MAX_SIZE in include/polarssl/bignum.h is
281 modified for 2048-bit keys only Gnuk.
283 The function mpi_mul_hlp in library/bignum.c is modified for more
284 optimization for ARM Cortex-M3. Functions mpi_montred, mpi_sub_hlp,
285 mpi_sub_abs, mpi_mul_mpi, mpi_montmul, and mpi_exp_mod are modified
286 to avoid side channel attacks. Note that we don't use RSA-blinding
287 technique for Gnuk. Function mpi_gen_prime and mpi_is_prime are
288 modified to use Fouque-Tibouchi method. Function mpi_exp_mod is
289 modified to use new function mpi_montsqr for speed up.
291 The file library/aes.c is modified so that some constants can
294 The file include/polarssl/config.h are modified not to define
295 POLARSSL_HAVE_LONGLONG to avoid linking libgcc, to define
296 POLARSSL_AES_ROM_TABLES to have AES tables, not to define
297 POLARSSL_CIPHER_MODE_CTR, POLARSSL_FS_IO, POLARSSL_PKCS1_V21,
298 POLARSSL_SELF_TEST, and POLARSSL_PADLOCK_C, and only define
299 POLARSSL_GENPRIME when defined KEYGEN_SUPPORT.
301 And polarssl/library/bignum.c is modified to work on 64-bit machine.
303 Aurelien Jarno also modified:
305 polarssl/include/polarssl/bn_mul.h
306 polarssl/library/bignum.c
308 See ChangeLog (and/or history of git) for detail.
311 USB vendor ID and product ID (USB device ID)
312 ============================================
314 When you have a vendor ID and assign a product ID for Gnuk, edit the
315 file GNUK_USB_DEVICE_ID and add an entry for yours. In this case,
316 please contact Niibe, so that it is listed to the file in the official
317 release of the source code.
319 When you are modifing Gnuk and installing the binary to device, you
320 should replace the vendor string and serial number to yours (in the
321 file GNUK_USB_DEVICE_ID and SERIALNO of the script of src/configure),
322 so that users can see it's not by original vendor, and it is modified
325 FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices
326 with Gnuk under one of following conditions:
328 * For everyone for experimental purpose:
330 - You must not distribute a binary with FSIJ's USB device ID, but
331 must use the binary by yourself only for your experiment. Note
332 that "Distributing binary" includes distributing a device which
335 * For general individuals:
337 - You must use your Gnuk device with a card serial number which is
338 *not* by FSIJ. Easy one would be a card serial number generated
341 * For individuals with explicit permission from FSIJ.
343 - You should have an assigned card serial number by FSIJ,
344 please use that number for your device.
345 (There a file 'GNUK_SERIAL_NUMBER' in the official release.)
347 FSIJ could give companies or business entities "second source
348 manufacturer" license to use USB device ID of FSIJ for devices with
349 unmodified version of Gnuk, provided they support Free Software and
350 respect users' freedom for computing. Please ask FSIJ for the
353 Otherwise, companies which want to distribute Gnuk devices, please use
354 your own USB vendor ID and product ID. Please replace vendor string
355 and possibly product string to yours, when you modify Gnuk.
361 For GNU/Linux, PC/SC service is an option, you can use GnuPG's
362 internal CCID driver instead. If you chose using PC/SC service,
363 libccid version >= 1.3.11 is recommended for GNU/Linux.
369 You need GNU toolchain and newlib for 'arm-none-eabi' target.
371 On Debian we can install the packages of gcc-arm-none-eabi,
372 gdb-arm-none-eabi and its friends. I'm using:
374 binutils-arm-none-eabi 2.31.1-2+10
375 gcc-arm-none-eabi 15:7-2018-q2-4
376 gdb-arm-none-eabi 7.12-6+9+b2
377 libnewlib-arm-none-eabi 3.0.0.20180802-2
379 Or else, see https://launchpad.net/gcc-arm-embedded for preparation of
380 GNU Toolchain for 'arm-none-eabi' target.
382 Change directory to `src':
384 $ cd gnuk-VERSION/src
386 Then, run `configure':
388 $ ./configure --vidpid=<VID:PID>
390 Here, you need to specify USB vendor ID and product ID. For FSIJ's,
391 it's: --vidpid=234b:0000 . Please read section 'USB vendor ID and
399 Then, we will have "gnuk.elf" under src/build directory.
401 If you are not the authorized vendor, please never distribute this
402 file of "gnuk.elf", which includes VID:PID in the image. If you would
403 like to distribute the image (for example, to check if it's
404 reproducible or not), the file "gnuk-no-vidpid.elf" is the one with no
411 Olimex STM32-H103 board
412 -----------------------
414 If you are using Olimex JTAG-Tiny, type following to invoke OpenOCD
415 and write "gnuk.elf" to Flash ROM:
417 $ openocd -f interface/ftdi/olimex-jtag-tiny.cfg \
418 -f board/olimex_stm32_h103.cfg \
419 -c "program build/gnuk.elf verify reset exit"
421 Command invocation is assumed in src/ directory.
427 If you are using Flying Stone Tiny 01, you need a SWD writer.
429 OpenOCD 0.9.0 now supports ST-Link/V2. We can use it like:
431 $ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
432 -c "program build/gnuk.elf verify reset exit"
439 Reset the board with "USER" switch pushed. Type following to write
443 # ./dfuse.py ../src/build/gnuk.hex
445 Then, reset the board.
448 How to protect flash ROM
449 ========================
451 To protect, invoke OpenOCD like (for FST-01):
453 $ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
454 -c init -c "reset halt" -c "stm32f1x lock 0" -c reset -c exit
456 After power-off / power-on sequence, the contents of flash ROM cannot
457 be accessible from JTAG debugger.
461 $ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
462 -c init -c "reset halt" -c "stm32f1x unlock 0" -c reset -c exit
464 Upon unprotection, flash is erased.
466 Note that it would be still possible for some implementation of DfuSe
467 to access the contents, even if it's protected. If you really want to
468 protect, killing DfuSe and accessing by JTAG debugger is recommended.
471 (Optional) Configure serial number and X.509 certificate
472 ========================================================
474 This is completely optional.
476 For this procedure, you need python and pyscard (python-pyscard
477 package in Debian) or PyUSB 0.4.3 (python-usb package in Debian).
479 (1) [pyscard] Stop scdaemon
480 [PyUSB] Stop the pcsc daemon.
482 If scdaemon is running, please kill it, or you will get "Smartcard
483 Exception" by "Sharing violation".
485 $ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
487 In case of PyUSB tool, you need to stop pcscd.
489 # /etc/init.d/pcscd stop
492 (2) [Optional] Write fixed serial number
494 If you use fixed serial number in the file 'GNUK_SERIAL_NUMBER', you can do:
496 $ EMAIL=<YOUR-EMAIL-ADDRESS> ../tool/gnuk_put_binary_usb.py -s ../GNUK_SERIAL_NUMBER
497 Writing serial number
500 (3) [Optional] Write card holder certificate
502 If you have card holder certificate binary file, you can do:
504 $ ../tool/gnuk_put_binary_usb.py ../../<YOUR-CERTIFICATE>.bin
505 ../../<YOUR-CERTIFICATE>.bin: <LENGTH-OF-YOUR-CERTIFICATE>
506 Updating card holder certificate
516 If you compiled with --enable-debug option, Gnuk has two interfaces
517 (one is CCID/ICCD device and another is virtual COM port). Open
522 and you will see debug output of Gnuk.
528 Type following command to see Gnuk runs:
533 Besides, there is a functionality test under tests/ directory. See
537 Personalize the Token, import keys, and change the password
538 -----------------------------------------------------------
540 You can personalize the token, putting your information like: Name,
541 Login name, Sex, Languages, URL. To do so, GnuPG command is:
545 Note that the factory setting of user password is "123456" and admin
546 password is "12345678" as the specification.
548 It is recommended to create your keys on your computer, and import
549 them to Gnuk Token. After you create your keys (they must be 2048-bit
550 RSA), you can import them.
552 Gnuk supports key generation, but this feature is young and should be
553 considered experimental.
555 For detail, please see documentation under doc/. You can see the HTML
556 version at: https://www.fsij.org/doc-gnuk/
564 $ arm-none-eabi-gdb gnuk.elf
567 Inside GDB, we can connect OpenOCD by:
569 (gdb) target remote localhost:3333
573 (gdb) target extended-remote localhost:3333
576 You can see the output of PCSCD:
578 # /etc/init.d/pcscd stop
579 # LIBCCID_ifdLogLevel=7 /usr/sbin/pcscd --debug --foreground
582 You can observe the traffic of USB using "usbmon". See the file:
583 linux/Documentation/usb/usbmon.txt
589 See doc/note/firmware-update.
595 Please use: https://salsa.debian.org/gnuk-team/gnuk/
599 $ git clone https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
601 It's also available at: www.gniibe.org
602 You can browse at: https://git.gniibe.org/gitweb?p=gnuk/gnuk.git;a=summary
604 I put Chopstx as a submodule of Git. Please do this:
606 $ git submodule update --init
609 Information on the Web
610 ======================
612 For more information, please visit: https://www.fsij.org/gnuk/
614 Please see the FST-01 support pages:
616 https://www.gniibe.org/category/fst-01.html
618 Please consider to join Gnuk-users mailing list:
620 https://lists.gnupg.org/mailman/listinfo/gnuk-users
627 FSIJ welcomes your contributions. Please assign your copyright
628 to FSIJ (if possible), as I do.
634 * NUK(R) is a registered trademark owend by MAPA GmbH, Germany.