Ticket #133: ldapplugin_tls.patch

File ldapplugin_tls.patch, 1.7 kB (added by tiziano.mueller@neuronics.ch, 2 years ago)

Patch (against revision 1254) of the ldap-plugin to add TLS support.

  • ldapplugin-0.10/ldapplugin/model.py

    old new  
    3636LDAP_DIRECTORY_PARAMS = [ 'host', 'port', 'basedn', 
    3737                          'bind_user', 'bind_passwd', 
    3838                          'groupname', 'groupmember', 
    39                           'groupattr', 'uidattr', 'permattr'] 
     39                          'groupattr', 'uidattr', 'permattr', 
     40                          'start_tls', 'cacertdir', 'cacertfile', 
     41                          'keyfile','certfile'] 
    4042                           
    4143GROUP_PREFIX = '@' 
    4244 
     
    511513        self.bind_user = None 
    512514        self.bind_passwd = None 
    513515        self.basedn = None 
     516        self.start_tls = False 
     517        self.cacertdir = '/etc/ssl/certs' 
     518        self.cacertfile = '' 
     519        self.keyfile = '' 
     520        self.certfile = '' 
    514521        for k, v in ldap.items(): 
    515522            self.__setattr__(k, v.encode('ascii')) 
    516523        if not isinstance(self.port, int): 
     
    594601        try: 
    595602            self._ds = ldap.initialize('ldap://%s:%d/' % (self.host, self.port)) 
    596603            self._ds.protocol_version = ldap.VERSION3 
     604            self._ds.x_tls_cacertdir = self.cacertdir 
     605            self._ds.x_tls_cacertfile = self.cacertfile 
     606            self._ds.x_tls_keyfile = self.keyfile 
     607            self._ds.x_tls_certfile = self.certfile 
     608 
     609            if self.start_tls == 'true': 
     610                self.log.debug("Starting TLS encryption.") 
     611                self._ds.start_tls_s() 
     612 
    597613            if self.bind: 
    598614                if not self.bind_user: 
    599615                    raise TracError("Bind enabled but credentials not defined")