44 def try_openssl_module(filename, format):
45 from OpenSSL
import crypto
47 FILETYPE_PEM: crypto.FILETYPE_PEM,
48 FILETYPE_DER: crypto.FILETYPE_ASN1
51 crl = crypto.load_crl(types[format], sys.stdin.buffer.read())
53 with open(filename,
'rb')
as f:
54 crl = crypto.load_crl(types[format], f.read())
55 return set(int(r.get_serial(), 16)
for r
in crl.get_revoked())
57 def try_openssl_exec(filename, format):
58 args = [
'openssl',
'crl',
'-inform', format,
'-text']
60 args += [
'-in', filename]
62 for line
in check_output(args, universal_newlines=
True).splitlines():
63 _, _, serial = line.partition(
'Serial Number:')
65 serials.add(int(serial.strip(), 16))
69 return try_openssl_module(filename, format)
71 return try_openssl_exec(filename, format)
109 parser = argparse.ArgumentParser(description=
'OpenVPN CRL extractor')
110 parser.add_argument(
'-f',
'--format',
112 default=FILETYPE_PEM, choices=[FILETYPE_PEM, FILETYPE_DER],
113 help=
'input CRL format - default {}'.format(FILETYPE_PEM)
115 parser.add_argument(
'crlfile', metavar=
'CRLFILE|-',
117 help=
'input CRL file or "-" for stdin'
119 parser.add_argument(
'outdir', metavar=
'OUTDIR',
121 help=
'output directory for serials numbers'
123 args = parser.parse_args()
125 certs, t =
load_crl(args.crlfile, args.format)
126 print(
'Loaded: {} revoked certs in {}s'.format(len(certs), t))
129 print(
'Scanned: {} files in {}s'.format(len(files), t))
132 print(
'Created: {} files in {}s'.format(len(created), t))
135 print(
'Removed: {} files in {}s'.format(len(removed), t))