fix things around write_binary
This commit is contained in:
5
AUTHORS
5
AUTHORS
@@ -27,9 +27,12 @@ NIIBE Yutaka:
|
|||||||
boards/CQ_STARM/board.h
|
boards/CQ_STARM/board.h
|
||||||
boards/CQ_STARM/board.mk
|
boards/CQ_STARM/board.mk
|
||||||
boards/CQ_STARM/mcuconf.h
|
boards/CQ_STARM/mcuconf.h
|
||||||
Wrote a tool for DfuSe:
|
Wrote tools for DfuSe:
|
||||||
tool/dfuse.py
|
tool/dfuse.py
|
||||||
|
tool/dump_mem.py
|
||||||
tool/intel_hex.py
|
tool/intel_hex.py
|
||||||
|
Wrote a tool for Gnuk:
|
||||||
|
tool/gnuk_put_binary.py
|
||||||
Wrote:
|
Wrote:
|
||||||
gnuk.svg
|
gnuk.svg
|
||||||
src/configure
|
src/configure
|
||||||
|
|||||||
15
ChangeLog
15
ChangeLog
@@ -1,3 +1,18 @@
|
|||||||
|
2011-02-09 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* src/usb_prop.c (gnukStringSerial): Updated.
|
||||||
|
|
||||||
|
* tool/gnuk_put_binary.py (gnuk_token.__del__): Removed.
|
||||||
|
Releasing the interface is done in PyUSB.
|
||||||
|
|
||||||
|
* tool/dfuse.py (DFU_STM32.__del__): Removed.
|
||||||
|
|
||||||
|
* src/openpgp.c (cmd_write_binary): Support random bits and card
|
||||||
|
holder certificate as well.
|
||||||
|
|
||||||
|
* src/openpgp-do.c (do_openpgpcard_aid): Add volatile to prevent
|
||||||
|
compiler optimization to access AID.
|
||||||
|
|
||||||
2011-02-08 NIIBE Yutaka <gniibe@fsij.org>
|
2011-02-08 NIIBE Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* tool/gnuk_put_binary.py: Renamed (was: gnuk_update_binary.py).
|
* tool/gnuk_put_binary.py: Renamed (was: gnuk_update_binary.py).
|
||||||
|
|||||||
@@ -416,7 +416,7 @@ const uint8_t openpgpcard_aid[] = {
|
|||||||
static int
|
static int
|
||||||
do_openpgpcard_aid (uint16_t tag, int with_tag)
|
do_openpgpcard_aid (uint16_t tag, int with_tag)
|
||||||
{
|
{
|
||||||
const uint16_t *vid_p = (const uint16_t *)&openpgpcard_aid[8];
|
uint16_t vid = *((const volatile uint16_t *)&openpgpcard_aid[8]);
|
||||||
|
|
||||||
if (with_tag)
|
if (with_tag)
|
||||||
{
|
{
|
||||||
@@ -424,7 +424,7 @@ do_openpgpcard_aid (uint16_t tag, int with_tag)
|
|||||||
*res_p++ = 16;
|
*res_p++ = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*vid_p == 0xffff || *vid_p == 0x0000)
|
if (vid == 0xffff || vid == 0x0000)
|
||||||
{
|
{
|
||||||
const uint8_t *u = unique_device_id ();
|
const uint8_t *u = unique_device_id ();
|
||||||
|
|
||||||
|
|||||||
@@ -870,7 +870,7 @@ cmd_update_binary (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((cmd_APDU[2] & 0x80))
|
if ((cmd_APDU[2] & 0x80))
|
||||||
if ((cmd_APDU[2] & 0x7f) <= 0x01)
|
if ((cmd_APDU[2] & 0x7f) <= FILEID_RANDOM)
|
||||||
{
|
{
|
||||||
file_selection = FILE_EF_CH_CERTIFICATE + (cmd_APDU[2] & 0x7f);
|
file_selection = FILE_EF_CH_CERTIFICATE + (cmd_APDU[2] & 0x7f);
|
||||||
r = flash_erase_binary (file_selection - FILE_EF_CH_CERTIFICATE);
|
r = flash_erase_binary (file_selection - FILE_EF_CH_CERTIFICATE);
|
||||||
@@ -941,7 +941,7 @@ cmd_write_binary (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((cmd_APDU[2] & 0x80))
|
if ((cmd_APDU[2] & 0x80))
|
||||||
if ((cmd_APDU[2] & 0x7f) == FILEID_SERIAL_NO)
|
if ((cmd_APDU[2] & 0x7f) <= FILEID_SERIAL_NO)
|
||||||
{
|
{
|
||||||
file_selection = FILE_EF_CH_CERTIFICATE + (cmd_APDU[2] & 0x7f);
|
file_selection = FILE_EF_CH_CERTIFICATE + (cmd_APDU[2] & 0x7f);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
@@ -953,7 +953,9 @@ cmd_write_binary (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (file_selection != FILEID_SERIAL_NO)
|
if (file_selection != FILE_EF_CH_CERTIFICATE
|
||||||
|
&& file_selection != FILE_EF_RANDOM
|
||||||
|
&& file_selection != FILEID_SERIAL_NO)
|
||||||
{
|
{
|
||||||
GPG_COMMAND_NOT_ALLOWED ();
|
GPG_COMMAND_NOT_ALLOWED ();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -37,19 +37,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint8_t gnukStringSerial[] = {
|
static uint8_t gnukStringSerial[] = {
|
||||||
14*2+2, /* bLength */
|
13*2+2, /* bLength */
|
||||||
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
|
||||||
#if defined(SERIAL_NUMBER_IN_AID)
|
'0', 0, '.', 0, '1', 0, '0', 0, /* Version number of Gnuk */
|
||||||
'F', 0, /* 'F' for Fixed */
|
|
||||||
#else
|
|
||||||
'C', 0, /* 'C' for Chip uniqure ID */
|
|
||||||
#endif
|
|
||||||
'-', 0,
|
|
||||||
'0', 0, '.', 0, '8', 0, /* Version number of Gnuk */
|
|
||||||
'-', 0,
|
'-', 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
};
|
};
|
||||||
|
#define ID_OFFSET 12
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gnuk_device_init (void)
|
gnuk_device_init (void)
|
||||||
@@ -59,10 +54,10 @@ gnuk_device_init (void)
|
|||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
gnukStringSerial[i*4+14] = (u[i*2] >> 4) + 'A';
|
gnukStringSerial[i*4+ID_OFFSET+0] = (u[i*2] >> 4) + 'A';
|
||||||
gnukStringSerial[i*4+15] = 0;
|
gnukStringSerial[i*4+ID_OFFSET+1] = 0;
|
||||||
gnukStringSerial[i*4+16] = (u[i*2+1] & 0x0f) + 'A';
|
gnukStringSerial[i*4+ID_OFFSET+2] = (u[i*2+1] & 0x0f) + 'A';
|
||||||
gnukStringSerial[i*4+17] = 0;
|
gnukStringSerial[i*4+ID_OFFSET+3] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInformation->Current_Configuration = 0;
|
pInformation->Current_Configuration = 0;
|
||||||
|
|||||||
@@ -119,13 +119,6 @@ class DFU_STM32:
|
|||||||
# Initialize members
|
# Initialize members
|
||||||
self.__blocknum = 0
|
self.__blocknum = 0
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
try:
|
|
||||||
self.__devhandle.releaseInterface()
|
|
||||||
del self.__devhandle
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def ll_getdev(self):
|
def ll_getdev(self):
|
||||||
return self.__devhandle
|
return self.__devhandle
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
from intel_hex import *
|
from intel_hex import *
|
||||||
from struct import *
|
from struct import *
|
||||||
import sys, time, os, binascii
|
import sys, time, os, binascii, string
|
||||||
|
|
||||||
# INPUT: binary file
|
# INPUT: binary file
|
||||||
|
|
||||||
@@ -81,14 +81,6 @@ class gnuk_token:
|
|||||||
self.__timeout = 10000
|
self.__timeout = 10000
|
||||||
self.__seq = 0
|
self.__seq = 0
|
||||||
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
try:
|
|
||||||
self.__devhandle.releaseInterface()
|
|
||||||
del self.__devhandle
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def icc_get_result(self):
|
def icc_get_result(self):
|
||||||
msg = self.__devhandle.bulkRead(self.__bulkin, 1024, self.__timeout)
|
msg = self.__devhandle.bulkRead(self.__bulkin, 1024, self.__timeout)
|
||||||
if len(msg) < 10:
|
if len(msg) < 10:
|
||||||
@@ -249,6 +241,7 @@ def main(fileid, is_update, data):
|
|||||||
else:
|
else:
|
||||||
icc.cmd_write_binary(fileid, data)
|
icc.cmd_write_binary(fileid, data)
|
||||||
icc.cmd_select_openpgp()
|
icc.cmd_select_openpgp()
|
||||||
|
if fileid == 0:
|
||||||
data = data[:-2]
|
data = data[:-2]
|
||||||
data_in_device = icc.cmd_get_data(0x7f, 0x21)
|
data_in_device = icc.cmd_get_data(0x7f, 0x21)
|
||||||
compare(data, data_in_device)
|
compare(data, data_in_device)
|
||||||
@@ -265,16 +258,16 @@ if __name__ == '__main__':
|
|||||||
fileid = 2 # serial number
|
fileid = 2 # serial number
|
||||||
filename = sys.argv[2]
|
filename = sys.argv[2]
|
||||||
f = open(filename)
|
f = open(filename)
|
||||||
email = os.environ['MAIL']
|
email = os.environ['EMAIL']
|
||||||
serial_data_hex = None
|
serial_data_hex = None
|
||||||
for line in f.readlines():
|
for line in f.readlines():
|
||||||
field = string.split(line)
|
field = string.split(line)
|
||||||
if field[0] == os.environ['MAIL']:
|
if field[0] == email:
|
||||||
serial_data_hex = field[1].replace(':','')
|
serial_data_hex = field[1].replace(':','')
|
||||||
f.close()
|
f.close()
|
||||||
if not serial_data_hex:
|
if not serial_data_hex:
|
||||||
print "No serial number"
|
print "No serial number"
|
||||||
exit 1
|
exit(1)
|
||||||
print "Writing serial number"
|
print "Writing serial number"
|
||||||
data = binascii.unhexlify(serial_data_hex)
|
data = binascii.unhexlify(serial_data_hex)
|
||||||
elif sys.argv[1] == '-r':
|
elif sys.argv[1] == '-r':
|
||||||
@@ -291,7 +284,7 @@ if __name__ == '__main__':
|
|||||||
print "Updating random bits"
|
print "Updating random bits"
|
||||||
else:
|
else:
|
||||||
fileid = 0 # Card holder certificate
|
fileid = 0 # Card holder certificate
|
||||||
filename = sys.argv[2]
|
filename = sys.argv[1]
|
||||||
f = open(filename)
|
f = open(filename)
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user