X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/fd42a1e558d856a1933385d7ed60e5fbe490f413..76a24ae6cece0604e3155b628622a4b425cb77f3:/keys/tripe-keys.in diff --git a/keys/tripe-keys.in b/keys/tripe-keys.in index 1e56282b..2be5e2dd 100644 --- a/keys/tripe-keys.in +++ b/keys/tripe-keys.in @@ -30,7 +30,7 @@ import catacomb as C import os as OS import sys as SYS -import sre as RX +import re as RX import getopt as O import shutil as SH import filecmp as FC @@ -59,6 +59,12 @@ rx_nonalpha = RX.compile(r'\W') ## Match the literal string "". rx_seq = RX.compile(r'\') +## Match a shell metacharacter. +rx_shmeta = RX.compile('[\\s`!"#$&*()\\[\\];\'|<>?\\\\]') + +## Match a character which needs escaping in a shell double-quoted string. +rx_shquote = RX.compile(r'["`$\\]') + ###-------------------------------------------------------------------------- ### Utility functions. @@ -97,6 +103,20 @@ def subst(s, rx, map): out.write(s[i:]) return out.getvalue() +def shell_quotify(arg): + """ + Quotify ARG to keep the shell happy. + + This isn't actually used for invoking commands, just for presentation + purposes; but correctness is still nice. + """ + if not rx_shmeta.search(arg): + return arg + elif arg.find("'") == -1: + return "'%s'" % arg + else: + return '"%s"' % rx_shquote.sub(lambda m: '\\' + m.group(0), arg) + def rmtree(path): """Delete the directory tree given by PATH.""" try: @@ -142,7 +162,8 @@ def run(args): else: nargs += a[1:].split() args = nargs - print '+ %s' % ' '.join(args) + print '+ %s' % ' '.join([shell_quotify(arg) for arg in args]) + SYS.stdout.flush() rc = OS.spawnvp(OS.P_WAIT, args[0], args) if rc != 0: raise SubprocessError, rc @@ -216,10 +237,10 @@ def conf_defaults(): ('conf-file', '${base-dir}tripe-keys.conf'), ('upload-hook', ': run upload hook'), ('kx', 'dh'), - ('kx-param', lambda: {'dh': '-LS -b2048 -B256', + ('kx-param', lambda: {'dh': '-LS -b3072 -B256', 'ec': '-Cnist-p256'}[conf['kx']]), ('kx-expire', 'now + 1 year'), - ('cipher', 'blowfish-cbc'), + ('cipher', 'rijndael-cbc'), ('hash', 'sha256'), ('master-keygen-flags', '-l'), ('mgf', '${hash}-mgf'), @@ -234,10 +255,10 @@ def conf_defaults(): 'rsapss': 'rsa', 'ecdsa': 'ec', 'eckcdsa': 'ec'}[conf['sig']]), - ('sig-param', lambda: {'dh': '-LS -b2048 -B256', - 'dsa': '-b2048 -B256', + ('sig-param', lambda: {'dh': '-LS -b3072 -B256', + 'dsa': '-b3072 -B256', 'ec': '-Cnist-p256', - 'rsa': '-b2048'}[conf['sig-genalg']]), + 'rsa': '-b3072'}[conf['sig-genalg']]), ('sig-hash', '${hash}'), ('sig-expire', 'forever'), ('fingerprint-hash', '${hash}')]: @@ -342,8 +363,8 @@ def cmd_setup(args): OS.mkdir('repos') run('''key -krepos/param add -a${kx}-param !${kx-param} - -eforever -tparam tripe-${kx}-param - cipher=${cipher} hash=${hash} mac=${mac} mgf=${mgf}''') + -eforever -tparam tripe-param + kx-group=${kx} cipher=${cipher} hash=${hash} mac=${mac} mgf=${mgf}''') cmd_newmaster(args) ###-------------------------------------------------------------------------- @@ -455,7 +476,7 @@ def cmd_generate(args): keyring_pub = 'peer-%s.pub' % tag zap('keyring'); zap(keyring_pub) run('key -kkeyring merge repos/param') - run('key -kkeyring add -a${kx} -pparam -e${kx-expire} -t%s tripe-${kx}' % + run('key -kkeyring add -a${kx} -pparam -e${kx-expire} -t%s tripe' % tag) run('key -kkeyring extract -f-secret %s %s' % (keyring_pub, tag)) @@ -472,6 +493,30 @@ def cmd_clean(args): r == 'keyring' or r == 'keyring.pub' or r.startswith('peer-')): zap(i) +###-------------------------------------------------------------------------- +### Commands: mtu + +def cmd_mtu(args): + mtu, = (lambda mtu = '1500': (mtu,))(*args) + mtu = int(mtu) + + blksz = C.gcciphers[conf['cipher']].blksz + + index = conf['mac'].find('/') + if index == -1: + tagsz = C.gcmacs[conf['mac']].tagsz + else: + tagsz = int(conf['mac'][index + 1:])/8 + + mtu -= 20 # Minimum IP header + mtu -= 8 # UDP header + mtu -= 1 # TrIPE packet type octet + mtu -= tagsz # MAC tag + mtu -= 4 # Sequence number + mtu -= blksz # Initialization vector + + print mtu + ###-------------------------------------------------------------------------- ### Main driver. @@ -484,6 +529,7 @@ commands = {'help': (cmd_help, 0, 1, ''), 'upload': (cmd_upload, 0, 0, ''), 'update': (cmd_update, 0, 0, ''), 'clean': (cmd_clean, 0, 0, ''), + 'mtu': (cmd_mtu, 0, 1, '[PATH-MTU]'), 'generate': (cmd_generate, 1, 1, 'TAG'), 'rebuild': (cmd_rebuild, 0, 0, '')}