def main(): parser = argparse.ArgumentParser(description='pbp') group = parser.add_mutually_exclusive_group() group.add_argument('--gen-key', '-g', dest='action', action='store_const', const='g', help="generates a new key") group.add_argument('--encrypt', '-c', dest='action', action='store_const', const='c', help="encrypts") group.add_argument('--decrypt', '-d', dest='action', action='store_const', const='d', help="decrypts") group.add_argument('--sign', '-s', dest='action', action='store_const', const='s', help="signs") group.add_argument('--master-sign', '-m', dest='action', action='store_const', const='m', help="signs keys with your masterkey") group.add_argument('--verify', '-v', dest='action', action='store_const', const='v', help="verifies") group.add_argument('--list', '-l', dest='action', action='store_const', const='l', help="lists public keys") group.add_argument('--list-secret', '-L', dest='action', action='store_const', const='L', help="Lists secret keys") group.add_argument('--export-key', '-x', dest='action', action='store_const', const='x', help="export public key") group.add_argument('--import-key', '-X', dest='action', action='store_const', const='X', help="import public key") group.add_argument('--check-sigs', '-C', dest='action', action='store_const', const='C', help="lists all known sigs on a public key") group.add_argument('--fcrypt', '-e', dest='action', action='store_const', const='e', help="encrypts a message using PFS to a peer") group.add_argument('--fdecrypt', '-E', dest='action', action='store_const', const='E', help="decrypts a message using PFS to a peer") group.add_argument('--dh-start', '-D1', dest='action', action='store_const', const='d1', help="initiates an ECDH key exchange") group.add_argument('--dh-respond', '-D2', dest='action', action='store_const', const='d2', help="responds to an ECDH key request") group.add_argument('--dh-end', '-D3', dest='action', action='store_const', const='d3', help="finalizes an ECDH key exchange") group.add_argument('--rand-stream', '-R', dest='action', action='store_const', const='R', help="generate arbitrary random stream") parser.add_argument( '--recipient', '-r', action='append', help="designates a recipient for public key encryption") parser.add_argument('--name', '-n', help="sets the name for a new key") parser.add_argument( '--basedir', '-b', '--base-dir', help="set the base directory for all key storage needs", default=defaultbase) parser.add_argument('--self', '-S', help="sets your own key") parser.add_argument('--dh-param', '-Dp', help="public parameter for ECDH key exchange") parser.add_argument('--dh-exp', '-De', help="public parameter for ECDH key exchange") parser.add_argument('--size', '-Rs', help="size of random stream to generate") parser.add_argument('--infile', '-i', help="file to operate on") parser.add_argument('--armor', '-a', action='store_true', help="ascii armors the output") parser.add_argument('--outfile', '-o', help="file to output to") opts = parser.parse_args() opts.basedir = os.path.expandvars(os.path.expanduser(opts.basedir)) # Generate key if opts.action == 'g': ensure_name_specified(opts) publickey.Identity(opts.name, create=True, basedir=opts.basedir) # list public keys elif opts.action == 'l': for i in publickey.get_public_keys(opts.basedir): print('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'invalid'), i.keyid(), i.name # list secret keys elif opts.action == 'L': for i in publickey.get_secret_keys(opts.basedir): print('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'invalid'), i.keyid(), i.name # encrypt elif opts.action == 'c': if opts.recipient or opts.self: ensure_self_specified(opts) ensure_recipient_specified(opts) encrypt_handler(infile=opts.infile, outfile=opts.outfile, recipient=opts.recipient, self=opts.self, basedir=opts.basedir) # decrypt elif opts.action == 'd': decrypt_handler(infile=opts.infile, outfile=opts.outfile, self=opts.self, basedir=opts.basedir) # sign elif opts.action == 's': ensure_self_specified(opts) sign_handler(infile=opts.infile, outfile=opts.outfile, self=opts.self, armor=opts.armor, basedir=opts.basedir) # verify elif opts.action == 'v': verify_handler(infile=opts.infile, outfile=opts.outfile, basedir=opts.basedir) # key sign elif opts.action == 'm': ensure_name_specified(opts) ensure_self_specified(opts) keysign_handler(name=opts.name, self=opts.self, basedir=opts.basedir) # lists signatures owners on public keys elif opts.action == 'C': ensure_name_specified(opts) keycheck_handler(name=opts.name, basedir=opts.basedir) # export public key elif opts.action == 'x': ensure_self_specified(opts) export_handler(opts.self, basedir=opts.basedir) # import public key elif opts.action == 'X': import_handler(infile=opts.infile, basedir=opts.basedir) # forward encrypt elif opts.action == 'e': ensure_recipient_specified(opts) ensure_only_one_recipient(opts) # TODO could try to find out this automatically if non-ambiguous ensure_self_specified(opts) chaining_encrypt_handler(opts.infile, outfile=opts.outfile, recipient=opts.recipient[0], self=opts.self, armor=opts.armor, basedir=opts.basedir) # forward decrypt elif opts.action == 'E': ensure_recipient_specified(opts) ensure_only_one_recipient(opts) # TODO could try to find out this automatically if non-ambiguous ensure_self_specified(opts) chaining_decrypt_handler(opts.infile, outfile=opts.outfile, recipient=opts.recipient[0], self=opts.self, basedir=opts.basedir) # start ECDH elif opts.action == 'd1': dh1_handler() # receive ECDH elif opts.action == 'd2': ensure_dhparam_specified(opts) dh2_handler(opts.dh_param) # finish ECDH elif opts.action == 'd3': ensure_dhparam_specified(opts) ensure_dhexp_specified(opts) dh3_handler(opts.dh_param, opts.dh_exp) elif opts.action == 'R': ensure_size_good(opts) random_stream_handler(opts.outfile, opts.size)
pitchfork.init() res = pitchfork.listkeys(opts.name) if(res): keys, stats = res pitchfork.print_keys(keys) pitchfork.storage_stats(stats, keys) else: print 'none' else: for i in publickey.get_public_keys(opts.basedir): print ('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'INVALID'), i.keyid(), i.name # list secret keys elif opts.action=='L': for i in publickey.get_secret_keys(opts.basedir): print ('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'INVALID'), i.keyid(), i.name # encrypt elif opts.action=='c': if PITCHFORK and opts.PITCHFORK: ensure_recipient_specified(opts) pitchfork.init() res=pitchfork.encrypt(opts.recipient[0], infile=opts.infile, outfile=opts.outfile) if res: print >>sys.stderr, b85encode(res) return if opts.recipient or opts.self:
def main(): # main command line handler for pbp parser = argparse.ArgumentParser(description='pbp') group = parser.add_mutually_exclusive_group() group.add_argument('--gen-key', '-g', dest='action', action='store_const', const='g', help="generates a new key") group.add_argument('--encrypt', '-c', dest='action', action='store_const', const='c',help="encrypts") group.add_argument('--decrypt', '-d', dest='action', action='store_const', const='d',help="decrypts") group.add_argument('--sign', '-s', dest='action', action='store_const', const='s',help="signs") group.add_argument('--master-sign', '-m', dest='action', action='store_const', const='m',help="signs keys with your masterkey") group.add_argument('--verify', '-v', dest='action', action='store_const', const='v',help="verifies") group.add_argument('--list', '-l', dest='action', action='store_const', const='l',help="lists public keys") group.add_argument('--list-secret', '-L', dest='action', action='store_const', const='L',help="Lists secret keys") group.add_argument('--export-key', '-x', dest='action', action='store_const', const='x',help="export public key") group.add_argument('--import-key', '-X', dest='action', action='store_const', const='X',help="import public key") group.add_argument('--check-sigs', '-C', dest='action', action='store_const', const='C',help="lists all known sigs on a public key") group.add_argument('--fcrypt', '-e', dest='action', action='store_const', const='e',help="encrypts a message using PFS to a peer") group.add_argument('--fdecrypt', '-E', dest='action', action='store_const', const='E',help="decrypts a message using PFS to a peer") group.add_argument('--dh-start', '-Ds', dest='action', action='store_const', const='ds',help="initiates an ECDH key exchange") group.add_argument('--dh-end', '-De', dest='action', action='store_const', const='de',help="finalizes an ECDH key exchange") group.add_argument('--rand-stream', '-R', dest='action', action='store_const', const='R',help="generate arbitrary random stream") parser.add_argument('--recipient', '-r', action='append', help="designates a recipient for public key encryption") parser.add_argument('--name', '-n', help="sets the name for a new key") parser.add_argument('--basedir', '-b', '--base-dir', help="set the base directory for all key storage needs", default=defaultbase) parser.add_argument('--self', '-S', help="sets your own key") parser.add_argument('--size', '-Rs',help="size of random stream to generate") parser.add_argument('--dh-peers', '-Dp',help="the number of peers participating in a ECDH key exchange") parser.add_argument('--infile', '-i', help="file to operate on") parser.add_argument('--armor', '-a', action='store_true', help="ascii armors the output") parser.add_argument('--outfile', '-o', help="file to output to") opts=parser.parse_args() opts.basedir=os.path.expandvars( os.path.expanduser(opts.basedir)) # Generate key if opts.action=='g': ensure_name_specified(opts) publickey.Identity(opts.name, create=True, basedir=opts.basedir) # list public keys elif opts.action=='l': for i in publickey.get_public_keys(opts.basedir): print ('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'invalid'), i.keyid(), i.name # list secret keys elif opts.action=='L': for i in publickey.get_secret_keys(opts.basedir): print ('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'invalid'), i.keyid(), i.name # encrypt elif opts.action=='c': if opts.recipient or opts.self: ensure_self_specified(opts) ensure_recipient_specified(opts) encrypt_handler(infile=opts.infile, outfile=opts.outfile, recipient=opts.recipient, self=opts.self, basedir=opts.basedir) # decrypt elif opts.action=='d': decrypt_handler(infile=opts.infile, outfile=opts.outfile, self=opts.self, basedir=opts.basedir) # sign elif opts.action=='s': ensure_self_specified(opts) sign_handler(infile=opts.infile, outfile=opts.outfile, self=opts.self, armor=opts.armor, basedir=opts.basedir) # verify elif opts.action=='v': res = verify_handler(infile=opts.infile, outfile=opts.outfile, basedir=opts.basedir) if res: print >>sys.stderr, "good message from", res else: print >>sys.stderr, 'verification failed' # key sign elif opts.action=='m': ensure_name_specified(opts) ensure_self_specified(opts) sig = keysign_handler(name=opts.name, self=opts.self, basedir=opts.basedir) if sig: print "key signed in", sig else: print >>sys.stderr, 'signature failed'
def main(): # main command line handler for pbp parser = argparse.ArgumentParser(description='pbp') group = parser.add_mutually_exclusive_group() group.add_argument('--gen-key', '-g', dest='action', action='store_const', const='g', help="generates a new key") group.add_argument('--encrypt', '-c', dest='action', action='store_const', const='c',help="encrypts") group.add_argument('--decrypt', '-d', dest='action', action='store_const', const='d',help="decrypts") group.add_argument('--sign', '-s', dest='action', action='store_const', const='s',help="signs") group.add_argument('--master-sign', '-m', dest='action', action='store_const', const='m',help="signs keys with your masterkey") group.add_argument('--verify', '-v', dest='action', action='store_const', const='v',help="verifies") group.add_argument('--hash', '-H', dest='action', action='store_const', const='h',help="hashes") group.add_argument('--list', '-l', dest='action', action='store_const', const='l',help="lists public keys") group.add_argument('--list-secret', '-L', dest='action', action='store_const', const='L',help="Lists secret keys") group.add_argument('--export-key', '-x', dest='action', action='store_const', const='x',help="export public key") group.add_argument('--import-key', '-X', dest='action', action='store_const', const='X',help="import public key") group.add_argument('--check-sigs', '-C', dest='action', action='store_const', const='C',help="lists all known sigs on a public key") group.add_argument('--fcrypt', '-e', dest='action', action='store_const', const='e',help="encrypts a message using PFS to a peer") group.add_argument('--fdecrypt', '-E', dest='action', action='store_const', const='E',help="decrypts a message using PFS to a peer") group.add_argument( '-D1', dest='action', action='store_const', const='d1',help="initiates an ECDH key exchange") group.add_argument( '-D2', dest='action', action='store_const', const='d2',help="responds to an ECDH key request") group.add_argument( '-D3', dest='action', action='store_const', const='d3',help="finalizes an ECDH key exchange") group.add_argument('--dh-start', '-Ds', dest='action', action='store_const', const='ds',help="initiates an ECDH key exchange") group.add_argument('--dh-end', '-De', dest='action', action='store_const', const='de',help="finalizes an ECDH key exchange") group.add_argument('--rand-stream', '-R', dest='action', action='store_const', const='R',help="generate arbitrary random stream") if PITCHFORK: parser.add_argument('--pitchfork', '-P', dest='PITCHFORK', action='store_const', const='P',help="arms PITCHFORK", default=False) parser.add_argument('--signature', '-z', help="sets the pitchfork sig to verify") parser.add_argument('--recipient', '-r', action='append', help="designates a recipient for public key encryption") parser.add_argument('--name', '-n', help="sets the name for a new key") parser.add_argument('--basedir', '-b', '--base-dir', help="set the base directory for all key storage needs", default=defaultbase) parser.add_argument('--self', '-S', help="sets your own key") parser.add_argument('--key', '-k', help="some password or secret") parser.add_argument('--dh-param', '-DP',help="public parameter for ECDH key exchange") parser.add_argument('--dh-exp', '-DE',help="secret exp for final step of a ECDH key exchange") parser.add_argument('--size', '-Rs',help="size of random stream to generate") parser.add_argument('--dh-peers', '-Dp',help="the number of peers participating in a ECDH key exchange") parser.add_argument('--infile', '-i', help="file to operate on") parser.add_argument('--armor', '-a', action='store_true', help="ascii armors the output") parser.add_argument('--outfile', '-o', help="file to output to") opts=parser.parse_args() opts.basedir=os.path.expandvars( os.path.expanduser(opts.basedir)) # Generate key if opts.action=='g': ensure_name_specified(opts) publickey.Identity(opts.name, create=True, basedir=opts.basedir) # list public keys elif opts.action=='l': if PITCHFORK: pitchfork.init() res = pitchfork.listkeys(opts.name) if(res): keys, stats = res pitchfork.print_keys(keys) pitchfork.storage_stats(stats, keys) else: print 'none' else: for i in publickey.get_public_keys(opts.basedir): print ('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'invalid'), i.keyid(), i.name # list secret keys elif opts.action=='L': for i in publickey.get_secret_keys(opts.basedir): print ('valid' if i.valid > datetime.datetime.utcnow() > i.created else 'invalid'), i.keyid(), i.name # encrypt elif opts.action=='c': if PITCHFORK: ensure_recipient_specified(opts) pitchfork.init() res=pitchfork.encrypt(opts.recipient[0], infile=opts.infile, outfile=opts.outfile) if res: print >>sys.stderr, b85encode(res) return if opts.recipient or opts.self: ensure_self_specified(opts) ensure_recipient_specified(opts) encrypt_handler(infile=opts.infile, outfile=opts.outfile, recipient=opts.recipient, self=opts.self, basedir=opts.basedir) # decrypt elif opts.action=='d': if PITCHFORK: ensure_recipient_specified(opts) pitchfork.init() res=pitchfork.decrypt(opts.recipient[0], infile=opts.infile, outfile=opts.outfile) else: sender = decrypt_handler(infile=opts.infile, outfile=opts.outfile, self=opts.self, basedir=opts.basedir) if sender: print >>sys.stderr, 'good message from', sender # sign elif opts.action=='s': if PITCHFORK: ensure_recipient_specified(opts) pitchfork.init() res=pitchfork.sign(opts.recipient[0], infile=opts.infile, outfile=opts.outfile) if res: print >>sys.stderr, b85encode(res[0]), b85encode(res[1]) return ensure_self_specified(opts) sign_handler(infile=opts.infile, outfile=opts.outfile, self=opts.self, armor=opts.armor, basedir=opts.basedir) # verify elif opts.action=='v': if PITCHFORK: ensure_signature_specified(opts) ensure_recipient_specified(opts) pitchfork.init() res=pitchfork.verify(opts.signature, opts.recipient[0], infile=opts.infile, outfile=opts.outfile) else: res = verify_handler(infile=opts.infile, outfile=opts.outfile, basedir=opts.basedir) if res: print >>sys.stderr, "good message from", res else: print >>sys.stderr, 'verification failed' # key sign elif opts.action=='m': ensure_name_specified(opts) ensure_self_specified(opts) sig = keysign_handler(name=opts.name, self=opts.self, basedir=opts.basedir) if sig: print "key signed in", sig else: print >>sys.stderr, 'signature failed'
def test_getskeys(self): self.assertEquals( list(publickey.get_secret_keys(basedir=self.pbp_path)), []) i = self.gen_key() skeys = list(publickey.get_secret_keys(basedir=self.pbp_path)) self.assertEquals(len(skeys), 1)
if PITCHFORK and opts.PITCHFORK: pitchfork.init() res = pitchfork.listkeys(opts.name) if res: keys, stats = res pitchfork.print_keys(keys) pitchfork.storage_stats(stats, keys) else: print "none" else: for i in publickey.get_public_keys(opts.basedir): print ("valid" if i.valid > datetime.datetime.utcnow() > i.created else "INVALID"), i.keyid(), i.name # list secret keys elif opts.action == "L": for i in publickey.get_secret_keys(opts.basedir): print ("valid" if i.valid > datetime.datetime.utcnow() > i.created else "INVALID"), i.keyid(), i.name # encrypt elif opts.action == "c": if PITCHFORK and opts.PITCHFORK: ensure_recipient_specified(opts) pitchfork.init() res = pitchfork.encrypt(opts.recipient[0], infile=opts.infile, outfile=opts.outfile) if res: print >> sys.stderr, b85encode(res) return if opts.recipient or opts.self: ensure_self_specified(opts) ensure_recipient_specified(opts) encrypt_handler(