diff options
author | Daniil Baturin <daniil@baturin.org> | 2023-08-09 17:54:31 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2023-08-09 17:54:31 +0100 |
commit | 9427d7b001bd9cb769fb2940cfa263a448d62b80 (patch) | |
tree | dae070a1f3ad40b6fb9bc503a7f4e6d1750f6468 /python | |
parent | e4b932ed0a140c9ced9a4eb501d520560b125406 (diff) | |
download | vyos-1x-9427d7b001bd9cb769fb2940cfa263a448d62b80.tar.gz vyos-1x-9427d7b001bd9cb769fb2940cfa263a448d62b80.zip |
pki: T5273: add a certificate fingerprint command
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/pki.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/python/vyos/pki.py b/python/vyos/pki.py index cd15e3878..792e24b76 100644 --- a/python/vyos/pki.py +++ b/python/vyos/pki.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2021 VyOS maintainers and contributors +# Copyright (C) 2023 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -63,6 +63,18 @@ private_format_map = { 'OpenSSH': serialization.PrivateFormat.OpenSSH } +hash_map = { + 'sha256': hashes.SHA256, + 'sha384': hashes.SHA384, + 'sha512': hashes.SHA512, +} + +def get_certificate_fingerprint(cert, hash): + hash_algorithm = hash_map[hash]() + fp = cert.fingerprint(hash_algorithm) + + return fp.hex(':').upper() + def encode_certificate(cert): return cert.public_bytes(encoding=serialization.Encoding.PEM).decode('utf-8') |