diff --git a/apps/backend/.env-example b/apps/backend/.env-example index 44dbff0057..606dab9a46 100644 --- a/apps/backend/.env-example +++ b/apps/backend/.env-example @@ -57,8 +57,6 @@ LDAP_NAMEFIELD=" LDAP_SSL_INSECURE= -LDAP_SSL_KEY= -LDAP_SSL_CERT= LDAP_SSL_CA= ## OAuth Client IDs and Secrets, If a variable does not have client id values assigned then the feature is disabled. diff --git a/apps/backend/src/authn/ldap.strategy.ts b/apps/backend/src/authn/ldap.strategy.ts index a0330fcdc3..19a530e03b 100644 --- a/apps/backend/src/authn/ldap.strategy.ts +++ b/apps/backend/src/authn/ldap.strategy.ts @@ -17,53 +17,21 @@ export class LDAPStrategy extends PassportStrategy(Strategy, 'ldap') { return false; } - let sslKey, sslCert, sslCA; - - if (typeof configService.get('LDAP_SSL_KEY') === 'string') { - if (configService.get('LDAP_SSL_KEY')?.indexOf('-BEGIN') !== -1) { - sslKey = configService.get('LDAP_SSL_KEY'); - } else { - // Verify file exists - if (fs.statSync(configService.get('LDAP_SSL_KEY')!).isFile()) { - sslKey = fs.readFileSync(configService.get('LDAP_SSL_KEY')!); - } else { - throw new Error('SSL Key file does not exist'); - } - } - } - - if (typeof configService.get('LDAP_SSL_CERT') === 'string') { - if (configService.get('LDAP_SSL_CERT')?.indexOf('-BEGIN') !== -1) { - sslCert = configService.get('LDAP_SSL_CERT'); - } else { - // Verify file exists - if (fs.statSync(configService.get('LDAP_SSL_CERT')!).isFile()) { - sslCert = fs.readFileSync(configService.get('LDAP_SSL_CERT')!); - } else { - throw new Error('SSL Cert file does not exist'); - } - } - } - - if (typeof configService.get('LDAP_SSL_CA') === 'string') { - if (configService.get('LDAP_SSL_CA')?.indexOf('-BEGIN') !== -1) { - sslCA = configService.get('LDAP_SSL_CA'); - } else { - // Verify file exists - if (fs.statSync(configService.get('LDAP_SSL_CA')!).isFile()) { - sslCA = fs.readFileSync(configService.get('LDAP_SSL_CA')!); - } else { - throw new Error('SSL CA file does not exist'); - } - } + let sslCA: string | Buffer | undefined = configService.get('LDAP_SSL_CA'); + if ( + sslCA && + sslCA.indexOf('-BEGIN') === -1 && + fs.statSync(sslCA).isFile() + ) { + sslCA = fs.readFileSync(sslCA); + } else { + throw new Error('SSL CA file does not exist'); } return { rejectUnauthorized: configService.get('LDAP_SSL_INSECURE') && configService.get('LDAP_SSL_INSECURE')?.toLowerCase() !== 'true', - key: sslKey, - cert: sslCert, ca: sslCA }; } @@ -90,9 +58,7 @@ export class LDAPStrategy extends PassportStrategy(Strategy, 'ldap') { ...(sslConfig && { tlsOptions: { rejectUnauthorized: sslConfig.rejectUnauthorized, - ca: sslConfig.ca, - cert: sslConfig.cert, - key: sslConfig.key + ca: sslConfig.ca } }) }