Guest User

Untitled

a guest
Nov 29th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. 3068126320:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:1185:
  2. 3068126320:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed:s3_clnt.c:1185:
  3. Failed to connect, return code -1
  4.  
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "string.h"
  8. #include "MQTTClient.h"
  9. #define PAYLOAD "Hello World!"
  10. #define QOS 1
  11. #define TIMEOUT 10000L
  12. #define TOPIC1 "devices/Manoj_Test/messages/events/"
  13. #define ADDRESS "ssl://xxxxxxxx.azure-devices.net:8883"
  14. #define CLIENTID1 "Manoj_Test"
  15.  
  16. int main(void)
  17. {
  18. MQTTClient client;
  19. MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
  20. MQTTClient_message pubmsg = MQTTClient_message_initializer;
  21. MQTTClient_deliveryToken token;
  22. int rc1;
  23.  
  24. MQTTClient_create(&client, ADDRESS, CLIENTID1, 1, NULL);
  25. conn_opts.cleansession = 1;
  26. conn_opts.username = "xxxxxxxx.azure-devices.net/Manoj_Test";
  27. conn_opts.password = "SharedAccessSignature sr=xxxxxxxx.azure-devices.net%2fdevices%2fManoj_Test&sig=GyizT%2b7uyIpOkMJjTfN%2fpOZh9CnuQedNB%2bre2NrL1Kg%3d&se=1496395529";
  28.  
  29.  
  30. MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
  31.  
  32.  
  33. if ((rc1 = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
  34. {
  35. printf("Failed to connect, return code %dn", rc1);
  36. exit(-1);
  37. }
  38.  
  39. MQTTClient_subscribe(client, TOPIC, QOS);
  40. while(1)
  41. {
  42. pubmsg.payload = PAYLOAD;
  43. pubmsg.payloadlen = strlen(PAYLOAD);
  44. pubmsg.qos = 1;
  45. pubmsg.retained = 0;
  46. MQTTClient_publishMessage(client, TOPIC1, &pubmsg, &token);
  47. printf("Waiting for up to %d seconds for publication of %snon topic %s for client with ClientID: %sn", (int)(TIMEOUT/1000), PAYLOAD, TOPIC1, CLIENTID1);
  48. rc1 = MQTTClient_waitForCompletion(client, token, TIMEOUT);
  49. printf("Message with delivery token %d deliveredn", token);
  50. usleep(100000);
  51. }
  52. MQTTClient_disconnect(client, 10000);
  53. MQTTClient_destroy(&client);
  54. return rc1;
  55. }
  56.  
  57. openssl s_client -showcerts -connect server.edu:443 </dev/null 2>/dev/null|openssl x509 -outform DER >mycertfile.crt
  58.  
  59. update-ca-certificates
  60.  
  61. conn_opts.ssl->trustStore = "/etc/ssl/certs/ca-certificates.crt";
Add Comment
Please, Sign In to add comment