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

IoT Core MQTT Sample - Error: self signed certificate #1563

Closed
prenna opened this issue Dec 7, 2019 · 6 comments
Closed

IoT Core MQTT Sample - Error: self signed certificate #1563

prenna opened this issue Dec 7, 2019 · 6 comments
Assignees
Labels
api: iot priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@prenna
Copy link

prenna commented Dec 7, 2019

Trying the mqtt example, but when I run and try to connect I get the following error through to client.on('error', error...

Message: Error: self signed certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1321:34)
    at TLSSocket.emit (events.js:210:5)
    at TLSSocket._finishInit (_tls_wrap.js:794:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:608:12)

I've generated a device key pair as per the docs, checked that the JWT is valid etc. I can't find any mention of this being an issue for anyone else anywhere. Please help.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Dec 8, 2019
@fhinkel fhinkel added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Dec 20, 2019
@fhinkel
Copy link
Contributor

fhinkel commented Dec 20, 2019

@gguuss Can you have a look at this IoT problem please. Thanks

@gguuss
Copy link
Contributor

gguuss commented Dec 21, 2019

Did you set the CA certificate configuration to a custom one at the registry level? I am not sure I have seen this error when using the default cert setup. Also are you using the LTS MQTT bridge or the mqtt.googleapis.com server? I believe the cert setup for each is different.

@gguuss
Copy link
Contributor

gguuss commented Jan 9, 2020

@prenna Let me know if checking whether you're using the root certificate matches the MQTT server you're using works.

@prenna
Copy link
Author

prenna commented Jan 14, 2020

Hi, sorry about the delay...

So, it turns out, I was trying to be too clever.

Since I'm using Typescript, I was getting told that secureProtocol does not exist in type 'IClientOptions' and decided I should try the only other property that did exist but wasn't being used ('protocolId' as below).

const connectionArgs: mqtt.IClientOptions = {
  host: mqttBridgeHostname,
  port: mqttBridgePort,
  clientId: mqttClientId,
  username: deviceId,
  password: createJWT(projectId, privateKeyFile, algorithm),
  protocol: 'mqtts',
  protocolId: 'TLSv1_2_method'
}

mqtt.connect(opts)

I changed 'protocolId' back to 'secureProtocol' and told typescript to ignore it and all is working as expected now.

As a side note

I feel like something is missing in the docs here: https://cloud.google.com/iot/docs/how-tos/mqtt-bridge#downloading_mqtt_server_certificates

At the end of the section 'Downloading MQTT server certificates' the sentence

After downloading Google root CA certificates to your device, you can configure an MQTT client to authenticate the device, connect to the MQTT server, and communicate over the MQTT bridge.

'configure an MQTT client to authenticate the device' is a link to a section on the page that doesn't exist.

There's nothing else in the documentation or in the code samples that explains or demonstrates what to do with the Google root CA certificate. Is it even needed?

@gguuss
Copy link
Contributor

gguuss commented Jan 15, 2020

The root certificate is needed to verify that the Google server "says who you think it is" but this check can be disabled.

@zoltanberkula
Copy link

zoltanberkula commented Sep 10, 2021

Hello I am facing kind of the same issue. I am trying to send telemetry data from a device up to the cloud using the gcic-mqtt client library. I have uploaded the keys (tried several types) but I got the same error back that says "Self signed certificate". I also tried to add CA certificate to the registry. Nothing seems to solve my issue. I am a beginner maybe I just flew above a trivial problem can somebody help me out? I would appreciate that.
#gpc #iotcore #nodeJS
pic

#1563

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: iot priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants