48_sslexample.c 819 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <curl/curl.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #define URL "https://example.com"
  5. size_t nop(void *ptr, size_t size, size_t nmemb, void *unused)
  6. {
  7. return size * nmemb;
  8. }
  9. int main()
  10. {
  11. printf("Loading " URL "\n");
  12. CURL *curl = curl_easy_init();
  13. curl_easy_setopt(curl, CURLOPT_URL, URL);
  14. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nop);
  15. curl_easy_setopt(curl, CURLOPT_CERTINFO, 1);
  16. curl_easy_perform(curl);
  17. struct curl_certinfo *certinfo;
  18. curl_easy_getinfo(curl, CURLINFO_CERTINFO, &certinfo);
  19. if (certinfo)
  20. {
  21. for (int i = 0; i < certinfo->num_of_certs; i++)
  22. {
  23. struct curl_slist *slist;
  24. for (slist = certinfo->certinfo[i]; slist; slist = slist->next)
  25. printf("%s\n", slist->data);
  26. }
  27. }
  28. else
  29. printf("Error loading SSL information\n");
  30. curl_easy_cleanup(curl);
  31. return 0;
  32. }