From 7e92e65190c04cc3c4699dbba329cbd6696576f1 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Wed, 24 Jul 2019 13:45:29 +1000 Subject: [PATCH] IPASecStore: support extra key arguments To support lightweight CA key replication using AES, while retaining backwards compatibility with old servers, it is necessary to signal support for AES. Whereas we currently request a key with the path: /keys/ca_wrapped/ and whereas paths with > 3 components are unsupported, add support for handlers to signal that they support extra arguments (defaulting to False), those arguments being conveyed as additional path components, e.g.: # 2.16.840.1.101.3.4.1.2 = aes128-cbc /keys/ca_wrapped//2.16.840.1.101.3.4.1.2 This commit only adds the Custodia support for extra handler arguments. Work to support LWCA key replication with AES wrapping will continue in subsequent commits. Part of: https://pagure.io/freeipa/issue/8020 Reviewed-By: Alexander Bokovoy --- ipaserver/secrets/store.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ipaserver/secrets/store.py b/ipaserver/secrets/store.py index b40008c18..684828dd8 100644 --- a/ipaserver/secrets/store.py +++ b/ipaserver/secrets/store.py @@ -15,8 +15,13 @@ class UnknownKeyName(Exception): pass +class InvalidKeyArguments(Exception): + pass + + class DBMAPHandler: dbtype = None + supports_extra_args = False def __init__(self, config, dbmap, nickname): dbtype = dbmap.get('type') @@ -162,12 +167,15 @@ class IPASecStore(CSStore): def _get_handler(self, key): path = key.split('/', 3) - if len(path) != 3 or path[0] != 'keys': + if len(path) < 3 or path[0] != 'keys': raise ValueError('Invalid name') if path[1] not in NAME_DB_MAP: raise UnknownKeyName("Unknown DB named '%s'" % path[1]) dbmap = NAME_DB_MAP[path[1]] - return dbmap['handler'](self.config, dbmap, path[2]) + handler = dbmap['handler'] + if len(path) > 3 and not handler.supports_extra_args: + raise InvalidKeyArguments('Handler does not support extra args') + return handler(self.config, dbmap, path[2], *path[3:]) def get(self, key): try: