node-ldapjs
node-ldapjs copied to clipboard
Error [InvalidAsn1Error]: Expected 0x2: got 0x3
I am trying to create a client to connect my company's ldap. However, I receive an error
jse_shortmsg: 'Parser error for 1__ldap://company:port', jse_cause: Error [InvalidAsn1Error]: Expected 0x2: got 0x3
My code:
const ldap = require("ldapjs");
const client = ldap.createClient({
url : 'ldap://company:port',
});
client.on("error", (err) => {
console.log("Client experienced an error: ", err);
});
async function searchUserbyUID(uid) {
try{
var opts ={
filter: `(uid=${uid})`,
scope: 'sub',
attributes: ['dn', 'sn', 'cn']
}
client.search("o=company", opts, (res) => {
return res;
});
} catch (Exception) {
console.log(Exception)
}
}
The full traceback:
VError: Parser error for 1__ldap://company:port: Expected 0x2: got 0x3
at Parser.onParseError (/dir/node_modules/ldapjs/lib/client/client.js:888:26)
at Parser.emit (node:events:378:20)
at Parser.write (/dir/node_modules/ldapjs/lib/messages/parser.js:103:10)
at Socket.onData (/dir/node_modules/ldapjs/lib/client/client.js:871:22)
at Socket.emit (node:events:378:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
jse_shortmsg: 'Parser error for 1__ldap://company:port',
jse_cause: Error [InvalidAsn1Error]: Expected 0x2: got 0x3
at newInvalidAsn1Error (/dir/node_modules/asn1/lib/ber/errors.js:7:13)
at Reader._readTag (/dir/node_modules/asn1/lib/ber/reader.js:230:11)
at Reader.readInt (/dir/node_modules/asn1/lib/ber/reader.js:146:15)
at Parser.getMessage (/dir/node_modules/ldapjs/lib/messages/parser.js:116:25)
at Parser.write (/dir/node_modules/ldapjs/lib/messages/parser.js:96:20)
at Socket.onData (/dir/node_modules/ldapjs/lib/client/client.js:871:22)
at Socket.emit (node:events:378:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10),
jse_info: {}
}
I'm not 100% sure but I think the error is saying that it expected an int and received a bit string. This might be an issue with the server.
I think you're showing that the error is happening during the searchUserbyUID
invocation. So I agree with @UziTech. This looks like your server returning an unexpected ASN.1 message. Which means ldapjs
is operating as it should by providing you with the error.
Commenting out this function and just creating the client connection, I receive this same traceback on error.
Unfortunately, without a way to reproduce it all we can do is guess at things.
Have you enabled trace logging? https://github.com/ldapjs/node-ldapjs/blob/1570e049526fffc47df00615ce48860cf3da77b3/docs/client.md#note-on-logger
Have you tried stepping through it with the debugger and inspecting the messages/processing?
Unfortunately, without a way to reproduce it all we can do is guess at things.
Have you enabled trace logging? https://github.com/ldapjs/node-ldapjs/blob/1570e049526fffc47df00615ce48860cf3da77b3/docs/client.md#note-on-logger
Have you tried stepping through it with the debugger and inspecting the messages/processing?
What type of information should I be looking for when I inspect through my debugger?
🤷♂️
@ajay340 did you solve this problem?
👋
On February 22, 2023, we released version 3 of this library. As a result, we are closing this issue/pull request.
Please see issue #839 for more information, including how to proceed if you feel this closure is in error.