08-ssl-fake-cacert.c 815 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <errno.h>
  2. #include <stdbool.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <mosquitto.h>
  6. static int run = -1;
  7. void on_connect(struct mosquitto *mosq, void *obj, int rc)
  8. {
  9. exit(1);
  10. }
  11. int main(int argc, char *argv[])
  12. {
  13. int rc;
  14. struct mosquitto *mosq;
  15. int port = atoi(argv[1]);
  16. mosquitto_lib_init();
  17. mosq = mosquitto_new("08-ssl-connect-crt-auth", true, NULL);
  18. if(mosq == NULL){
  19. return 1;
  20. }
  21. mosquitto_tls_set(mosq, "../ssl/test-fake-root-ca.crt", NULL, "../ssl/client.crt", "../ssl/client.key", NULL);
  22. mosquitto_connect_callback_set(mosq, on_connect);
  23. rc = mosquitto_connect(mosq, "localhost", port, 60);
  24. rc = mosquitto_loop_forever(mosq, -1, 1);
  25. mosquitto_destroy(mosq);
  26. mosquitto_lib_cleanup();
  27. if(rc == MOSQ_ERR_ERRNO && errno == EPROTO){
  28. return 0;
  29. }else{
  30. return 1;
  31. }
  32. }