Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is it possible to use client certificate for authentication in paho-mqtt javascript client? #187

Open
bharanidharan81 opened this issue Jan 17, 2019 · 8 comments

Comments

@bharanidharan81
Copy link

bharanidharan81 commented Jan 17, 2019

From the application point of view, you will have only one option (set useSSL to true). Then Paho JavaScript client will establish a secure websocket connection (i.e. wss://) .
For two authentication, client requires a certificate to establish the connection.

Is it possible to use client authentication with a certificate instead of username/password with the Paho javascript client ? If so, how? please share the tutorials and documentation to proceed.

@bharanidharan81 bharanidharan81 changed the title Is it possible to use client authentication with a certificate with the Paho javascript client? Is it possible to use client certificate for authentication with the Paho javascript client? Jan 17, 2019
@bharanidharan81 bharanidharan81 changed the title Is it possible to use client certificate for authentication with the Paho javascript client? Is it possible to use client certificate for authentication in paho-mqtt javascript client? Jan 23, 2019
@bharanidharan81 bharanidharan81 changed the title Is it possible to use client certificate for authentication in paho-mqtt javascript client? Question: Is it possible to use client certificate for authentication in paho-mqtt javascript client? Jan 23, 2019
@acervantess
Copy link

x2

@KateJC
Copy link

KateJC commented Sep 23, 2019

I have the same question

@gathasite
Copy link

@bharanidharan81 Any update on this issue? Have you found the solution??
Is there anyone who has a solution as I'm also looking for the same.

@nijisakai
Copy link

looking for the solution

@nijisakai
Copy link

nijisakai commented Mar 4, 2020

I solved it by using browserMqtt.js
based on MQTT.js
https://www.npmjs.com/package/mqtt

I got the browserMqtt.js by these steps:

npm install mqtt --save
npm install -g browserify
npm install -g webpack-cli
npm install -g webpack@4
cd node_modules/mqtt
npm install . 
browserify mqtt.js -s mqtt > browserMqtt.js
webpack mqtt.js ./browserMqtt.js --output-library mqtt

the server side is using mosquitto
the client side config using cert file is

<script src="./browserMqtt.js"></script>
<script>
            // var KEY = '/var/www/html/test02/client-key.key';
            // var CERT = '/var/www/html/test02/client-cert.crt';
            // var TRUSTED_CA_LIST = '/var/www/html/test02/cacert.crt';
            // var PORT = '8883';
            // var HOST = '159.210.65.6';
            var options = {
                port: '8081',
                host: '159.210.65.6',
                keyPath: '/var/www/html/test02/client-key.pem',
                certPath: '/var/www/html/test02/client-cert.pem',
                rejectUnauthorized : false, 
                //The CA list will be used to determine if server is authorized
                ca: ['/var/www/html/test02/cacert.pem'],
                protocol: 'wss',
                protocolId: 'MQTT',
                // username: 'qqq',
                // password: 'bbb',
                clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8)
            };

            var client = mqtt.connect(options);

            client.subscribe('messages');
            client.publish('messages', 'Current time is: ' + new Date());
            client.on('message', function(topic, message) {
            console.log(message);
            });

            client.on('connect', function(){
                console.log('Connected');
            });    
                    
</script>

@KrifaYounes
Copy link

From the application point of view, you will have only one option (set useSSL to true). Then Paho JavaScript client will establish a secure websocket connection (i.e. wss://) .
For two authentication, client requires a certificate to establish the connection.

Is it possible to use client authentication with a certificate instead of username/password with the Paho javascript client ? If so, how? please share the tutorials and documentation to proceed.

have found a response ?
I try to establish connection with client certificate in react native app

@aravindarc
Copy link

I solved it by using browserMqtt.js
based on MQTT.js
https://www.npmjs.com/package/mqtt

I got the browserMqtt.js by these steps:

npm install mqtt --save
npm install -g browserify
npm install -g webpack-cli
npm install -g webpack@4
cd node_modules/mqtt
npm install . 
browserify mqtt.js -s mqtt > browserMqtt.js
webpack mqtt.js ./browserMqtt.js --output-library mqtt

the server side is using mosquitto
the client side config using cert file is

<script src="./browserMqtt.js"></script>
<script>
            // var KEY = '/var/www/html/test02/client-key.key';
            // var CERT = '/var/www/html/test02/client-cert.crt';
            // var TRUSTED_CA_LIST = '/var/www/html/test02/cacert.crt';
            // var PORT = '8883';
            // var HOST = '159.210.65.6';
            var options = {
                port: '8081',
                host: '159.210.65.6',
                keyPath: '/var/www/html/test02/client-key.pem',
                certPath: '/var/www/html/test02/client-cert.pem',
                rejectUnauthorized : false, 
                //The CA list will be used to determine if server is authorized
                ca: ['/var/www/html/test02/cacert.pem'],
                protocol: 'wss',
                protocolId: 'MQTT',
                // username: 'qqq',
                // password: 'bbb',
                clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8)
            };

            var client = mqtt.connect(options);

            client.subscribe('messages');
            client.publish('messages', 'Current time is: ' + new Date());
            client.on('message', function(topic, message) {
            console.log(message);
            });

            client.on('connect', function(){
                console.log('Connected');
            });    
                    
</script>

@nijisakai is this working, can we use this

@nijisakai
Copy link

I solved it by using browserMqtt.js
based on MQTT.js
https://www.npmjs.com/package/mqtt
I got the browserMqtt.js by these steps:

npm install mqtt --save
npm install -g browserify
npm install -g webpack-cli
npm install -g webpack@4
cd node_modules/mqtt
npm install . 
browserify mqtt.js -s mqtt > browserMqtt.js
webpack mqtt.js ./browserMqtt.js --output-library mqtt

the server side is using mosquitto
the client side config using cert file is

<script src="./browserMqtt.js"></script>
<script>
            // var KEY = '/var/www/html/test02/client-key.key';
            // var CERT = '/var/www/html/test02/client-cert.crt';
            // var TRUSTED_CA_LIST = '/var/www/html/test02/cacert.crt';
            // var PORT = '8883';
            // var HOST = '159.210.65.6';
            var options = {
                port: '8081',
                host: '159.210.65.6',
                keyPath: '/var/www/html/test02/client-key.pem',
                certPath: '/var/www/html/test02/client-cert.pem',
                rejectUnauthorized : false, 
                //The CA list will be used to determine if server is authorized
                ca: ['/var/www/html/test02/cacert.pem'],
                protocol: 'wss',
                protocolId: 'MQTT',
                // username: 'qqq',
                // password: 'bbb',
                clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8)
            };

            var client = mqtt.connect(options);

            client.subscribe('messages');
            client.publish('messages', 'Current time is: ' + new Date());
            client.on('message', function(topic, message) {
            console.log(message);
            });

            client.on('connect', function(){
                console.log('Connected');
            });    
                    
</script>

@nijisakai is this working, can we use this

It works fine with my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants