Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031
00032 #include <curl/curl.h>
00033 #include <gnutls/gnutls.h>
00034
00035 static CURL *curl;
00036
00037 static size_t wrfu(void *ptr, size_t size, size_t nmemb, void *stream)
00038 {
00039 const struct curl_tlssessioninfo *info;
00040 unsigned int cert_list_size;
00041 const gnutls_datum_t *chainp;
00042 CURLcode res;
00043
00044 (void)stream;
00045 (void)ptr;
00046
00047 res = curl_easy_getinfo(curl, CURLINFO_TLS_SESSION, &info);
00048
00049 if(!res) {
00050 switch(info->backend) {
00051 case CURLSSLBACKEND_GNUTLS:
00052
00053 chainp = gnutls_certificate_get_peers(info->internals, &cert_list_size);
00054 if((chainp) && (cert_list_size)) {
00055 unsigned int i;
00056
00057 for(i = 0; i < cert_list_size; i++) {
00058 gnutls_x509_crt_t cert;
00059 gnutls_datum_t dn;
00060
00061 if(GNUTLS_E_SUCCESS == gnutls_x509_crt_init(&cert)) {
00062 if(GNUTLS_E_SUCCESS ==
00063 gnutls_x509_crt_import(cert, &chainp[i], GNUTLS_X509_FMT_DER)) {
00064 if(GNUTLS_E_SUCCESS ==
00065 gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_FULL, &dn)) {
00066 fprintf(stderr, "Certificate #%d: %.*s", i, dn.size, dn.data);
00067
00068 gnutls_free(dn.data);
00069 }
00070 }
00071
00072 gnutls_x509_crt_deinit(cert);
00073 }
00074 }
00075 }
00076 break;
00077 case CURLSSLBACKEND_NONE:
00078 default:
00079 break;
00080 }
00081 }
00082
00083 return size * nmemb;
00084 }
00085
00086 int main(void)
00087 {
00088 curl_global_init(CURL_GLOBAL_DEFAULT);
00089
00090 curl = curl_easy_init();
00091 if(curl) {
00092 curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
00093
00094 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wrfu);
00095
00096 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
00097 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
00098
00099 curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
00100
00101 (void) curl_easy_perform(curl);
00102
00103 curl_easy_cleanup(curl);
00104 }
00105
00106 curl_global_cleanup();
00107
00108 return 0;
00109 }