Certs module initial checkin 44/1144/1
authorRajesh <rajesh.velandy@riftio.com>
Thu, 23 Feb 2017 10:12:08 +0000 (05:12 -0500)
committerRajesh <rajesh.velandy@riftio.com>
Thu, 23 Feb 2017 10:12:08 +0000 (05:12 -0500)
test/certs.py [new file with mode: 0644]

diff --git a/test/certs.py b/test/certs.py
new file mode 100644 (file)
index 0000000..595dd20
--- /dev/null
@@ -0,0 +1,32 @@
+# RIFT_IO_STANDARD_CMAKE_COPYRIGHT_HEADER(BEGIN)
+# Creation Date: 2/5/16
+# RIFT_IO_STANDARD_CMAKE_COPYRIGHT_HEADER(END)
+
+import os
+
+class BootstrapSslMissingException(Exception):
+    pass
+
+# True if the environment variable is unset, otherwise False
+USE_SSL = os.environ.get("RIFT_BOOT_WITHOUT_HTTPS", None) is None
+
+def get_bootstrap_cert_and_key():
+    '''
+    Lookup the bootstrap certificate and key and return their paths
+    '''
+
+    user_cert = os.path.join("/", "etc", "ssl", "current.cert")
+    user_key = os.path.join("/", "etc", "ssl", "current.key")
+
+    if os.path.isfile(user_cert) and os.path.isfile(user_key):
+        return USE_SSL, user_cert, user_key
+
+    rift_install = os.environ["RIFT_INSTALL"]
+    rift_cert = os.path.join(rift_install, "etc", "ssl", "current.cert")
+    rift_key = os.path.join(rift_install, "etc", "ssl", "current.key")
+
+    if os.path.isfile(rift_cert) and os.path.isfile(rift_key):
+        return USE_SSL, rift_cert, rift_key
+
+    raise BootstrapSslMissingException()
+