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

TLS Certificate Authentication Not Working #111

Open
fightinglawnornaments opened this issue Sep 28, 2019 · 1 comment
Open

TLS Certificate Authentication Not Working #111

fightinglawnornaments opened this issue Sep 28, 2019 · 1 comment

Comments

@fightinglawnornaments
Copy link

Problem:
I cannot connect to my Mosquitto broker when using TLS certificate authentication.

This connection issue only happens when using Mosquitto-PHP and using TLS certificate authentication. My CA certificate is stored in the same folder as my php file. The error I get is listed at the bottom of my post: the mosquitto broker outputs a 'Socket error on client' message. I have no problems connecting when I am just using username and password but NOT using TLS certificates. I have a different client on a completely different raspberryPi using python (python paho-mqtt, not using Mosquitto-PHP) that connects to my Mosquitto broker successfully using TLS certificate authentication. Therefore I don't believe the problem is with my Mosquitto broker, I believe the problem is with my code or with Mosquitto-PHP.I have been trying to solve this for about 2 weeks now. Any help would be greatly appreciated!

My code:
use Mosquitto\Client;
define('CLIENT_ID', "pubclient_" + getmypid());
$topic = 'myTestTopic';
$qos = 1;
$myusername = 'myTestUsername';
$mypassword = 'myTestPassword';
/* Construct a new client instance, passing a client ID of “MyClient” /
$client = new Mosquitto\Client(CLIENT_ID);
/
CA certificate is contained in a file /
$client->setTlsCertificates('/var/www/html/ca.crt');
$client->setCredentials($myusername,$mypassword);
$client->setTlsOptions(Mosquitto\Client::SSL_VERIFY_PEER,'tlsv1.2');
$client->setTlsInsecure(true);
$client->onMessage(function($message) {
/
Display the message's topic and payload */
echo $message->topic, "\n", $message->payload, "\n\n";
});
$client->connect('192.168.86.27', 1883);
$client->loop(2000);
$client->disconnect();

Mosquitto Log Output:
1569687780: New connection from 192.168.86.27 on port 1883.
1569687780: Socket error on client , disconnecting.

@digitalprecision
Copy link

I am having the same issue, when using TLS I am unable to connect, it just silently fails. I can connect with the same cert stack (root, cert, key) via mosquitto_pub but will not work when going through the php wrapper. Any help would be appreciated.

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

2 participants