From c8fa357699e03dab78cbd15fcbe4876eb2348242 Mon Sep 17 00:00:00 2001 From: vg Date: Tue, 21 May 2019 17:22:44 +0200 Subject: fix update-acme-challenge in examples --- doc/ssh_api_example/update-acme-challenge | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/ssh_api_example/update-acme-challenge b/doc/ssh_api_example/update-acme-challenge index 39b90d0..3fd0c28 100755 --- a/doc/ssh_api_example/update-acme-challenge +++ b/doc/ssh_api_example/update-acme-challenge @@ -8,7 +8,7 @@ Takes json in stdin to modify a challenge in a zone txt record. Usage: update-acme-challenge --zones=ZONES Options: - --zones comma separated list of authorized zones to be changed + --zones=ZONES json object: {"zone-to-check": "zone-to-modify"} Json format: { @@ -29,19 +29,20 @@ def nsupdate(zone, challenge): content = f''' server ::1 del {zone} TXT - add {zone} TXT "{challenge}" + add {zone} 60 TXT "{challenge}" send ''' - subprocess.run(['nsupdate'], check=True, input=content) + subprocess.run(['nsupdate'], check=True, input=content, encoding='utf8') def main(): args = docopt.docopt(__doc__) - jsonmap = json.load(sys.stdin.read()) + jsonmap = json.loads(sys.stdin.read()) - zones = [x.strip() for x in args['--zones'].split(',')] + zones = json.loads(args['--zones']) zone = jsonmap.get('zone', '') + zone = zone[:-1] if zone.endswith('.') else zone if zone not in zones: raise ValueError(f'not permitted to modify zone {zone}') @@ -50,10 +51,11 @@ def main(): raise ValueError(f'bad value for action content: {action}') challenge = jsonmap.get('challenge', '') - if not all(x.isalnum() or x in ('+', '/') for x in challenge): + if not all(x.isalnum() or x in '_-' for x in challenge): + # base64url as in acme spec raise ValueError('bad format for challenge content') - nsupdate(zone, challenge if action == 'add' else '') + nsupdate(zones[zone], challenge if action == 'add' else '') main() -- cgit v1.2.3