@@ -170,7 +170,6 @@ ASN1_SEQUENCE(CatalogAuthAttr) = {
170170
171171IMPLEMENT_ASN1_FUNCTIONS (CatalogAuthAttr )
172172
173- #ifdef ENABLE_CURL
174173/*
175174 * Structures for Authenticode Timestamp
176175 */
@@ -188,7 +187,6 @@ ASN1_SEQUENCE(TimeStampRequest) = {
188187
189188IMPLEMENT_ASN1_FUNCTIONS (TimeStampRequest )
190189
191- #endif /* ENABLE_CURL */
192190
193191ASN1_SEQUENCE (CatalogInfo ) = {
194192 ASN1_SIMPLE (CatalogInfo , digest , ASN1_OCTET_STRING ),
@@ -223,46 +221,9 @@ static STACK_OF(PKCS7) *signature_list_create(PKCS7 *p7);
223221static int PKCS7_compare (const PKCS7 * const * a , const PKCS7 * const * b );
224222static PKCS7 * pkcs7_get_sigfile (FILE_FORMAT_CTX * ctx );
225223
226- #ifdef ENABLE_CURL
227224
228225static int blob_has_nl = 0 ;
229226
230- static void print_proxy (char * proxy )
231- {
232- if (proxy ) {
233- printf ("Using configured proxy: %s\n" , proxy );
234- } else {
235- char * http_proxy , * https_proxy ;
236-
237- http_proxy = getenv ("http_proxy" );
238- if (!http_proxy )
239- http_proxy = getenv ("HTTP_PROXY" );
240- if (http_proxy && * http_proxy != '\0' )
241- printf ("Using environmental HTTP proxy: %s\n" , http_proxy );
242- https_proxy = getenv ("https_proxy" );
243- if (!https_proxy )
244- https_proxy = getenv ("HTTPS_PROXY" );
245- if (https_proxy && * https_proxy != '\0' )
246- printf ("Using environmental HTTPS proxy: %s\n" , https_proxy );
247- }
248- }
249-
250- /*
251- * Callback for writing received data
252- */
253- static size_t curl_write (void * ptr , size_t sz , size_t nmemb , void * stream )
254- {
255- size_t written , len = sz * nmemb ;
256-
257- if (len > 0 && !blob_has_nl ) {
258- if (memchr (ptr , '\n' , len ))
259- blob_has_nl = 1 ;
260- }
261- if (!BIO_write_ex ((BIO * )stream , ptr , len , & written ) || written != len )
262- return 0 ; /* FAILED */
263- return written ;
264- }
265-
266227/*
267228 A timestamp request looks like this:
268229
@@ -523,6 +484,44 @@ static int attach_authenticode_response(PKCS7 *p7, PKCS7 *resp, int verbose)
523484 return 0 ; /* OK */
524485}
525486
487+ #ifdef ENABLE_CURL
488+
489+ static void print_proxy (char * proxy )
490+ {
491+ if (proxy ) {
492+ printf ("Using configured proxy: %s\n" , proxy );
493+ } else {
494+ char * http_proxy , * https_proxy ;
495+
496+ http_proxy = getenv ("http_proxy" );
497+ if (!http_proxy )
498+ http_proxy = getenv ("HTTP_PROXY" );
499+ if (http_proxy && * http_proxy != '\0' )
500+ printf ("Using environmental HTTP proxy: %s\n" , http_proxy );
501+ https_proxy = getenv ("https_proxy" );
502+ if (!https_proxy )
503+ https_proxy = getenv ("HTTPS_PROXY" );
504+ if (https_proxy && * https_proxy != '\0' )
505+ printf ("Using environmental HTTPS proxy: %s\n" , https_proxy );
506+ }
507+ }
508+
509+ /*
510+ * Callback for writing received data
511+ */
512+ static size_t curl_write (void * ptr , size_t sz , size_t nmemb , void * stream )
513+ {
514+ size_t written , len = sz * nmemb ;
515+
516+ if (len > 0 && !blob_has_nl ) {
517+ if (memchr (ptr , '\n' , len ))
518+ blob_has_nl = 1 ;
519+ }
520+ if (!BIO_write_ex ((BIO * )stream , ptr , len , & written ) || written != len )
521+ return 0 ; /* FAILED */
522+ return written ;
523+ }
524+
526525/*
527526 * Get data from HTTP server.
528527 * [out] http_code: HTTP status
@@ -643,6 +642,7 @@ static BIO *bio_get_http(long *http_code, char *url, BIO *bout, char *proxy,
643642 curl_easy_cleanup (curl );
644643 return bin ;
645644}
645+ #endif /* ENABLE_CURL */
646646
647647/*
648648 * Decode a curl response from BIO and write it into the PKCS7 structure
@@ -670,6 +670,7 @@ static int add_timestamp(PKCS7 *p7, FILE_FORMAT_CTX *ctx, char *url, int rfc3161
670670 if (!bout ) {
671671 return 1 ; /* FAILED */
672672 }
673+ #ifdef ENABLE_CURL
673674 if (rfc3161 ) {
674675 bin = bio_get_http (& http_code , url , bout , ctx -> options -> proxy ,
675676 ctx -> options -> noverifypeer , verbose , 1 );
@@ -678,6 +679,11 @@ static int add_timestamp(PKCS7 *p7, FILE_FORMAT_CTX *ctx, char *url, int rfc3161
678679 ctx -> options -> noverifypeer , verbose , 2 );
679680 }
680681 BIO_free_all (bout );
682+ #else /* ENABLE_CURL */
683+ /* TODO implement an HTTP session */
684+ printf ("Could NOT find CURL\n" );
685+ return 1 ; /* FAILED */
686+ #endif /* ENABLE_CURL */
681687
682688 if (bin ) {
683689 if (rfc3161 ) {
@@ -744,7 +750,6 @@ static int add_timestamp_rfc3161(PKCS7 *p7, FILE_FORMAT_CTX *ctx)
744750 }
745751 return 0 ; /* FAILED */
746752}
747- #endif /* ENABLE_CURL */
748753
749754/*
750755 * [in] resp_ctx: a response context that can be used for generating responses
@@ -1026,7 +1031,6 @@ static int add_unauthenticated_blob(PKCS7 *p7)
10261031 */
10271032static int add_timestamp_and_blob (PKCS7 * p7 , FILE_FORMAT_CTX * ctx )
10281033{
1029- #ifdef ENABLE_CURL
10301034 /* add counter-signature/timestamp */
10311035 if (ctx -> options -> nturl && !add_timestamp_authenticode (p7 , ctx )) {
10321036 printf ("%s\n%s\n" , "Authenticode timestamping failed" ,
@@ -1042,7 +1046,6 @@ static int add_timestamp_and_blob(PKCS7 *p7, FILE_FORMAT_CTX *ctx)
10421046 printf ("Built-in timestamping failed\n" );
10431047 return 1 ; /* FAILED */
10441048 }
1045- #endif /* ENABLE_CURL */
10461049 if (ctx -> options -> addBlob && !add_unauthenticated_blob (p7 )) {
10471050 printf ("Adding unauthenticated blob failed\n" );
10481051 return 1 ; /* FAILED */
@@ -1619,10 +1622,17 @@ static char *clrdp_url_get_x509(X509 *cert)
16191622static X509_CRL * x509_crl_get (char * proxy , char * url )
16201623{
16211624 X509_CRL * crl ;
1622- BIO * bio ;
1625+ BIO * bio = NULL ;
1626+ #ifdef ENABLE_CURL
16231627 long http_code = -1 ;
16241628
16251629 bio = bio_get_http (& http_code , url , NULL , proxy , 0 , 1 , 0 );
1630+ #else /* ENABLE_CURL */
1631+ /* TODO implement an HTTP session */
1632+ (void )proxy ;
1633+ printf ("Could NOT find CURL\n" );
1634+ return NULL ; /* FAILED */
1635+ #endif /* ENABLE_CURL */
16261636 if (!bio ) {
16271637 printf ("Warning: Faild to get CRL from %s\n\n" , url );
16281638 return NULL ; /* FAILED */
@@ -1814,7 +1824,6 @@ static int verify_timestamp(FILE_FORMAT_CTX *ctx, PKCS7 *p7, CMS_ContentInfo *ti
18141824
18151825 /* verify a Certificate Revocation List */
18161826 url = clrdp_url_get_x509 (signer );
1817- #ifdef ENABLE_CURL
18181827 if (url ) {
18191828 if (ctx -> options -> ignore_cdp ) {
18201829 printf ("Ignored TSA's CRL distribution point: %s\n" , url );
@@ -1828,7 +1837,6 @@ static int verify_timestamp(FILE_FORMAT_CTX *ctx, PKCS7 *p7, CMS_ContentInfo *ti
18281837 goto out ;
18291838 }
18301839 }
1831- #endif /* ENABLE_CURL */
18321840 if (p7 -> d .sign -> crl || crl ) {
18331841 crls = x509_crl_list_get (p7 , crl );
18341842 if (!crls ) {
@@ -1940,7 +1948,6 @@ static int verify_authenticode(FILE_FORMAT_CTX *ctx, PKCS7 *p7, time_t time, X50
19401948
19411949 /* verify a Certificate Revocation List */
19421950 url = clrdp_url_get_x509 (signer );
1943- #ifdef ENABLE_CURL
19441951 if (url ) {
19451952 if (ctx -> options -> ignore_cdp ) {
19461953 printf ("Ignored CRL distribution point: %s\n" , url );
@@ -1954,7 +1961,6 @@ static int verify_authenticode(FILE_FORMAT_CTX *ctx, PKCS7 *p7, time_t time, X50
19541961 goto out ;
19551962 }
19561963 }
1957- #endif /* ENABLE_CURL */
19581964 if (p7 -> d .sign -> crl || crl ) {
19591965 crls = x509_crl_list_get (p7 , crl );
19601966 if (!crls ) {
@@ -2331,9 +2337,9 @@ static time_t time_t_get_asn1_time(const ASN1_TIME *s)
23312337 if (ASN1_TIME_to_tm (s , & tm )) {
23322338#ifdef _WIN32
23332339 return _mkgmtime (& tm );
2334- #else
2340+ #else /* _WIN32 */
23352341 return timegm (& tm );
2336- #endif
2342+ #endif /* _WIN32 */
23372343 } else {
23382344 return INVALID_TIME ;
23392345 }
@@ -2999,10 +3005,8 @@ static void usage(const char *argv0, const char *cmd)
29993005 printf ("%12s[ -h {md5,sha1,sha2(56),sha384,sha512} ]\n" , "" );
30003006 printf ("%12s[ -n <desc> ] [ -i <url> ] [ -jp <level> ] [ -comm ]\n" , "" );
30013007 printf ("%12s[ -ph ]\n" , "" );
3002- #ifdef ENABLE_CURL
30033008 printf ("%12s[ -t <timestampurl> [ -t ... ] [ -p <proxy> ] [ -noverifypeer ]\n" , "" );
30043009 printf ("%12s[ -ts <timestampurl> [ -ts ... ] [ -p <proxy> ] [ -noverifypeer ] ]\n" , "" );
3005- #endif /* ENABLE_CURL */
30063010 printf ("%12s[ -TSA-certs <TSA-certfile> ] [ -TSA-key <TSA-keyfile> ]\n" , "" );
30073011 printf ("%12s[ -TSA-time <unix-time> ]\n" , "" );
30083012 printf ("%12s[ -time <unix-time> ]\n" , "" );
@@ -3022,10 +3026,8 @@ static void usage(const char *argv0, const char *cmd)
30223026 }
30233027 if (on_list (cmd , cmds_add )) {
30243028 printf ("%1sadd [-addUnauthenticatedBlob]\n" , "" );
3025- #ifdef ENABLE_CURL
30263029 printf ("%12s[ -t <timestampurl> [ -t ... ] [ -p <proxy> ] [ -noverifypeer ]\n" , "" );
30273030 printf ("%12s[ -ts <timestampurl> [ -ts ... ] [ -p <proxy> ] [ -noverifypeer ] ]\n" , "" );
3028- #endif /* ENABLE_CURL */
30293031 printf ("%12s[ -TSA-certs <TSA-certfile> ] [ -TSA-key <TSA-keyfile> ]\n" , "" );
30303032 printf ("%12s[ -TSA-time <unix-time> ]\n" , "" );
30313033 printf ("%12s[ -h {md5,sha1,sha2(56),sha384,sha512} ]\n" , "" );
@@ -3108,14 +3110,10 @@ static void help_for(const char *argv0, const char *cmd)
31083110#endif /* OPENSSL_VERSION_NUMBER>=0x30000000L */
31093111 const char * cmds_n [] = {"sign" , NULL };
31103112 const char * cmds_nest [] = {"attach-signature" , "sign" , NULL };
3111- #ifdef ENABLE_CURL
31123113 const char * cmds_noverifypeer [] = {"add" , "sign" , NULL };
3113- #endif /* ENABLE_CURL */
31143114 const char * cmds_out [] = {"add" , "attach-signature" , "extract-signature" ,
31153115 "remove-signature" , "sign" , "extract-data" , NULL };
3116- #ifdef ENABLE_CURL
31173116 const char * cmds_p [] = {"add" , "sign" , "verify" , NULL };
3118- #endif /* ENABLE_CURL */
31193117 const char * cmds_pass [] = {"sign" , NULL };
31203118 const char * cmds_pem [] = {"sign" , "extract-data" , "extract-signature" , NULL };
31213119 const char * cmds_ph [] = {"sign" , "extract-data" , NULL };
@@ -3129,10 +3127,8 @@ static void help_for(const char *argv0, const char *cmd)
31293127 const char * cmds_time [] = {"attach-signature" , "sign" , "verify" , NULL };
31303128 const char * cmds_ignore_timestamp [] = {"verify" , NULL };
31313129 const char * cmds_ignore_cdp [] = {"verify" , NULL };
3132- #ifdef ENABLE_CURL
31333130 const char * cmds_t [] = {"add" , "sign" , NULL };
31343131 const char * cmds_ts [] = {"add" , "sign" , NULL };
3135- #endif /* ENABLE_CURL */
31363132 const char * cmds_CAfileTSA [] = {"attach-signature" , "verify" , NULL };
31373133 const char * cmds_certsTSA [] = {"add" , "sign" , NULL };
31383134 const char * cmds_keyTSA [] = {"add" , "sign" , NULL };
@@ -3239,16 +3235,12 @@ static void help_for(const char *argv0, const char *cmd)
32393235 printf ("%-24s= specifies a description of the signed content\n" , "-n" );
32403236 if (on_list (cmd , cmds_nest ))
32413237 printf ("%-24s= add the new nested signature instead of replacing the first one\n" , "-nest" );
3242- #ifdef ENABLE_CURL
32433238 if (on_list (cmd , cmds_noverifypeer ))
32443239 printf ("%-24s= do not verify the Time-Stamp Authority's SSL certificate\n" , "-noverifypeer" );
3245- #endif /* ENABLE_CURL */
32463240 if (on_list (cmd , cmds_out ))
32473241 printf ("%-24s= output file\n" , "-out" );
3248- #ifdef ENABLE_CURL
32493242 if (on_list (cmd , cmds_p ))
32503243 printf ("%-24s= proxy to connect to the desired Time-Stamp Authority server or CRL distribution point\n" , "-p" );
3251- #endif /* ENABLE_CURL */
32523244 if (on_list (cmd , cmds_pass ))
32533245 printf ("%-24s= the private key password\n" , "-pass" );
32543246 if (on_list (cmd , cmds_pem ))
@@ -3277,7 +3269,6 @@ static void help_for(const char *argv0, const char *cmd)
32773269 printf ("%-24s= disable verification of the Timestamp Server signature\n" , "-ignore-timestamp" );
32783270 if (on_list (cmd , cmds_ignore_cdp ))
32793271 printf ("%-24s= disable CRL Distribution Points online verification\n" , "-ignore-cdp" );
3280- #ifdef ENABLE_CURL
32813272 if (on_list (cmd , cmds_t )) {
32823273 printf ("%-24s= specifies that the digital signature will be timestamped\n" , "-t" );
32833274 printf ("%26sby the Time-Stamp Authority (TSA) indicated by the URL\n" , "" );
@@ -3287,7 +3278,6 @@ static void help_for(const char *argv0, const char *cmd)
32873278 printf ("%-24s= specifies the URL of the RFC 3161 Time-Stamp Authority server\n" , "-ts" );
32883279 printf ("%26sthis option cannot be used with the -t option\n" , "" );
32893280 }
3290- #endif /* ENABLE_CURL */
32913281 if (on_list (cmd , cmds_time ))
32923282 printf ("%-24s= the unix-time to set the signing and/or verifying time\n" , "-time" );
32933283 if (on_list (cmd , cmds_CAfileTSA ))
@@ -3338,11 +3328,11 @@ static char *getpassword(const char *prompt)
33383328 pass = OPENSSL_strdup (passbuf );
33393329 memset (passbuf , 0 , sizeof passbuf );
33403330 return pass ;
3341- #else
3331+ #else /* HAVE_TERMIOS_H */
33423332 return getpass (prompt );
3343- #endif
3333+ #endif /* HAVE_TERMIOS_H */
33443334}
3345- #endif
3335+ #endif /* PROVIDE_ASKPASS */
33463336
33473337/*
33483338 * [in, out] options: structure holds the input data
@@ -3375,7 +3365,7 @@ static int read_password(GLOBAL_OPTIONS *options)
33753365 memcpy (passbuf , faddress , passlen );
33763366 UnmapViewOfFile (faddress );
33773367 CloseHandle (fhandle );
3378- #else
3368+ #else /* WIN32 */
33793369 int passfd = open (options -> readpass , O_RDONLY );
33803370 if (passfd < 0 ) {
33813371 return 0 ; /* FAILED */
@@ -3838,7 +3828,7 @@ static char *get_cafile(void)
38383828 return OPENSSL_strdup (files [i ]);
38393829 }
38403830 }
3841- #endif
3831+ #endif /* WIN32 */
38423832 return NULL ;
38433833}
38443834
@@ -4085,7 +4075,7 @@ static int main_configure(int argc, char **argv, GLOBAL_OPTIONS *options)
40854075 return 0 ; /* FAILED */
40864076 }
40874077 options -> askpass = 1 ;
4088- #endif
4078+ #endif /* PROVIDE_ASKPASS */
40894079 } else if ((cmd == CMD_SIGN ) && !strcmp (* argv , "-readpass" )) {
40904080 if (options -> askpass || options -> pass ) {
40914081 usage (argv0 , "all" );
@@ -4140,7 +4130,6 @@ static int main_configure(int argc, char **argv, GLOBAL_OPTIONS *options)
41404130 return 0 ; /* FAILED */
41414131 }
41424132 options -> time = (time_t )strtoull (* (++ argv ), NULL , 10 );
4143- #ifdef ENABLE_CURL
41444133 } else if ((cmd == CMD_SIGN || cmd == CMD_ADD ) && !strcmp (* argv , "-t" )) {
41454134 if (-- argc < 1 ) {
41464135 usage (argv0 , "all" );
@@ -4161,7 +4150,6 @@ static int main_configure(int argc, char **argv, GLOBAL_OPTIONS *options)
41614150 options -> proxy = * (++ argv );
41624151 } else if ((cmd == CMD_SIGN || cmd == CMD_ADD ) && !strcmp (* argv , "-noverifypeer" )) {
41634152 options -> noverifypeer = 1 ;
4164- #endif
41654153 } else if ((cmd == CMD_SIGN || cmd == CMD_ADD ) && !strcmp (* argv , "-addUnauthenticatedBlob" )) {
41664154 options -> addBlob = 1 ;
41674155 } else if ((cmd == CMD_SIGN || cmd == CMD_ATTACH ) && !strcmp (* argv , "-nest" )) {
@@ -4313,11 +4301,9 @@ static int main_configure(int argc, char **argv, GLOBAL_OPTIONS *options)
43134301 return 0 ; /* FAILED */
43144302 }
43154303 if (argc > 0 ||
4316- #ifdef ENABLE_CURL
43174304 (options -> nturl && options -> ntsurl ) ||
43184305 (options -> nturl && options -> tsa_certfile && options -> tsa_keyfile ) ||
43194306 (options -> ntsurl && options -> tsa_certfile && options -> tsa_keyfile ) ||
4320- #endif
43214307 !options -> infile ||
43224308 (cmd != CMD_VERIFY && !options -> outfile ) ||
43234309 (cmd == CMD_SIGN && !((options -> certfile && options -> keyfile ) ||
0 commit comments