Compare commits

...

45 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
53cbb62738 Update readme 2022-07-17 00:47:47 +02:00
511f6de8b1 Change default configuration 2022-07-17 00:00:54 +02:00
0132723c7a Move license info into root of project 2022-07-16 23:59:01 +02:00
a37f7aca5c Update readme 2022-07-16 23:52:00 +02:00
531be827dd Remove unnecessary svg 2022-07-16 23:44:27 +02:00
d6c040400a Update readme 2022-07-16 23:28:47 +02:00
b8ada80163 Remove redundant files 2022-07-16 21:46:55 +02:00
1d63372017 Remove old ChangeLog 2022-07-16 21:24:23 +02:00
8dfbf63452 Fix compile bug when acknowledgement button is disabled 2022-07-16 20:56:25 +02:00
b9f6c3be7a Update submodule url 2022-07-16 20:05:23 +02:00
NIIBE Yutaka
9d3c08bd2b Version 1.2.20.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2022-04-22 11:19:41 +09:00
NIIBE Yutaka
a909502388 Update Chopstx to 1.21.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2022-04-22 11:17:22 +09:00
NIIBE Yutaka
286b620648 Fix for address calculation and access to object on memory.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2022-04-22 10:36:13 +09:00
Bertrand Jacquin
cce65c6d34 regnual: remove duplicate type declaration. 2022-03-29 15:11:24 +09:00
NIIBE Yutaka
57fdadf283 Version 1.2.19.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2021-10-12 11:42:44 +09:00
NIIBE Yutaka
870de72ee2 configure: Allow override of kdf_do variable.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2021-10-11 11:51:55 +09:00
NIIBE Yutaka
fa667b04f7 configure: Add KDF configuration.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2021-07-01 13:43:42 +09:00
Bertrand Jacquin
2a72f3df08 regnual: add missing header
regnual.c:32:1: note: ‘memset’ is declared in header ‘<string.h>’
2021-06-15 10:56:57 +09:00
NIIBE Yutaka
db2527459f Fix scripts.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2021-06-10 14:31:45 +09:00
NIIBE Yutaka
1ca3bbdaae Fix for key attributes (long standing bug).
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2021-04-30 13:55:52 +09:00
32 changed files with 227 additions and 6760 deletions

2
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "chopstx"] [submodule "chopstx"]
path = chopstx path = chopstx
url = ../../chopstx/chopstx.git url = ../chopstx.git

106
AUTHORS
View File

@@ -1,106 +0,0 @@
Aurelien Jarno:
Modified:
src/Makefile
src/configure
src/main.c
src/stack-def.h
Anthony Romano:
Modified:
src/call-rsa.c
src/main.c
src/mod.c
Bertrand Jacquin
Modified:
tool/add_openpgp_authkey_from_gpgssh.py
tool/calc_precompute_table_ecc.py
tool/dfuse.py
tool/dump_mem.py
tool/get_raw_public_key.py
tool/pageant_proxy_to_gpg.py
tool/pinpadtest.py
Jeremy Drake:
Modified:
regnual/regnual.c
Kaz Kojima:
Added STM32 Primer2 support.
NIIBE Yutaka:
Founder of the project.
Wrote tools for STLink/V2:
tool/stlinkv2.py
Wrote tools for DfuSe:
tool/dfuse.py
tool/dump_mem.py
tool/intel_hex.py
Wrote a tool for Gnuk:
tool/gnuk_put_binary.py
tool/gnuk_put_binary_libusb.py
tool/gnuk_remove_keys.py
tool/gnuk_upgrade.py
Wrote a tool for USB Hub:
tool/hub_ctrl.py
Wrote a tool for testing card reader with pinpad:
tool/pinpadtest.py
Wrote reGNUal implementation:
regnual/regnual.c
regnual/sys.c
Wrote Gnuk implementation:
gnuk.svg
src/configure
src/ac.c
src/call-rsa.c
src/debug.c
src/flash.c
src/gnuk.h
src/main.c
src/neug.c
src/openpgp-do.c
src/openpgp.c
src/openpgp.h
src/pin-cir.c
src/pin-dial.c
src/pin-dnd.c
src/random.c
src/sys.c
src/usb-icc.c
src/usb-msc.c
src/usb-msc.h
src/usb_ctrl.c
src/usb_desc.c
src/usb_lld.c
src/usb_lld.h
*
and others.
Peter Lebbing:
Modified:
src/config.h.in
src/configure
src/main.c
src/Makefile
Wrote:
src/stdaln-sys.ld.in
Vincent Pelletier:
Modified:
test/features/202_setup_passphrase.feature
test/rsa_keys.py
tests/card_const.py
tests/card_reader.py
tests/rsa_keys.py
tool/gnuk_token.py
Wrote:
tests/card_test_ansix9p256r1.py
tests/card_test_ansix9p384r1.py
tests/card_test_ansix9p512r1.py
tests/card_test_brainpoolp256r1.py
tests/card_test_brainpoolp384r1.py
tests/card_test_brainpoolp512r1.py
tests/card_test_ed25519.py
tests/card_test_x25519.py
tests/func_pso_auth.py
tests/test_006_pso.py

2864
ChangeLog

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

43
NEWS
View File

@@ -1,6 +1,49 @@
Gnuk NEWS - User visible changes Gnuk NEWS - User visible changes
* Major changes in Gnuk 1.2.20
Released 2022-04-22, by NIIBE Yutaka
** Minor fixes for newer compiler
For build with newer compiler, Gnuk and regnual are fixed for address
calculation and access to object on memory, as well as declarations of
function and type in standard C library.
** Upgrade of Chopstx
We use Chopstx 1.21. This includes fix to silence compiler warnings.
* Major changes in Gnuk 1.2.19
Released 2021-10-12, by NIIBE Yutaka
** KDF Data Object configuration
KDF Data Object should be highly recommended for all configurations.
Nevertheless, for backward compatibillity, in Gnuk 1.2, it is optional
by default; It is up to user to configure KDF Data Object before
importing private keys. In this situation, it is not good to
introduce new build-time option like --enable-always-require-kdf-do,
because it might wrongly encourage use of Gnuk with no KDF Data Object
setting, by confusion. If needed, please run configure:
kdf_do=required ./configure --enable-factory-reset --target...
or
kdf_do=optional ./configure --enable-factory-reset --target...
Please note that such a use of variable by shell command line is not
well supported by the configure script (for other variables), but
override of kdf_do is needed in some situations.
** Upgrade of Chopstx
We use Chopstx 1.20. This enables use with PC/SC for GNU/Linux
emulation.
* Major changes in Gnuk 1.2.18 * Major changes in Gnuk 1.2.18
Released 2021-04-02, by NIIBE Yutaka Released 2021-04-02, by NIIBE Yutaka

631
README
View File

@@ -1,631 +0,0 @@
Gnuk - An Implementation of USB Cryptographic Token for GnuPG
Version 1.2.18
2021-04-02
Niibe Yutaka
Free Software Initiative of Japan
Release Notes
=============
This is the release of Gnuk, version 1.2.18, which has major
incompatible changes to Gnuk 1.0.x. Specifically, it now supports
overriding key import, but importing keys (or generating keys) results
password reset. Also, you need to import private keys before changing
your password. Please update your documentation for Gnuk Token, so
that the instruction of importing keys won't cause any confusion.
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.
It supports new KDF-DO feature. Please note that this is
experimental. To use the feature, you need to use newer GnuPG (2.2.6
or later). You need to prepare the KDF-DO on your token by the
card-edit/kdf-setup command.
With FST-01SZ and GNU/Linux emulation, experimental ack button support
is available for test.
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).
I wish that Gnuk will be a developer's soother who uses GnuPG. I have
been nervous of storing secret key(s) on usual secondary storage.
There is a solution with OpenPGP card, but it is not the choice for
me, as card reader is not common device. With Gnuk, this issue will
be solved by a USB token.
Please look at the graphics of "gnuk.svg" for the software name. My
son used to be with his NUK(R), always, everywhere. Now, I am with a
USB Cryptographic Token by "Gnuk", always, everywhere.
FAQ
===
Q0: How Gnuk USB Token is superior than other solutions (OpenPGP
card 2.0/3.3/3.4, YubiKey, etc.) ?
https://www.g10code.de/p-card.html
https://www.yubico.com/
A0: Good points of Gnuk are:
* If you have skill of electronics and like DIY, you can build
Gnuk Token cheaper (see Q8-A8).
* You can study Gnuk to modify and to enhance. For example, you
can implement your own authentication method with some sensor
such as an acceleration sensor.
* It is "of Free Software"; Gnuk is distributed under GPLv3+,
"by Free Software"; Gnuk development requires only Free Software
(GNU Toolchain, Python, etc.),
"for Free Software"; Gnuk supports GnuPG.
Q1: What kind of key algorithm is supported?
A1: Gnuk version 1.0 only supports RSA-2048.
Gnuk version 1.2.x supports 255-bit EdDSA, as well as RSA-4096.
(Note that it takes long time to sign with RSA-4096.)
Q2: How long does it take for digital signing?
A2: It takes a second and a half or so for RSA-2048.
It takes more than 8 seconds for RSA-4096.
Q3: What's your recommendation for target board?
A3: Orthodox choice is Olimex STM32-H103.
FST-01SZ (Flying Stone Tiny 01 SZ) is available for sale, and it
is a kind of the best choice, hopefully. If you have a skill of
electronics, STM32 Nucleo F103 is the best choice for experiment.
Q4: What's version of GnuPG are you using?
A4: In Debian GNU/Linux system, I use GnuPG modern 2.2.23.
Q5: What's version of pcscd and libccid are you using?
A5: I don't use them, pcscd and libccid are optional, you can use Gnuk
Token without them.
I tested pcscd 1.5.5-4 and libccid 1.3.11-2 which were in Debian
squeeze.
Q6: What kinds of hardware is required for development?
A6: You need a target board plus a JTAG/SWD debugger. If you just
want to test Gnuk for target boards with DfuSe, JTAG debugger is
not the requirement. Note that for real use, you need JTAG/SWD
debugger to enable flash ROM protection.
Q7: How much does it cost?
A7: Olimex STM32-H103 plus ARM-USB-TINY-H cost 70 Euro or so.
Q8: How much does it cost for DIY version?
A8: STM32 Nucleo F103 costs about $10 USD.
Q9: I got an error like "gpg: selecting openpgp failed: ec=6.108", what's up?
A9: Older GnuPG's SCDaemon has problems for handling insertion/removal of
card/reader. When your newly inserted token is not found by
GnuPG, try killing scdaemon and let it to be invoked again. I do:
$ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
and confirm scdaemon doesn't exist, then,
$ gpg-connect-agent learn /bye
Qa: With GNOME 2, I can't use Gnuk Token for SSH. How can we use it for SSH?
Aa: You need to deactivate seahorse-agent and gnome-keyring, but use
gpg-agant for the role of ssh-agent. For gnome-keyring please do:
$ gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
Qb: With GNOME 3.0, I can't use Gnuk Token at all. Why?
Ab: That's because gnome-keyring-daemon interferes GnuPG. Type:
$ gnome-session-properties
and at the tab of "Startup Programs", disable check buttons for
"GPG Password Agent" and "SSH Key Agent".
Qc: With GNOME 3.x (x >= 8?), I can't use Gnuk Token at all. Why?
Ac: That's because gnome-keyring-daemon interferes GnuPG. Please
disable the invocation of gnome-keyring-daemon. In Debian
wheezy, it's in the files /etc/xdg/autostart/gnome-keyring-ssh.desktop
and /etc/xdg/autostart/gnome-keyring-gpg.desktop.
We have a line something like:
OnlyShowIn=GNOME;Unity;MATE;
Please edit this line to:
OnlyShowIn=
Qd: Do you know a good SWD debugger to connect FST-01 or something?
Ad: ST-Link/V2 is cheap one. We have a tool/stlinkv2.py as flash ROM
writer program. STM32 Nucleo F103 comes with the valiant of
ST-Link/V2. Note that the firmware of ST-Link/V2 is proprietary.
So, in case of transparency matters, ST-Link/V2 would not be your
choice.
I care transparency for our process of manufacturing FST-01SZ (and
better control by Free Software, in general), thus, I develop
BBG-SWD, SWD debugger by BeagleBone Green.
I use ST-Link/V2 for daily development. For serious task like
flashing product, I use BBG-SWD.
Tested features
===============
Gnuk is tested by test suite. Please see the "tests" directory.
* Personalization of the card
* Changing Login name, URL, Name, Sex, Language, etc.
* Password handling (PW1, RC, PW3)
* Key import for three types:
* key for digital signing
* key for decryption
* key for authentication
* PSO: Digital Signature
* PSO: Decipher
* INTERNAL AUTHENTICATE
* Changing value of password status bytes (0x00C4): forcesig
* Verify with pin pad
* Modify with pin pad
* Card holder certificate (read)
* Removal of keys
* Key generation on device side for RSA-2048
* Overriding key import
Original features of Gnuk, tested manually lightly:
* OpenPGP card serial number setup
* Card holder certificate (write by UPDATE BINARY)
* Upgrading with "EXTERNAL AUTHENTICATE" by reGNUal
Targets
=======
We use Olimex STM32-H103 board and Flying Stone Tiny 01 (FST-01).
With DfuSe support, STBee is also our targets. But this target with
DfuSe is for experiment only, because it is impossible for DfuSe to
disable read from flash. For real use, please consider killing DfuSe
and enabling read protection using JTAG debugger.
Build system and Host system
============================
Makefile is written for GNU make. You need Bash 4.x for configure.
If your bash is not installed as /bin/bash, you need to run configure
script prepending 'bash' before './configure'.
Some tools are written in Python. If your Python is not installed as
/usr/bin/python, please prepend 'python' or 'python3' for your command
invocation. I use Python 3.8 and PyUSB 1.0.2.
Source code
===========
Gnuk source code is under src/ directory.
Note that SHA-2 hash function implementation, src/sha256.c, is based
on the original implementation by Dr. Brian Gladman. See:
http://brg.a2hosted.com//oldsite/cryptography_technology/sha/index.php
(was at:
http://gladman.plushost.co.uk/oldsite/cryptography_technology/sha/index.php)
License
=======
It is distributed under GNU General Public Licence version 3 or later
(GPLv3+). Please see src/COPYING.
Please note that it is distributed with external source code too.
Please read relevant licenses for external source code as well.
The author(s) of Gnuk expect users of Gnuk will be able to access the
source code of Gnuk, so that users can study the code and can modify
if needed. This doesn't mean person who has a Gnuk Token should be
able to access everything on the Token, regardless of its protections.
Private keys, and other information should be protected properly.
External source code
====================
Gnuk is distributed with external source code.
* chopstx/ -- Chopstx 1.19
We use Chopstx as the kernel for Gnuk.
Chopstx is distributed under GPLv3+ (with a special exception).
* polarssl/ -- based on PolarSSL 1.2.10 (now mbedTLS)
Souce code taken from: http://polarssl.org/
We use PolarSSL for RSA computation, and AES encryption/decryption.
PolarSSL is distributed under GPLv2+. We use PolarSSL under GPLv3
as our options.
The file include/polarssl/bn_mul.h is heavily modified for ARM
Cortex-M3.
The function rsa_private in polarssl/library/rsa.c is modified so
that it doesn't check T against N. The function rsa_pkcs1_sign is
modified to avoid warnings in case of !POLARSSL_PKCS1_V21.
The functions rsa_pkcs1_verify and rsa_rsassa_pkcs1_v15_verify in
include/polarssl/rsa.h and polarssl/library/rsa.c are modified
(fixed) for last argument SIG, as the memory at SIG aren't modified
by those routines.
The constant POLARSSL_MPI_MAX_SIZE in include/polarssl/bignum.h is
modified for 2048-bit keys only Gnuk.
The function mpi_mul_hlp in library/bignum.c is modified for more
optimization for ARM Cortex-M3. Functions mpi_montred, mpi_sub_hlp,
mpi_sub_abs, mpi_mul_mpi, mpi_montmul, and mpi_exp_mod are modified
to avoid side channel attacks. Note that we don't use RSA-blinding
technique for Gnuk. Function mpi_gen_prime and mpi_is_prime are
modified to use Fouque-Tibouchi method. Function mpi_exp_mod is
modified to use new function mpi_montsqr for speed up.
The file library/aes.c is modified so that some constants can
go to .sys section.
The file include/polarssl/config.h are modified not to define
POLARSSL_HAVE_LONGLONG to avoid linking libgcc, to define
POLARSSL_AES_ROM_TABLES to have AES tables, not to define
POLARSSL_CIPHER_MODE_CTR, POLARSSL_FS_IO, POLARSSL_PKCS1_V21,
POLARSSL_SELF_TEST, and POLARSSL_PADLOCK_C, and only define
POLARSSL_GENPRIME when defined KEYGEN_SUPPORT.
And polarssl/library/bignum.c is modified to work on 64-bit machine.
Aurelien Jarno also modified:
polarssl/include/polarssl/bn_mul.h
polarssl/library/bignum.c
See ChangeLog (and/or history of git) for detail.
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 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.
* 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.
* For individuals with explicit permission from FSIJ.
- 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.
Host Requirements
=================
For GNU/Linux, PC/SC service is an option, you can use GnuPG's
internal CCID driver instead. If you chose using PC/SC service,
libccid version >= 1.3.11 is recommended for GNU/Linux.
How to compile
==============
You need GNU toolchain and newlib for 'arm-none-eabi' target.
On Debian we can install the packages of gcc-arm-none-eabi
and its friends. I'm using:
binutils-arm-none-eabi 2.35.2-2+14+b2
gcc-arm-none-eabi 15:8-2019-q3-1+b1
libnewlib-arm-none-eabi 3.3.0-1
gdb-multiarch 10.1-2
Or else, see https://launchpad.net/gcc-arm-embedded for preparation of
GNU Toolchain for 'arm-none-eabi' target.
Change directory to `src':
$ cd gnuk-VERSION/src
Then, run `configure':
$ ./configure --vidpid=<VID:PID>
Here, you need to specify USB vendor ID and product ID. For FSIJ's,
it's: --vidpid=234b:0000 . Please read section 'USB vendor ID and
product ID' above.
Then, type:
$ make
Then, we will have "gnuk.elf" under src/build directory.
If you are not the authorized vendor, please never distribute this
file of "gnuk.elf", which includes VID:PID in the image. If you would
like to distribute the image (for example, to check if it's
reproducible or not), the file "gnuk-no-vidpid.elf" is the one with no
VID:PID.
How to install
==============
Olimex STM32-H103 board
-----------------------
If you are using Olimex JTAG-Tiny, type following to invoke OpenOCD
and write "gnuk.elf" to Flash ROM:
$ openocd -f interface/ftdi/olimex-jtag-tiny.cfg \
-f board/olimex_stm32_h103.cfg \
-c "program build/gnuk.elf verify reset exit"
Command invocation is assumed in src/ directory.
Flying Stone Tiny 01
--------------------
If you are using Flying Stone Tiny 01, you need a SWD writer.
OpenOCD 0.9.0 now supports ST-Link/V2. We can use it like:
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
-c "program build/gnuk.elf verify reset exit"
STBee
-----
Note that this is only for your experiment; Your private key materials
on the board can be accessed by DfuSe.
Reset the board with "USER" switch pushed. Type following to write
to flash:
# cd ../tool
# ./dfuse.py ../src/build/gnuk.hex
Then, reset the board.
How to protect flash ROM
========================
To protect, invoke OpenOCD like (for FST-01):
$ openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg \
-c init -c "reset halt" -c "stm32f1x lock 0" -c reset -c exit
After power-off / power-on sequence, the contents of flash ROM cannot
be accessible from JTAG debugger.
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.
(Optional) Configure serial number and X.509 certificate
========================================================
This is completely optional.
For this procedure, you need python and pyscard (python-pyscard
package in Debian) or PyUSB (python-usb package in Debian).
(1) [pyscard] Stop scdaemon
[PyUSB] Stop the pcsc daemon.
If scdaemon is running, please kill it, or you will get "Smartcard
Exception" by "Sharing violation".
$ gpg-connect-agent "SCD KILLSCD" "SCD BYE" /bye
In case of PyUSB tool, you need to stop pcscd.
# systemctl stop pcscd
(2) [Optional] Write fixed serial number
If you use fixed serial number in the file 'GNUK_SERIAL_NUMBER', you can do:
$ EMAIL=<YOUR-EMAIL-ADDRESS> ../tool/gnuk_put_binary_usb.py -s ../GNUK_SERIAL_NUMBER
Writing serial number
...
(3) [Optional] Write card holder certificate
If you have card holder certificate binary file, you can do:
$ ../tool/gnuk_put_binary_usb.py ../../<YOUR-CERTIFICATE>.bin
../../<YOUR-CERTIFICATE>.bin: <LENGTH-OF-YOUR-CERTIFICATE>
Updating card holder certificate
...
How to run
==========
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.
Testing Gnuk
------------
Type following command to see Gnuk runs:
$ gpg --card-status
Besides, there is a functionality test under tests/ directory. See
tests/README.
Personalize the Token, import keys, and change the password
-----------------------------------------------------------
You can personalize the token, putting your information like: Name,
Login name, Sex, Languages, URL. To do so, GnuPG command is:
$ gpg --card-edit
Note that the factory setting of user password is "123456" and admin
password is "12345678" as the specification.
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/
How to debug
============
We can use GDB.
$ arm-none-eabi-gdb gnuk.elf
Inside GDB, we can connect OpenOCD by:
(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
Firmware update
===============
See doc/note/firmware-update.
Git Repositories
================
Please use: https://salsa.debian.org/gnuk-team/gnuk/
You can get it by:
$ git clone https://salsa.debian.org/gnuk-team/gnuk/gnuk.git
It's also available at: www.gniibe.org
You can browse at: https://git.gniibe.org/cgit/gnuk/gnuk.git/
I put Chopstx as a submodule of Git. Please do this:
$ git submodule update --init
Information on the Web
======================
For more information, please visit: https://www.fsij.org/gnuk/
Please see the FST-01 support pages:
https://www.gniibe.org/category/fst-01.html
Please consider to join Gnuk-users mailing list:
https://lists.gnupg.org/mailman/listinfo/gnuk-users
Your Contributions
==================
FSIJ welcomes your contributions. Please assign your copyright
to FSIJ (if possible), as I do.
Foot note
==========
* NUK(R) is a registered trademark owend by MAPA GmbH, Germany.
--

138
README.md Normal file
View File

@@ -0,0 +1,138 @@
***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 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).
Gnuk supports the Key Derived Function (KDF) functionality. To use this feature one will need to use GnuPG 2.2.6 or later.
How to build the Gnuk firmware
==============================
You will need the GNU toolchain for arm-none-eabi and newlib.
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 --vidpid=1337:0010
make
```
Then, you will have "gnuk.bin" under src/build directory.
***Please read section 'USB vendor ID and product ID' below.***
How to flash the Gnuk firmware
==============================
In order to flash the firmware ensure that you have openocd installed.
Execute openocd and connect with telnet
```
openocd -f ../misc/stm32f103.cfg
telnet localhost 4444
```
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
```
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.
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 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.
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.
***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.
To configure your Gnuk token use the following command.
```
gpg --card-edit
```
For further details, please see documentation under doc.
Firmware update
===============
See doc/note/firmware-update.
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.
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
```
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 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.
* 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.
* For individuals with explicit permission from FSIJ.
- 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.

46
THANKS
View File

@@ -1,46 +0,0 @@
-*- coding: utf-8 -*-
We would like to express our gratitudes to Werner Koch for GnuPG, and
Giovanni Di Sirio for ChibiOS/RT.
Gnuk was originally written by NIIBE Yutaka. People contributed by
encouraging the development, testing the implementation, suggesting
improvements, or fixing bugs. Here is a list of those people.
Aurelien Jarno aurelien@aurel32.net
Achim Pietig achim@pietig.com
Aidan Thornton
Anibal Monsalve Salazar anibal@debian.org
Andre Zepezauer andre.zepezauer@student.uni-halle.de
Anthony Romano anthony.romano@coreos.com
Bertrand Jacquin bertrand@jacquin.bzh
Clint Adams clint@softwarefreedom.org
Daniel Kahn Gillmor dkg@fifthhorseman.net
Elliott Mitchell
Fabio Utzig utzig@apache.org
Hironobu SUZUKI hironobu@h2np.net
Jan Suhr jan@suhr.info
Jeremy Drake jeremydrake+gnuk@eacceleration.com
Jonathan McDowell noodles@earth.li
Kaz Kojima kkojima@rr.iij4u.or.jp
Kenji Rikitake
Ludovic Rousseau ludovic.rousseau@free.fr
Luis Felipe R. Murillo luisfelipe@ucla.edu
Mateusz Zalega mateusz@nitrokey.com
MATSUU Takuto matsuu@gentoo.org
Micah Anderson micah@debian.org
NAGAMI Takeshi nagami-takeshi@aist.go.jp
Nguyễn Hồng Quân quannguyen@mbm.vn
Nico Rikken nico@nicorikken.eu
NOKUBI Takatsugu knok@daionet.gr.jp
Paul Fertser
Paul Bakker polarssl_maintainer@polarssl.org
Peter Lebbing peter@digitalbrains.com
Santiago Ruano Rincón santiago@debian.org
Shane Coughlan scoughlan@openinventionnetwork.com
Stanislas Bach sbach@0g.re
Szczepan Zalega szczepan@nitrokey.com
Vasily Evseenko
Vincent Pelletier plr.vincent@gmail.com
Werner Koch wk@gnupg.org
Yuji Imai ug@xcast.jp

View File

@@ -1 +1 @@
release/1.2.18 release/1.2.20

Submodule chopstx updated: 71cc5a8f32...a8e9074faf

View File

@@ -122,7 +122,7 @@ your environment for Gnuk Token.
How to run the script: :: How to run the script: ::
$ cd tool $ cd tool
$ ./upgrade_by_passwd.py ../regnual/regnual.bin ../src/build/gnuk.bin $ ./upgrade_by_passwd.py
Then, the script on your host PC invoke the steps described above, and Then, the script on your host PC invoke the steps described above, and
you will get new version of Gnuk installed. you will get new version of Gnuk installed.

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

View File

@@ -1,553 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
id="svg3961"
version="1.1"
inkscape:version="0.47 r22583"
sodipodi:docname="gnuk-sticers.svg">
<defs
id="defs3">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective3967" />
<linearGradient
gradientUnits="userSpaceOnUse"
y2="1031.615"
x2="240.89818"
y1="1031.615"
x1="85.996228"
id="linearGradient4296"
xlink:href="#linearGradient4290"
inkscape:collect="always" />
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
id="perspective3903" />
<filter
id="filter3875"
inkscape:collect="always">
<feBlend
id="feBlend3877"
in2="BackgroundImage"
mode="screen"
inkscape:collect="always" />
</filter>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
id="perspective3830" />
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10-5" />
<linearGradient
id="linearGradient0">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop3620" />
<stop
id="stop3632"
offset="0.07"
style="stop-color:#c8c8e0;stop-opacity:1;" />
<stop
id="stop3630"
offset="0.17"
style="stop-color:#9696c8;stop-opacity:1;" />
<stop
id="stop3628"
offset="0.33"
style="stop-color:#6464b4;stop-opacity:1;" />
<stop
style="stop-color:#3232a0;stop-opacity:1;"
offset="0.5"
id="stop3634" />
<stop
id="stop3636"
offset="0.66"
style="stop-color:#282898;stop-opacity:1;" />
<stop
id="stop3626"
offset="0.85"
style="stop-color:#1e1e90;stop-opacity:1;" />
<stop
style="stop-color:#000088;stop-opacity:1;"
offset="1"
id="stop3622" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient0"
id="radialGradient0"
cx="450"
cy="750"
fx="450"
fy="750"
r="201.5"
gradientTransform="matrix(1,0,0,0.75369458,-1.760006,108.15135)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient1">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop0" />
<stop
id="stop1"
offset="0.0625"
style="stop-color:#f8fcff;stop-opacity:1;" />
<stop
id="stop2"
offset="0.17166339"
style="stop-color:#f0f8ff;stop-opacity:1;" />
<stop
id="stop3"
offset="0.30279359"
style="stop-color:#ecf4ff;stop-opacity:1;" />
<stop
style="stop-color:#e8f0ff;stop-opacity:1;"
offset="0.5"
id="stop4" />
<stop
id="stop5"
offset="0.65893352"
style="stop-color:#e0ecff;stop-opacity:1;" />
<stop
id="stop6"
offset="0.83552629"
style="stop-color:#d8e8ff;stop-opacity:1;" />
<stop
style="stop-color:#d0e0ff;stop-opacity:1;"
offset="1"
id="stop7" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient1"
id="radialGradient1"
cx="0"
cy="440"
fx="0"
fy="440"
r="80"
gradientUnits="userSpaceOnUse" />
<filter
inkscape:collect="always"
id="filter0"
x="-0.1423529"
width="1.2847058"
y="-0.13404847"
height="1.2680969">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="2.0538481"
id="feGaussianBlur0" />
</filter>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
id="perspective2884" />
<inkscape:perspective
id="perspective10"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 526.18109 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
id="linearGradient4290"
inkscape:collect="always">
<stop
id="stop4292"
offset="0"
style="stop-color:#000734;stop-opacity:1;" />
<stop
id="stop4294"
offset="1"
style="stop-color:#000734;stop-opacity:0;" />
</linearGradient>
</defs>
<sodipodi:namedview
inkscape:document-units="mm"
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-75.714286"
inkscape:cy="520"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1122"
inkscape:window-height="692"
inkscape:window-x="150"
inkscape:window-y="51"
inkscape:window-maximized="0" />
<metadata
id="metadata4">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<g
style="display:inline"
transform="translate(0.5,-946.62598)"
id="layer1-63"
inkscape:label="Layer1"
inkscape:tile-cx="124.59931"
inkscape:tile-cy="53.118107"
inkscape:tile-w="248.19862"
inkscape:tile-h="105.23622"
inkscape:tile-x0="0.5"
inkscape:tile-y0="0.49999656">
<rect
y="947.12598"
x="0"
height="105.23622"
width="248.19862"
id="rect0"
style="fill:#d9fffe;fill-opacity:1;stroke:none" />
<line id="line0"
x1="0" y1="947.12598" x2="20" y2="947.12598"
style="stroke:#000044;stroke-width:0.5;stroke-opacity:1;stroke-dasharray:2,1;stroke-dashoffset:1" />
<line id="line1"
x1="248.19862" y1="947.12598" x2="248.19862" y2="957.12598"
style="stroke:#000044;stroke-width:0.5;stroke-opacity:1;stroke-dasharray:2,1;stroke-dashoffset:1" />
<line id="line2"
x1="248.19862" y1="1052.3622" x2="228.19862" y2="1052.3622"
style="stroke:#000044;stroke-width:0.5;stroke-opacity:1;stroke-dasharray:2,1;stroke-dashoffset:1" />
<line id="line3"
x1="0" y1="1052.3622" x2="0" y2="1042.3622"
style="stroke:#000044;stroke-width:0.5;stroke-opacity:1;stroke-dasharray:2,1;stroke-dashoffset:1" />
<image
xlink:href="FSIJ-s.png"
width="41.757679"
height="28.346457"
id="image2886"
x="202.27382"
y="951.12598" />
<text
sodipodi:linespacing="100%"
id="text2890"
y="1014.9048"
x="94.433884"
style="font-size:52.27830124px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:100%;writing-mode:lr-tb;text-anchor:start;fill:#032b7f;fill-opacity:1;stroke:none;font-family:Courier 10 Pitch;-inkscape-font-specification:Courier 10 Pitch Bold"
xml:space="preserve"><tspan
y="1014.9048"
x="94.433884"
id="tspan2892"
sodipodi:role="line">GNUK</tspan></text>
<g
inkscape:label="Layer 1"
id="layer1-6"
transform="matrix(-0.1014557,0,0,0.1014557,90.73972,926.6016)">
<path
style="fill:#000050;fill-opacity:1;stroke:#000000;stroke-width:2.29999995px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 0,0 c 0,0 0,0 -76,0 0,0 -8,-9 -12,-12 -18,-15 -48,-48 -36,-84 4,-14 12,-36 12,-36 -10,6 -50,26 -66,54 -8,16 -18,30 -18,54 0,24 25,100 48,108 0,0 0,0 150,0 0,0 0,0 150,0 23,-8 48,-84 48,-108 0,-24 -10,-38 -18,-54 -16,-28 -46,-48 -66,-54 0,0 8,22 12,36 12,36 -18,69 -36,84 C 88,-9 80,0 80,0 z"
transform="matrix(-1.76,0,0,1.76,410,560)"
id="path0" />
<path
inkscape:connector-curvature="0"
style="fill:#000040;fill-opacity:1;stroke:none"
d="m 411.01194,560.94628 c 0,0 0,0 133.76,0 0,0 14.08,-15.84 21.12,-21.12 31.68,-26.4 84.48,-84.48 63.36,-147.84 -7.04,-24.64 -21.12,-63.36 -21.12,-63.36 17.6,10.56 38,45.76 66.16,95.04 14.08,28.16 19.18,52.8 19.18,95.04 0,42.24 -44,176 -84.48,190.08 0,0 62.5,0 -201.5,0 0,0 62.5,0 -201.5,0 -40.48,-14.08 -84.48,-147.84 -84.48,-190.08 0,-42.24 5.1,-66.88 19.18,-95.04 28.16,-49.28 30.96,-84.48 66.16,-95.04 0,0 -14.08,38.72 -21.12,63.36 -21.12,63.36 31.68,121.44 63.36,147.84 7.04,5.28 21.12,21.12 21.12,21.12 z"
id="path0-9"
sodipodi:nodetypes="ccccccscccscccccc" />
<path
style="fill:#c0c0fd;fill-opacity:1;stroke:#000000;stroke-width:4px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 409.21999,592 c 0,0 90,0 90,-33 0,-20 -4,-28 -12,-40 -5,-8 -8,-18 -8,-28 -1,-13 -1,-20 8,-36 6,-9 8,-23 5,-33 -5,-14 -19,-23 -33,-25 -16,-5 -35,-4 -50,-5 -15,1 -34,0 -50,5 -14,2 -28,9 -33,25 -3,10 1,24 5,33 9,16 9,23 8,36 0,10 -3,20 -8,28 -8,12 -12,20 -12,40 0,33 90,33 90,33 z"
id="path1" />
<path
style="fill:url(#radialGradient1);fill-opacity:1;fill-rule:evenodd;stroke:#d0e0ff;stroke-width:10px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 0,592 c 0,0 -90,0 -90,-33 0,-20 4,-28 12,-40 5,-8 8,-18 8,-28 1,-13 1,-20 -8,-36 -6,-9 -8,-23 -5,-33 5,-14 19,-23 33,-25 16,-5 35,-4 50,-5 15,1 34,0 50,5 14,2 28,9 33,25 3,10 -1,24 -5,33 -9,16 -9,23 -8,36 0,10 3,20 8,28 8,12 12,20 12,40 0,33 -90,33 -90,33 z"
id="path1-1"
transform="matrix(-0.75,0,0,0.8,410,100)" />
<path
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;filter:url(#filter0)"
d="m 344.11439,411.54794 c 7.16035,-2.82917 12.68023,-7.05316 25.88561,-1.83463 -11.82218,3.36559 -30.19974,8.74598 -28.4554,30.10894 0,1.43822 0.19526,2.84651 0.53302,4.18858 -5.07909,-3.45362 -6.70449,-9.04022 -6.70449,-15.93734 0,-10.74221 5.00989,-12.63545 8.74126,-16.52555 z"
id="path1-2"
sodipodi:nodetypes="ccccsc" />
<path
style="fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:none;filter:url(#filter0)"
d="m 474.68123,406.16125 c 7.16035,-2.82917 12.68023,-7.05316 25.88561,-1.83463 -11.82218,3.36559 -30.19974,8.74598 -28.4554,30.10894 0,1.43822 0.19526,2.84651 0.53302,4.18858 -5.07909,-3.45362 -6.70449,-9.04022 -6.70449,-15.93734 0,-10.74221 5.00989,-12.63545 8.74126,-16.52555 z"
id="path1-3"
sodipodi:nodetypes="ccccsc"
transform="matrix(-1,0,0,1,949.00681,5.38669)" />
<path
style="fill:#afcfff;fill-opacity:1;stroke:#000000;stroke-width:4px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 236.90125,452.90625 C 135.34805,496.35376 97.060607,634.496 151.37,761.4375 c 50.02335,116.92341 158.1859,159.40625 257.75,159.40625 99.5641,0 207.72665,-42.48284 257.75,-159.40625 C 721.17939,634.496 682.89195,496.35376 581.33875,452.90625 526.07714,429.26367 466.8919,524.375 409.12,524.375 c -57.7719,0 -116.77668,-94.67646 -172.21875,-71.46875 z"
id="path2"
inkscape:connector-curvature="0" />
<path
style="fill:url(#radialGradient0);fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:4px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="path3"
d="m 538.23999,720 a 130,150 0 0 1 -260,0 130,150 0 1 1 260,0 z"
inkscape:connector-curvature="0" />
<path
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:4.47213602px;stroke-opacity:1"
d="m 538.30032,722.21875 c 56.32313,26.16396 100.82185,68.68738 119.76563,119.4375 33.50451,82.59901 -5.55269,179.72665 -93.67188,230.71875 -89.66782,55.4574 -224.43374,55.4574 -314.10156,0 -88.11919,-50.9921 -127.13733,-148.11974 -93.63281,-230.71875 18.61816,-50.41349 63.06491,-92.92973 119.25781,-119.1875 11.1304,10.32118 18.58377,23.0939 22.34375,36.6875 -5.94376,3.59375 -11.63988,7.47175 -16.99219,11.625 -73.95399,55.19241 -81.85302,155.28934 -18.59375,218.125 47.75721,51.30795 139.68,72.55545 213.4375,46.68755 87.41094,-28.2229 135.47694,-110.93384 113.94531,-183.2813 -9.09953,-36.85675 -36.47131,-70.33241 -73.67187,-92.96875 2.51871,-9.1715 6.69761,-18.00492 12.57812,-26 2.55237,-3.99852 5.70954,-7.71801 9.33594,-11.125 z"
id="path4"
inkscape:connector-curvature="0" />
</g>
<text
sodipodi:linespacing="85.000002%"
id="text3817"
y="1038.1145"
x="98.368591"
style="font-size:18px;font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:85.00000238%;writing-mode:lr-tb;text-anchor:start;fill:#120054;fill-opacity:1;stroke:none;display:inline;font-family:Gentium Basic;-inkscape-font-specification:Gentium Basic Bold Italic"
xml:space="preserve"><tspan
y="1038.1145"
x="98.368591"
style="fill:#120054;fill-opacity:1"
id="tspan4288"
sodipodi:role="line">GnuPG USB Token</tspan></text>
</g>
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
id="use4758" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,105.23622)"
id="use4760" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,210.47244)"
id="use4762" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,315.70866)"
id="use4764" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,420.94489)"
id="use4766" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,526.18111)"
id="use4768" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,631.41733)"
id="use4770" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,736.65355)"
id="use4772" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,841.88977)"
id="use4774" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(0,947.12599)"
id="use4776" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,0)"
id="use4778" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,105.23622)"
id="use4780" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,210.47244)"
id="use4782" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,315.70866)"
id="use4784" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,420.94489)"
id="use4786" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,526.18111)"
id="use4788" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,631.41733)"
id="use4790" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,736.65355)"
id="use4792" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,841.88977)"
id="use4794" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(248.19862,947.12599)"
id="use4796" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,0)"
id="use4798" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,105.23622)"
id="use4800" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,210.47244)"
id="use4802" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,315.70866)"
id="use4804" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,420.94489)"
id="use4806" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,526.18111)"
id="use4808" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,631.41733)"
id="use4810" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,736.65355)"
id="use4812" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,841.88977)"
id="use4814" />
<use
x="0"
y="0"
inkscape:tiled-clone-of="#layer1-63"
xlink:href="#layer1-63"
transform="translate(496.39725,947.12599)"
id="use4816" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 20 KiB

BIN
gnuk.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

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

View File

@@ -26,12 +26,12 @@
* ReGNUal * ReGNUal
*/ */
#include <string.h>
#include "types.h" #include "types.h"
#include "usb_lld.h" #include "usb_lld.h"
#include "sys.h" #include "sys.h"
extern void *memset (void *s, int c, size_t n);
extern void set_led (int); extern void set_led (int);
extern int flash_write (uint32_t dst_addr, const uint8_t *src, size_t len); extern int flash_write (uint32_t dst_addr, const uint8_t *src, size_t len);
extern int flash_protect (void); extern int flash_protect (void);

View File

@@ -1,5 +1,3 @@
typedef unsigned long size_t;
typedef unsigned char uint8_t; typedef unsigned char uint8_t;
typedef unsigned short uint16_t; typedef unsigned short uint16_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
@@ -7,5 +5,3 @@ typedef unsigned int uintptr_t;
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define NULL 0

16
src/configure vendored
View File

@@ -36,17 +36,17 @@ fi
# Default settings # Default settings
help=no help=no
vidpid=none vidpid=none
target=FST_01 target=ST_DONGLE
with_dfu=default with_dfu=default
debug=no debug=no
sys1_compat=yes sys1_compat=yes
pinpad=no pinpad=no
certdo=no certdo=no
hid_card_change=no hid_card_change=no
factory_reset=no factory_reset=yes
ackbtn_support=yes ackbtn_support=yes
flash_override="" flash_override=""
kdf_do_required=no kdf_do=${kdf_do:-optional}
# For emulation # For emulation
prefix=/usr/local prefix=/usr/local
exec_prefix='${prefix}' exec_prefix='${prefix}'
@@ -219,7 +219,7 @@ if test "$target" = "GNU_LINUX"; then
emulation="yes" emulation="yes"
cross="" cross=""
mcu="none" mcu="none"
kdf_do_required=yes kdf_do=${kdf_do:-required}
def_emulation="-DGNU_LINUX_EMULATION" def_emulation="-DGNU_LINUX_EMULATION"
def_memory_size="-DMEMORY_SIZE=1024" def_memory_size="-DMEMORY_SIZE=1024"
enable_hexoutput="" enable_hexoutput=""
@@ -341,7 +341,7 @@ else
fi fi
# KDF Data Object is always required for GNU/Linux emulation # KDF Data Object is always required for GNU/Linux emulation
if test "$kdf_do_required" = "yes"; then if test "$kdf_do" = "required"; then
KDF_DO_REQUIRED_DEFINE="#define KDF_DO_REQUIRED 1" KDF_DO_REQUIRED_DEFINE="#define KDF_DO_REQUIRED 1"
echo "KDF DO is required before key import/generation" echo "KDF DO is required before key import/generation"
else else
@@ -349,13 +349,13 @@ else
fi fi
### !!! Replace following string of "FSIJ" to yours !!! #### ### !!! 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}" SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}"
if test "$sys1_compat" = "yes"; then if test "$sys1_compat" = "yes"; then
CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:factory_reset=$factory_reset" CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:factory_reset=$factory_reset:kdf=$kdf_do"
else else
if test "$with_dfu" = "yes"; then if test "$with_dfu" = "yes"; then
echo "Common binary can't support DFU loader, don't use --with-dfu." >&2 echo "Common binary can't support DFU loader, don't use --with-dfu." >&2
@@ -365,7 +365,7 @@ else
FLASH_PAGE_SIZE=2048 FLASH_PAGE_SIZE=2048
FLASH_SIZE=128 FLASH_SIZE=128
MEMORY_SIZE=20 MEMORY_SIZE=20
CONFIG="common:debug=$debug:pinpad=$pinpad:certdo=$certdo:factory_reset=$factory_reset" CONFIG="common:debug=$debug:pinpad=$pinpad:certdo=$certdo:factory_reset=$factory_reset:kdf=$kdf_do"
fi fi
output_vid_pid_version () { output_vid_pid_version () {

View File

@@ -82,10 +82,10 @@ extern uint8_t *flash_addr_data_storage_start;
#define FLASH_ADDR_DATA_STORAGE_START flash_addr_data_storage_start #define FLASH_ADDR_DATA_STORAGE_START flash_addr_data_storage_start
#else #else
/* Linker sets these symbols */ /* Linker sets these symbols */
extern uint8_t _keystore_pool; extern uint8_t _keystore_pool[];
extern uint8_t _data_pool; extern uint8_t _data_pool[];
#define FLASH_ADDR_KEY_STORAGE_START ((&_keystore_pool)) #define FLASH_ADDR_KEY_STORAGE_START ((_keystore_pool))
#define FLASH_ADDR_DATA_STORAGE_START ((&_data_pool)) #define FLASH_ADDR_DATA_STORAGE_START ((_data_pool))
#endif #endif
static int key_available_at (const uint8_t *k, int key_size) static int key_available_at (const uint8_t *k, int key_size)

View File

@@ -475,6 +475,6 @@ int pinpad_getline (int msg_code, uint32_t timeout_usec);
#endif #endif
extern uint8_t _regnual_start, __heap_end__[]; extern uint8_t _regnual_start[], __heap_end__[];
uint8_t * sram_address (uint32_t offset); uint8_t * sram_address (uint32_t offset);

View File

@@ -503,8 +503,8 @@ main (int argc, const char *argv[])
#ifdef FLASH_UPGRADE_SUPPORT #ifdef FLASH_UPGRADE_SUPPORT
/* Set vector */ /* Set vector */
SCB->VTOR = (uintptr_t)&_regnual_start; SCB->VTOR = (uintptr_t)_regnual_start;
entry = calculate_regnual_entry_address (&_regnual_start); entry = calculate_regnual_entry_address (_regnual_start);
#ifdef DFU_SUPPORT #ifdef DFU_SUPPORT
{ {
/* Use SYS at ORIGIN_REAL instead of the one at ORIGIN */ /* Use SYS at ORIGIN_REAL instead of the one at ORIGIN */

View File

@@ -815,6 +815,8 @@ rw_algorithm_attr (uint16_t tag, int with_tag,
else if (algo == ALGO_RSA2K && *algo_attr_pp != NULL) else if (algo == ALGO_RSA2K && *algo_attr_pp != NULL)
{ {
gpg_reset_algo_attr (kk); gpg_reset_algo_attr (kk);
/* Read it again, since GC may occur. */
algo_attr_pp = get_algo_attr_pointer (kk);
flash_enum_clear (algo_attr_pp); flash_enum_clear (algo_attr_pp);
if (*algo_attr_pp != NULL) if (*algo_attr_pp != NULL)
return 0; return 0;
@@ -823,6 +825,10 @@ rw_algorithm_attr (uint16_t tag, int with_tag,
(*algo_attr_pp != NULL && (*algo_attr_pp)[1] != algo)) (*algo_attr_pp != NULL && (*algo_attr_pp)[1] != algo))
{ {
gpg_reset_algo_attr (kk); gpg_reset_algo_attr (kk);
/* Read it again, since GC may occur. */
algo_attr_pp = get_algo_attr_pointer (kk);
if (*algo_attr_pp)
flash_enum_clear (algo_attr_pp);
*algo_attr_pp = flash_enum_write (kk_to_nr (kk), algo); *algo_attr_pp = flash_enum_write (kk_to_nr (kk), algo);
if (*algo_attr_pp == NULL) if (*algo_attr_pp == NULL)
return 0; return 0;

View File

@@ -1929,6 +1929,7 @@ ccid_thread (void *arg)
} }
else /* Timeout */ else /* Timeout */
{ {
#ifdef ACKBTN_SUPPORT
if (c->timeout_cnt == 7 if (c->timeout_cnt == 7
&& c->ccid_state == CCID_STATE_ACK_REQUIRED_1) && c->ccid_state == CCID_STATE_ACK_REQUIRED_1)
{ {
@@ -1940,6 +1941,7 @@ ccid_thread (void *arg)
goto exec_done; goto exec_done;
} }
else else
#endif
c->ccid_state = ccid_handle_timeout (c); c->ccid_state = ccid_handle_timeout (c);
} }
} }

View File

@@ -227,7 +227,7 @@ static const uint8_t lun_table[] = { 0, 0, 0, 0, };
#endif #endif
#ifdef FLASH_UPGRADE_SUPPORT #ifdef FLASH_UPGRADE_SUPPORT
static const uint8_t *const mem_info[] = { &_regnual_start, __heap_end__, }; static const uint8_t *const mem_info[] = { _regnual_start, __heap_end__, };
#endif #endif
#define USB_FSIJ_GNUK_MEMINFO 0 #define USB_FSIJ_GNUK_MEMINFO 0
@@ -284,7 +284,7 @@ usb_setup (struct usb_dev *dev)
if (ccid_get_ccid_state () != CCID_STATE_EXITED) if (ccid_get_ccid_state () != CCID_STATE_EXITED)
return -1; return -1;
if (addr < &_regnual_start || addr + arg->len > __heap_end__) if (addr < _regnual_start || addr + arg->len > __heap_end__)
return -1; return -1;
if (arg->index + arg->len < 256) if (arg->index + arg->len < 256)

View File

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

View File

@@ -1,4 +1,4 @@
#! /usr/bin/python #! /usr/bin/python3
""" """
stlinkv2.py - a tool to control ST-Link/V2 stlinkv2.py - a tool to control ST-Link/V2

View File

@@ -131,19 +131,25 @@ if __name__ == '__main__':
skip_check = False skip_check = False
while len(sys.argv) > 1: while len(sys.argv) > 1:
option = sys.argv[1] option = sys.argv[1]
sys.argv.pop(1)
if option == '-f': # F for Factory setting if option == '-f': # F for Factory setting
sys.argv.pop(1)
passwd = DEFAULT_PW3 passwd = DEFAULT_PW3
elif option == '-e': # E for Enumeration elif option == '-e': # E for Enumeration
sys.argv.pop(1)
wait_e = int(sys.argv[1]) wait_e = int(sys.argv[1])
sys.argv.pop(1) sys.argv.pop(1)
elif option == '-k': # K for Key number elif option == '-k': # K for Key number
sys.argv.pop(1)
keyno = int(sys.argv[1]) keyno = int(sys.argv[1])
sys.argv.pop(1) sys.argv.pop(1)
elif option == '-s': # S for skip the check of target elif option == '-s': # S for skip the check of target
sys.argv.pop(1)
skip_check = True skip_check = True
else: else:
if option[0] == '-':
raise ValueError("unknown option", option) raise ValueError("unknown option", option)
else:
break
if not passwd: if not passwd:
passwd = getpass("Admin password: ") passwd = getpass("Admin password: ")
if len(sys.argv) > 1: if len(sys.argv) > 1: