source: fedd/creddy_split.py @ 6fd2b29

axis_examplecompt_changesinfo-ops
Last change on this file since 6fd2b29 was 353db8c, checked in by Ted Faber <faber@…>, 14 years ago

Vairous ABAC tweaks, mostly concerned with making key splitting less visible.

  • Property mode set to 100755
File size: 1.3 KB
RevLine 
[87c0fc1]1#!/usr/local/bin/python
2
3import sys
4import re
5import os
6
7from optparse import OptionParser
[353db8c]8from federation.util import abac_split_cert, abac_pem_type
[87c0fc1]9
10# Options
11class Parser(OptionParser):
12    def __init__(self):
13        OptionParser.__init__(self, usage="%prog [options] file.pem")
14        self.add_option('--cert', dest='cert', default='./cert.pem', 
15                help='File to extract certificate into, default: [%default]')
16        self.add_option('--key', dest='key', default='./key.pem', 
17                help='File to extract key into, default: [%default]')
18        self.add_option('--force', action='store_true', dest='force',
19                default=False,
20                help=('Overwite existing certificate and key files. ' + \
21                        'default: [%default]'))
22
23# Option validation
24parser = Parser()
25opts, args = parser.parse_args()
26
27if len(args) == 1:
28    combo = args[0]
29else:
30    parser.print_help()
31    sys.exit('\nMust have one file argument')
32
[353db8c]33for fn in (opts.cert, opts.key):
34    if os.access(fn, os.F_OK):
35        if opts.force: os.unlink(fn)
36        else: sys.exit('%s exists.  --force to overwite it' % fn)
[87c0fc1]37
38try:
[353db8c]39    type = abac_pem_type(combo)
40    if type == 'both':
41        abac_split_cert(combo, opts.key, opts.cert)
42    else:
43        sys.exit('Cannot split %s as it is a %s' % (combo, type or 'dunno'));
[87c0fc1]44except EnvironmentError, e:
45    sys.exit("%s: %s" % (e.strerror, e.filename or '?!'))
Note: See TracBrowser for help on using the repository browser.