From 2d91b4c383f50f50d68f6a65bf35d2c87bd6c4d9 Mon Sep 17 00:00:00 2001 From: Praphull Purohit Date: Tue, 5 Mar 2024 13:52:07 +0100 Subject: [PATCH] Create secureContext when both keys & certs are defined Signed-off-by: Praphull Purohit --- .../src/ldap/client.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/plugins/catalog-backend-module-ldap/src/ldap/client.ts b/plugins/catalog-backend-module-ldap/src/ldap/client.ts index 5d6303a943..47e8b1f397 100644 --- a/plugins/catalog-backend-module-ldap/src/ldap/client.ts +++ b/plugins/catalog-backend-module-ldap/src/ldap/client.ts @@ -23,10 +23,10 @@ import { Logger } from 'winston'; import { BindConfig, TLSConfig } from './config'; import { createOptions, errorString } from './util'; import { + AEDirVendor, ActiveDirectoryVendor, DefaultLdapVendor, FreeIpaVendor, - AEDirVendor, LdapVendor, } from './vendors'; @@ -46,27 +46,20 @@ export class LdapClient { bind?: BindConfig, tls?: TLSConfig, ): Promise { - const readTLSOptionFile = (file?: string) => - file !== undefined ? readFileSync(file).toString() : undefined; - - const certs = readTLSOptionFile(tls?.certs); - const keys = readTLSOptionFile(tls?.keys); const secureContext = - certs !== undefined || keys !== undefined + tls && tls.certs && tls.keys ? tlsLib.createSecureContext({ - cert: certs, - key: keys, + cert: readFileSync(tls.certs).toString(), + key: readFileSync(tls.keys).toString(), }) : undefined; - const tlsOptions = { - secureContext, - rejectUnauthorized: tls?.rejectUnauthorized, - }; - const client = ldap.createClient({ url: target, - tlsOptions: tlsOptions, + tlsOptions: { + secureContext, + rejectUnauthorized: tls?.rejectUnauthorized, + }, }); // We want to have a catch-all error handler at the top, since the default