(self, ssl_params)
return tls
Return a TLS object to establish a secure connection to a server
Return a TLS object to establish a secure connection to a server
Return a TLS object to establish a secure connection to a server
def _get_tls_object(self, ssl_params):
        """
        Return a TLS object to establish a secure connection to a server
        """
        if ssl_params is None:
            return None

        if not ssl_params["verify"] and ssl_params["ca_certs"]:
            self.warning(
                "Incorrect configuration: trying to disable server certificate validation, "
                "while also specifying a capath. No validation will be performed. Fix your "
                "configuration to remove this warning"
            )

        validate = ssl.CERT_REQUIRED if ssl_params["verify"] else ssl.CERT_NONE

        if ssl_params["ca_certs"] is None or os.path.isfile(ssl_params["ca_certs"]):
            tls = ldap3.core.tls.Tls(
                local_private_key_file=ssl_params["key"],
                local_certificate_file=ssl_params["cert"],
                ca_certs_file=ssl_params["ca_certs"],
                version=ssl.PROTOCOL_SSLv23,
                validate=validate,
            )
        elif os.path.isdir(ssl_params["ca_certs"]):
            tls = ldap3.core.tls.Tls(
                local_private_key_file=ssl_params["key"],
                local_certificate_file=ssl_params["cert"],
                ca_certs_path=ssl_params["ca_certs"],
                version=ssl.PROTOCOL_SSLv23,
                validate=validate,
            )
        else:
            raise ConfigurationError(
                'Invalid path {} for ssl_ca_certs: no such file or directory'.format(ssl_params['ca_certs'])
            )
        return tls
def _get_tls_object ( self , ssl_params ) : if ssl_params is None : return None if not ssl_params [ "verify" ] and ssl_params [ "ca_certs" ] : self . warning ( "Incorrect configuration: trying to disable server certificate validation, " "while also specifying a capath. No validation will be performed. Fix your " "configuration to remove this warning" ) validate = ssl . CERT_REQUIRED if ssl_params [ "verify" ] else ssl . CERT_NONE if ssl_params [ "ca_certs" ] is None or os . path . isfile ( ssl_params [ "ca_certs" ] ) : tls = ldap3 . core . tls . Tls ( local_private_key_file = ssl_params [ "key" ] , local_certificate_file = ssl_params [ "cert" ] , ca_certs_file = ssl_params [ "ca_certs" ] , version = ssl . PROTOCOL_SSLv23 , validate = validate , ) elif os . path . isdir ( ssl_params [ "ca_certs" ] ) : tls = ldap3 . core . tls . Tls ( local_private_key_file = ssl_params [ "key" ] , local_certificate_file = ssl_params [ "cert" ] , ca_certs_path = ssl_params [ "ca_certs" ] , version = ssl . PROTOCOL_SSLv23 , validate = validate , ) else : raise ConfigurationError ( 'Invalid path {} for ssl_ca_certs: no such file or directory' . format ( ssl_params [ 'ca_certs' ] ) ) return tls