1 ************* THIS IS DEVELOPMENT BRANCH OF GNUK *************
2 ************* Text written below is for release 1.0.2, *************
3 ************* which might not be vaild for this code *************
5 For those who follow Git master:
7 We migrate from ChibiOS/RT to Chopstix. You need:
9 Edit .git/config to remove chibios reference
10 git rm --cached chibios
14 Gnuk - An Implementation of USB Cryptographic Token for GnuPG
19 Free Software Initiative of Japan
24 Gnuk is an implementation of USB cryptographic token for GNU Privacy
25 Guard. Gnuk supports OpenPGP card protocol version 2, and it runs on
28 I wish that Gnuk will be a developer's soother who uses GnuPG. I have
29 been nervous of storing secret key(s) on usual secondary storage.
30 There is a solution with OpenPGP card, but it is not the choice for
31 me, as card reader is not common device. With Gnuk, this issue will
32 be solved by a USB token.
34 Please look at the graphics of "gnuk.svg" for the software name. My
35 son used to be with his NUK(R), always, everywhere. Now, I am with a
36 USB Cryptographic Token by "Gnuk", always, everywhere.
42 Q0: How Gnuk USB Token is superior than other solutions (OpenPGP
43 card 2.0, GPF Crypto Stick, etc.) ?
44 http://www.g10code.de/p-card.html
45 http://www.privacyfoundation.de/crypto_stick/
46 A0: Good points of Gnuk are:
47 * If you have skill of electronics and like DIY, you can build
48 Gnuk Token cheaper (see Q8-A8).
49 * You can study Gnuk to modify and to enhance. For example, you
50 can implement your own authentication method with some sensor
51 such as an acceleration sensor.
52 * It is "of Free Software"; Gnuk is distributed under GPLv3+,
53 "by Free Software"; Gnuk development requires only Free Software
54 (GNU Toolchain, Python, etc.),
55 "for Free Software"; Gnuk supports GnuPG.
57 Q1: What kind of key algorithm is supported?
58 A1: Gnuk version 1 only supports 2048-bit RSA.
60 Q2: How long does it take for digital signing?
61 A2: It takes a second and a half or so.
63 Q3: What's your recommendation for target board?
64 A3: Orthodox choice is Olimex STM32-H103.
65 If you have skill of electronics and like DIY, STM32 part of STM8S
66 Discovery Kit might be the best choice.
67 FST-01 (Flying Stone Tiny 01) will be soon available for sale,
68 and it will be the best choice, hopefully.
70 Q4: What's version of GnuPG are you using?
71 A4: In Debian GNU/Linux system, I use gnupg 1.4.11-3 and gnupg-agent
72 2.0.18-2. With older versions, you can only sign with SHA1.
73 See: http://www.fsij.org/gnuk/gnupg2-fixes-needed
75 Q5: What's version of pcscd and libccid are you using?
76 A5: In Debian GNU/Linux system, I use pcscd 1.5.5-4 and libccid 1.3.11-2,
77 which is in squeeze. Note that you need to edit /etc/libccid_Info.plist
78 when using libccid (< 1.4.1).
79 Note that pcscd and libccid are optional, you can use Gnuk without them.
81 Q6: What kinds of hardware is required for development?
82 A6: You need a target board plus a JTAG/SWD debugger. If you just
83 want to test Gnuk for target boards with DfuSe, JTAG debugger is
84 not the requirement. Note that for real use, you need JTAG/SWD
85 debugger to enable flash ROM protection.
87 Q7: How much does it cost?
88 A7: Olimex STM32-H103 plus ARM-USB-TINY-H cost 70 Euro or so.
90 Q8: How much does it cost for DIY version?
91 A8: STM8S Discovery Kit costs 750 JPY (< $10 USD) only. You can build
92 your own JTAG debugger using FTDI2232 module (1450 JPY), see:
93 http://www.fsij.org/gnuk/jtag_dongle_ftdi2232
95 Q9: I got an error like "gpg: selecting openpgp failed: ec=6.108", what's up?
97 A9: GnuPG's SCDaemon has problems for handling insertion/removal of
98 card/reader (problems are fixed in trunk, and backported to 2.0
99 branch, it will be 2.0.20). When your newly inserted token is not
100 found by GnuPG, try killing scdaemon and let it to be invoked
103 $ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
105 and confirm scdaemon doesn't exist, then,
107 $ gpg-connect-agent learn /bye
109 Qa: With GNOME 2, I can't use Gnuk Token for SSH. How can we use it for SSH?
110 Aa: You need to deactivate seahorse-agent and gnome-keyring, but use
111 gpg-agant for the role of ssh-agent. For gnome-keyring please do:
113 $ gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
115 Qb: With GNOME 3, I can't use Gnuk Token at all. Why?
116 Ab: That's because gnome-keyring-daemon interferes GnuPG. Type:
118 $ gnome-session-properties
120 and at the tab of "Startup Programs", disable check buttons for
121 "GPG Password Agent" and "SSH Key Agent".
123 Qc: Do you know a good SWD debugger to connect FST-01 or something?
124 Ac: ST-Link/V2 is cheap one. We have a tool/stlinkv2.py as flash ROM
131 This is a second minor release in version 1.0 series of Gnuk.
133 While it is daily use for a year and a half, some newly introduced
134 features (including key generation and firmware upgrade) should be
135 considered experimental.
139 * Personalization of the card
140 * Changing Login name, URL, Name, Sex, Language, etc.
141 * Password handling (PW1, RC, PW3)
142 * Key import for three types:
143 * key for digital signing
145 * key for authentication
146 * PSO: Digital Signature
148 * INTERNAL AUTHENTICATE
149 * Changing value of password status bytes (0x00C4): forcesig
150 * Verify with pin pad
151 * Modify with pin pad
152 * Card holder certificate (read)
154 (Overriding key import is not supported,
155 but you can remove all keys to import again).
156 * Key generation on device side
158 Original features of Gnuk, tested lightly:
160 * OpenPGP card serial number setup
161 * Card holder certificate (write by UPDATE BINARY)
162 * Upgrading with "EXTERNAL AUTHENTICATE" by reGNUal
164 It is known not-working well:
166 * For some version of kernel and libccid, --enable-debug can't
167 work well. Please make sure to disable DEBUG option if it
170 It is known that the combination of libccid 1.4.1 (or newer) with
171 libusb 1.0.8 (or older) has a minor problem. It is rare but it is
172 possible for USB communication to be failed, because of a bug in
173 libusb implementation. Use libusbx 1.0.9 or newer, or don't use
174 PC/SC, but use internal CCID driver of GnuPG.
180 We use Olimex STM32-H103 board and Flying Stone Tiny 01 (FST-01). We
181 also use STM32 part of STM8S Discovery Kit.
183 With DfuSe support, CQ STARM, STBee, and STBee Mini are also our
184 targets. But those targets with DfuSe are basically not for normal
185 use but for experiments, because it would be 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 I think that it could run on Olimex STM32-P103, or other boards with
190 STM32F103. Besides, we are porting it to STM32 Primer 2.
192 For PIN-pad support, I connect a consumer IR receive module to STBee
193 Mini and STM8S Discovery Kit, and use controller for TV. PIN
194 verification is supported by this configuration. Yes, it is not
195 secure at all, since it is very easy to monitor IR output of the
196 controllers. It is just an experiment. Note that hardware needed for
197 this experiment is only a consumer IR receive module which is as cheap
200 Another PIN-pad support is connecting rotary encoder, push switch and
201 7-segment LED display. Both of PIN verification and PIN modification
202 are supported for this circuit extension.
204 Note that you need pinpad support for GnuPG to use PIN-pad enabled
205 Gnuk. The pinpad support for GnuPG is currently in the master branch
206 of GnuPG git repository at git.gnupg.org, and it's under evaluation.
207 When it will be considered stable, it will be put onto stable branch.
213 Gnuk source code is under src/ directory.
215 Note that SHA-2 hash function implementation, src/sha256.c, is based
216 on the original implementation by Dr. Brian Gladman. See:
218 http://gladman.plushost.co.uk/oldsite/cryptography_technology/sha/index.php
224 It is distributed under GNU General Public Licence version 3 or later
225 (GPLv3+). Please see src/COPYING.
227 Please note that it is distributed with external source code too.
228 Please read relevant licenses for external source code as well.
230 The author(s) of Gnuk expect users of Gnuk will be able to access the
231 source code of Gnuk, so that users can study the code and can modify
232 if needed. This doesn't mean person who has a USB Token by Gnuk
233 should be able to access everything on the Token, regardless of its
234 protections. Private keys, and other information should be protected
241 Gnuk is distributed with external source code.
243 * chibios/ -- ChibiOS/RT 2.4.3
245 Source code taken from: http://chibios.sourceforge.net/
247 We use ChibiOS/RT as the kernel for Gnuk.
249 ChibiOS/RT is distributed under GPLv3+ (with a special exception
250 for unmodified code).
253 * polarssl/ -- PolarSSL 1.2.6
255 Souce code taken from: http://polarssl.org/
257 We use PolarSSL for RSA computation, and AES encryption/decryption.
259 PolarSSL is distributed under GPLv2+. We use PolarSSL under GPLv3
262 The file include/polarssl/bn_mul.h is heavily modified for ARM
265 The function rsa_private in polarssl/library/rsa.c is modified so
266 that it doesn't check T against N. The function rsa_pkcs1_sign is
267 modified to avoid warnings in case of !POLARSSL_PKCS1_V21.
269 The functions rsa_pkcs1_verify and rsa_rsassa_pkcs1_v15_verify in
270 include/polarssl/rsa.h and polarssl/library/rsa.c are modified
271 (fixed) for last argument SIG, as the memory at SIG aren't modified
274 The constant POLARSSL_MPI_MAX_SIZE in include/polarssl/bignum.h is
275 modified for 2048-bit keys only Gnuk.
277 The function mpi_mul_hlp in library/bignum.c is modified for more
278 optimization for ARM Cortex-M3.
280 The file library/aes.c is modified so that some constants can
283 The file include/polarssl/config.h are modified not to define
284 POLARSSL_HAVE_LONGLONG to avoid linking libgcc, to define
285 POLARSSL_AES_ROM_TABLES to have AES tables, not to define
286 POLARSSL_CIPHER_MODE_CTR, POLARSSL_FS_IO, POLARSSL_PKCS1_V21,
287 POLARSSL_SELF_TEST, and POLARSSL_PADLOCK_C, and only define
288 POLARSSL_GENPRIME when defined KEYGEN_SUPPORT.
291 USB vendor ID and product ID (USB device ID)
292 ============================================
294 When you have a vender ID and assign a product ID for Gnuk, edit the
295 file GNUK_USB_DEVICE_ID and add an entry for yours. In this case,
296 please contact Niibe, so that it is listed to the file in the official
297 release of the source code.
299 When you are modifing Gnuk and installing the binary to device, you
300 should replace the vendor string and serial number to yours (in the
301 file GNUK_USB_DEVICE_ID and SERIALNO of the script of src/configure),
302 so that users can see it's not by original vendor, and it is modified
305 FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices
306 with Gnuk under one of following conditions:
308 * For everyone for experimental purpose:
310 - You must not distribute a binary with FSIJ's USB device ID, but
311 must use the binary by yourself only for your experiment. Note
312 that "Distributing binary" includes distributing a device which
315 * For general individuals:
317 - You must use your Gnuk device with a card serial number which is
318 *not* by FSIJ. Easy one would be a card serial number generated
321 * For individuals with explicit permission from FSIJ.
323 - You should have an assigned card serial number by FSIJ,
324 please use that number for your device.
325 (There a file 'GNUK_SERIAL_NUMBER' in the official release.)
327 FSIJ could give companies or business entities "second source
328 manufacturer" license to use USB device ID of FSIJ for devices with
329 unmodified version of Gnuk, provided they support Free Software and
330 respect users' freedom for computing. Please ask FSIJ for the
333 Otherwise, companies which want to distribute Gnuk devices, please use
334 your own USB vendor ID and product ID. Please replace vendor string
335 and possibly product string to yours, when you modify Gnuk.
341 For GNU/Linux, PC/SC service is an option, you can use GnuPG's
342 internal CCID driver instead. If you chose using PC/SC service,
343 libccid version >= 1.3.11 is recommended for GNU/Linux.
345 I think that it should not be requirment but the kernel version of my use is:
346 Linux version 2.6.32-5-686 (Debian 2.6.32-18) (ben@decadent.org.uk) (gcc version 4.3.5 (Debian 4.3.5-2) ) #1 SMP Sat Jul 24 02:27:10 UTC 2010
348 Linux 2.6.30 is known *NOT* working well with DEBUG option.
349 Linux 2.6.24 is known working well with DEBUG option.
355 You need GNU toolchain and newlib for 'arm-none-eabi' target.
357 See http://github.com/esden/summon-arm-toolchain/ (which includes fix
358 of binutils-2.21.1) for preparation of GNU Toolchain for
359 'arm-none-eabi' target. This is for GCC 4.5.
361 # Note that we need to link correct C library (for string functions).
362 # For this purpose, Makefile.in contains following line:
364 # MCFLAGS= -mcpu=$(MCU) -mfix-cortex-m3-ldrd
366 # This should not be needed (as -mcpu=cortex-m3 means
367 # -mfix-cortex-m3-ldrd), but in practice it is needed for
368 # the configuration of patch-gcc-config-arm-t-arm-elf.diff in
369 # summon-arm-toolchain.
371 # In ChibiOS_2.0.8/os/ports/GCC/ARM/rules.mk, it specifies
372 # -mno-thumb-interwork option. This means that you should not
373 # link C library which contains ARM (not Thumb) code.
375 Recently, there is "gcc-arm-embedded" project. See:
377 https://launchpad.net/gcc-arm-embedded/
379 It is based on GCC 4.6. For version 4.6-2012-q2-update, you'd
380 need "-O3 -Os" instead of "-O2" and it will be slightly better.
383 Change directory to `src':
385 $ cd gnuk-VERSION/src
387 Then, run `configure':
389 $ ./configure --vidpid=<VID:PID>
391 Here, you need to specify USB vendor ID and product ID. For FSIJ's,
392 it's: --vidpid=234b:0000 . Please read section 'USB vendor ID and
399 Then, we will have "gnuk.elf".
405 Olimex STM32-H103 board
406 -----------------------
408 If you are using Olimex JTAG-Tiny, type following to invoke OpenOCD:
410 $ openocd -f interface/olimex-jtag-tiny.cfg -f board/olimex_stm32_h103.cfg
412 Then, with another terminal, type following to write "gnuk.elf" to Flash ROM:
414 $ telnet localhost 4444
416 > flash write_image erase gnuk.elf
425 If you are using Flying Stone Tiny 01, you need a SWD writer. I am
426 using revision 946 of Simon Qian's Versaloon.
428 svn checkout -r 946 http://vsprog.googlecode.com/svn/trunk/
430 For OpenOCD, we need unofficial patch.
432 See the article of Versaloon Forum:
434 http://www.versaloon.com/bbs/viewtopic.php?p=16179
437 Type following to invoke OpenOCD:
439 $ openocd -f interface/vsllink.cfg -c "transport select swd" -c "swd_mode 2" -f target/stm32f1x.cfg
441 Then, with another terminal, type following to write "gnuk.elf" to Flash ROM:
443 $ telnet localhost 4444
445 > flash write_image erase gnuk.elf
450 OpenOCD 0.6.1 now supports ST-Link/V2. We can use it:
452 $ openocd -f interface/stlink-v2.cfg -f target/stm32f1x_stlink.cfg
454 But it doesn't support option bytes handling yet.
460 If you are using FTDI-2232D module and the connection is standard, type:
462 $ openocd -f interface/openocd-usb.cfg -f target/stm32f1x.cfg
464 Initially, the flash ROM of the chip is protected. you need to do:
466 $ telnet localhost 4444
473 and re-connect the board. Note that power-off / power-on sequence is
474 required to reset flash ROM.
476 Then, invoke OpenOCD again and telnet to connect OpenCD and write
477 image as above example of Olimex STM32-H103.
483 Put jumper for J6 to enable DfuSe. Connecting the board, and type:
486 # ./dfuse.py ../src/gnuk.hex
488 Then, remove the jumper and reset the board.
494 Reset the board with "USER" switch pushed. Type following to write
498 # ./dfuse.py ../src/gnuk.hex
500 Then, reset the board.
503 How to protect flash ROM
504 ========================
506 Invoke your OpenOCD and type:
508 $ telnet localhost 4444
514 After power-off / power-on sequence, the contents of flash ROM cannot
515 be accessible from JTAG debugger.
517 Note that it would be still possible for some implementation of DfuSe
518 to access the contents. If you want to protect, killing DfuSe and
519 accessing by JTAG debugger is recommended.
525 You need python and pyscard (python-pyscard package in Debian) or
526 PyUSB (python-usb package in Debian).
528 (1) [pyscard] Stop scdaemon
529 [PyUSB] Stop the pcsc daemon.
531 If scdaemon is running, please kill it, or you will get "Smartcard
532 Exception" by "Sharing violation".
534 $ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
536 In case of PyUSB tool, you need to stop pcscd.
538 # /etc/init.d/pcscd stop
541 (2) [Optional] Write fixed serial number
543 If you use fixed serial number in the file 'GNUK_SERIAL_NUMBER', you can do:
545 $ EMAIL=<YOUR-EMAIL-ADDRESS> ../tool/gnuk_put_binary.py -s ../GNUK_SERIAL_NUMBER
546 Writing serial number
549 (3) [Optional] Write card holder certificate
551 If you have card holder certificate binary file, you can do:
553 $ ../tool/gnuk_put_binary.py ../../<YOUR-CERTIFICATE>.bin
554 ../../<YOUR-CERTIFICATE>.bin: <LENGTH-OF-YOUR-CERTIFICATE>
555 Updating card holder certificate
565 If you compiled with --enable-debug option, Gnuk has two interfaces
566 (one is CCID/ICCD device and another is virtual COM port). Open
571 and you will see debug output of Gnuk.
577 For libccid (< 1.4.1), we need following change:
579 --- /etc/libccid_Info.plist.dpkg-dist 2009-07-29 06:50:20.000000000 +0900
580 +++ /etc/libccid_Info.plist 2010-09-05 09:09:49.000000000 +0900
583 <key>ifdVendorID</key>
585 + <string>0x234B</string>
586 <string>0x08E6</string>
587 <string>0x08E6</string>
588 <string>0x08E6</string>
591 <key>ifdProductID</key>
593 + <string>0x0000</string>
594 <string>0x2202</string>
595 <string>0x3437</string>
596 <string>0x3438</string>
599 <key>ifdFriendlyName</key>
601 + <string>FSIJ USB Token</string>
602 <string>Gemplus Gem e-Seal Pro</string>
603 <string>Gemplus GemPC Twin</string>
604 <string>Gemplus GemPC Key</string>
607 This entry has been added into libccid 1.4.1 already ([r5425]).
613 Type following command to see Gnuk runs:
618 Besides, there is a functinality test under test/ directory. See
622 Personalize the Token and import keys
623 -------------------------------------
625 You can personalize the token, putting your information like: Name,
626 Login name, Sex, Languages, URL, etc., and password. To do so, GnuPG
631 Note that the factory setting of user password is "123456" and admin
632 password is "12345678" as the specification.
634 It is recommended to create your keys on your computer, and import
635 them to Gnuk Token. After you create your keys (they must be 2048-bit
636 RSA), you can import them.
638 Gnuk supports key generation, but this feature is young and should be
639 considered experimental.
641 For detail, please see doc/note/DEMO and doc/note/DEMO-2.
643 Note that it make sense to preserve your keys on your computer so that
644 you can import the keys (again) to (possibly another) Gnuk Token. In
645 this case, you can use GnuPG's option to specify the home directory by
648 After creating keys on your computer by:
653 Copy directory which contains your secret keys to new directory named
654 <gpgdir-with-your-secret-keys>:
656 $ cp -pa $HOME/.gnupg <gpgdir-with-your-secret-keys>
658 Then, import keys by:
660 $ gpg --edit-key <YOUR-KEYID>
662 While your $HOME/.gnupg now doesn't have your secret keys after
663 import, <gpgdir-with-your-secret-keys> still has them. You can again
666 $ gpg --homedir=<gpgdir-with-your-secret-keys> --edit-key <YOUR-KEYID>
668 Note that you *should not* save changes this time to preserve keys
669 on your computer. The session goes like this:
672 Save changes? (y/N) n
673 Quit without saving? (y/N) y
682 $ arm-none-eabi-gdb gnuk.elf
685 Inside GDB, we can connect OpenOCD by:
687 (gdb) target remote localhost:3333
690 You can see the output of PCSCD:
692 # /etc/init.d/pcscd stop
693 # LIBCCID_ifdLogLevel=7 /usr/sbin/pcscd --debug --foreground
696 You can observe the traffic of USB using "usbmon". See the file:
697 linux/Documentation/usb/usbmon.txt
703 See doc/note/firmware-update.
709 You can browse at: http://www.gniibe.org/gitweb?p=gnuk.git;a=summary
713 $ git clone git://www.gniibe.org/gnuk.git/
717 $ git clone http://www.gniibe.org/git/gnuk.git/
720 Copy is available at: http://gitorious.org/gnuk
723 Information on the Web
724 ======================
726 Please visit: http://www.fsij.org/gnuk/
732 FSIJ welcomes your contributions. Please assign your copyright
733 to FSIJ (if possible).
738 * NUK(R) is a registered trademark owend by MAPA GmbH, Germany.