Skip to content

Cloud IoT: Not authorized to connect #1025

Closed

Description

@sdouche

Describe the issue

After generated keys with the script (/iot/api-client/generate_keys.sh), created a registry, a device (and pushed the content of the file rsa_cert.pem), and a subscription, I try to push MQTT messages with the code example given in the folder iot/api-client/manager. But I have got a Not authorized to connect error:

mvn exec:java Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
                        -Dexec.args="-project_id=myproject \
                                                -registry_id=myregistry \
                                                -device_id=mydevice \
                                                -private_key_file=../rsa_private_pkcs8 \
                                                -algorithm=RS256"
...

[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ cloudiot-manager-demo ---
An error occurred: Not authorized to connect
[WARNING] 
org.eclipse.paho.client.mqttv3.MqttSecurityException: Not authorized to connect
    at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException (ExceptionHelper.java:28)
    at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck (ClientState.java:988)
    at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run (CommsReceiver.java:145)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201 (ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)

It works with the Python and NodeJS example codes (with the right privacy key).

Did I do something wrong?

PS: Also tried the keys in the repository w/o success.

Thanks.

Activity

  1. gguuss commented on Feb 18, 2018

    @gguuss
    Contributor

    You're correctly using the pkcs8 key, because the Java sample is the only one that requires the pkcs8 key, this makes me guess it's the source of the issue. I just successfully tested registering a device with new keys using the Java manager and MQTT client. Maybe there's a bug with key expirations?

    PS: Also tried the keys in the repository w/o success.

    These keys are just used to build up the tests and should not be used for development.

    You might want to try deleting your keys and then re-creating them before registering your virtual device and connecting to the MQTT bridge. I'm invoking the sample as:

        java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
          com.example.cloud.iot.examples.DeviceRegistryExample \
          -project_id=<my-project-id> \
          -command=create-rsa \
          -rsa_certificate_file=../rsa_cert.pem \
          -pubsub_topic=none  \
          -device_id=<my-device-id> \
          -registry_name=<my-registry>
    
       mvn exec:java \
          -Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
          -Dexec.args="-project_id=<my-project-id> \
                         -registry_id=<my-registry> \
                         -device_id=<my-device-id> \
                         -private_key_file=../rsa_private_pkcs8 \
                         -algorithm=RS256"
    

    It's possible that the openssl defaults are setting an expiration date and your (old) keys have expired (e.g. missing -days xxxxx flag.

  2. gguuss commented on Feb 18, 2018

    @gguuss
    Contributor

    Also, which version of Java are you using? I'm currently testing with 1.8.

  3. sdouche commented on Feb 19, 2018

    @sdouche
    Author

    Hi @gguuss, thanks for your reply. As you would suggest, I tried to register the client with the code and got a region error. Bingo! That's the thing I forgot :(. With the cloud_region option, it works.

    Sorry.

  4. gguuss commented on Feb 20, 2018

    @gguuss
    Contributor

    @sdouche Feel free to file a feature request / issue to check the parameters and improve the README.

  5. added a commit that references this issue on Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions