certinfo.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 /* <DESC>
00023  * Extract lots of TLS certificate info.
00024  * </DESC>
00025  */
00026 #include <stdio.h>
00027 
00028 #include <curl/curl.h>
00029 
00030 static size_t wrfu(void *ptr,  size_t  size,  size_t  nmemb,  void *stream)
00031 {
00032   (void)stream;
00033   (void)ptr;
00034   return size * nmemb;
00035 }
00036 
00037 int main(void)
00038 {
00039   CURL *curl;
00040   CURLcode res;
00041 
00042   curl_global_init(CURL_GLOBAL_DEFAULT);
00043 
00044   curl = curl_easy_init();
00045   if(curl) {
00046     curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
00047 
00048     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);
00049 
00050     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
00051     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
00052 
00053     curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
00054     curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
00055 
00056     res = curl_easy_perform(curl);
00057 
00058     if(!res) {
00059       union {
00060         struct curl_slist    *to_info;
00061         struct curl_certinfo *to_certinfo;
00062       } ptr;
00063 
00064       ptr.to_info = NULL;
00065 
00066       res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ptr.to_info);
00067 
00068       if(!res && ptr.to_info) {
00069         int i;
00070 
00071         printf("%d certs!\n", ptr.to_certinfo->num_of_certs);
00072 
00073         for(i = 0; i < ptr.to_certinfo->num_of_certs; i++) {
00074           struct curl_slist *slist;
00075 
00076           for(slist = ptr.to_certinfo->certinfo[i]; slist; slist = slist->next)
00077             printf("%s\n", slist->data);
00078 
00079         }
00080       }
00081 
00082     }
00083 
00084     curl_easy_cleanup(curl);
00085   }
00086 
00087   curl_global_cleanup();
00088 
00089   return 0;
00090 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02