Skip to content
Snippets Groups Projects
Commit 76ec9091 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Factor key-loading implementation into helper function

parent e1872518
No related branches found
No related tags found
1 merge request!198Signing key whitespace handling
......@@ -142,10 +142,10 @@ class ZKAPAuthorizer(object):
kwargs = configuration.copy()
root_url = kwargs.pop(u"ristretto-issuer-root-url")
pass_value = int(kwargs.pop(u"pass-value", BYTES_PER_PASS))
signing_key = SigningKey.decode_base64(
signing_key = load_signing_key(
FilePath(
kwargs.pop(u"ristretto-signing-key-path"),
).getContent().strip(),
),
)
announcement = {
u"ristretto-issuer-root-url": root_url,
......@@ -288,3 +288,23 @@ def get_root_nodes(client_node, node_config):
return []
else:
return [client_node.create_node_from_uri(rootcap)]
def load_signing_key(path):
"""
Read a serialized Ristretto signing key from the given path and return it
as a ``challenge_bypass_ristretto.SigningKey``.
Unlike ``challenge_bypass_ristretto.SigningKey.decode_base64`` this
function will clean up any whitespace around the key.
:param FilePath path: The path from which to read the key.
:raise challenge_bypass_ristretto.DecodeException: If
``SigningKey.decode_base64`` raises this exception it will be passed
through.
:return challenge_bypass_ristretto.SigningKey: An object representing the
key read.
"""
return SigningKey.decode_base64(path.getContent())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment