From 24836d30f516976b5f11a7e5a34a14cbbf67eb66 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 3 Oct 2003 13:46:27 +0000 Subject: Peter Sylvester's curlx.c code example added --- docs/examples/curlx.c | 480 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 480 insertions(+) create mode 100644 docs/examples/curlx.c (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c new file mode 100644 index 000000000..c5aabd344 --- /dev/null +++ b/docs/examples/curlx.c @@ -0,0 +1,480 @@ +/* + curlx.c Authors: Peter Sylvester, Jean-Paul Merlin + + This is a little program to demonstrate the usage of + + - an ssl initialisation callback setting a user key and trustbases + coming from a pkcs12 file + - using an ssl application callback to find a URI in the + certificate presented during ssl session establishment. + +*/ + + +/* + * Copyright (c) 2003 The OpenEvidence Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, the following disclaimer, + * and the original OpenSSL and SSLeay Licences below. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, the following disclaimer + * and the original OpenSSL and SSLeay Licences below in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgments: + * "This product includes software developed by the Openevidence Project + * for use in the OpenEvidence Toolkit. (http://www.openevidence.org/)" + * This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com)." + * + * 4. The names "OpenEvidence Toolkit" and "OpenEvidence Project" must not be + * used to endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openevidence-core@openevidence.org. + * + * 5. Products derived from this software may not be called "OpenEvidence" + * nor may "OpenEvidence" appear in their names without prior written + * permission of the OpenEvidence Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgments: + * "This product includes software developed by the OpenEvidence Project + * for use in the OpenEvidence Toolkit (http://www.openevidence.org/) + * This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com)." + * + * THIS SOFTWARE IS PROVIDED BY THE OpenEvidence PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenEvidence PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/) + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char *curlx_usage[]={ +"usage: curlx args\n", +" -p12 arg - tia file ", +" -envpass arg - environement variable which content the tia private key password", +" -out arg - output file (response)- default stdout", +" -in arg - input file (request)- default stdin", +" -connect arg - URL of the server for the connection ex: www.openevidenve.org", +" -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", +" -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", +" -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", +NULL +}; + +/* + + ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS + -mimetype application/dvcs -acceptmime application/dvcs -out response + +*/ + +/* This is a context that we pass to all callbacks */ + +typedef struct sslctxparm_st { + unsigned char * p12file ; + const char * pst ; + PKCS12 * p12 ; + EVP_PKEY * pkey ; + X509 * usercert ; + STACK_OF(X509) * ca ; + CURL * curl; + BIO * errorbio; + int accesstype ; + int verbose; + +} sslctxparm; + +/* some helper function. */ + +static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) +{ + char *tmp; + if(!ia5 || !ia5->length) return NULL; + tmp = OPENSSL_malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; +} + +/* A conveniance routine to get an access URI. */ + +static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) { + + int i; + STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; + accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; + + if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; + for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { + ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); + if (OBJ_obj2nid(ad->method) == type) { + if (ad->location->type == GEN_URI) { + return i2s_ASN1_IA5STRING(ad->location->d.ia5); + } + return NULL; + } + } + return NULL; +} + +/* This is an application verification call back, it does not + perform any addition verification but tries to find a URL + in the presented certificat. If found, this will become + the URL to be used in the POST. +*/ + +static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) { + sslctxparm * p = (sslctxparm *) arg; + int ok; + + if (p->verbose > 2) BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); + if ((ok= X509_verify_cert(ctx)) && ctx->cert) { + unsigned char * accessinfo ; + if (p->verbose > 1) X509_print_ex(p->errorbio,ctx->cert,0,0); + if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { + if (p->verbose) BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n",accessinfo); + curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + } else if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_info_access)) { + if (p->verbose) BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n",accessinfo); + curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + } + } + if (p->verbose > 2) BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n",ok); + return(ok); +} + + +/* This is an example of an curl SSL initialisation call back. The callback sets: + - a private key and certificate + - a trusted ca certificate + - a preferred cipherlist + - an application verification callback (the function above) +*/ + +static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { + + sslctxparm * p = (sslctxparm *) parm; + SSL_CTX * ctx = (SSL_CTX *) sslctx ; + + if (!SSL_CTX_use_certificate(ctx,p->usercert)) { + BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; + } + if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { + BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; + } + + if (!SSL_CTX_check_private_key(ctx)) { + BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; + } + + SSL_CTX_set_quiet_shutdown(ctx,1); + SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); + SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); + + X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca,sk_X509_num(p->ca)-1)); + + SSL_CTX_set_verify_depth(ctx,2); + + SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); + + SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); + + + return CURLE_OK ; +err: + ERR_print_errors(p->errorbio); + return CURLE_SSL_CERTPROBLEM; + +} + +int main(int argc, char **argv) { + + BIO* in=NULL; + BIO* out=NULL; + + + char * outfile = NULL; + char * infile = NULL ; + + int tabLength=100; + char *binaryptr; + char* mimetype; + char* mimetypeaccept=NULL; + char* contenttype; + char** pp; + unsigned char* hostporturl = NULL; + binaryptr=(char*)malloc(tabLength); + BIO * p12bio ; + char **args = argv + 1; + unsigned char * serverurl; + sslctxparm p; + char *response; + p.verbose = 0; + + CURLcode res; + struct curl_slist * headers=NULL; + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + curl_global_init(CURL_GLOBAL_DEFAULT); + +/* we need some more for the P12 decoding */ + + OpenSSL_add_all_ciphers(); + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + + + int badarg=0; + + while (*args && *args[0] == '-') { + if (!strcmp (*args, "-in")) { + if (args[1]) { + infile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + outfile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-p12")) { + if (args[1]) { + p.p12file = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-envpass") == 0) { + if (args[1]) { + p.pst = getenv(*(++args)); + } else badarg=1; + } else if (strcmp(*args,"-connect") == 0) { + if (args[1]) { + hostporturl = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-mimetype") == 0) { + if (args[1]) { + mimetype = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-acceptmime") == 0) { + if (args[1]) { + mimetypeaccept = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-accesstype") == 0) { + if (args[1]) { + if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; + } else badarg=1; + } else if (strcmp(*args,"-verbose") == 0) { + p.verbose++; + } else badarg=1; + args++; + } + + if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; + + if (badarg) { + for (pp=curlx_usage; (*pp != NULL); pp++) + BIO_printf(p.errorbio,"%s\n",*pp); + BIO_printf(p.errorbio,"\n"); + goto err; + } + + + + /* set input */ + + if ((in=BIO_new(BIO_s_file())) == NULL) { + BIO_printf(p.errorbio, "Error setting input bio\n"); + goto err; + } else if (infile == NULL) + BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); + else if (BIO_read_filename(in,infile) <= 0) { + BIO_printf(p.errorbio, "Error opening input file %s\n", infile); + BIO_free(in); + goto err; + } + + /* set output */ + + if ((out=BIO_new(BIO_s_file())) == NULL) { + BIO_printf(p.errorbio, "Error setting output bio.\n"); + goto err; + } else if (outfile == NULL) + BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); + else if (BIO_write_filename(out,outfile) <= 0) { + BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); + BIO_free(out); + goto err; + } + + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + if (!(p.curl = curl_easy_init())) { + BIO_printf(p.errorbio, "Cannot init curl lib\n"); + goto err; + } + + + + if (!(p12bio = BIO_new_file(p.p12file , "rb"))) { + BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); goto err; + } + if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { + BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err; + } + + p.ca= NULL; + if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { + BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err; + } + + if (sk_X509_num(p.ca) <= 0) { + BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; + } + + if (p.verbose > 1) X509_print_ex(p.errorbio,p.usercert,0,0); + + /* determine URL to go */ + + if (hostporturl) { + serverurl=(char*) malloc(9+strlen(hostporturl)); + sprintf(serverurl,"https://%s",hostporturl); + } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ + if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { + BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); + int j=0; + int find=0; + for (j=0;j\n", serverurl); + curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); + + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* pass our list of custom made headers */ + + contenttype=(char*) malloc(15+strlen(mimetype)); + sprintf(contenttype,"Content-type: %s",mimetype); + headers = curl_slist_append(headers,contenttype); + curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); + + if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); + + { + FILE *outfp; + BIO_get_fp(out,&outfp); + curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + } + + res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; + + if (res != CURLE_OK) + BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); + + curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); + + { + int lu; int i=0; + while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) { + i+=lu; + if (i== tabLength) { + tabLength+=100; + binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + } + } + tabLength = i; + } + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + + /* Perform the request, res will get the return code */ + + BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); + { + int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); + if( mimetypeaccept && p.verbose) + if(!strcmp(mimetypeaccept,response)) + BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",response); + else + BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); + } + + /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ + +/* free the header list*/ + + curl_slist_free_all(headers); + + /* always cleanup */ + curl_easy_cleanup(p.curl); + + BIO_free(in); + BIO_free(out); + return (EXIT_SUCCESS); + + + err: BIO_printf(p.errorbio,"error"); + exit(1); +} + + + + -- cgit v1.2.1 From 39af394a1c3ae1d8ac71ad263a7c524988702c2e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:50:18 +0000 Subject: removed tabs and trailing whitespace from source --- docs/examples/curlx.c | 572 +++++++++++++++++++++++++------------------------- 1 file changed, 286 insertions(+), 286 deletions(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index c5aabd344..2bb9a064d 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -1,4 +1,4 @@ -/* +/* curlx.c Authors: Peter Sylvester, Jean-Paul Merlin This is a little program to demonstrate the usage of @@ -6,7 +6,7 @@ - an ssl initialisation callback setting a user key and trustbases coming from a pkcs12 file - using an ssl application callback to find a URI in the - certificate presented during ssl session establishment. + certificate presented during ssl session establishment. */ @@ -20,13 +20,13 @@ * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, the following disclaimer, - * and the original OpenSSL and SSLeay Licences below. + * and the original OpenSSL and SSLeay Licences below. * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions, the following disclaimer + * notice, this list of conditions, the following disclaimer * and the original OpenSSL and SSLeay Licences below in * the documentation and/or other materials provided with the - * distribution. + * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgments: @@ -100,7 +100,7 @@ static char *curlx_usage[]={ " -envpass arg - environement variable which content the tia private key password", " -out arg - output file (response)- default stdout", " -in arg - input file (request)- default stdin", -" -connect arg - URL of the server for the connection ex: www.openevidenve.org", +" -connect arg - URL of the server for the connection ex: www.openevidenve.org", " -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", " -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", " -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", @@ -109,7 +109,7 @@ NULL /* - ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS + ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS -mimetype application/dvcs -acceptmime application/dvcs -out response */ @@ -134,33 +134,33 @@ typedef struct sslctxparm_st { static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) { - char *tmp; - if(!ia5 || !ia5->length) return NULL; - tmp = OPENSSL_malloc(ia5->length + 1); - memcpy(tmp, ia5->data, ia5->length); - tmp[ia5->length] = 0; - return tmp; + char *tmp; + if(!ia5 || !ia5->length) return NULL; + tmp = OPENSSL_malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; } /* A conveniance routine to get an access URI. */ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) { - int i; - STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; - accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; - - if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; - for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { - ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); - if (OBJ_obj2nid(ad->method) == type) { - if (ad->location->type == GEN_URI) { - return i2s_ASN1_IA5STRING(ad->location->d.ia5); - } - return NULL; - } - } - return NULL; + int i; + STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; + accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; + + if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; + for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { + ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); + if (OBJ_obj2nid(ad->method) == type) { + if (ad->location->type == GEN_URI) { + return i2s_ASN1_IA5STRING(ad->location->d.ia5); + } + return NULL; + } + } + return NULL; } /* This is an application verification call back, it does not @@ -170,192 +170,192 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) */ static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) { - sslctxparm * p = (sslctxparm *) arg; - int ok; - - if (p->verbose > 2) BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); - if ((ok= X509_verify_cert(ctx)) && ctx->cert) { - unsigned char * accessinfo ; - if (p->verbose > 1) X509_print_ex(p->errorbio,ctx->cert,0,0); - if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { - if (p->verbose) BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n",accessinfo); - curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); - } else if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_info_access)) { - if (p->verbose) BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n",accessinfo); - curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); - } - } - if (p->verbose > 2) BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n",ok); - return(ok); + sslctxparm * p = (sslctxparm *) arg; + int ok; + + if (p->verbose > 2) BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); + if ((ok= X509_verify_cert(ctx)) && ctx->cert) { + unsigned char * accessinfo ; + if (p->verbose > 1) X509_print_ex(p->errorbio,ctx->cert,0,0); + if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { + if (p->verbose) BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n",accessinfo); + curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + } else if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_info_access)) { + if (p->verbose) BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n",accessinfo); + curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + } + } + if (p->verbose > 2) BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n",ok); + return(ok); } /* This is an example of an curl SSL initialisation call back. The callback sets: - - a private key and certificate + - a private key and certificate - a trusted ca certificate - a preferred cipherlist - an application verification callback (the function above) */ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { - - sslctxparm * p = (sslctxparm *) parm; - SSL_CTX * ctx = (SSL_CTX *) sslctx ; - - if (!SSL_CTX_use_certificate(ctx,p->usercert)) { - BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; - } - if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { - BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; - } - - if (!SSL_CTX_check_private_key(ctx)) { - BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; - } - - SSL_CTX_set_quiet_shutdown(ctx,1); - SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); - SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); - - X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca,sk_X509_num(p->ca)-1)); - - SSL_CTX_set_verify_depth(ctx,2); - - SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); - - SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); - - - return CURLE_OK ; -err: - ERR_print_errors(p->errorbio); - return CURLE_SSL_CERTPROBLEM; + + sslctxparm * p = (sslctxparm *) parm; + SSL_CTX * ctx = (SSL_CTX *) sslctx ; + + if (!SSL_CTX_use_certificate(ctx,p->usercert)) { + BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; + } + if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { + BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; + } + + if (!SSL_CTX_check_private_key(ctx)) { + BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; + } + + SSL_CTX_set_quiet_shutdown(ctx,1); + SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); + SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); + + X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca,sk_X509_num(p->ca)-1)); + + SSL_CTX_set_verify_depth(ctx,2); + + SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); + + SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); + + + return CURLE_OK ; +err: + ERR_print_errors(p->errorbio); + return CURLE_SSL_CERTPROBLEM; } int main(int argc, char **argv) { - BIO* in=NULL; - BIO* out=NULL; - - - char * outfile = NULL; - char * infile = NULL ; - - int tabLength=100; - char *binaryptr; - char* mimetype; - char* mimetypeaccept=NULL; - char* contenttype; - char** pp; - unsigned char* hostporturl = NULL; - binaryptr=(char*)malloc(tabLength); - BIO * p12bio ; - char **args = argv + 1; - unsigned char * serverurl; - sslctxparm p; - char *response; - p.verbose = 0; - - CURLcode res; - struct curl_slist * headers=NULL; - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - curl_global_init(CURL_GLOBAL_DEFAULT); - + BIO* in=NULL; + BIO* out=NULL; + + + char * outfile = NULL; + char * infile = NULL ; + + int tabLength=100; + char *binaryptr; + char* mimetype; + char* mimetypeaccept=NULL; + char* contenttype; + char** pp; + unsigned char* hostporturl = NULL; + binaryptr=(char*)malloc(tabLength); + BIO * p12bio ; + char **args = argv + 1; + unsigned char * serverurl; + sslctxparm p; + char *response; + p.verbose = 0; + + CURLcode res; + struct curl_slist * headers=NULL; + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + curl_global_init(CURL_GLOBAL_DEFAULT); + /* we need some more for the P12 decoding */ OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); - ERR_load_crypto_strings(); - - - int badarg=0; - - while (*args && *args[0] == '-') { - if (!strcmp (*args, "-in")) { - if (args[1]) { - infile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-out")) { - if (args[1]) { - outfile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-p12")) { - if (args[1]) { - p.p12file = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-envpass") == 0) { - if (args[1]) { - p.pst = getenv(*(++args)); - } else badarg=1; - } else if (strcmp(*args,"-connect") == 0) { - if (args[1]) { - hostporturl = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-mimetype") == 0) { - if (args[1]) { - mimetype = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-acceptmime") == 0) { - if (args[1]) { - mimetypeaccept = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-accesstype") == 0) { - if (args[1]) { - if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; - } else badarg=1; - } else if (strcmp(*args,"-verbose") == 0) { - p.verbose++; - } else badarg=1; - args++; - } - - if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; - - if (badarg) { - for (pp=curlx_usage; (*pp != NULL); pp++) - BIO_printf(p.errorbio,"%s\n",*pp); - BIO_printf(p.errorbio,"\n"); - goto err; - } - - - - /* set input */ - - if ((in=BIO_new(BIO_s_file())) == NULL) { - BIO_printf(p.errorbio, "Error setting input bio\n"); - goto err; - } else if (infile == NULL) - BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); - else if (BIO_read_filename(in,infile) <= 0) { - BIO_printf(p.errorbio, "Error opening input file %s\n", infile); - BIO_free(in); - goto err; - } - - /* set output */ - - if ((out=BIO_new(BIO_s_file())) == NULL) { - BIO_printf(p.errorbio, "Error setting output bio.\n"); - goto err; - } else if (outfile == NULL) - BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); - else if (BIO_write_filename(out,outfile) <= 0) { - BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); - BIO_free(out); - goto err; - } - - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - if (!(p.curl = curl_easy_init())) { - BIO_printf(p.errorbio, "Cannot init curl lib\n"); - goto err; - } + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + + + int badarg=0; + + while (*args && *args[0] == '-') { + if (!strcmp (*args, "-in")) { + if (args[1]) { + infile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + outfile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-p12")) { + if (args[1]) { + p.p12file = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-envpass") == 0) { + if (args[1]) { + p.pst = getenv(*(++args)); + } else badarg=1; + } else if (strcmp(*args,"-connect") == 0) { + if (args[1]) { + hostporturl = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-mimetype") == 0) { + if (args[1]) { + mimetype = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-acceptmime") == 0) { + if (args[1]) { + mimetypeaccept = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-accesstype") == 0) { + if (args[1]) { + if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; + } else badarg=1; + } else if (strcmp(*args,"-verbose") == 0) { + p.verbose++; + } else badarg=1; + args++; + } + + if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; + + if (badarg) { + for (pp=curlx_usage; (*pp != NULL); pp++) + BIO_printf(p.errorbio,"%s\n",*pp); + BIO_printf(p.errorbio,"\n"); + goto err; + } + + + + /* set input */ + + if ((in=BIO_new(BIO_s_file())) == NULL) { + BIO_printf(p.errorbio, "Error setting input bio\n"); + goto err; + } else if (infile == NULL) + BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); + else if (BIO_read_filename(in,infile) <= 0) { + BIO_printf(p.errorbio, "Error opening input file %s\n", infile); + BIO_free(in); + goto err; + } + + /* set output */ + + if ((out=BIO_new(BIO_s_file())) == NULL) { + BIO_printf(p.errorbio, "Error setting output bio.\n"); + goto err; + } else if (outfile == NULL) + BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); + else if (BIO_write_filename(out,outfile) <= 0) { + BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); + BIO_free(out); + goto err; + } + + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + if (!(p.curl = curl_easy_init())) { + BIO_printf(p.errorbio, "Cannot init curl lib\n"); + goto err; + } @@ -365,112 +365,112 @@ int main(int argc, char **argv) { if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err; } - - p.ca= NULL; - if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { + + p.ca= NULL; + if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err; - } + } - if (sk_X509_num(p.ca) <= 0) { + if (sk_X509_num(p.ca) <= 0) { BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; - } - - if (p.verbose > 1) X509_print_ex(p.errorbio,p.usercert,0,0); - - /* determine URL to go */ - - if (hostporturl) { - serverurl=(char*) malloc(9+strlen(hostporturl)); - sprintf(serverurl,"https://%s",hostporturl); - } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ - if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { - BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); - int j=0; - int find=0; - for (j=0;j\n", serverurl); - curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); - - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - /* pass our list of custom made headers */ - - contenttype=(char*) malloc(15+strlen(mimetype)); - sprintf(contenttype,"Content-type: %s",mimetype); - headers = curl_slist_append(headers,contenttype); - curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); - - if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); - - { - FILE *outfp; - BIO_get_fp(out,&outfp); - curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); - } - - res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; - - if (res != CURLE_OK) - BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); - - curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); - - { - int lu; int i=0; - while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) { - i+=lu; - if (i== tabLength) { - tabLength+=100; - binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ - } - } - tabLength = i; - } - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - + } + + if (p.verbose > 1) X509_print_ex(p.errorbio,p.usercert,0,0); + + /* determine URL to go */ + + if (hostporturl) { + serverurl=(char*) malloc(9+strlen(hostporturl)); + sprintf(serverurl,"https://%s",hostporturl); + } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ + if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { + BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); + int j=0; + int find=0; + for (j=0;j\n", serverurl); + curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); + + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* pass our list of custom made headers */ + + contenttype=(char*) malloc(15+strlen(mimetype)); + sprintf(contenttype,"Content-type: %s",mimetype); + headers = curl_slist_append(headers,contenttype); + curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); + + if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); + + { + FILE *outfp; + BIO_get_fp(out,&outfp); + curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + } + + res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; + + if (res != CURLE_OK) + BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); + + curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); + + { + int lu; int i=0; + while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) { + i+=lu; + if (i== tabLength) { + tabLength+=100; + binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + } + } + tabLength = i; + } + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* Perform the request, res will get the return code */ - BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); + BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); { - int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); - if( mimetypeaccept && p.verbose) - if(!strcmp(mimetypeaccept,response)) - BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",response); - else - BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); - } + int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); + if( mimetypeaccept && p.verbose) + if(!strcmp(mimetypeaccept,response)) + BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",response); + else + BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); + } - /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ + /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ /* free the header list*/ curl_slist_free_all(headers); - + /* always cleanup */ curl_easy_cleanup(p.curl); - + BIO_free(in); BIO_free(out); return (EXIT_SUCCESS); - - + + err: BIO_printf(p.errorbio,"error"); exit(1); } -- cgit v1.2.1 From 7f447134873959e3faca64070f7eb4be4d7708b1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Nov 2004 13:48:35 +0000 Subject: re-indented to curl style --- docs/examples/curlx.c | 676 ++++++++++++++++++++++++++------------------------ 1 file changed, 351 insertions(+), 325 deletions(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 2bb9a064d..1ee384ff2 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -4,9 +4,9 @@ This is a little program to demonstrate the usage of - an ssl initialisation callback setting a user key and trustbases - coming from a pkcs12 file + coming from a pkcs12 file - using an ssl application callback to find a URI in the - certificate presented during ssl session establishment. + certificate presented during ssl session establishment. */ @@ -95,38 +95,38 @@ #include static char *curlx_usage[]={ -"usage: curlx args\n", -" -p12 arg - tia file ", -" -envpass arg - environement variable which content the tia private key password", -" -out arg - output file (response)- default stdout", -" -in arg - input file (request)- default stdin", -" -connect arg - URL of the server for the connection ex: www.openevidenve.org", -" -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", -" -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", -" -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", -NULL + "usage: curlx args\n", + " -p12 arg - tia file ", + " -envpass arg - environement variable which content the tia private key password", + " -out arg - output file (response)- default stdout", + " -in arg - input file (request)- default stdin", + " -connect arg - URL of the server for the connection ex: www.openevidenve.org", + " -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", + " -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", + " -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", + NULL }; /* - ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS - -mimetype application/dvcs -acceptmime application/dvcs -out response +./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS +-mimetype application/dvcs -acceptmime application/dvcs -out response */ /* This is a context that we pass to all callbacks */ typedef struct sslctxparm_st { - unsigned char * p12file ; - const char * pst ; - PKCS12 * p12 ; - EVP_PKEY * pkey ; - X509 * usercert ; - STACK_OF(X509) * ca ; - CURL * curl; - BIO * errorbio; - int accesstype ; - int verbose; + unsigned char * p12file ; + const char * pst ; + PKCS12 * p12 ; + EVP_PKEY * pkey ; + X509 * usercert ; + STACK_OF(X509) * ca ; + CURL * curl; + BIO * errorbio; + int accesstype ; + int verbose; } sslctxparm; @@ -134,33 +134,35 @@ typedef struct sslctxparm_st { static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) { - char *tmp; - if(!ia5 || !ia5->length) return NULL; - tmp = OPENSSL_malloc(ia5->length + 1); - memcpy(tmp, ia5->data, ia5->length); - tmp[ia5->length] = 0; - return tmp; + char *tmp; + if(!ia5 || !ia5->length) + return NULL; + tmp = OPENSSL_malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; } /* A conveniance routine to get an access URI. */ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) { - int i; - STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; - accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; - - if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; - for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { - ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); - if (OBJ_obj2nid(ad->method) == type) { - if (ad->location->type == GEN_URI) { - return i2s_ASN1_IA5STRING(ad->location->d.ia5); - } - return NULL; - } - } - return NULL; + int i; + STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; + accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; + + if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) + return NULL; + for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { + ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); + if (OBJ_obj2nid(ad->method) == type) { + if (ad->location->type == GEN_URI) { + return i2s_ASN1_IA5STRING(ad->location->d.ia5); + } + return NULL; + } + } + return NULL; } /* This is an application verification call back, it does not @@ -169,312 +171,336 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) the URL to be used in the POST. */ -static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) { - sslctxparm * p = (sslctxparm *) arg; - int ok; - - if (p->verbose > 2) BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); - if ((ok= X509_verify_cert(ctx)) && ctx->cert) { - unsigned char * accessinfo ; - if (p->verbose > 1) X509_print_ex(p->errorbio,ctx->cert,0,0); - if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { - if (p->verbose) BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n",accessinfo); - curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); - } else if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_info_access)) { - if (p->verbose) BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n",accessinfo); - curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); - } - } - if (p->verbose > 2) BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n",ok); - return(ok); +static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) +{ + sslctxparm * p = (sslctxparm *) arg; + int ok; + + if (p->verbose > 2) + BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); + + if ((ok= X509_verify_cert(ctx)) && ctx->cert) { + unsigned char * accessinfo ; + if (p->verbose > 1) + X509_print_ex(p->errorbio,ctx->cert,0,0); + + if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { + if (p->verbose) + BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n", accessinfo); + + curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + } + else if (accessinfo = my_get_ext(ctx->cert,p->accesstype, + NID_info_access)) { + if (p->verbose) + BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n", accessinfo); + + curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); + } + } + if (p->verbose > 2) + BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n", ok); + return(ok); } /* This is an example of an curl SSL initialisation call back. The callback sets: - - a private key and certificate - - a trusted ca certificate - - a preferred cipherlist - - an application verification callback (the function above) + - a private key and certificate + - a trusted ca certificate + - a preferred cipherlist + - an application verification callback (the function above) */ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { - sslctxparm * p = (sslctxparm *) parm; - SSL_CTX * ctx = (SSL_CTX *) sslctx ; + sslctxparm * p = (sslctxparm *) parm; + SSL_CTX * ctx = (SSL_CTX *) sslctx ; - if (!SSL_CTX_use_certificate(ctx,p->usercert)) { - BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; - } - if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { - BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; - } + if (!SSL_CTX_use_certificate(ctx,p->usercert)) { + BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; + } + if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { + BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; + } - if (!SSL_CTX_check_private_key(ctx)) { - BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; - } + if (!SSL_CTX_check_private_key(ctx)) { + BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; + } - SSL_CTX_set_quiet_shutdown(ctx,1); - SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); - SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); + SSL_CTX_set_quiet_shutdown(ctx,1); + SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); + SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); - X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca,sk_X509_num(p->ca)-1)); + X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca, + sk_X509_num(p->ca)-1)); - SSL_CTX_set_verify_depth(ctx,2); + SSL_CTX_set_verify_depth(ctx,2); - SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); + SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); - SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); + SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); - return CURLE_OK ; -err: - ERR_print_errors(p->errorbio); - return CURLE_SSL_CERTPROBLEM; + return CURLE_OK ; + err: + ERR_print_errors(p->errorbio); + return CURLE_SSL_CERTPROBLEM; } int main(int argc, char **argv) { - BIO* in=NULL; - BIO* out=NULL; - - - char * outfile = NULL; - char * infile = NULL ; - - int tabLength=100; - char *binaryptr; - char* mimetype; - char* mimetypeaccept=NULL; - char* contenttype; - char** pp; - unsigned char* hostporturl = NULL; - binaryptr=(char*)malloc(tabLength); - BIO * p12bio ; - char **args = argv + 1; - unsigned char * serverurl; - sslctxparm p; - char *response; - p.verbose = 0; - - CURLcode res; - struct curl_slist * headers=NULL; - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - curl_global_init(CURL_GLOBAL_DEFAULT); - -/* we need some more for the P12 decoding */ - - OpenSSL_add_all_ciphers(); - OpenSSL_add_all_digests(); - ERR_load_crypto_strings(); - - - int badarg=0; - - while (*args && *args[0] == '-') { - if (!strcmp (*args, "-in")) { - if (args[1]) { - infile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-out")) { - if (args[1]) { - outfile=*(++args); - } else badarg=1; - } else if (!strcmp (*args, "-p12")) { - if (args[1]) { - p.p12file = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-envpass") == 0) { - if (args[1]) { - p.pst = getenv(*(++args)); - } else badarg=1; - } else if (strcmp(*args,"-connect") == 0) { - if (args[1]) { - hostporturl = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-mimetype") == 0) { - if (args[1]) { - mimetype = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-acceptmime") == 0) { - if (args[1]) { - mimetypeaccept = *(++args); - } else badarg=1; - } else if (strcmp(*args,"-accesstype") == 0) { - if (args[1]) { - if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; - } else badarg=1; - } else if (strcmp(*args,"-verbose") == 0) { - p.verbose++; - } else badarg=1; - args++; - } - - if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; - - if (badarg) { - for (pp=curlx_usage; (*pp != NULL); pp++) - BIO_printf(p.errorbio,"%s\n",*pp); - BIO_printf(p.errorbio,"\n"); - goto err; - } - - - - /* set input */ - - if ((in=BIO_new(BIO_s_file())) == NULL) { - BIO_printf(p.errorbio, "Error setting input bio\n"); - goto err; - } else if (infile == NULL) - BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); - else if (BIO_read_filename(in,infile) <= 0) { - BIO_printf(p.errorbio, "Error opening input file %s\n", infile); - BIO_free(in); - goto err; - } - - /* set output */ - - if ((out=BIO_new(BIO_s_file())) == NULL) { - BIO_printf(p.errorbio, "Error setting output bio.\n"); - goto err; - } else if (outfile == NULL) - BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); - else if (BIO_write_filename(out,outfile) <= 0) { - BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); - BIO_free(out); - goto err; - } - - - p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); - - if (!(p.curl = curl_easy_init())) { - BIO_printf(p.errorbio, "Cannot init curl lib\n"); - goto err; - } - - - - if (!(p12bio = BIO_new_file(p.p12file , "rb"))) { - BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); goto err; - } - if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { - BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err; - } - - p.ca= NULL; - if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { - BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err; - } - - if (sk_X509_num(p.ca) <= 0) { - BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; - } - - if (p.verbose > 1) X509_print_ex(p.errorbio,p.usercert,0,0); - - /* determine URL to go */ - - if (hostporturl) { - serverurl=(char*) malloc(9+strlen(hostporturl)); - sprintf(serverurl,"https://%s",hostporturl); - } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ - if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { - BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); - int j=0; - int find=0; - for (j=0;j\n", serverurl); - curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); - - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - /* pass our list of custom made headers */ - - contenttype=(char*) malloc(15+strlen(mimetype)); - sprintf(contenttype,"Content-type: %s",mimetype); - headers = curl_slist_append(headers,contenttype); - curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); - - if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); - - { - FILE *outfp; - BIO_get_fp(out,&outfp); - curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); - } - - res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; - - if (res != CURLE_OK) - BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); - - curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); - - { - int lu; int i=0; - while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) { - i+=lu; - if (i== tabLength) { - tabLength+=100; - binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ - } - } - tabLength = i; - } - /* Now specify the POST binary data */ - - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); - - - /* Perform the request, res will get the return code */ - - BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); - { - int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); - if( mimetypeaccept && p.verbose) - if(!strcmp(mimetypeaccept,response)) - BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",response); - else - BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); - } - - /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ - -/* free the header list*/ - - curl_slist_free_all(headers); - - /* always cleanup */ - curl_easy_cleanup(p.curl); - + BIO* in=NULL; + BIO* out=NULL; + + char * outfile = NULL; + char * infile = NULL ; + + int tabLength=100; + char *binaryptr; + char* mimetype; + char* mimetypeaccept=NULL; + char* contenttype; + char** pp; + unsigned char* hostporturl = NULL; + binaryptr=(char*)malloc(tabLength); + BIO * p12bio ; + char **args = argv + 1; + unsigned char * serverurl; + sslctxparm p; + char *response; + p.verbose = 0; + + CURLcode res; + struct curl_slist * headers=NULL; + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + curl_global_init(CURL_GLOBAL_DEFAULT); + + /* we need some more for the P12 decoding */ + + OpenSSL_add_all_ciphers(); + OpenSSL_add_all_digests(); + ERR_load_crypto_strings(); + + + int badarg=0; + + while (*args && *args[0] == '-') { + if (!strcmp (*args, "-in")) { + if (args[1]) { + infile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-out")) { + if (args[1]) { + outfile=*(++args); + } else badarg=1; + } else if (!strcmp (*args, "-p12")) { + if (args[1]) { + p.p12file = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-envpass") == 0) { + if (args[1]) { + p.pst = getenv(*(++args)); + } else badarg=1; + } else if (strcmp(*args,"-connect") == 0) { + if (args[1]) { + hostporturl = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-mimetype") == 0) { + if (args[1]) { + mimetype = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-acceptmime") == 0) { + if (args[1]) { + mimetypeaccept = *(++args); + } else badarg=1; + } else if (strcmp(*args,"-accesstype") == 0) { + if (args[1]) { + if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; + } else badarg=1; + } else if (strcmp(*args,"-verbose") == 0) { + p.verbose++; + } else badarg=1; + args++; + } + + if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; + + if (badarg) { + for (pp=curlx_usage; (*pp != NULL); pp++) + BIO_printf(p.errorbio,"%s\n",*pp); + BIO_printf(p.errorbio,"\n"); + goto err; + } + + + + /* set input */ + + if ((in=BIO_new(BIO_s_file())) == NULL) { + BIO_printf(p.errorbio, "Error setting input bio\n"); + goto err; + } else if (infile == NULL) + BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); + else if (BIO_read_filename(in,infile) <= 0) { + BIO_printf(p.errorbio, "Error opening input file %s\n", infile); BIO_free(in); + goto err; + } + + /* set output */ + + if ((out=BIO_new(BIO_s_file())) == NULL) { + BIO_printf(p.errorbio, "Error setting output bio.\n"); + goto err; + } else if (outfile == NULL) + BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); + else if (BIO_write_filename(out,outfile) <= 0) { + BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); BIO_free(out); - return (EXIT_SUCCESS); + goto err; + } + + + p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); + + if (!(p.curl = curl_easy_init())) { + BIO_printf(p.errorbio, "Cannot init curl lib\n"); + goto err; + } + + + + if (!(p12bio = BIO_new_file(p.p12file , "rb"))) { + BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); goto err; + } + if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { + BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err; + } + + p.ca= NULL; + if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { + BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err; + } + + if (sk_X509_num(p.ca) <= 0) { + BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; + } + + if (p.verbose > 1) + X509_print_ex(p.errorbio,p.usercert,0,0); + + /* determine URL to go */ + + if (hostporturl) { + serverurl=(char*) malloc(9+strlen(hostporturl)); + sprintf(serverurl,"https://%s",hostporturl); + } + else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ + if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { + BIO_printf(p.errorbio,"no service URL in user cert " + "cherching in others certificats\n"); + int j=0; + int find=0; + for (j=0;j\n", serverurl); + + curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); + + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + /* pass our list of custom made headers */ + + contenttype=(char*) malloc(15+strlen(mimetype)); + sprintf(contenttype,"Content-type: %s",mimetype); + headers = curl_slist_append(headers,contenttype); + curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); + + if (p.verbose) + BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); + + { + FILE *outfp; + BIO_get_fp(out,&outfp); + curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + } + + res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; + + if (res != CURLE_OK) + BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); + + curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); + + { + int lu; int i=0; + while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) { + i+=lu; + if (i== tabLength) { + tabLength+=100; + binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + } + } + tabLength = i; + } + /* Now specify the POST binary data */ + + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + + + /* Perform the request, res will get the return code */ + + BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", + res = curl_easy_perform(p.curl)); + { + int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); + if( mimetypeaccept && p.verbose) + if(!strcmp(mimetypeaccept,response)) + BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n", + response); + else + BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable " + "mime type, it is %s instead of %s\n", + response,mimetypeaccept); + } + + /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ +/* free the header list*/ - err: BIO_printf(p.errorbio,"error"); - exit(1); -} - + curl_slist_free_all(headers); + /* always cleanup */ + curl_easy_cleanup(p.curl); + BIO_free(in); + BIO_free(out); + return (EXIT_SUCCESS); + err: BIO_printf(p.errorbio,"error"); + exit(1); +} -- cgit v1.2.1 From 609044aea2ffa2520b14b810e46e2a256c8db56c Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 29 Oct 2006 21:19:23 +0000 Subject: Compiler warning fix --- docs/examples/curlx.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 1ee384ff2..31f01e8ad 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -114,6 +114,13 @@ static char *curlx_usage[]={ */ +/* + * We use this ZERO_NULL to avoid picky compiler warnings, + * when assigning a NULL pointer to a function pointer var. + */ + +#define ZERO_NULL 0 + /* This is a context that we pass to all callbacks */ typedef struct sslctxparm_st { @@ -236,7 +243,7 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { SSL_CTX_set_verify_depth(ctx,2); - SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); + SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,ZERO_NULL); SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); -- cgit v1.2.1 From 49ce3e5160a9576e797bf87cef012b09d1c54ecb Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 12 Jul 2007 21:11:10 +0000 Subject: Fixed some compile warnings and errors and improved portability in the examples. Removed ftp3rdparty.c since libcurl doesn't support 3rd party FTP transfers any longer. --- docs/examples/curlx.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 31f01e8ad..636c8b4fe 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -81,6 +81,7 @@ #include #include +#include #include #include #include @@ -94,13 +95,13 @@ #include #include -static char *curlx_usage[]={ +static const char *curlx_usage[]={ "usage: curlx args\n", " -p12 arg - tia file ", " -envpass arg - environement variable which content the tia private key password", " -out arg - output file (response)- default stdout", " -in arg - input file (request)- default stdin", - " -connect arg - URL of the server for the connection ex: www.openevidenve.org", + " -connect arg - URL of the server for the connection ex: www.openevidence.org", " -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", " -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", " -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", @@ -268,19 +269,21 @@ int main(int argc, char **argv) { char* mimetype; char* mimetypeaccept=NULL; char* contenttype; - char** pp; + const char** pp; unsigned char* hostporturl = NULL; - binaryptr=(char*)malloc(tabLength); BIO * p12bio ; char **args = argv + 1; unsigned char * serverurl; sslctxparm p; char *response; - p.verbose = 0; CURLcode res; struct curl_slist * headers=NULL; + int badarg=0; + + binaryptr=(char*)malloc(tabLength); + p.verbose = 0; p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); curl_global_init(CURL_GLOBAL_DEFAULT); @@ -292,7 +295,6 @@ int main(int argc, char **argv) { ERR_load_crypto_strings(); - int badarg=0; while (*args && *args[0] == '-') { if (!strcmp (*args, "-in")) { @@ -407,10 +409,9 @@ int main(int argc, char **argv) { } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { + int j=0; BIO_printf(p.errorbio,"no service URL in user cert " "cherching in others certificats\n"); - int j=0; - int find=0; for (j=0;j Date: Thu, 22 May 2008 21:20:07 +0000 Subject: Fixed a surprising number of example programs that were passing int arguments to curl_easy_setopt instead of long. --- docs/examples/curlx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 636c8b4fe..bd192865f 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -438,7 +438,7 @@ int main(int argc, char **argv) { /* Now specify the POST binary data */ curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,(long)tabLength); /* pass our list of custom made headers */ @@ -477,7 +477,7 @@ int main(int argc, char **argv) { /* Now specify the POST binary data */ curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); - curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); + curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,(long)tabLength); /* Perform the request, res will get the return code */ -- cgit v1.2.1 From 861b647e7b1da564b831a5b07312a30feb7b6c58 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 04:28:43 +0000 Subject: remove unnecessary typecasting of realloc() --- docs/examples/curlx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index bd192865f..521812b9a 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -469,7 +469,7 @@ int main(int argc, char **argv) { i+=lu; if (i== tabLength) { tabLength+=100; - binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */ + binaryptr=realloc(binaryptr,tabLength); /* should be more careful */ } } tabLength = i; -- cgit v1.2.1 From 59e378f48fed849e8e41f0bc6a10bf7a1732ae8a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 05:29:05 +0000 Subject: remove unnecessary typecasting of malloc() --- docs/examples/curlx.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 521812b9a..09d27cc97 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -281,7 +281,7 @@ int main(int argc, char **argv) { struct curl_slist * headers=NULL; int badarg=0; - binaryptr=(char*)malloc(tabLength); + binaryptr = malloc(tabLength); p.verbose = 0; p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); @@ -404,7 +404,7 @@ int main(int argc, char **argv) { /* determine URL to go */ if (hostporturl) { - serverurl=(char*) malloc(9+strlen(hostporturl)); + serverurl = malloc(9+strlen(hostporturl)); sprintf(serverurl,"https://%s",hostporturl); } else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ @@ -442,7 +442,7 @@ int main(int argc, char **argv) { /* pass our list of custom made headers */ - contenttype=(char*) malloc(15+strlen(mimetype)); + contenttype = malloc(15+strlen(mimetype)); sprintf(contenttype,"Content-type: %s",mimetype); headers = curl_slist_append(headers,contenttype); curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); -- cgit v1.2.1 From 2e830066031e1aa1e6bc4bef8d02dd30bbde205a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 4 Jan 2010 18:43:29 +0000 Subject: use the modern name for this option --- docs/examples/curlx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 09d27cc97..9b1c29158 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -453,7 +453,7 @@ int main(int argc, char **argv) { { FILE *outfp; BIO_get_fp(out,&outfp); - curl_easy_setopt(p.curl, CURLOPT_FILE,outfp); + curl_easy_setopt(p.curl, CURLOPT_WRITEDATA, outfp); } res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; -- cgit v1.2.1 From a07bc79117971b96ebf3188c0a34a73ee0a3609b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sun, 14 Feb 2010 19:40:18 +0000 Subject: removed trailing whitespace --- docs/examples/curlx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 9b1c29158..62bdfe405 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -115,7 +115,7 @@ static const char *curlx_usage[]={ */ -/* +/* * We use this ZERO_NULL to avoid picky compiler warnings, * when assigning a NULL pointer to a function pointer var. */ -- cgit v1.2.1 From 81524cbfa02f8882040ecf2947dcf5c8523591ca Mon Sep 17 00:00:00 2001 From: Peter Sylvester Date: Wed, 4 Jan 2012 23:02:36 +0100 Subject: OpenSSL: remove reference to openssl internal struct With this change, curl compiles with the new OPENSSL_NO_SSL_INTERN cflag. This flag might become the default in some distant future. --- docs/examples/curlx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/examples/curlx.c') diff --git a/docs/examples/curlx.c b/docs/examples/curlx.c index 62bdfe405..89d5f407b 100644 --- a/docs/examples/curlx.c +++ b/docs/examples/curlx.c @@ -239,8 +239,7 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); - X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca, - sk_X509_num(p->ca)-1)); + X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), sk_X509_value(p->ca, sk_X509_num(p->ca)-1)); SSL_CTX_set_verify_depth(ctx,2); -- cgit v1.2.1