Loading docs/examples/curlx.c +351 −325 Original line number Diff line number Diff line Loading @@ -135,7 +135,8 @@ typedef struct sslctxparm_st { static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) { char *tmp; if(!ia5 || !ia5->length) return NULL; if(!ia5 || !ia5->length) return NULL; tmp = OPENSSL_malloc(ia5->length + 1); memcpy(tmp, ia5->data, ia5->length); tmp[ia5->length] = 0; Loading @@ -150,7 +151,8 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; 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++) { ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); if (OBJ_obj2nid(ad->method) == type) { Loading @@ -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. */ 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; 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) { 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 (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); } 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); } } 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); } Loading Loading @@ -217,7 +231,8 @@ 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(ctx->cert_store,sk_X509_value(p->ca, sk_X509_num(p->ca)-1)); SSL_CTX_set_verify_depth(ctx,2); Loading @@ -238,7 +253,6 @@ int main(int argc, char **argv) { BIO* in=NULL; BIO* out=NULL; char * outfile = NULL; char * infile = NULL ; Loading Loading @@ -375,30 +389,42 @@ int main(int argc, char **argv) { 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 */ 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 */ } 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"); 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<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,NID_sinfo_access))) break; 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, NID_sinfo_access))) break; } } } 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); /* Now specify the POST binary data */ Loading @@ -413,7 +439,8 @@ int main(int argc, char **argv) { 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); if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); { FILE *outfp; Loading Loading @@ -447,14 +474,18 @@ int main(int argc, char **argv) { /* 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); 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); 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 ***/ Loading @@ -470,11 +501,6 @@ int main(int argc, char **argv) { BIO_free(out); return (EXIT_SUCCESS); err: BIO_printf(p.errorbio,"error"); exit(1); } Loading
docs/examples/curlx.c +351 −325 Original line number Diff line number Diff line Loading @@ -135,7 +135,8 @@ typedef struct sslctxparm_st { static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) { char *tmp; if(!ia5 || !ia5->length) return NULL; if(!ia5 || !ia5->length) return NULL; tmp = OPENSSL_malloc(ia5->length + 1); memcpy(tmp, ia5->data, ia5->length); tmp[ia5->length] = 0; Loading @@ -150,7 +151,8 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; 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++) { ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); if (OBJ_obj2nid(ad->method) == type) { Loading @@ -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. */ 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; 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) { 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 (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); } 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); } } 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); } Loading Loading @@ -217,7 +231,8 @@ 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(ctx->cert_store,sk_X509_value(p->ca, sk_X509_num(p->ca)-1)); SSL_CTX_set_verify_depth(ctx,2); Loading @@ -238,7 +253,6 @@ int main(int argc, char **argv) { BIO* in=NULL; BIO* out=NULL; char * outfile = NULL; char * infile = NULL ; Loading Loading @@ -375,30 +389,42 @@ int main(int argc, char **argv) { 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 */ 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 */ } 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"); 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<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,NID_sinfo_access))) break; 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, NID_sinfo_access))) break; } } } 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); /* Now specify the POST binary data */ Loading @@ -413,7 +439,8 @@ int main(int argc, char **argv) { 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); if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); { FILE *outfp; Loading Loading @@ -447,14 +474,18 @@ int main(int argc, char **argv) { /* 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); 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); 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 ***/ Loading @@ -470,11 +501,6 @@ int main(int argc, char **argv) { BIO_free(out); return (EXIT_SUCCESS); err: BIO_printf(p.errorbio,"error"); exit(1); }