def load_cert_chain(self, certfile, keyfile=None, password=None): """ Load a private key and the corresponding certificate. The certfile string must be the path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate's authenticity. The keyfile string, if present, must point to a file containing the private key in. The password parameter is not supported yet. """ if password is not None: raise NotImplementedError("password callback support not " "implemented yet") if certfile is not None: ret = _lib.wolfSSL_CTX_use_certificate_chain_file( self.native_object, t2b(certfile)) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load certificate chain. Err %d"% ret) else: raise TypeError("certfile should be a valid filesystem path") if keyfile is not None: ret = _lib.wolfSSL_CTX_use_PrivateKey_file( self.native_object, t2b(keyfile), _SSL_FILETYPE_PEM) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load private key. Err %d" % ret)
def load_verify_locations(self, cafile=None, capath=None, cadata=None): """ Load a set of "certification authority" (CA) certificates used to validate other peers' certificates when verify_mode is other than CERT_NONE. At least one of cafile or capath must be specified. The cafile string, if present, is the path to a file of concatenated CA certificates in PEM format. The capath string, if present, is the path to a directory containing several CA certificates in PEM format. """ if cafile is None and capath is None and cadata is None: raise TypeError("cafile, capath and cadata cannot be all omitted") if cafile is not None or capath is not None: ret = _lib.wolfSSL_CTX_load_verify_locations( self.native_object, t2b(cafile) if cafile else _ffi.NULL, t2b(capath) if capath else _ffi.NULL) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load verify locations. Err %d" % ret) if cadata is not None: ret = _lib.wolfSSL_CTX_load_verify_buffer( self.native_object, t2b(cadata), len(cadata), _SSL_FILETYPE_PEM) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load verify locations. Err %d" % ret)
def load_verify_locations(self, cafile=None, capath=None, cadata=None): """ Load a set of "certification authority" (CA) certificates used to validate other peers' certificates when verify_mode is other than CERT_NONE. At least one of cafile or capath must be specified. The cafile string, if present, is the path to a file of concatenated CA certificates in PEM format. The capath string, if present, is the path to a directory containing several CA certificates in PEM format. """ if cafile is None and capath is None and cadata is None: raise TypeError("cafile, capath and cadata cannot be all omitted") if cafile is not None or capath is not None: ret = _lib.wolfSSL_CTX_load_verify_locations( self.native_object, t2b(cafile) if cafile else _ffi.NULL, t2b(capath) if capath else _ffi.NULL) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load verify locations. Err %d" % ret) if cadata is not None: ret = _lib.wolfSSL_CTX_load_verify_buffer( self.native_object, t2b(cadata), len(cadata), _SSL_FILETYPE_PEM) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load verify locations. Err %d" % ret)
def load_cert_chain(self, certfile, keyfile=None, password=None): """ Load a private key and the corresponding certificate. The certfile string must be the path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate's authenticity. The keyfile string, if present, must point to a file containing the private key in. The password parameter is not supported yet. """ if password is not None: raise NotImplementedError("password callback support not " "implemented yet") if certfile is not None: ret = _lib.wolfSSL_CTX_use_certificate_chain_file( self.native_object, t2b(certfile)) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load certificate chain. Err %d"% ret) else: raise TypeError("certfile should be a valid filesystem path") if keyfile is not None: ret = _lib.wolfSSL_CTX_use_PrivateKey_file( self.native_object, t2b(keyfile), _SSL_FILETYPE_PEM) if ret != _SSL_SUCCESS: raise SSLError("Unnable to load private key. Err %d" % ret)
def load_cert_chain(self, certfile, keyfile=None, password=None): """ Load a private key and the corresponding certificate. The certfile string must be the path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate's authenticity. The keyfile string, if present, must point to a file containing the private key in. If you are using a key protected cert or key file, you must call set_passwd_cb before calling load_cert_chain because wolfSSL validates the provided file the first time it is loaded. wolfSSL does not support loading a certificate file that contains both the certificate AND private key. In this case, users should split them into two separate files and load using the certfile and keyfile parameters, respectively. """ if certfile is not None: ret = _lib.wolfSSL_CTX_use_certificate_chain_file( self.native_object, t2b(certfile)) if ret != _SSL_SUCCESS: raise SSLError("Unable to load certificate chain. E(%d)" % ret) else: raise TypeError("certfile should be a valid filesystem path") if keyfile is not None: ret = _lib.wolfSSL_CTX_use_PrivateKey_file(self.native_object, t2b(keyfile), _SSL_FILETYPE_PEM) if ret != _SSL_SUCCESS: raise SSLError("Unable to load private key. E(%d)" % ret)
def write(self, data): """ Write DATA to the underlying secure channel. Returns number of bytes of DATA actually transmitted. """ self._check_closed("write") self._check_connected() data = t2b(data) return _lib.wolfSSL_write(self.native_object, data, len(data))
def set_ciphers(self, ciphers): """ Set the available ciphers for sockets created with this context. It should be a string in the wolfSSL cipher list format. If no cipher can be selected (because compile-time options or other configuration forbids use of all the specified ciphers), an SSLError will be raised. """ ret = _lib.wolfSSL_CTX_set_cipher_list(self.native_object, t2b(ciphers)) if ret != _SSL_SUCCESS: raise SSLError("Unnable to set cipher list")
def write(self, data): """ Write DATA to the underlying secure channel. Returns number of bytes of DATA actually transmitted. """ self._check_closed("write") self._check_connected() data = t2b(data) return _lib.wolfSSL_write(self.native_object, data, len(data))
def set_ciphers(self, ciphers): """ Set the available ciphers for sockets created with this context. It should be a string in the wolfSSL cipher list format. If no cipher can be selected (because compile-time options or other configuration forbids use of all the specified ciphers), an SSLError will be raised. """ ret = _lib.wolfSSL_CTX_set_cipher_list(self.native_object, t2b(ciphers)) if ret != _SSL_SUCCESS: raise SSLError("Unnable to set cipher list")
def use_sni(self, server_hostname): """ Sets the SNI hostname, wraps native wolfSSL_UseSNI() """ sni = t2b(server_hostname) ret = _lib.wolfSSL_UseSNI(self.native_object, 0, sni, len(sni)) if ret != _SSL_SUCCESS: raise SSLError("Unable to set wolfSSL SNI")