tool: Improve tool/*.py.

--

Szczepan Zalega's idea of using the file GNUK_USB_DEVICE_ID would
good, but not merged yet.  Because it makes difficult to distribute
the scripts.  We need to consider installing tools and the file
like GNUK_USB_DEVICE_ID altogether.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka
2017-02-01 12:34:35 +09:00
parent d4469c24ec
commit 7ef417ae36
5 changed files with 34 additions and 26 deletions

View File

@@ -1,3 +1,14 @@
2017-02-01 NIIBE Yutaka <gniibe@fsij.org>
* tool/upgrade_by_passwd.py (main): More verbose messages
suggested by Szczepan Zalega <szczepan@nitrokey.com>.
* tool/gnuk_token.py (USB_PRODUCT_LIST): New.
(gnuk_devices_by_vidpid): Support searching by USB_PRODUCT_LIST.
Thanks to Szczepan Zalega <szczepan@nitrokey.com>.
* tool/usb_strings.py: Use gnuk_token.py.
2016-10-21 Niibe Yutaka <gniibe@fsij.org> 2016-10-21 Niibe Yutaka <gniibe@fsij.org>
* src/ecc.c (check_secret): Fix condition. * src/ecc.c (check_secret): Fix condition.

1
THANKS
View File

@@ -32,6 +32,7 @@ NOKUBI Takatsugu knok@daionet.gr.jp
Paul Bakker polarssl_maintainer@polarssl.org Paul Bakker polarssl_maintainer@polarssl.org
Santiago Ruano Rincón santiago@debian.org Santiago Ruano Rincón santiago@debian.org
Shane Coughlan scoughlan@openinventionnetwork.com Shane Coughlan scoughlan@openinventionnetwork.com
Szczepan Zalega szczepan@nitrokey.com
Vasily Evseenko Vasily Evseenko
Werner Koch wk@gnupg.org Werner Koch wk@gnupg.org
Yuji Imai ug@xcast.jp Yuji Imai ug@xcast.jp

View File

@@ -1,7 +1,7 @@
""" """
gnuk_token.py - a library for Gnuk Token gnuk_token.py - a library for Gnuk Token
Copyright (C) 2011, 2012, 2013, 2015 Copyright (C) 2011, 2012, 2013, 2015, 2017
Free Software Initiative of Japan Free Software Initiative of Japan
Author: NIIBE Yutaka <gniibe@fsij.org> Author: NIIBE Yutaka <gniibe@fsij.org>
@@ -26,6 +26,12 @@ import binascii
import usb, time import usb, time
from array import array from array import array
# Possible Gnuk Token products
USB_PRODUCT_LIST=[
{ 'vendor' : 0x234b, 'product' : 0x0000 }, # FSIJ Gnuk Token
{ 'vendor' : 0x20a0, 'product' : 0x4211 }, # Nitrokey Start
]
# USB class, subclass, protocol # USB class, subclass, protocol
CCID_CLASS = 0x0B CCID_CLASS = 0x0B
CCID_SUBCLASS = 0x00 CCID_SUBCLASS = 0x00
@@ -586,19 +592,18 @@ def gnuk_devices():
alt.interfaceProtocol == CCID_PROTOCOL_0: alt.interfaceProtocol == CCID_PROTOCOL_0:
yield dev, config, alt yield dev, config, alt
USB_VENDOR_FSIJ=0x234b
USB_PRODUCT_GNUK=0x0000
def gnuk_devices_by_vidpid(): def gnuk_devices_by_vidpid():
busses = usb.busses() busses = usb.busses()
for bus in busses: for bus in busses:
devices = bus.devices devices = bus.devices
for dev in devices: for dev in devices:
if dev.idVendor != USB_VENDOR_FSIJ: for cand in USB_PRODUCT_LIST:
if dev.idVendor != cand['vendor']:
continue continue
if dev.idProduct != USB_PRODUCT_GNUK: if dev.idProduct != cand['product']:
continue continue
yield dev yield dev
break
def get_gnuk_device(): def get_gnuk_device():
icc = None icc = None

View File

@@ -69,6 +69,7 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
gnuk = None gnuk = None
# #
reg = None reg = None
print("Waiting for device to appear:")
while reg == None: while reg == None:
print(" Wait %d seconds..." % wait_e) print(" Wait %d seconds..." % wait_e)
time.sleep(wait_e) time.sleep(wait_e)
@@ -84,9 +85,13 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade):
print("%08x:%08x" % mem_info) print("%08x:%08x" % mem_info)
print("Downloading the program") print("Downloading the program")
reg.download(mem_info[0], data_upgrade) reg.download(mem_info[0], data_upgrade)
print("Protecting device")
reg.protect() reg.protect()
print("Finish flashing")
reg.finish() reg.finish()
print("Resetting device")
reg.reset_device() reg.reset_device()
print("Update procedure finished")
return 0 return 0
from getpass import getpass from getpass import getpass

View File

@@ -3,7 +3,7 @@
""" """
usb_strings.py - a tool to dump USB string usb_strings.py - a tool to dump USB string
Copyright (C) 2012, 2015 Free Software Initiative of Japan Copyright (C) 2012, 2015, 2017 Free Software Initiative of Japan
Author: NIIBE Yutaka <gniibe@fsij.org> Author: NIIBE Yutaka <gniibe@fsij.org>
This file is a part of Gnuk, a GnuPG USB Token implementation. This file is a part of Gnuk, a GnuPG USB Token implementation.
@@ -22,28 +22,14 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from gnuk_token import *
import usb, sys import usb, sys
USB_VENDOR_FSIJ=0x234b
USB_PRODUCT_GNUK=0x0000
def gnuk_devices_by_vidpid():
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
if dev.idVendor != USB_VENDOR_FSIJ:
continue
if dev.idProduct != USB_PRODUCT_GNUK:
continue
yield dev
field = ['', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys', 'Board'] field = ['', 'Vendor', 'Product', 'Serial', 'Revision', 'Config', 'Sys', 'Board']
def main(n): def main(n):
for dev in gnuk_devices_by_vidpid(): for dev in gnuk_devices_by_vidpid():
handle = dev.open() handle = dev.open()
print("Device: %s" % dev.filename)
try: try:
for i in range(1,n): for i in range(1,n):
s = handle.getString(i, 512) s = handle.getString(i, 512)