aboutsummaryrefslogtreecommitdiff
path: root/scripts/rpki/x509.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-10-03 00:50:46 +0000
committerRob Austein <sra@hactrn.net>2007-10-03 00:50:46 +0000
commit2c5dfca16386daa00afca77b8c7edd042a0f27a8 (patch)
tree35c77b4b12dbe839f7253c363269112454696148 /scripts/rpki/x509.py
parentbc34d54e960b5680deb3b601e8a9af10e1b3af7f (diff)
Fix CMS code not to expect keys on disk
svn path=/scripts/rpki/cms.py; revision=1080
Diffstat (limited to 'scripts/rpki/x509.py')
-rw-r--r--scripts/rpki/x509.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/scripts/rpki/x509.py b/scripts/rpki/x509.py
index 58c1ab06..3eb16c7d 100644
--- a/scripts/rpki/x509.py
+++ b/scripts/rpki/x509.py
@@ -13,7 +13,7 @@ some of the nasty details. This involves a lot of format conversion.
"""
import POW, tlslite.api, POW.pkix, base64, time
-import rpki.exceptions, rpki.resource_set
+import rpki.exceptions, rpki.resource_set, rpki.manifest
class PEM_converter(object):
"""Convert between DER and PEM encodings for various kinds of ASN.1 data."""
@@ -291,6 +291,18 @@ class X509_chain(list):
packages.
"""
+ def __init__(self, *args, **kw):
+ if args:
+ self[:] = args
+ elif "PEM_files" in kw:
+ self.load_from_PEM(kw["PEM_files"])
+ elif "DER_files" in kw:
+ self.load_from_DER(kw["DER_files"])
+ elif "Auto_files" in kw:
+ self.load_from_Auto(kw["Auto_files"])
+ elif kw:
+ raise TypeError
+
def chainsort(self):
"""Sort a bag of certs into a chain, leaf first.
@@ -334,6 +346,10 @@ class X509_chain(list):
"""Load a set of certs from a list of DER files."""
self.extend([X509(DER_file=f) for f in files])
+ def load_from_Auto(self, files):
+ """Load a set of certs from a list of DER or PEM files (guessing)."""
+ self.extend([X509(Auto_file=f) for f in files])
+
class PKCS10_Request(DER_object):
"""Class to hold a PKCS #10 request."""
@@ -434,3 +450,28 @@ class RSA_Keypair(DER_object):
def get_public_DER(self):
return self.get_POW().derWrite(POW.RSA_PUBLIC_KEY)
+
+class Manifest(DER_object):
+ """Class to hold a signed manifest."""
+
+ formats = ("DER", "POWpkix")
+ pem_converter = PEM_converter("RPKI MANIFEST")
+
+ def get_DER(self):
+ """Get the DER value of this manifest."""
+ assert not self.empty()
+ if self.DER:
+ return self.DER
+ if self.POWpkix:
+ self.DER = self.POWpkix.toString()
+ return self.get_DER()
+ raise rpki.exceptions.DERObjectConversionError, "No conversion path to DER available"
+
+ def get_POWpkix(self):
+ """Get the POW.pkix value of this manifest."""
+ assert not self.empty()
+ if not self.POWpkix:
+ mani = rpki.manifest.Manifest()
+ mani.fromString(self.get_DER())
+ self.POWpkix = mani
+ return self.POWpkix