polhenarejos / pico-hsm

Hardware Security Module for Raspberry Pico
GNU General Public License v3.0
180 stars 23 forks source link

mistake in pico-hsm-tool.py #25

Closed fchaxel closed 8 months ago

fchaxel commented 1 year ago

Hi all,

Very good job ... an HSM module for 4 euros !

Line 114 it should be parser._init.add_argument('--pin', help='PIN number') not parser.add_argument('--pin', help='PIN number')

Line 131 it should be parser_rtc_get = subparser_rtc.add_parser('get', help='Gets the current datetime.') not parser_rtc_get = subparser_rtc.add_parser('set', help='Gets the current datetime.')

bye

polhenarejos commented 1 year ago

parser.add_argument('--pin', help='PIN number') is correct. --pin argument is available not only for initialization, but also for other commands. It is a common parameter for all.

Fixed rtc_get.

fchaxel commented 1 year ago

So in https://github.com/polhenarejos/pico-hsm/blob/master/doc/usage.md

$ python3 pico-hsm-tool.py initialize --so-pin 3537363231383830 --pin 648219

should be

$ python3 pico-hsm-tool.py --pin 648219 initialize --so-pin 3537363231383830

at the end of the command line --pin generates an error

HSM module work like a charm with XCA tool on Windows.

Bye

fchaxel commented 1 year ago

Hi,

Back again with def parse_args(): in the script

In order to get the --pin args to be place after the command, and to use it with several sub command one can write something like this :

subparser = parser.add_subparsers(title="commands", dest="command")
parent = argparse.ArgumentParser(add_help=False)
parent.add_argument('--pin', help='PIN number')
parser_init = subparser.add_parser('initialize', help='Performs the first initialization of the Pico HSM.',parents=[parent])
parser_init.add_argument('--so-pin', help='SO-PIN number')  

And you have to add the parameter parents=[parent] in each subcommand where the --pin argument can be use.

Bye.