diff options
author | Rob Austein <sra@hactrn.net> | 2008-05-08 16:30:18 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2008-05-08 16:30:18 +0000 |
commit | 686637518ba61b4052d536728952a2ae708b0afb (patch) | |
tree | 4db612177638434850c1bec7eeb2c269831f0005 /rpkid/cross-certify.py | |
parent | 429df3509115bfce062d5d29a35982f683870a15 (diff) |
Initial version of cross certification tool. Not quite working yet,
POW.pkix apparently has trouble with some kinds of subject names.
svn path=/rpkid/cross-certify.py; revision=1752
Diffstat (limited to 'rpkid/cross-certify.py')
-rw-r--r-- | rpkid/cross-certify.py | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/rpkid/cross-certify.py b/rpkid/cross-certify.py new file mode 100644 index 00000000..20044f18 --- /dev/null +++ b/rpkid/cross-certify.py @@ -0,0 +1,99 @@ +# $Id$ + +# Copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +"""Cross-certification tool to issue a new certificate based on an old +one that was issued by somebody else. The point of the exercise is to +end up with a valid certificate in our own BPKI which has the same +subject name and subject public key as the one we're replacing. + +Much of this code lifted from rpki.x509.X509.issue(), but this is a +sufficiently different purpose that it's probably not worth +refactoring. + +Usage: python cross-certify.py { -i | --in } input_cert + { -c | --ca } issuing_cert + { -k | --key } issuing_cert_key + { -s | --serial } serial_number + [ { -h | --help } ] + [ { -o | --out } output_filename ] +""" + +import os, time, getopt, sys, POW +import rpki.x509, rpki.sundial + +os.environ["TZ"] = "UTC" +time.tzset() + +def usage(code): + print __doc__ + sys.exit(code) + +output = None + +# debugging only + +if True: + child = rpki.x509.X509(Auto_file = "APNIC-CMS-CERT.cer") + parent = rpki.x509.X509(Auto_file = "ISC-SELF-1.cer") + keypair = rpki.x509.RSA(Auto_file = "ISC-SELF-1.key") + serial = 99 + +opts,argv = getopt.getopt(sys.argv[1:], "h?i:o:c:k:s:", + ["help", "in", "out", "ca", "key", "serial"]) +for o,a in opts: + if o in ("-h", "--help", "-?"): + usage(0) + elif o in ("-i", "--in"): + child = rpki.x509.X509(Auto_file = a) + elif o in ("-o", "--out"): + output = a + elif o in ("-c", "--ca"): + parent = rpki.x509.X509(Auto_file = a) + elif o in ("-k", "--key"): + keypair = rpki.x509.RSA(Auto_file = a) + elif o in ("-s", "--serial"): + serial = int(a) +if argv: + usage(1) + +now = rpki.sundial.now() +notAfter = now + rpki.sundial.timedelta(days = 30) + +x = POW.pkix.Certificate() +x.setVersion(2) +x.setSerial(serial) +x.setIssuer(parent.get_POWpkix().getSubject()) +x.setSubject(child.get_POWpkix().getSubject()) +x.setNotBefore(now.toASN1tuple()) +x.setNotAfter(notAfter.toASN1tuple()) +x.tbs.subjectPublicKeyInfo.set(child.get_POWpkix().tbs.subjectPublicKeyInfo.get()) +x.setExtensions(((rpki.oids.name2oid["subjectKeyIdentifier"], False, + child.get_SKI()), + (rpki.oids.name2oid["authorityKeyIdentifier"], False, + (parent.get_SKI(), (), None)), + (rpki.oids.name2oid["basicConstraints"], True, + (1, None)))) +x.sign(keypair.get_POW(), POW.SHA256_DIGEST) + +cert = rpki.x509.X509(POWpkix = x) + +if output is None: + print cert.get_PEM() +else: + f = open(output, "w") + f.write(cert.get_PEM()) + f.close() + |