예제 #1
0
 def test_verify_with_extra_negative(self):
     self.assertFalse(signedjson.verify(_('signed_extra_baz_BADSIG.json')))
예제 #2
0
 def test_verify_with_extra(self):
     self.assertTrue(signedjson.verify(_('signed_extra_baz.json')))
예제 #3
0
 def test_verify_negative(self):
     self.assertFalse(signedjson.verify(_('signed_BADSIG.json')))
예제 #4
0
                        type=argparse.FileType('r'),
                        help="Key in DER form")
    parser.add_argument('-e',
                        '--extrakeys',
                        metavar="extrakeys",
                        nargs='+',
                        help="Extra key names to be signed")
    parser.add_argument('-r', '--role', metavar="role", type=str, help="Role")
    args = parser.parse_args()

    if 'sign' == args.action:
        if not args.role:
            print 'ERROR: --role argument required'
            parser.print_help()
            exit(1)
        if not args.keyfile:
            print 'ERROR: --keyfile argument required'
            parser.print_help()
            exit(1)
        ek = [] if not args.extrakeys else args.extrakeys
        j = signedjson.sign(args.infile.read(),
                            args.keyfile.read(),
                            args.role,
                            extra_keys=ek)
        print json.dumps(j)
    elif 'verify' == args.action:
        rv = signedjson.verify(args.infile.read())
        print bool(rv)
    else:
        parser.print_help()
예제 #5
0
 def test_verify(self):
     self.assertTrue(signedjson.verify(_('signed.json')))
예제 #6
0
 def test_verify_with_extra_negative(self):
     self.assertFalse(signedjson.verify(_('signed_extra_baz_BADSIG.json')))
예제 #7
0
 def test_verify_negative(self):
     self.assertFalse(signedjson.verify(_('signed_BADSIG.json')))
예제 #8
0
 def test_verify_with_extra(self):
     self.assertTrue(signedjson.verify(_('signed_extra_baz.json')))
예제 #9
0
 def test_verify(self):
     self.assertTrue(signedjson.verify(_('signed.json')))
예제 #10
0
    parser = argparse.ArgumentParser(description='Sign/verify JSON documents.')
    parser.add_argument('-a', '--action', choices=['sign','verify'],
            default='sign', help="Action: sign/verify given input")
    parser.add_argument('-i', '--infile', metavar="infile", required=1,
            type=argparse.FileType('r'), help="Input JSON")
    parser.add_argument('-k', '--keyfile', metavar="keyfile", required=0,
            type=argparse.FileType('r'), help="Key in DER form")
    parser.add_argument('-e', '--extrakeys', metavar="extrakeys", nargs='+',
            help="Extra key names to be signed")
    parser.add_argument('-r', '--role', metavar="role", type=str, help="Role")
    args = parser.parse_args()

    if 'sign' == args.action:
        if not args.role:
            print 'ERROR: --role argument required'
            parser.print_help()
            exit(1)
        if not args.keyfile:
            print 'ERROR: --keyfile argument required'
            parser.print_help()
            exit(1)
        ek = [] if not args.extrakeys else args.extrakeys
        j = signedjson.sign(
            args.infile.read(), args.keyfile.read(), args.role, extra_keys=ek)
        print json.dumps(j)
    elif 'verify' == args.action:
        rv = signedjson.verify(args.infile.read())
        print bool(rv)
    else:
        parser.print_help()