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 #include <stdio.h>
00027
00028 #include <curl/curl.h>
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 int main(void)
00049 {
00050 CURL *curl;
00051 CURLcode res;
00052 FILE *headerfile;
00053 const char *pPassphrase = NULL;
00054
00055 static const char *pCertFile = "testcert.pem";
00056 static const char *pCACertFile="cacert.pem";
00057 static const char *pHeaderFile = "dumpit";
00058
00059 const char *pKeyName;
00060 const char *pKeyType;
00061
00062 const char *pEngine;
00063
00064 #ifdef USE_ENGINE
00065 pKeyName = "rsa_test";
00066 pKeyType = "ENG";
00067 pEngine = "chil";
00068 #else
00069 pKeyName = "testkey.pem";
00070 pKeyType = "PEM";
00071 pEngine = NULL;
00072 #endif
00073
00074 headerfile = fopen(pHeaderFile, "wb");
00075
00076 curl_global_init(CURL_GLOBAL_DEFAULT);
00077
00078 curl = curl_easy_init();
00079 if(curl) {
00080
00081 curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site");
00082 curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile);
00083
00084 do {
00085 if(pEngine) {
00086
00087 if(curl_easy_setopt(curl, CURLOPT_SSLENGINE, pEngine) != CURLE_OK) {
00088
00089 fprintf(stderr, "can't set crypto engine\n");
00090 break;
00091 }
00092 if(curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK) {
00093
00094
00095
00096 fprintf(stderr, "can't set crypto engine as default\n");
00097 break;
00098 }
00099 }
00100
00101
00102 curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");
00103
00104
00105 curl_easy_setopt(curl, CURLOPT_SSLCERT, pCertFile);
00106
00107
00108
00109 if(pPassphrase)
00110 curl_easy_setopt(curl, CURLOPT_KEYPASSWD, pPassphrase);
00111
00112
00113
00114 curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, pKeyType);
00115
00116
00117 curl_easy_setopt(curl, CURLOPT_SSLKEY, pKeyName);
00118
00119
00120 curl_easy_setopt(curl, CURLOPT_CAINFO, pCACertFile);
00121
00122
00123 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
00124
00125
00126 res = curl_easy_perform(curl);
00127
00128 if(res != CURLE_OK)
00129 fprintf(stderr, "curl_easy_perform() failed: %s\n",
00130 curl_easy_strerror(res));
00131
00132
00133 } while(0);
00134
00135 curl_easy_cleanup(curl);
00136 }
00137
00138 curl_global_cleanup();
00139
00140 return 0;
00141 }