diff options
author | Pavol Žáčik <[email protected]> | 2019-10-18 22:08:39 +0200 |
---|---|---|
committer | Pavol Žáčik <[email protected]> | 2019-10-22 19:15:03 +0200 |
commit | 430e6c7c1236dfed90821e75b3909264b55bb00e (patch) | |
tree | 00ca52683198f94c449d7576427ea5879cdca9a4 | |
parent | cb34802ed24b0963ed5a0180236cabd593268987 (diff) |
Add missing X509 Python functions
Make Python verify function prettier
-rwxr-xr-x | src/python/botan2.py | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py index 7db8cd9b3..3f7e54ae5 100755 --- a/src/python/botan2.py +++ b/src/python/botan2.py @@ -376,7 +376,7 @@ def _set_prototypes(dll): [c_void_p, c_char_p, c_size_t, c_char_p, POINTER(c_size_t)]) ffi_api(dll.botan_x509_cert_to_string, [c_void_p, c_char_p, POINTER(c_size_t)]) ffi_api(dll.botan_x509_cert_allowed_usage, [c_void_p, c_uint]) - ffi_api(dll.botan_x509_cert_hostname_match, [c_void_p, c_char_p]) + ffi_api(dll.botan_x509_cert_hostname_match, [c_void_p, c_char_p], [-1]) ffi_api(dll.botan_x509_cert_verify, [POINTER(c_int), c_void_p, c_void_p, c_size_t, c_void_p, c_size_t, c_char_p, c_size_t, c_char_p, c_uint64]) @@ -1338,6 +1338,62 @@ class X509Cert(object): # pylint: disable=invalid-name return _call_fn_returning_str( 0, lambda b, bl: _DLL.botan_x509_cert_get_subject_dn(self.__obj, _ctype_str(key), index, b, bl)) + def issuer_dn(self, key, index): + return _call_fn_returning_str( + 0, lambda b, bl: _DLL.botan_x509_cert_get_issuer_dn(self.__obj, _ctype_str(key), index, b, bl)) + + def hostname_match(self, hostname): + rc = _DLL.botan_x509_cert_hostname_match(self.__obj, _ctype_str(hostname)) + return rc == 0 + + def not_before(self): + return _call_fn_returning_sz(lambda l: _DLL.botan_x509_cert_not_before(self.__obj, l)) + + def not_after(self): + return _call_fn_returning_sz(lambda l: _DLL.botan_x509_cert_not_after(self.__obj, l)) + + def allowed_usage(self, usage): + rc = _DLL.botan_x509_cert_allowed_usage(self.__obj, usage) + return rc == 0 + + def get_obj(self): + return self.__obj + + def verify(self, + intermediates, + trusted, + trusted_path, + required_strength=0, + hostname="", + reference_time=0): + + c_intermediates = len(intermediates) * c_void_p + arr_intermediates = c_intermediates() + for i, ca in enumerate(intermediates): + arr_intermediates[i] = ca.get_obj() + + c_trusted = len(trusted) * c_void_p + arr_trusted = c_trusted() + for i, ca in enumerate(trusted): + arr_trusted[i] = ca.get_obj() + + error_code = c_int(0) + + _DLL.botan_x509_cert_verify(byref(error_code), + self.__obj, + byref(arr_intermediates), + c_size_t(len(intermediates)), + byref(arr_trusted), + c_size_t(len(trusted)), + _ctype_str(trusted_path), + c_size_t(required_strength), + _ctype_str(hostname), + c_uint64(reference_time)) + return error_code.value + + @classmethod + def validation_status(cls, error_code): + return _ctype_to_str(_DLL.botan_x509_cert_validation_status(c_int(error_code))) class MPI(object): |