Use file-based certificates by default

This commit is contained in:
Timotej Lazar 2024-01-16 21:51:47 +01:00
parent af62cc41a9
commit 0578bdffcb

View file

@ -40,9 +40,9 @@ def sign(data, key, pin=None, engine=None):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Fake the MargTools application.') parser = argparse.ArgumentParser(description='Fake the MargTools application.')
parser.add_argument('url', type=urllib.parse.urlparse, help='bc-digsign:// url') parser.add_argument('url', type=urllib.parse.urlparse, help='bc-digsign:// url')
parser.add_argument('-e', '--engine', type=str, help='"pkcs11" for smart card')
parser.add_argument('-k', '--key', type=pathlib.Path, help='key file') parser.add_argument('-k', '--key', type=pathlib.Path, help='key file')
parser.add_argument('-c', '--cert', type=pathlib.Path, help='certificate file') parser.add_argument('-c', '--cert', type=pathlib.Path, help='certificate file')
parser.add_argument('-e', '--engine', type=str, help='"pkcs11" for smart card')
args = parser.parse_args() args = parser.parse_args()
try: try:
@ -51,9 +51,11 @@ if __name__ == '__main__':
url = params['baseUrl'][0] url = params['baseUrl'][0]
token = params['accessToken'][0] token = params['accessToken'][0]
# if missing, get key and cert from section [url] in ~/.margfools # if missing, get options from section [url] in ~/.margfools
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(os.path.expanduser('~') + '/.margfools') config.read(os.path.expanduser('~') + '/.margfools')
if not args.engine:
args.engine = config.get(url, 'engine', fallback=None)
if not args.key: if not args.key:
args.key = config.get(url, 'key') args.key = config.get(url, 'key')
if not args.cert: if not args.cert:
@ -61,8 +63,6 @@ if __name__ == '__main__':
if not args.key: if not args.key:
print('key not specified', file=sys.stderr) print('key not specified', file=sys.stderr)
sys.exit(1) sys.exit(1)
if not args.engine:
args.engine = config.get(url, 'engine')
pin = None pin = None