1
0
mirror of https://github.com/moparisthebest/curl synced 2024-10-31 15:45:12 -04:00

re-indented to curl style

This commit is contained in:
Daniel Stenberg 2004-11-22 13:48:35 +00:00
parent b7a6b78e0c
commit 7f44713487

View File

@ -95,22 +95,22 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
static char *curlx_usage[]={ static char *curlx_usage[]={
"usage: curlx args\n", "usage: curlx args\n",
" -p12 arg - tia file ", " -p12 arg - tia file ",
" -envpass arg - environement variable which content the tia private key password", " -envpass arg - environement variable which content the tia private key password",
" -out arg - output file (response)- default stdout", " -out arg - output file (response)- default stdout",
" -in arg - input file (request)- default stdin", " -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", " -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", " -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", " -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping",
NULL 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 -mimetype application/dvcs -acceptmime application/dvcs -out response
*/ */
@ -135,7 +135,8 @@ typedef struct sslctxparm_st {
static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5)
{ {
char *tmp; char *tmp;
if(!ia5 || !ia5->length) return NULL; if(!ia5 || !ia5->length)
return NULL;
tmp = OPENSSL_malloc(ia5->length + 1); tmp = OPENSSL_malloc(ia5->length + 1);
memcpy(tmp, ia5->data, ia5->length); memcpy(tmp, ia5->data, ia5->length);
tmp[ia5->length] = 0; tmp[ia5->length] = 0;
@ -150,7 +151,8 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype)
STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; STACK_OF(ACCESS_DESCRIPTION) * accessinfo ;
accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ;
if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; if (!sk_ACCESS_DESCRIPTION_num(accessinfo))
return NULL;
for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) {
ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i);
if (OBJ_obj2nid(ad->method) == type) { if (OBJ_obj2nid(ad->method) == type) {
@ -169,23 +171,35 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype)
the URL to be used in the POST. the URL to be used in the POST.
*/ */
static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) { static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg)
{
sslctxparm * p = (sslctxparm *) arg; sslctxparm * p = (sslctxparm *) arg;
int ok; int ok;
if (p->verbose > 2) BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); if (p->verbose > 2)
BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n");
if ((ok= X509_verify_cert(ctx)) && ctx->cert) { if ((ok= X509_verify_cert(ctx)) && ctx->cert) {
unsigned char * accessinfo ; unsigned char * accessinfo ;
if (p->verbose > 1) X509_print_ex(p->errorbio,ctx->cert,0,0); 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 (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); if (p->verbose)
BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n", accessinfo);
curl_easy_setopt(p->curl, CURLOPT_URL,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); 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); 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); if (p->verbose > 2)
BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n", ok);
return(ok); return(ok);
} }
@ -217,7 +231,8 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) {
SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); SSL_CTX_set_cipher_list(ctx,"RC4-MD5");
SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); 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);
@ -227,7 +242,7 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) {
return CURLE_OK ; return CURLE_OK ;
err: err:
ERR_print_errors(p->errorbio); ERR_print_errors(p->errorbio);
return CURLE_SSL_CERTPROBLEM; return CURLE_SSL_CERTPROBLEM;
@ -238,7 +253,6 @@ int main(int argc, char **argv) {
BIO* in=NULL; BIO* in=NULL;
BIO* out=NULL; BIO* out=NULL;
char * outfile = NULL; char * outfile = NULL;
char * infile = NULL ; char * infile = NULL ;
@ -264,7 +278,7 @@ int main(int argc, char **argv) {
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
/* we need some more for the P12 decoding */ /* we need some more for the P12 decoding */
OpenSSL_add_all_ciphers(); OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests(); OpenSSL_add_all_digests();
@ -375,30 +389,42 @@ int main(int argc, char **argv) {
BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; 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); if (p.verbose > 1)
X509_print_ex(p.errorbio,p.usercert,0,0);
/* determine URL to go */ /* determine URL to go */
if (hostporturl) { if (hostporturl) {
serverurl=(char*) malloc(9+strlen(hostporturl)); serverurl=(char*) malloc(9+strlen(hostporturl));
sprintf(serverurl,"https://%s",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 */ }
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))) { 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"); BIO_printf(p.errorbio,"no service URL in user cert "
"cherching in others certificats\n");
int j=0; int j=0;
int find=0; int find=0;
for (j=0;j<sk_X509_num(p.ca);j++) { for (j=0;j<sk_X509_num(p.ca);j++) {
if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,NID_info_access))) break; if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,
if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,NID_sinfo_access))) break; NID_info_access)))
break;
if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,
NID_sinfo_access)))
break;
} }
} }
} }
if (!serverurl) { if (!serverurl) {
BIO_printf(p.errorbio, "no service URL in certificats, check '-accesstype (AD_DVCS | ad_timestamping)' or use '-connect'\n"); goto err; BIO_printf(p.errorbio, "no service URL in certificats,"
" check '-accesstype (AD_DVCS | ad_timestamping)'"
" or use '-connect'\n");
goto err;
} }
if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); if (p.verbose)
BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl);
curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); curl_easy_setopt(p.curl, CURLOPT_URL, serverurl);
/* Now specify the POST binary data */ /* Now specify the POST binary data */
@ -413,7 +439,8 @@ int main(int argc, char **argv) {
headers = curl_slist_append(headers,contenttype); headers = curl_slist_append(headers,contenttype);
curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers);
if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); if (p.verbose)
BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl);
{ {
FILE *outfp; FILE *outfp;
@ -447,14 +474,18 @@ int main(int argc, char **argv) {
/* Perform the request, res will get the return code */ /* 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); int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response);
if( mimetypeaccept && p.verbose) if( mimetypeaccept && p.verbose)
if(!strcmp(mimetypeaccept,response)) if(!strcmp(mimetypeaccept,response))
BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",response); BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",
response);
else else
BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); 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 ***/
@ -470,11 +501,6 @@ int main(int argc, char **argv) {
BIO_free(out); BIO_free(out);
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
err: BIO_printf(p.errorbio,"error"); err: BIO_printf(p.errorbio,"error");
exit(1); exit(1);
} }