mirror of https://github.com/wolfSSL/wolfssl
adds load_verify_locations and load_cert_chain implementations.
This commit is contained in:
parent
c8ae6abb43
commit
bd14611879
|
@ -24,11 +24,14 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from wolfssl._methods import WolfSSLMethod
|
from wolfssl._methods import WolfSSLMethod
|
||||||
|
from wolfssl._exceptions import *
|
||||||
|
|
||||||
CERT_NONE = 0
|
CERT_NONE = 0
|
||||||
CERT_OPTIONAL = 1
|
CERT_OPTIONAL = 1
|
||||||
CERT_REQUIRED = 2
|
CERT_REQUIRED = 2
|
||||||
|
|
||||||
|
_SSL_FILETYPE_PEM = 1
|
||||||
|
|
||||||
class SSLContext:
|
class SSLContext:
|
||||||
"""An SSLContext holds various SSL-related configuration options and
|
"""An SSLContext holds various SSL-related configuration options and
|
||||||
data, such as certificates and possibly a private key."""
|
data, such as certificates and possibly a private key."""
|
||||||
|
@ -66,9 +69,31 @@ class SSLContext:
|
||||||
# _context=self)
|
# _context=self)
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# def load_cert_chain(self, certfile, keyfile=None, password=None):
|
def load_cert_chain(self, certfile, keyfile=None, password=None):
|
||||||
# pass
|
if certfile:
|
||||||
#
|
ret = _lib.wolfSSL_CTX_use_certificate_chain_file(
|
||||||
#
|
self.native_object, certfile)
|
||||||
# def load_verify_locations(self, cafile=None, capath=None, cadata=None):
|
if ret != 0:
|
||||||
# pass
|
raise SSLError("Unnable to load certificate chain")
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
"certfile needs to be string or buffer, NoneType found")
|
||||||
|
|
||||||
|
if keyfile:
|
||||||
|
ret = _lib.wolfSSL_CTX_use_PrivateKey_file(
|
||||||
|
self.native_object, keyfile, _SSL_FILETYPE_PEM)
|
||||||
|
if ret != 0:
|
||||||
|
raise SSLError("Unnable to load private key")
|
||||||
|
|
||||||
|
|
||||||
|
def load_verify_locations(self, cafile=None, capath=None, cadata=None):
|
||||||
|
if cafile is None and capath is None:
|
||||||
|
raise SSLError("Unnable to load verify locations")
|
||||||
|
|
||||||
|
ret = _lib.wolfSSL_CTX_load_verify_locations(
|
||||||
|
self.native_object,
|
||||||
|
cafile if cafile else _ffi.NULL,
|
||||||
|
capath if capath else _ffi.NULL)
|
||||||
|
|
||||||
|
if ret != 0:
|
||||||
|
raise SSLError("Unnable to load verify locations")
|
||||||
|
|
Loading…
Reference in New Issue