From 39130548c2edf671d9bff1cdfae004b107e9dcb8 Mon Sep 17 00:00:00 2001 From: Tim Henkes Date: Sun, 10 Jun 2018 11:23:24 +0200 Subject: [PATCH] Allow for external OTPK handling, fix requirements in setup.py --- setup.py | 6 +++--- x3dh/__init__.py | 1 - x3dh/implementations/__init__.py | 4 ---- .../implementations/curvetypeencryptionkeyencoder.py | 9 --------- x3dh/state.py | 12 ++++++++++-- 5 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 x3dh/implementations/__init__.py delete mode 100644 x3dh/implementations/curvetypeencryptionkeyencoder.py diff --git a/setup.py b/setup.py index e327d3f..4d6cefb 100644 --- a/setup.py +++ b/setup.py @@ -4,11 +4,11 @@ setup( name = "X3DH", - version = "0.1.0", + version = "0.2.0", description = "A python implementation of the Extended Triple Diffie-Hellman key agreement protocol.", author = "Tim Henkes", url = "https://github.com/Syndace/python-x3dh", - packages = ["x3dh", "x3dh.exceptions", "x3dh.implementations"], - requires = ["scci", "pynacl", "hkdf"], + packages = ["x3dh", "x3dh.exceptions"], + requires = ["scci", "xeddsa", "hkdf"], provides = ["x3dh"] ) diff --git a/x3dh/__init__.py b/x3dh/__init__.py index 7b8107c..52240a7 100644 --- a/x3dh/__init__.py +++ b/x3dh/__init__.py @@ -1,7 +1,6 @@ from __future__ import absolute_import from . import exceptions -from . import implementations from .config import Config from .publicbundle import PublicBundle diff --git a/x3dh/implementations/__init__.py b/x3dh/implementations/__init__.py deleted file mode 100644 index d869f51..0000000 --- a/x3dh/implementations/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from __future__ import absolute_import - - -from .curvetypeencryptionkeyencoder import CurveTypeEncryptionKeyEncoder diff --git a/x3dh/implementations/curvetypeencryptionkeyencoder.py b/x3dh/implementations/curvetypeencryptionkeyencoder.py deleted file mode 100644 index 520f983..0000000 --- a/x3dh/implementations/curvetypeencryptionkeyencoder.py +++ /dev/null @@ -1,9 +0,0 @@ -from __future__ import absolute_import - -from ..encryptionkeyencoder import EncryptionKeyEncoder - -class CurveTypeEncryptionKeyEncoder(EncryptionKeyEncoder): - @staticmethod - def encodeEncryptionKey(encryption_key, encryption_key_type): - if encryption_key_type == "25519": - return b'\x05' + encryption_key diff --git a/x3dh/state.py b/x3dh/state.py index a917ced..9855993 100644 --- a/x3dh/state.py +++ b/x3dh/state.py @@ -176,7 +176,15 @@ def initSessionActive(self, other_public_bundle, allow_zero_otpks = False): "sk": sk } - def initSessionPassive(self, session_init_data, allow_no_otpk = False): + def initSessionPassive(self, session_init_data, allow_no_otpk = False, keep_otpk = False): + """ + The specification of X3DH dictates to delete the one time pre keys as soon as they are used. + This behaviour provides security but may lead to considerable usability downsides in some environments. + For that reason the keep_otpk flag exists. If set to True, the one time pre key is not automatically deleted. + USE WITH CARE, THIS MAY INTRODUCE SECURITY LEAKS IF USED INCORRECTLY. + If you decide set the flag and to keep the otpks, you have to manage deleting them yourself, e.g. by subclassing this class and overriding this method. + """ + other_ik = self.__KeyQuad(encryption_key = session_init_data["ik"]) other_ek = self.__KeyQuad(encryption_key = session_init_data["ek"]) @@ -210,7 +218,7 @@ def initSessionPassive(self, session_init_data, allow_no_otpk = False): ad = other_ik_enc_serialized + ik_enc_serialized - if my_otpk: + if my_otpk and not keep_otpk: self.__otpks.remove(my_otpk) self._changed = True self.__refillOTPKs()