lundi 30 mars 2015

Mosquitto security error: OpenSSL Error: routines:SSL3_GET_RECORD:wrong version number

I'm trying to store MQTT payloads in a MongoDB database using NodeJS. When I run my code I get the following error popped up at the Mosquitto server:



1427756032: Socket error on client <unknown>, disconnecting.
1427756033: New connection from 146.175.138.141 on port 8883.
1427756033: OpenSSL Error: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number


I'm not the only one facing this error but the proposed solutions on google won't work for me.


I'm working in a Ubuntu14.04 TLS (trusty) server environment. The version of OpenSSL which I used to make my own keys and certificates is:



OpenSSL 1.0.1f 6 Jan 2014


For making these keys I followed the manual of Mosquitto.


The version of nodejs is:



v0.10.25


The configuration file of mosquitto:



port 8883
cafile /etc/keys/ca.crt
certfile /etc/keys/server.crt
keyfile /etc/keys/server.key
tls_version tlsv1
require_certificate true


The nodejs file:



var mqtt=require('mqtt')
var mongodbClient=require('mongodb').MongoClient;
var deviceRoot="demo/device/"
var mqtthost = '146.175.138.141';
var KEY = '/etc/keys/client.key';
var CERT = '/etc/keys/client.crt';
var CAfile = '/etc/keys/ca.crt';

var options = {
host: mqtthost,
port: 8883,
protocolId: 'MQIsdp',
ca: CAfile,
keyPath: KEY,
certPath: CERT,
secureProtocol: 'TLSv1_method',
protocolId: 'MQIsdp',
protocolVersion: 3
};

var collection,client;

mongodbClient.connect("mongodb://localhost:27017/exampleDb", function(err,db){
if(err){return console.dir(err);}

collection=db.collection("test_mqtt");

client=mqtt.connect(options);

client.subscribe("#");
client.publish(deviceRoot, '21');

client.on('message', function(topic,payload){
str = payload.toString();
console.log(str);
var key=topic.replace(deviceRoot,'');

collection.update(
{ _id:key },
{ $push: { events: { event: { value:str, when:new Date() } } } },
{ upsert:true }
)})})


The keys should be working because publishing with the following command is not a problem:



mosquitto_pub -h 146.175.138.141 -p 8883 -t Server -m helloworld --cafile /etc/keys/ca.crt --cert /etc/keys/client.crt --key /etc/keys/client.key --tls-version tlsv1


Any idea what I'm doing wrong?


Aucun commentaire:

Enregistrer un commentaire