Last active
July 9, 2020 14:38
-
-
Save b4ldr/7e31bddcf108fc622d613d75692043cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <curl/curl.h> | |
#include <openssl/crypto.h> | |
#include <openssl/x509.h> | |
#include <openssl/pem.h> | |
#include <openssl/ssl.h> | |
#include <openssl/err.h> | |
CURLcode cas_curl_ssl_ctx(CURL *curl, void *sslctx, void *parm) | |
{ | |
SSL_CTX *ctx = (SSL_CTX *) sslctx; | |
// the following causes a segfault | |
SSL_CTX_set_verify_depth(ctx, 3); | |
return CURLE_OK; | |
} | |
int main(void) { | |
CURL *curl; | |
CURLcode res; | |
char curlError[CURL_ERROR_SIZE]; | |
curl = curl_easy_init(); | |
if(curl) { | |
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L); | |
curl_easy_setopt(curl, CURLOPT_HEADER, 0L); | |
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); | |
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); | |
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlError); | |
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); | |
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L); | |
curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, cas_curl_ssl_ctx); | |
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L); | |
curl_easy_setopt(curl, CURLOPT_CAPATH, "/etc/ssl/certs"); | |
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); | |
curl_easy_setopt(curl, CURLOPT_USERAGENT, "mod_auth_cas 1.0.10"); | |
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); | |
curl_easy_setopt(curl, CURLOPT_URL, "https://idp.wikimedia.org/serviceValidate"); | |
res = curl_easy_perform(curl); | |
if(res != CURLE_OK) | |
fprintf(stderr, "curl_easy_perform() failed: %s\n", | |
curl_easy_strerror(res)); | |
curl_easy_cleanup(curl); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment