Coverage for admin/authorize_signer.py: 96%
25 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-07-10 13:43 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-07-10 13:43 +0000
1# The MIT License (MIT)
2#
3# Copyright (c) 2021 RSK Labs Ltd
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy of
6# this software and associated documentation files (the "Software"), to deal in
7# the Software without restriction, including without limitation the rights to
8# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9# of the Software, and to permit persons to whom the Software is furnished to do
10# so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
23from .misc import info, head, get_hsm, dispose_hsm, AdminError
24from .unlock import do_unlock
25from .signer_authorization import SignerAuthorization
28def do_authorize_signer(options):
29 head("### -> Authorize signer", fill="#")
30 hsm = None
32 # Require a signer authorization file
33 if options.signer_authorization_file_path is None:
34 raise AdminError("No signer authorization file path given")
36 # Load the given signer authorization
37 try:
38 signer_authorization = SignerAuthorization.from_jsonfile(
39 options.signer_authorization_file_path)
40 except Exception as e:
41 raise AdminError(f"While loading the signer authorization file: {str(e)}")
43 # Attempt to unlock the device without exiting the UI
44 try:
45 do_unlock(options, label=False, exit=False)
46 except Exception as e:
47 raise AdminError(f"Failed to unlock device: {str(e)}")
49 # Signer authorization
50 hsm = None
51 info("Authorising signer... ", options.verbose)
52 try:
53 hsm = get_hsm(options.verbose)
54 hsm.authorize_signer(signer_authorization)
55 except Exception as e:
56 raise AdminError(f"Failed to authorize signer: {str(e)}")
57 finally:
58 dispose_hsm(hsm)
60 info("Signer authorized")