summaryrefslogtreecommitdiff
path: root/tools/certtools.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/certtools.py')
-rw-r--r--tools/certtools.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/tools/certtools.py b/tools/certtools.py
index cbb4ff7..af94fb8 100644
--- a/tools/certtools.py
+++ b/tools/certtools.py
@@ -42,22 +42,31 @@ def get_cert_info(s):
result[key] = value
return result
-def get_certs_from_file(certfile):
- certs = []
- cert = ""
- incert = False
- for line in open(certfile):
+def get_pemlike(filename, marker):
+ entries = []
+ entry = ""
+ inentry = False
+
+ for line in open(filename):
line = line.strip()
- if line == "-----BEGIN CERTIFICATE-----":
- cert = ""
- incert = True
- elif line == "-----END CERTIFICATE-----":
- certs.append(base64.decodestring(cert))
- incert = False
- elif incert:
- cert += line
- return certs
+ if line == "-----BEGIN " + marker + "-----":
+ entry = ""
+ inentry = True
+ elif line == "-----END " + marker + "-----":
+ entries.append(base64.decodestring(entry))
+ inentry = False
+ elif inentry:
+ entry += line
+ return entries
+
+def get_certs_from_file(certfile):
+ return get_pemlike(certfile, "CERTIFICATE")
+
+def get_eckey_from_file(keyfile):
+ keys = get_pemlike(keyfile, "EC PRIVATE KEY")
+ assert len(keys) == 1
+ return keys[0]
def get_root_cert(issuer):
accepted_certs = \