4 # SFA Certificate Signing and management
9 from optparse import OptionParser
10 from sfa.trust.certificate import Keypair, Certificate
11 from sfa.trust.gid import GID, create_uuid
12 from sfa.trust.hierarchy import Hierarchy
13 from sfa.util.config import Config
18 parser = OptionParser(usage="%(script_name)s [options]" % locals())
19 parser.add_option("-d", "--display", dest="display", default=None,
20 help="print contents of specified gid")
21 parser.add_option("-s", "--sign", dest="sign", default=None,
23 parser.add_option("-k", "--key", dest="key", default=None,
24 help="keyfile to use for signing")
25 parser.add_option("-i", "--import", dest="importgid", default=None,
26 help="gid file to import into the registry")
27 parser.add_option("-e", "--export", dest="export",
28 help="name of gid to export from registry")
29 parser.add_option("-o", "--outfile", dest="outfile",
30 help="where to write the exprted gid")
31 parser.add_option("-v", "--verbose", dest="verobse",
34 (options, args) = parser.parse_args()
41 elif options.importgid:
51 gidfile = os.path.abspath(options.display)
53 if not gidfile or not os.path.isfile(gidfile):
54 print "No such gid: %s" % gidfile
56 gid = GID(filename=gidfile)
57 gid.dump(dump_parents=True)
60 from sfa.util.table import SfaTable
61 hierarchy = Hierarchy()
63 parent_hrn = config.SFA_INTERFACE_HRN
64 auth_info = hierarchy.get_auth_info(parent_hrn)
67 gidfile = os.path.abspath(options.sign)
68 if not os.path.isfile(gidfile):
69 print "no such gid: %s" % gidfile
71 gid = GID(filename=gidfile)
73 # load the parent private key
74 pkeyfile = options.key
75 # if no pkey was specified, then use the this authority's key
77 pkeyfile = auth_info.privkey_filename
78 if not os.path.isfile(pkeyfile):
79 print "no such pkey: %s.\nPlease specify a valid private key" % pkeyfile
81 parent_key = Keypair(filename=pkeyfile)
84 parent_gid = auth_info.gid_object
87 outfile = options.outfile
89 outfile = os.path.abspath('./signed-%s.gid' % gid.get_hrn())
92 gid.set_issuer(parent_key, parent_hrn)
93 gid.set_parent(parent_gid)
94 gid.save_to_file(outfile, save_parents=True)
98 from sfa.util.table import SfaTable
101 def import_gid(options):
102 from sfa.util.table import SfaTable
105 if __name__ == '__main__':