89 #include <openssl/x509v3.h> 90 #include <openssl/x509_vfy.h> 91 #include <openssl/crypto.h> 92 #include <openssl/lhash.h> 93 #include <openssl/objects.h> 94 #include <openssl/err.h> 95 #include <openssl/evp.h> 96 #include <openssl/x509.h> 97 #include <openssl/pkcs12.h> 98 #include <openssl/bio.h> 99 #include <openssl/ssl.h> 102 "usage: curlx args\n",
103 " -p12 arg - tia file ",
104 " -envpass arg - environment variable which content the tia private" 106 " -out arg - output file (response)- default stdout",
107 " -in arg - input file (request)- default stdin",
108 " -connect arg - URL of the server for the connection ex:" 109 " www.openevidence.org",
110 " -mimetype arg - MIME type for data in ex : application/timestamp-query" 111 " or application/dvcs -default application/timestamp-query",
112 " -acceptmime arg - MIME type acceptable for the response ex : " 113 "application/timestamp-response or application/dvcs -default none",
114 " -accesstype arg - an Object identifier in an AIA/SIA method, e.g." 115 " AD_DVCS or ad_timestamping",
154 if(!ia5 || !ia5->length)
156 tmp = OPENSSL_malloc(ia5->length + 1);
157 memcpy(tmp, ia5->data, ia5->length);
158 tmp[ia5->length] = 0;
167 STACK_OF(ACCESS_DESCRIPTION) * accessinfo;
170 if(!sk_ACCESS_DESCRIPTION_num(accessinfo))
172 for(i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) {
173 ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i);
174 if(OBJ_obj2nid(ad->method) == type) {
175 if(ad->location->type == GEN_URI) {
196 BIO_printf(p->errorbio,
"entering ssl_app_verify_callback\n");
198 ok = X509_verify_cert(ctx);
199 if(ok && ctx->cert) {
200 unsigned char *accessinfo;
202 X509_print_ex(p->errorbio, ctx->cert, 0, 0);
204 accessinfo =
my_get_ext(ctx->cert, p->accesstype, NID_sinfo_access);
207 BIO_printf(p->errorbio,
"Setting URL from SIA to: %s\n", accessinfo);
211 else if(accessinfo =
my_get_ext(ctx->cert, p->accesstype,
214 BIO_printf(p->errorbio,
"Setting URL from AIA to: %s\n", accessinfo);
220 BIO_printf(p->errorbio,
"leaving ssl_app_verify_callback with %d\n", ok);
239 BIO_printf(p->errorbio,
"SSL_CTX_use_certificate problem\n");
243 BIO_printf(p->errorbio,
"SSL_CTX_use_PrivateKey\n");
248 BIO_printf(p->errorbio,
"SSL_CTX_check_private_key\n");
252 SSL_CTX_set_quiet_shutdown(ctx, 1);
254 SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);
257 sk_X509_value(p->ca, sk_X509_num(p->ca)-1));
259 SSL_CTX_set_verify_depth(ctx, 2);
265 ERR_print_errors(p->errorbio);
270 int main(
int argc,
char **argv)
275 char *outfile = NULL;
281 char *mimetypeaccept = NULL;
284 unsigned char *hostporturl = NULL;
286 char **
args = argv + 1;
287 unsigned char *serverurl;
295 binaryptr =
malloc(tabLength);
298 p.errorbio = BIO_new_fp(stderr, BIO_NOCLOSE);
304 OpenSSL_add_all_ciphers();
305 OpenSSL_add_all_digests();
306 ERR_load_crypto_strings();
308 while(*args && *args[0] ==
'-') {
309 if(!strcmp (*args,
"-in")) {
316 else if(!strcmp (*args,
"-out")) {
323 else if(!strcmp (*args,
"-p12")) {
330 else if(strcmp(*args,
"-envpass") == 0) {
337 else if(strcmp(*args,
"-connect") == 0) {
339 hostporturl = *(++args);
344 else if(strcmp(*args,
"-mimetype") == 0) {
346 mimetype = *(++args);
351 else if(strcmp(*args,
"-acceptmime") == 0) {
353 mimetypeaccept = *(++args);
358 else if(strcmp(*args,
"-accesstype") == 0) {
360 p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args, 0));
361 if(p.accesstype == 0)
367 else if(strcmp(*args,
"-verbose") == 0) {
375 if(mimetype == NULL || mimetypeaccept == NULL)
380 BIO_printf(p.errorbio,
"%s\n", *pp);
381 BIO_printf(p.errorbio,
"\n");
389 BIO_printf(p.errorbio,
"Error setting input bio\n");
392 else if(infile == NULL)
393 BIO_set_fp(in, stdin, BIO_NOCLOSE|BIO_FP_TEXT);
394 else if(BIO_read_filename(in, infile) <= 0) {
395 BIO_printf(p.errorbio,
"Error opening input file %s\n", infile);
404 BIO_printf(p.errorbio,
"Error setting output bio.\n");
407 else if(outfile == NULL)
408 BIO_set_fp(out, stdout, BIO_NOCLOSE|BIO_FP_TEXT);
409 else if(BIO_write_filename(out, outfile) <= 0) {
410 BIO_printf(p.errorbio,
"Error opening output file %s\n", outfile);
416 p.errorbio = BIO_new_fp(stderr, BIO_NOCLOSE);
420 BIO_printf(p.errorbio,
"Cannot init curl lib\n");
424 p12bio = BIO_new_file(p.
p12file,
"rb");
426 BIO_printf(p.errorbio,
"Error opening P12 file %s\n", p.
p12file);
429 p.
p12 = d2i_PKCS12_bio(p12bio, NULL);
431 BIO_printf(p.errorbio,
"Cannot decode P12 structure %s\n", p.
p12file);
437 BIO_printf(p.errorbio,
"Invalid P12 structure in %s\n", p.
p12file);
441 if(sk_X509_num(p.ca) <= 0) {
442 BIO_printf(p.errorbio,
"No trustworthy CA given.%s\n", p.
p12file);
447 X509_print_ex(p.errorbio, p.
usercert, 0, 0);
452 size_t len = strlen(hostporturl) + 9;
454 snprintf(serverurl, len,
"https://%s", hostporturl);
456 else if(p.accesstype != 0) {
461 BIO_printf(p.errorbio,
"no service URL in user cert " 462 "cherching in others certificats\n");
463 for(j = 0; j<sk_X509_num(p.ca); j++) {
464 serverurl =
my_get_ext(sk_X509_value(p.ca, j), p.accesstype,
468 serverurl =
my_get_ext(sk_X509_value(p.ca, j), p.accesstype,
477 BIO_printf(p.errorbio,
"no service URL in certificats," 478 " check '-accesstype (AD_DVCS | ad_timestamping)'" 479 " or use '-connect'\n");
484 BIO_printf(p.errorbio,
"Service URL: <%s>\n", serverurl);
495 contenttype =
malloc(15 + strlen(mimetype));
496 snprintf(contenttype, 15 + strlen(mimetype),
"Content-type: %s", mimetype);
501 BIO_printf(p.errorbio,
"Service URL: <%s>\n", serverurl);
505 BIO_get_fp(out, &outfp);
512 BIO_printf(p.errorbio,
"%d %s=%d %d\n", __LINE__,
513 "CURLOPT_SSL_CTX_FUNCTION", CURLOPT_SSL_CTX_FUNCTION, res);
519 while((lu = BIO_read(in, &binaryptr[i], tabLength-i)) >0) {
523 binaryptr =
realloc(binaryptr, tabLength);
536 BIO_printf(p.errorbio,
"%d %s %d\n", __LINE__,
"curl_easy_perform",
540 if(mimetypeaccept && p.verbose)
541 if(!strcmp(mimetypeaccept, response))
542 BIO_printf(p.errorbio,
"the response has a correct mimetype : %s\n",
545 BIO_printf(p.errorbio,
"the response doesn\'t have an acceptable " 546 "mime type, it is %s instead of %s\n",
547 response, mimetypeaccept);
561 return (EXIT_SUCCESS);
563 err: BIO_printf(p.errorbio,
"error");
#define SSL_CTX_use_PrivateKey
static char * ia5string(ASN1_IA5STRING *ia5)
static CURLcode sslctxfun(CURL *curl, void *sslctx, void *parm)
#define realloc(ptr, size)
#define SSL_CTX_set_cipher_list
UNITTEST_START int result
#define curl_easy_setopt(handle, option, value)
memcpy(filename, filename1, strlen(filename1))
static unsigned char * my_get_ext(X509 *cert, const int type, int extensiontype)
#define curl_easy_getinfo(handle, info, arg)
CURL_EXTERN struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
#define CURL_GLOBAL_DEFAULT
CURL_EXTERN CURL * curl_easy_init(void)
#define SSL_CTX_get_cert_store
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
#define SSL_CTX_set_verify
#define SSL_CTX_use_certificate
static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg)
int main(int argc, char **argv)
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
#define SSL_CTX_check_private_key
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
static const char * curlx_usage[]
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)
struct sslctxparm_st sslctxparm