ldapjs / node-ldapjs

LDAP Client and Server API for node.js
http://ldapjs.org
MIT License
1.61k stars 448 forks source link

Assistance Needed with LDAPS Connection to Windows Server 2012 R2 AD #975

Closed WanpengQian closed 7 months ago

WanpengQian commented 7 months ago

I am reaching out for assistance regarding my efforts to establish an LDAPS connection to a Windows Server 2012 R2 environment using ldapjs. From my understanding, when modifying the password field in Active Directory, LDAPS connection is required instead of LDAP.

I have encountered some difficulties when attempting to connect to the Windows Server 2012 using LDAPS. The server is utilizing a self-signed certificate and has been configured correctly. I am able to connect to the server using LDAPS without any issues via Softerra LDAP Browser.

Below is a snippet of the code I am currently testing:

const ldap = require('ldapjs');

const dn = "CN=xxx,CN=Users,DC=xx,DC=xx,DC=xx";
const password = "xxxxxxxxxx";
const url = "ldaps://192.168.2.200:636";
//const url = "ldap://192.168.2.200:389";

var client = ldap.createClient({
  url: url,
  tlsOptions: {
    rejectUnauthorized: false,
    ca: ["ADCERT.cer"]
  }
});

client.bind(dn, password, (err) => {
  if (err) {
    console.error(err)
    throw err;
  } 
  client.unbind();
});

However, executing this code results in the following error:

Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}
/home/user/repo/ldapauth/index.js:19
    throw err;
    ^

Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}

Node.js v18.19.0

I can confirm that LDAP connection works perfectly fine. I'm running Node.js v18.19.0. Your insights and assistance in resolving this issue would be greatly appreciated. Thank you.

WanpengQian commented 7 months ago

I installed a fresh Windows Server 2022 instance for further comparison. It works fine compared to Windows Server 2012 R2.

Therefore, there seems to be a compatibility issue with Windows Server 2012 R2.

jsumners commented 7 months ago

Closing as not an issue with ldapjs.