diff options
author | Fraser Tweedale <ftweedal@redhat.com> | 2016-10-11 12:43:22 +1000 |
---|---|---|
committer | David Kupka <dkupka@redhat.com> | 2016-11-10 10:21:47 +0100 |
commit | 44c2d685f01eb4c03e4659125e41d73b8be47c19 (patch) | |
tree | 5f4f45dd6dcce1b96e630e400b80324412843c75 /ipalib | |
parent | 85487281cdc09720f6a0385ebb7157742d762a0c (diff) | |
download | freeipa-44c2d685f01eb4c03e4659125e41d73b8be47c19.tar.gz freeipa-44c2d685f01eb4c03e4659125e41d73b8be47c19.tar.xz freeipa-44c2d685f01eb4c03e4659125e41d73b8be47c19.zip |
x509: avoid use of nss.data_to_hex
Avoid use of the nss.data_to_hex function for formatting certificate
fingerprints. Add our own helper functions to format the
fingerprints as hex (with colons).
Part of: https://fedorahosted.org/freeipa/ticket/6398
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/x509.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ipalib/x509.py b/ipalib/x509.py index e67aab628..cac5e9c59 100644 --- a/ipalib/x509.py +++ b/ipalib/x509.py @@ -33,6 +33,7 @@ from __future__ import print_function +import binascii import collections import os import sys @@ -552,6 +553,28 @@ def process_othernames(gns): yield gn +def chunk(size, s): + """Yield chunks of the specified size from the given string. + + The input must be a multiple of the chunk size (otherwise + trailing characters are dropped). + + Works on character strings only. + + """ + return (u''.join(span) for span in six.moves.zip(*[iter(s)] * size)) + + +def add_colons(s): + """Add colons between each nibble pair in a hex string.""" + return u':'.join(chunk(2, s)) + + +def to_hex_with_colons(bs): + """Convert bytes to a hex string with colons.""" + return add_colons(binascii.hexlify(bs).decode('utf-8')) + + if __name__ == '__main__': # this can be run with: # python ipalib/x509.py < /etc/ipa/ca.crt |