1 Gnuk - An Implementation of USB Cryptographic Token for GnuPG
6 Free Software Initiative of Japan
11 This is another experimental release of Gnuk, version 1.1.4, which has
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. Please update your documentation for Gnuk Token, so
15 that the instruction of importing keys won't cause any confusion. It
16 has supports of ECDSA (with NIST P256 and secp256k1) and EdDSA with
17 EdDSA, but this feature is pretty much experimental, and it requires
18 development version of GnuPG with newest version of libgcrypt. You
19 will not able to keep using EdDSA keys, as the key format is subject
20 to change. It also support RSA-4096 experimentally, but users should
21 know that it takes more than 8 second to sign/decrypt.
27 Gnuk is an implementation of USB cryptographic token for GNU Privacy
28 Guard. Gnuk supports OpenPGP card protocol version 2, and it runs on
31 I wish that Gnuk will be a developer's soother who uses GnuPG. I have
32 been nervous of storing secret key(s) on usual secondary storage.
33 There is a solution with OpenPGP card, but it is not the choice for
34 me, as card reader is not common device. With Gnuk, this issue will
35 be solved by a USB token.
37 Please look at the graphics of "gnuk.svg" for the software name. My
38 son used to be with his NUK(R), always, everywhere. Now, I am with a
39 USB Cryptographic Token by "Gnuk", always, everywhere.
45 Q0: How Gnuk USB Token is superior than other solutions (OpenPGP
46 card 2.0, GPF Crypto Stick, etc.) ?
47 http://www.g10code.de/p-card.html
48 http://www.privacyfoundation.de/crypto_stick/
49 A0: Good points of Gnuk are:
50 * If you have skill of electronics and like DIY, you can build
51 Gnuk Token cheaper (see Q8-A8).
52 * You can study Gnuk to modify and to enhance. For example, you
53 can implement your own authentication method with some sensor
54 such as an acceleration sensor.
55 * It is "of Free Software"; Gnuk is distributed under GPLv3+,
56 "by Free Software"; Gnuk development requires only Free Software
57 (GNU Toolchain, Python, etc.),
58 "for Free Software"; Gnuk supports GnuPG.
60 Q1: What kind of key algorithm is supported?
61 A1: Gnuk version 1.0 only supports RSA 2048.
62 Development version of Gnuk (1.1.x) supports 256-bit ECDSA and EdDSA,
63 as well as RSA 4096-bit. But it takes long time to sign with RSA 4096.
65 Q2: How long does it take for digital signing?
66 A2: It takes a second and a half or so.
68 Q3: What's your recommendation for target board?
69 A3: Orthodox choice is Olimex STM32-H103.
70 FST-01 (Flying Stone Tiny 01) is available for sale, and it is a
71 kind of the best choice, hopefully.
73 Q4: What's version of GnuPG are you using?
74 A4: In Debian GNU/Linux system, I use gnupg 1.4.12-7 and gnupg-agent
77 Q5: What's version of pcscd and libccid are you using?
78 A5: I don't use them, pcscd and libccid are optional, you can use Gnuk
80 I tested pcscd 1.5.5-4 and libccid 1.3.11-2 which were in Debian
83 Q6: What kinds of hardware is required for development?
84 A6: You need a target board plus a JTAG/SWD debugger. If you just
85 want to test Gnuk for target boards with DfuSe, JTAG debugger is
86 not the requirement. Note that for real use, you need JTAG/SWD
87 debugger to enable flash ROM protection.
89 Q7: How much does it cost?
90 A7: Olimex STM32-H103 plus ARM-USB-TINY-H cost 70 Euro or so.
92 Q9: I got an error like "gpg: selecting openpgp failed: ec=6.108", what's up?
93 A9: GnuPG's SCDaemon has problems for handling insertion/removal of
94 card/reader. When your newly inserted token is not found by
95 GnuPG, try killing scdaemon and let it to be invoked again. I do:
97 $ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
99 and confirm scdaemon doesn't exist, then,
101 $ gpg-connect-agent learn /bye
103 Qa: With GNOME 2, I can't use Gnuk Token for SSH. How can we use it for SSH?
104 Aa: You need to deactivate seahorse-agent and gnome-keyring, but use
105 gpg-agant for the role of ssh-agent. For gnome-keyring please do:
107 $ gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
109 Qb: With GNOME 3.0, I can't use Gnuk Token at all. Why?
110 Ab: That's because gnome-keyring-daemon interferes GnuPG. Type:
112 $ gnome-session-properties
114 and at the tab of "Startup Programs", disable check buttons for
115 "GPG Password Agent" and "SSH Key Agent".
117 Qc: Do you know a good SWD debugger to connect FST-01 or something?
118 Ac: ST-Link/V2 is cheap one. We have a tool/stlinkv2.py as flash ROM
121 Qd: With GNOME 3.x (x >= 8?), I can't use Gnuk Token at all. Why?
122 Ad: Please set the configration variable OnlyShowIn as none. Like:
126 In the files of /etc/xdg/autostart/gnome-keyring-gpg.desktop and
127 /etc/xdg/autostart/gnome-keyring-ssh.desktop
135 This is third experimental release in version 1.1 series of Gnuk.
137 While it is daily use by its developer, some newly introduced features
138 (including ECDSA/EdDSA, key generation and firmware upgrade) should be
139 considered experimental. ECDSA/EdDSA is really experimental.
140 Further, EdDSA is much experimental. You won't be able to keep using
141 the EdDSA key, as the key format of GnuPG is subject to change.
145 * Personalization of the card
146 * Changing Login name, URL, Name, Sex, Language, etc.
147 * Password handling (PW1, RC, PW3)
148 * Key import for three types:
149 * key for digital signing
151 * key for authentication
152 * PSO: Digital Signature
154 * INTERNAL AUTHENTICATE
155 * Changing value of password status bytes (0x00C4): forcesig
156 * Verify with pin pad
157 * Modify with pin pad
158 * Card holder certificate (read)
160 * Key generation on device side
161 * Overriding key import
163 Original features of Gnuk, tested lightly:
165 * OpenPGP card serial number setup
166 * Card holder certificate (write by UPDATE BINARY)
167 * Upgrading with "EXTERNAL AUTHENTICATE" by reGNUal
169 It is known not-working well:
171 * It is known that the combination of libccid 1.4.1 (or newer)
172 with libusb 1.0.8 (or older) has a minor problem. It is
173 rare but it is possible for USB communication to be failed,
174 because of a bug in libusb implementation. Use libusbx
175 1.0.9 or newer, or don't use PC/SC, but use internal CCID
182 We use Olimex STM32-H103 board and Flying Stone Tiny 01 (FST-01).
184 With DfuSe support, STBee is also our targets. But this target with
185 DfuSe is for experiment only, because it is impossible for DfuSe to
186 disable read from flash. For real use, please consider killing DfuSe
187 and enabling read protection using JTAG debugger.
189 For PIN-pad support, I connect a consumer IR receive module to FST-01,
190 and use controller for TV. PIN verification is supported by this
191 configuration. Yes, it is not secure at all, since it is very easy to
192 monitor IR output of the controllers. It is just an experiment. Note
193 that hardware needed for this experiment is only a consumer IR receive
194 module which is as cheap as 50 JPY.
196 Note that you need pinpad support for GnuPG to use PIN-pad enabled
197 Gnuk. The pinpad support for GnuPG is only available in version 2.
203 Gnuk source code is under src/ directory.
205 Note that SHA-2 hash function implementation, src/sha256.c, is based
206 on the original implementation by Dr. Brian Gladman. See:
208 http://gladman.plushost.co.uk/oldsite/cryptography_technology/sha/index.php
214 It is distributed under GNU General Public Licence version 3 or later
215 (GPLv3+). Please see src/COPYING.
217 Please note that it is distributed with external source code too.
218 Please read relevant licenses for external source code as well.
220 The author(s) of Gnuk expect users of Gnuk will be able to access the
221 source code of Gnuk, so that users can study the code and can modify
222 if needed. This doesn't mean person who has a Gnuk Token should be
223 able to access everything on the Token, regardless of its protections.
224 Private keys, and other information should be protected properly.
230 Gnuk is distributed with external source code.
232 * chopstx/ -- Chopstx 0.04
234 We use Chopstx as the kernel for Gnuk.
236 Chopstx is distributed under GPLv3+ (with a special exception).
239 * polarssl/ -- PolarSSL 1.2.10
241 Souce code taken from: http://polarssl.org/
243 We use PolarSSL for RSA computation, and AES encryption/decryption.
245 PolarSSL is distributed under GPLv2+. We use PolarSSL under GPLv3
248 The file include/polarssl/bn_mul.h is heavily modified for ARM
251 The function rsa_private in polarssl/library/rsa.c is modified so
252 that it doesn't check T against N. The function rsa_pkcs1_sign is
253 modified to avoid warnings in case of !POLARSSL_PKCS1_V21.
255 The functions rsa_pkcs1_verify and rsa_rsassa_pkcs1_v15_verify in
256 include/polarssl/rsa.h and polarssl/library/rsa.c are modified
257 (fixed) for last argument SIG, as the memory at SIG aren't modified
260 The constant POLARSSL_MPI_MAX_SIZE in include/polarssl/bignum.h is
261 modified for 2048-bit keys only Gnuk.
263 The function mpi_mul_hlp in library/bignum.c is modified for more
264 optimization for ARM Cortex-M3. Functions mpi_montred, mpi_sub_hlp,
265 mpi_sub_abs, mpi_mul_mpi, mpi_montmul, and mpi_exp_mod are modified
266 to avoid side channel attacks. Note that we don't use RSA-blinding
267 technique for Gnuk. Function mpi_gen_prime and mpi_is_prime are
268 modified to use Fouque-Tibouchi method. Function mpi_exp_mod is
269 modified to use new function mpi_montsqr for speed up.
271 The file library/aes.c is modified so that some constants can
274 The file include/polarssl/config.h are modified not to define
275 POLARSSL_HAVE_LONGLONG to avoid linking libgcc, to define
276 POLARSSL_AES_ROM_TABLES to have AES tables, not to define
277 POLARSSL_CIPHER_MODE_CTR, POLARSSL_FS_IO, POLARSSL_PKCS1_V21,
278 POLARSSL_SELF_TEST, and POLARSSL_PADLOCK_C, and only define
279 POLARSSL_GENPRIME when defined KEYGEN_SUPPORT.
282 USB vendor ID and product ID (USB device ID)
283 ============================================
285 When you have a vender ID and assign a product ID for Gnuk, edit the
286 file GNUK_USB_DEVICE_ID and add an entry for yours. In this case,
287 please contact Niibe, so that it is listed to the file in the official
288 release of the source code.
290 When you are modifing Gnuk and installing the binary to device, you
291 should replace the vendor string and serial number to yours (in the
292 file GNUK_USB_DEVICE_ID and SERIALNO of the script of src/configure),
293 so that users can see it's not by original vendor, and it is modified
296 FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices
297 with Gnuk under one of following conditions:
299 * For everyone for experimental purpose:
301 - You must not distribute a binary with FSIJ's USB device ID, but
302 must use the binary by yourself only for your experiment. Note
303 that "Distributing binary" includes distributing a device which
306 * For general individuals:
308 - You must use your Gnuk device with a card serial number which is
309 *not* by FSIJ. Easy one would be a card serial number generated
312 * For individuals with explicit permission from FSIJ.
314 - You should have an assigned card serial number by FSIJ,
315 please use that number for your device.
316 (There a file 'GNUK_SERIAL_NUMBER' in the official release.)
318 FSIJ could give companies or business entities "second source
319 manufacturer" license to use USB device ID of FSIJ for devices with
320 unmodified version of Gnuk, provided they support Free Software and
321 respect users' freedom for computing. Please ask FSIJ for the
324 Otherwise, companies which want to distribute Gnuk devices, please use
325 your own USB vendor ID and product ID. Please replace vendor string
326 and possibly product string to yours, when you modify Gnuk.
332 For GNU/Linux, PC/SC service is an option, you can use GnuPG's
333 internal CCID driver instead. If you chose using PC/SC service,
334 libccid version >= 1.3.11 is recommended for GNU/Linux.
340 You need GNU toolchain and newlib for 'arm-none-eabi' target.
342 There is "gcc-arm-embedded" project. See:
344 https://launchpad.net/gcc-arm-embedded/
347 Change directory to `src':
349 $ cd gnuk-VERSION/src
351 Then, run `configure':
353 $ ./configure --vidpid=<VID:PID>
355 Here, you need to specify USB vendor ID and product ID. For FSIJ's,
356 it's: --vidpid=234b:0000 . Please read section 'USB vendor ID and
363 Then, we will have "gnuk.elf" under src/build directory.
369 Olimex STM32-H103 board
370 -----------------------
372 If you are using Olimex JTAG-Tiny, type following to invoke OpenOCD:
374 $ openocd -f interface/ftdi/olimex-jtag-tiny.cfg -f board/olimex_stm32_h103.cfg
376 Then, with another terminal, type following to write "gnuk.elf" to Flash ROM:
378 $ telnet localhost 4444
380 > flash write_image erase gnuk.elf
389 If you are using Flying Stone Tiny 01, you need a SWD writer.
391 OpenOCD 0.6.1 now supports ST-Link/V2. We can use it:
393 $ openocd -f interface/stlink-v2.cfg -f target/stm32f1x_stlink.cfg
395 But it doesn't support option bytes handling (protection) yet.
401 Reset the board with "USER" switch pushed. Type following to write
405 # ./dfuse.py ../src/build/gnuk.hex
407 Then, reset the board.
410 How to protect flash ROM
411 ========================
413 Invoke your OpenOCD and type:
415 $ telnet localhost 4444
421 After power-off / power-on sequence, the contents of flash ROM cannot
422 be accessible from JTAG debugger.
424 Note that it would be still possible for some implementation of DfuSe
425 to access the contents. If you want to protect, killing DfuSe and
426 accessing by JTAG debugger is recommended.
432 You need python and pyscard (python-pyscard package in Debian) or
433 PyUSB 0.4.3 (python-usb package in Debian).
435 (1) [pyscard] Stop scdaemon
436 [PyUSB] Stop the pcsc daemon.
438 If scdaemon is running, please kill it, or you will get "Smartcard
439 Exception" by "Sharing violation".
441 $ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
443 In case of PyUSB tool, you need to stop pcscd.
445 # /etc/init.d/pcscd stop
448 (2) [Optional] Write fixed serial number
450 If you use fixed serial number in the file 'GNUK_SERIAL_NUMBER', you can do:
452 $ EMAIL=<YOUR-EMAIL-ADDRESS> ../tool/gnuk_put_binary.py -s ../GNUK_SERIAL_NUMBER
453 Writing serial number
456 (3) [Optional] Write card holder certificate
458 If you have card holder certificate binary file, you can do:
460 $ ../tool/gnuk_put_binary.py ../../<YOUR-CERTIFICATE>.bin
461 ../../<YOUR-CERTIFICATE>.bin: <LENGTH-OF-YOUR-CERTIFICATE>
462 Updating card holder certificate
472 If you compiled with --enable-debug option, Gnuk has two interfaces
473 (one is CCID/ICCD device and another is virtual COM port). Open
478 and you will see debug output of Gnuk.
484 Type following command to see Gnuk runs:
489 Besides, there is a functionality test under test/ directory. See
493 Personalize the Token, import keys, and change the password
494 -----------------------------------------------------------
496 You can personalize the token, putting your information like: Name,
497 Login name, Sex, Languages, URL. To do so, GnuPG command is:
501 Note that the factory setting of user password is "123456" and admin
502 password is "12345678" as the specification.
504 It is recommended to create your keys on your computer, and import
505 them to Gnuk Token. After you create your keys (they must be 2048-bit
506 RSA), you can import them.
508 Gnuk supports key generation, but this feature is young and should be
509 considered experimental.
511 For detail, please see documentation under doc/. You can see the HTML
512 version at: http://www.fsij.org/doc-gnuk/
520 $ arm-none-eabi-gdb gnuk.elf
523 Inside GDB, we can connect OpenOCD by:
525 (gdb) target remote localhost:3333
528 You can see the output of PCSCD:
530 # /etc/init.d/pcscd stop
531 # LIBCCID_ifdLogLevel=7 /usr/sbin/pcscd --debug --foreground
534 You can observe the traffic of USB using "usbmon". See the file:
535 linux/Documentation/usb/usbmon.txt
541 See doc/note/firmware-update.
547 Please use: http://gitorious.org/gnuk
551 $ git clone git://gitorious.org/gnuk/gnuk.git
553 It's also available at: www.gniibe.org
554 You can browse at: http://git.gniibe.org/gitweb?p=gnuk/gnuk.git;a=summary
556 I put Chopstx as a submodule of Git. Please do this:
559 $ git submodule update
561 We have migrated from ChibiOS/RT to Chopstx. If you have old code of
562 ChibiOS/RT, you need:
564 Edit .git/config to remove chibios reference
565 git rm --cached chibios
568 Information on the Web
569 ======================
571 Please visit: http://www.fsij.org/gnuk/
577 FSIJ welcomes your contributions. Please assign your copyright
578 to FSIJ (if possible).
583 * NUK(R) is a registered trademark owend by MAPA GmbH, Germany.