Compare commits

...

25 Commits

Author SHA1 Message Date
2519f799fd Default acknowledgement button to yes 2022-07-30 13:29:09 +02:00
32f563a28d Add chopstx update for ST-Dongle 2022-07-30 13:15:50 +02:00
7b471948b4 How to reflash st-link 2022-07-30 12:55:04 +02:00
d2363c8ad8 Add DTS token 2022-07-30 12:40:24 +02:00
9306ad5043 Update how to flash firmware 2022-07-19 10:49:50 +02:00
54d031bc27 Remove docker as I will not be maintaning it 2022-07-19 10:42:06 +02:00
6909e0359c Add VID/PID 2022-07-19 10:39:40 +02:00
5acd8a23d9 Change serial 2022-07-19 10:39:11 +02:00
d5a539986e Correct OpenPGP version 2022-07-19 10:29:44 +02:00
8a19a2cb66 Update openocd documentation 2022-07-18 23:38:33 +02:00
5e4a264ac0 Update readme 2022-07-17 23:02:30 +02:00
a9079e8b5c Update readme 2022-07-17 22:41:25 +02:00
057920600f Update readme 2022-07-17 12:39:26 +02:00
7d1b5e4b71 Update readme 2022-07-17 12:28:58 +02:00
fe66b67317 Update readme 2022-07-17 12:25:42 +02:00
14f0acd749 Update readme 2022-07-17 12:20:41 +02:00
9ccbd5804a Update readme 2022-07-17 12:14:38 +02:00
b4b82e1557 Update readme 2022-07-17 11:52:09 +02:00
357a4b3510 Update readme 2022-07-17 11:44:42 +02:00
1fdb74eb10 Update readme 2022-07-17 10:57:37 +02:00
977a09f69f Update readme 2022-07-17 10:49:35 +02:00
cd271fbeb5 Update readme 2022-07-17 01:31:11 +02:00
7e17548610 Update readme 2022-07-17 01:28:57 +02:00
fd7a7c7dfa Update build section in README 2022-07-17 01:00:38 +02:00
8de235b26f Don't set default VID:PID 2022-07-17 00:57:08 +02:00
10 changed files with 91 additions and 192 deletions

View File

@@ -3,4 +3,5 @@
234b:0000 0200 Gnuk Token Free Software Initiative of Japan
20a0:4211 0200 Nitrokey Start Nitrokey
1209:2440 0200 Gnuk Token GnuPG e.V.
1337:0010 0200 Gnuk Token Deon Spengler
##########<TAB> ##<TAB> ##########<TAB> #################

216
README.md
View File

@@ -1,192 +1,138 @@
***Note:*** *This fork of Gnuk fixes some compiling bugs and focuses on using the ST-Link v2 clone hardware.*
***Note:*** *This fork of Gnuk fixes some compiling bugs and focuses on using the "ST-Link V2" clone hardware.*
Here is the link to the original project: <http://git.gniibe.org/cgit/gnuk/gnuk.git/>
What's Gnuk?
============
Gnuk is an implementation of USB cryptographic token for GNU Privacy Guard. Gnuk supports OpenPGP card protocol version 3, and it runs on STM32F103 processor (and its compatible). Gnuk allows one to converting a Cheap $2 ST-Link v2 clone into a Hardware GPG Key.
Gnuk is an implementation of a USB cryptographic security token that supports the OpenPGP card protocol version 2. It runs on a STM32F103 processor (and its compatible). In short it allows one to convert a cheap $2 "ST-Link V2" clone device into a hardware security token.
It has supports of Ed25519 and X25519 (ECDH on Curve25519). It also has experimental support of ECDSA (on NIST P256 and secp256k1) and ECDH (on NIST P256 and secp256k1).
It also supports RSA-4096, but users should know that it takes more than 8 seconds to sign/decrypt. Key generation of RSA-4096 just fails, because the device doesn't have enough memory.
Gnuk supports the Key Derived Function (KDF) functionality. To use this feature one will need to use GnuPG 2.2.6 or later.
Gnuk supports the Key Derived Function (KDF) functionality. With the KDF function enabled, the PIN is stored as a hash on the Gnuk. To use the feature, you need to use GnuPG (2.2.6 or later). The KDF setting needs to be enabled before any keys is put on the Gnuk. Once a key has been placed on the Gnuk and changes to the KDF settings will be prevented until the Gnuk has been reset. Your Gnuk token can be configured with the card-edit/kdf-setup command of GnuPG.
How to build the Gnuk firmware
==============================
You will need the GNU toolchain for arm-none-eabi and newlib.
How to build the firmware
=========================
You will need the GNU toolchain and newlib for arm-none-eabi.
On Arch Linux this can be installed with the following
```
sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib
```
On Debian or Ubuntu one can use the following command
```
sudo apt-get install gcc-arm-none-eabi
```
Cloning source code and compiling
---------------------------------
To clone the source code and compile, use the following commands.
```
git clone --recursive https://git.spengler.co.za/deon/gnuk.git gnuk
cd gnuk/src
./configure
./configure --vidpid=1337:0010
make
```
Then, we will have "gnuk.bin" under src/build directory.
Then, you will have "gnuk.bin" under src/build directory.
***Please read section 'USB vendor ID and product ID' below.***
How to protect flash ROM
========================
How to flash the Gnuk firmware
==============================
In order to flash the firmware ensure that you have openocd installed.
To protect, invoke OpenOCD like (for FST-01):
Execute openocd and connect with telnet
```
openocd -f ../misc/stm32f103.cfg
telnet localhost 4444
```
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
-c init -c "reset halt" -c "stm32f1x lock 0" -c reset -c exit
Use the following commands to unlock, flash the firmware and lock the device again.
```
reset halt
stm32f1x unlock 0
reset halt
flash write_bank 0 ./build/gnuk.bin 0
stm32f1x lock 0
reset halt
```
After power-off / power-on sequence, the contents of flash ROM cannot
be accessible from JTAG debugger.
How to reflash the ST-LINK
==========================
To reflash the ST-LINK, connect the device to a programmer as before while keeping pins 7 and 8 shorted. While the LED is blinking, run openocd. Once its running (i.e. it doesnt show any errors), you can unshort the pins.
Unprotecting is:
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
-c init -c "reset halt" -c "stm32f1x unlock 0" -c reset -c exit
Upon unprotection, flash is erased.
Note that it would be still possible for some implementation of DfuSe
to access the contents, even if it's protected. If you really want to
protect, killing DfuSe and accessing by JTAG debugger is recommended.
Then use the following to unlock and reflash.
```
reset halt
stm32f1x unlock 0
reset halt
stm32f1x mass_erase 0
flash write_bank 0 ./build/gnuk.bin 0
stm32f1x lock 0
reset halt
```
***Note: That reprograming will wipe the flash memory and you will lose all key's that was on the device.***
Testing Gnuk
------------
Type following command to see Gnuk runs:
$ gpg --card-status
Besides, there is a functionality test under tests/ directory. See
tests/README.
============
Type following command to see if GnuPG detects the Gnuk token.
```
gpg --card-status
```
***See tests/README for functionality tests.***
Personalize the Token, import keys, and change the password
-----------------------------------------------------------
===========================================================
You can personalize your token by putting in your information like: Name, Login and Language.
You can personalize the token, putting your information like: Name,
Login name, Sex, Languages, URL. To do so, GnuPG command is:
The KDF setting needs to be enabled before any keys are imported into the Gnuk token. Once a key has been imported the KDF setting can't be changed until the token has been reset.
$ gpg --card-edit
***Note:*** That the factory user password is "123456" and admin password is "12345678". It is recommended to create your keys on your computer, and import them into the token. Gnuk supports key generation, but this feature is young and should be considered experimental.
Note that the factory setting of user password is "123456" and admin
password is "12345678" as the specification.
To configure your Gnuk token use the following command.
```
gpg --card-edit
```
It is recommended to create your keys on your computer, and import
them to Gnuk Token. After you create your keys (they must be 2048-bit
RSA), you can import them.
Gnuk supports key generation, but this feature is young and should be
considered experimental.
For detail, please see documentation under doc/. You can see the HTML
version at: https://www.fsij.org/doc-gnuk/
For further details, please see documentation under doc.
Firmware update
===============
See doc/note/firmware-update.
Debug enabled
-------------
If you compiled with --enable-debug option, Gnuk has two interfaces
(one is CCID/ICCD device and another is virtual COM port). Open
virtual COM port by:
$ cu -l /dev/ttyACM0
and you will see debug output of Gnuk.
How to debug
============
Ensure that you have arm-none-eabi-gdb installed and then you must configure and compile the Gnuk firmware with --enable-debug option. After flashing Gnuk debug firmware one will see two interfaces, one is CCID/ICCD device and the another is a virtual COM port.
We can use GDB.
$ arm-none-eabi-gdb gnuk.elf
Open the virtual COM with the following command:
```
picocom /dev/ttyACM0
```
and you will see debug output of Gnuk firmware.
You can now use GDB with the following command.
```
arm-none-eabi-gdb src/build/gnuk.elf
```
Inside GDB, we can connect OpenOCD by:
```
(gdb) target remote localhost:3333
```
(gdb) target remote localhost:3333
or
(gdb) target extended-remote localhost:3333
You can see the output of PCSCD:
# /etc/init.d/pcscd stop
# LIBCCID_ifdLogLevel=7 /usr/sbin/pcscd --debug --foreground
You can observe the traffic of USB using "usbmon". See the file:
linux/Documentation/usb/usbmon.txt
You can see the output of PCSCD with the following command:
```
/usr/bin/pcscd --debug --foreground
```
You can also observe the traffic of the USB interface using "usbmon".
USB vendor ID and product ID (USB device ID)
============================================
When you have a vendor ID and assign a product ID for Gnuk, edit the file GNUK_USB_DEVICE_ID and add an entry for yours. In this case, please contact Niibe, so that it is listed to the file in the official release of the source code.
When you have a vendor ID and assign a product ID for Gnuk, edit the
file GNUK_USB_DEVICE_ID and add an entry for yours. In this case,
please contact Niibe, so that it is listed to the file in the official
release of the source code.
When you are modifing Gnuk and installing the binary to device, you
should replace the vendor string and serial number to yours (in the
file GNUK_USB_DEVICE_ID and SERIALNO of the script of src/configure),
so that users can see it's not by original vendor, and it is modified
version.
FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices
with Gnuk under one of following conditions:
When you are modifing Gnuk and installing the binary to device, you should replace the vendor string and serial number to yours (in the file GNUK_USB_DEVICE_ID and SERIALNO of the script of src/configure), so that users can see it's not by original vendor, and it is modified version.
FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices with Gnuk under one of following conditions:
* For everyone for experimental purpose:
- You must not distribute a binary with FSIJ's USB device ID, but
must use the binary by yourself only for your experiment. Note
that "Distributing binary" includes distributing a device which
holds the binary.
- You must not distribute a binary with FSIJ's USB device ID, but must use the binary by yourself only for your experiment. Note that "Distributing binary" includes distributing a device which holds the binary.
* For general individuals:
- You must use your Gnuk device with a card serial number which is
*not* by FSIJ. Easy one would be a card serial number generated
by chip unique ID.
- You must use your Gnuk device with a card serial number which is *not* by FSIJ. Easy one would be a card serial number generated by chip unique ID.
* For individuals with explicit permission from FSIJ.
- You should have an assigned card serial number by FSIJ,
please use that number for your device.
- You should have an assigned card serial number by FSIJ, please use that number for your device.
(There a file 'GNUK_SERIAL_NUMBER' in the official release.)
FSIJ could give companies or business entities "second source
manufacturer" license to use USB device ID of FSIJ for devices with
unmodified version of Gnuk, provided they support Free Software and
respect users' freedom for computing. Please ask FSIJ for the
license.
Otherwise, companies which want to distribute Gnuk devices, please use
your own USB vendor ID and product ID. Please replace vendor string
and possibly product string to yours, when you modify Gnuk.
FSIJ could give companies or business entities "second source manufacturer" license to use USB device ID of FSIJ for devices with unmodified version of Gnuk, provided they support Free Software and respect users' freedom for computing. Please ask FSIJ for the license.
Otherwise, companies which want to distribute Gnuk devices, please use your own USB vendor ID and product ID. Please replace vendor string and possibly product string to yours, when you modify Gnuk.

Submodule chopstx updated: e12a7e0bb3...a8e9074faf

View File

@@ -1,7 +0,0 @@
FROM gnuk:latest
LABEL Description="Image for checking gnuK"
RUN apt install -y shellcheck
RUN apt install -y clang libfindbin-libs-perl
RUN apt clean

View File

@@ -1,4 +0,0 @@
FROM gnuk:latest
LABEL Description="Image for building gnuK with debugging"
RUN apt install -y gdb-arm-none-eabi && apt clean

View File

@@ -1,6 +0,0 @@
FROM debian:latest
LABEL Description="Image for building gnuK"
RUN apt update -y && apt install -y make gcc-arm-none-eabi && apt clean
CMD ["/bin/sh", "-c", "cd /gnuk/src && make clean && ./configure $GNUK_CONFIG && make"]

View File

@@ -1,36 +0,0 @@
ifndef GNUK_CONFIG
$(warning configuration flags not set in GNUK_CONFIG)
endif
all: ../chopstx docker-build-release
docker run --user=`id -u` --env GNUK_CONFIG --rm -v `pwd`/..:/gnuk/ -t gnuk:latest
clean: docker-build-release
docker run --user=`id -u` --env GNUK_CONFIG --rm -v `pwd`/..:/gnuk/ -w /gnuk/src -t gnuk:latest make clean
gdb: docker-build-debug
docker run --net host --rm -i -v `pwd`/..:/gnuk/ -t gnuk:latest-debug arm-none-eabi-gdb /gnuk/src/build/gnuk.elf
shellcheck: docker-build-check
docker run --rm -v `pwd`/..:/gnuk/ -t gnuk:latest-check shellcheck /gnuk/src/configure
CHECKERS=security optin nullability core deadcode alpha.core alpha.security
scan-build: clean docker-build-check
docker run --user=`id -u` --rm -v `pwd`/..:/gnuk/ -w /gnuk/src -t gnuk:latest-check scan-build -o scan-build \
-analyze-headers -stats $(addprefix -enable-checker ,$(CHECKERS)) -k \
--use-cc=arm-none-eabi-gcc \
make
../chopstx:
git submodule update --init
docker-build-release:
docker build -t gnuk:latest -f `pwd`/Dockerfile.release ..
docker-build-debug: docker-build-release
docker build -t gnuk:latest-debug -f `pwd`/Dockerfile.debug ..
docker-build-check: docker-build-release
docker build -t gnuk:latest-check -f `pwd`/Dockerfile.check ..
.PHONY: all clean gdb shellcheck scan-build \
docker-build-release docker-build-debug docker-build-check

4
misc/stm32f103.cfg Normal file
View File

@@ -0,0 +1,4 @@
telnet_port 4444
source [find interface/stlink.cfg]
source [find target/stm32f1x.cfg]
set WORKAREASIZE 0x10000

6
src/configure vendored
View File

@@ -35,7 +35,7 @@ fi
# Default settings
help=no
vidpid=1209:2440
vidpid=none
target=ST_DONGLE
with_dfu=default
debug=no
@@ -44,7 +44,7 @@ pinpad=no
certdo=no
hid_card_change=no
factory_reset=yes
ackbtn_support=no
ackbtn_support=yes
flash_override=""
kdf_do=${kdf_do:-optional}
# For emulation
@@ -349,7 +349,7 @@ else
fi
### !!! Replace following string of "FSIJ" to yours !!! ####
SERIALNO="FSIJ-$(sed -e 's%^[^/]*/%%' <../VERSION)-"
SERIALNO="DTS-$(sed -e 's%^[^/]*/%%' <../VERSION)-"
SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}"

View File

@@ -31,6 +31,7 @@ USB_PRODUCT_LIST=[
{ 'vendor' : 0x234b, 'product' : 0x0000 }, # FSIJ Gnuk Token
{ 'vendor' : 0x20a0, 'product' : 0x4211 }, # Nitrokey Start
{ 'vendor' : 0x1209, 'product' : 0x2440 }, # GnuPG e.V.
{ 'vendor' : 0x1337, 'product' : 0x0010 }, # DTS Gnuk Token
]
# USB class, subclass, protocol