Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TLS for LDAP Authentication #1774

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ all:
response_header: Content-Security-Policy-Report-Only
# Configure CSP response directives.
directives: "default-src 'self'; font-src 'self' https://fonts.gstatic.com; img-src 'self' https://*.googleapis.com https://*.gstatic.com *.google.com *.googleusercontent.com data: https://www.gravatar.com/avatar/ https://*.google-analytics.com https://*.googletagmanager.com blob:; script-src 'self' https://*.googletagmanager.com 'nonce' https://*.googleapis.com https://*.gstatic.com *.google.com https://*.ggpht.com *.googleusercontent.com blob:; style-src 'self' 'nonce' https://fonts.googleapis.com; worker-src 'self' blob:; connect-src 'self' https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://*.googleapis.com *.google.com https://*.gstatic.com data: blob:; frame-ancestors 'self';"

ldap:
enable_tls_encryption: true
19 changes: 18 additions & 1 deletion lib/ldapUser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ldapUser extends myUser implements Zend_Acl_Role_Interface

public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = [])
{
$this->logger = sfContext::getInstance()->getLogger();

// initialize parent
parent::initialize($dispatcher, $storage, $options);

Expand Down Expand Up @@ -113,20 +115,35 @@ protected function getLdapConnection()

$this->ldapConnection = $connection;

return $connection;
return $this->ldapConnection;
}
}

protected function ldapBind($username, $password)
{
$tls_encryption = sfConfig::get('app_ldap_enable_tls_encryption', true);
if ($conn = $this->getLdapConnection()) {
$base_dn = (string) QubitSetting::getByName('ldapBaseDn');
$bind_attribute = (string) QubitSetting::getByName('ldapBindAttribute');
$dn = $bind_attribute.'='.$username.','.$base_dn;

// Close LDAP connection if TLS encryption failed to start
if ($tls_encryption && false == ldap_start_tls($conn)) {
$this->logger->err('Error starting TLS encryption for LDAP authentication.');
ldap_close($conn);

return false;
}
if (!$tls_encryption) {
anvit marked this conversation as resolved.
Show resolved Hide resolved
$this->logger->info('TLS encryption turned off for LDAP authentication.');
}

// The @ suppresses a warning if the auth fails
$this->ldapBound = @ldap_bind($conn, $dn, $password);

// Close LDAP connection
ldap_close($conn);

return $this->ldapBound;
}
}
Expand Down
Loading