I'm attempting to connect to an Active Directory domain controller to make some basic LDAP queries using JavaScript. I'm using the LDAPJS library and the built-in node tls module. I'm getting an error when attempting to run client.bind
The TLS connection seems to be working fine (it's coming back as authorized===true, though on the secureConnect event, I'm getting undefined.
The related code and output is below:
var tlsOptions = {
host: "my.domain.controller.net",
port: portNumber,
ca: fs.readFileSync("C:\\myCA.pem"),
};
var server = tls.connect(tlsOptions, function () {
console.log(
"Server connected",
server.authorized ? "and authorized" : "but UNAUTHORIZED"
);
if (server.authorized) {
var client = ldap.createClient({
url: "ldaps://domiancontroler",
tlsOptions: tlsOptions,
});
console.log("Client created!")
client.bind(userDN, userPW, function (err) {
console.log("Client binding error:", err)
process.exit()
});
}
});
server.setEncoding("utf8");
server.on("data", function (data) {
console.log("server data callback: ", data);
});
server.on("secureConnect", function (data) {
console.log("server secureConnect callback: ", data);
});
server.on("error", function (error) {
console.log("server error callback", error);
});
Produces the following output:
> Server connected and authorized
> Client created!
> server secureConnect callback: undefined
> Client binding error: null
Related
MQTT.createClient({
uri: 'mqtts://there is a host:8883',
clientId: '',
protocol: 'mqtts'
}).then(function (client) {
client.on('closed', function () {
console.log('mqtt.event.closed');
});
client.on('error', function (msg) {
console.log('mqtt.event.error', msg);
});
client.on('message', function (msg) {
console.log('mqtt.event.message', msg);
});
client.on('connect', (msg) => {
msg.reconnect = true
console.log('connected');
client.subscribe("here was a topic", 0);
})
client.connect((input) => {
console.log('adjisioudjjh', input);
});
}).catch(function (err) {
console.log('error is from here', err);
});
}
i am trying to build mqtts connection for a secured connection with server and i got this error, can't build connection, how to and where to upload private key, CA certificate, and also this library(sp-react-native-mqtt) doesn't support any type of certificate, please help me to find a library for this
I built a Socket.io server which handle connection and event :
import { createServer } from "http";
import { Server } from "socket.io";
const httpServer = createServer();
const io = new Server(httpServer);
io.on("connection", (socket) => {
console.log('New connection');
socket.on('join', data => {
console.log(data);
});
...
});
I'm trying to built a Socker.io client using npm module socket.io-client
import { io } from 'socket.io-client';
const socket = io(servHost);
socket.on('connect', () => {
console.log(`Connected : ${socket.id}`);
socket.emit('join', "Some data");
socket.emit('otherEvent');
});
socket.on('disconnect', (err) => {
console.log(err);
console.log("Disconnected");
});
Server log :
New connection
New connection
...
Client log :
Connected : IyR4Gr0Gvao16UD6AAAD
parse error
Disconnected
Connected : m8aSe6HI67i6VIBNAAAF
parse error
Disconnected
...
Note : If I comment socket.emit('join', "Some data"); everything works fine, even the otherEvent is emited and client can handle the expected event in return (not shown on the code). So I guess the error comes from the data inside join event.
some data can be string / array or object (I tried everything) I have the same error.
I'm using :
"socket.io": "^4.5.2",
"socket.io-client": "^4.5.2"
Looks like .emit() expects object as 2nd argument.
I had exactly the same issue, fixed by passing an object:
socket.emit('join', {text: "Some data"});
I need to make a websocket connection to a wss address (a secure websocket connection). When I run the program I get Connect Error: Error: unable to verify the first certificate. Is there some way to set ssl certificates for the client so that I do not see this error?
Code:
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function (error)
{
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function (connection)
{
console.log('WebSocket Client Connected');
connection.on('error', function (error)
{
console.log("Connection Error2: " + error.toString());
});
});
client.connect('wss://dev-api.dev2.test.com:4900/ws/v1/4/Data/Value', 'echo-protocol');
I have a two webservers both running https with the same certificates, I have a main shard that the user connects to example.com, they retrieve some data and try to connect to an ip address on the 2nd shard via websocket.
But no matter what I configure I get an Error 1006 on the client side when connecting to the 2nd shard. Firefox devtooling gives me multiple errors - ssl_error_bad_cert_domain, SSL_ERROR_RX_RECORD_TOO_LONG.
The certificates are issued and signed, I was wondering where I should go from here. Thanks :)
SHARD2
const options = {
key: './server.key',
cert: './server.cert'
};
var https = require('https').Server(options);
https.listen(443, function () {
// console.log('Https listening on *: 443');
});
let WebSocket = require('ws');
let socket = new WebSocket.Server({ server:https });
socket.on('connection', function (ws, req) {
ws.on('message', (msgRaw) =>{
});
ws.on('close', function(code, reason) {
});
ws.on('error', function(error) {
console.log(error);
ws.close();
});
});
CLIENT
function connect() {
"use strict";
window.WebSocket = window.WebSocket || window.MozWebSocket;
if (!window.WebSocket) {
alert('Your browser doesn\'t support WebSocket');
return;
}
wss = new WebSocket('wss://123.123.123.120/:443');
wss.onmessage = function(event) {
};
wss.onerror = function(event) {
console.log(`wss error: ${JSON.stringify(event)}`);
};
wss.onclose = function(event) {
};
}
Useful sys diagram?
var app = require('http').createServer(handler);
var Rcon = require('rcon');
var url = require('url');
app.listen(7777);
console.log('Server started.');
function handler (req, res) {
console.log('New connection!');
res.writeHead(200);
var urlParts = url.parse(req.url, true);
var server = urlParts.query;
var conn = new Rcon(server.ip, server.port, server.password);
conn.on('auth', function() {
conn.send(server.command);
console.log('Sent command!');
}).on('response', function(data) {
res.end(data);
console.log('Response: '+data);
}).on('error', function(data) {
res.end('error');
console.log('Error: '+data);
}).on('err', function(data) {
res.end('error');
console.log('Error: '+data);
});
conn.connect();
}
All of that works perfectly on localhost but when I upload to a remote server and run it, it responds with error in browser and with this in the console:
Server started. New connection! Error: TypeError: Object 0�P�q has no
method 'writeInt32LE' New connection! Error: Error: EINVAL, Invalid
argument
First guess: rcon module contains compiled extensions and you checked the files of node_modules/rcon into git and then tried to run them on a different CPU architecture. You need to run npm rebuild on the remote server for a quick fix and to get your node_modules folder out of your git repository as the correct long-term fix.