Skip to content

Commit d777eec

Browse files
committed
feat(ldap): Allow to use global default_certificates_bundle_path for ldap
Signed-off-by: Simon L. <[email protected]>
1 parent 594d220 commit d777eec

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

apps/user_ldap/lib/Connection.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCA\User_LDAP\Exceptions\ConfigurationIssueException;
1212
use OCP\ICache;
1313
use OCP\ICacheFactory;
14+
use OCP\ICertificateManager;
1415
use OCP\IL10N;
1516
use OCP\Server;
1617
use OCP\Util;
@@ -686,6 +687,26 @@ private function doConnect($host, $port): bool {
686687
$this->ldap->setOption(null, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
687688
}
688689

690+
/** @var ICertificateManager $certManager */
691+
$certManager = Server::get(ICertificateManager::class);
692+
$defaultCertificatePath = $certManager->getDefaultCertificatesBundlePath();
693+
// We check if default certificate path is actually set to a custom value.
694+
// Otherwise this would be a breaking change and cannot be backported.
695+
if (!empty($defaultCertificatePath) && $defaultCertificatePath !== \OC::$SERVERROOT . '/resources/config/ca-bundle.crt') {
696+
$absoluteBundlePath = $certManager->getAbsoluteBundlePath();
697+
if ($this->ldap->setOption(null, LDAP_OPT_X_TLS_CACERTFILE, $absoluteBundlePath)) {
698+
$this->logger->debug(
699+
'Adjusted the tls certificate file path to ' . $absoluteBundlePath,
700+
['app' => 'user_ldap']
701+
);
702+
} else {
703+
$this->logger->warning(
704+
'Could not change the tls certificate file path.',
705+
['app' => 'user_ldap']
706+
);
707+
}
708+
}
709+
689710
$this->ldapConnectionRes = $this->ldap->connect($host, $port) ?: null;
690711

691712
if ($this->ldapConnectionRes === null) {

0 commit comments

Comments
 (0)