summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/backend/utils.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2014-07-08 16:45:43 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2014-07-14 12:11:50 -0300
commit1eae3af1906f95d9d2d76c205b61799d248f0e71 (patch)
tree9fc8f3d0a6b01963068878582e9520933544023a /src/leap/bitmask/backend/utils.py
parent3795dedd26fc239e143ca2a29b7e16d433f964ba (diff)
Add base communication framework.
Diffstat (limited to 'src/leap/bitmask/backend/utils.py')
-rw-r--r--src/leap/bitmask/backend/utils.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/leap/bitmask/backend/utils.py b/src/leap/bitmask/backend/utils.py
new file mode 100644
index 00000000..5fe59a62
--- /dev/null
+++ b/src/leap/bitmask/backend/utils.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# encoding: utf-8
+import os
+import shutil
+
+import zmq.auth
+
+from leap.bitmask.util import get_path_prefix
+
+KEYS_DIR = os.path.join(get_path_prefix(), 'leap', 'zmq_certificates')
+
+
+def generate_certificates():
+ """
+ Generate client and server CURVE certificate files.
+ """
+ # Create directory for certificates, remove old content if necessary
+ if os.path.exists(KEYS_DIR):
+ shutil.rmtree(KEYS_DIR)
+ os.mkdir(KEYS_DIR)
+
+ # create new keys in certificates dir
+ # public_file, secret_file = create_certificates(...)
+ zmq.auth.create_certificates(KEYS_DIR, "frontend")
+ zmq.auth.create_certificates(KEYS_DIR, "backend")
+
+
+def get_frontend_certificates():
+ """
+ Return the frontend's public and secret certificates.
+ """
+ frontend_secret_file = os.path.join(KEYS_DIR, "frontend.key_secret")
+ public, secret = zmq.auth.load_certificate(frontend_secret_file)
+ return public, secret
+
+
+def get_backend_certificates(base_dir='.'):
+ """
+ Return the backend's public and secret certificates.
+ """
+ backend_secret_file = os.path.join(KEYS_DIR, "backend.key_secret")
+ public, secret = zmq.auth.load_certificate(backend_secret_file)
+ return public, secret