Browse code

Fix to correctly detect libcurl installations that depend on openssl installs in alternative install locations, and to properly get and compare x509 certificate names when using openssl 1.1+.

Micah Snyder authored on 2019/09/24 11:00:49
Showing 5 changed files
... ...
@@ -323,8 +323,8 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/clamav-config.h.in \
323 323
 	$(top_srcdir)/docs/man/sigtool.1.in \
324 324
 	$(top_srcdir)/libclammspack/config.h.in COPYING config/ar-lib \
325 325
 	config/compile config/config.guess config/config.rpath \
326
-	config/config.sub config/depcomp config/install-sh \
327
-	config/ltmain.sh config/missing config/ylwrap
326
+	config/config.sub config/install-sh config/ltmain.sh \
327
+	config/missing config/ylwrap
328 328
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
329 329
 distdir = $(PACKAGE)-$(VERSION)
330 330
 top_distdir = $(distdir)
... ...
@@ -29170,7 +29170,7 @@ $as_echo "$LIBCURL_HOME" >&6; }
29170 29170
         CURL_LIBS="-lcurl"
29171 29171
     fi
29172 29172
     save_LDFLAGS="$LDFLAGS"
29173
-    LDFLAGS="$CURL_LDFLAGS $CURL_LIBS"
29173
+    LDFLAGS="$CURL_LDFLAGS $CURL_LIBS $SSL_LDFLAGS $SSL_LIBS"
29174 29174
 
29175 29175
         for ac_prog in gawk mawk nawk awk
29176 29176
 do
... ...
@@ -418,7 +418,7 @@ static fc_error_t create_curl_handle(
418 418
 
419 419
 #if defined(C_DARWIN) || defined(_WIN32)
420 420
     if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function)) {
421
-        logg("!create_curl_handle: Failed to set SSL CTX function!\n");
421
+        logg("*create_curl_handle: Failed to set SSL CTX function. Your libcurl may use an SSL backend that does not support CURLOPT_SSL_CTX_FUNCTION.\n");
422 422
     }
423 423
 #endif
424 424
 
... ...
@@ -584,25 +584,25 @@ static fc_error_t remote_cvdhead(
584 584
        if both callbacks are set. */
585 585
 
586 586
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo)) {
587
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
587
+            logg("!create_curl_handle: Failed to set transfer info function!\n");
588 588
         }
589 589
         /* pass the struct pointer into the xferinfo function, note that this is
590
-       an alias to CURLOPT_PROGRESSDATA */
590
+           an alias to CURLOPT_PROGRESSDATA */
591 591
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog)) {
592
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
592
+            logg("!create_curl_handle: Failed to set transfer info data structure!\n");
593 593
         }
594 594
 #else
595 595
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, older_progress)) {
596
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
596
+            logg("!create_curl_handle: Failed to set progress function!\n");
597 597
         }
598 598
         /* pass the struct pointer into the progress function */
599 599
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog)) {
600
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
600
+            logg("!create_curl_handle: Failed to set progress data structure!\n");
601 601
         }
602 602
 #endif
603 603
 
604 604
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L)) {
605
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
605
+            logg("!create_curl_handle: Failed to disable progress function!\n");
606 606
         }
607 607
     }
608 608
 
... ...
@@ -847,25 +847,25 @@ static fc_error_t downloadFile(
847 847
        if both callbacks are set. */
848 848
 
849 849
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo)) {
850
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
850
+            logg("!downloadFile: Failed to set transfer info function!\n");
851 851
         }
852 852
         /* pass the struct pointer into the xferinfo function, note that this is
853 853
        an alias to CURLOPT_PROGRESSDATA */
854 854
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog)) {
855
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
855
+            logg("!downloadFile: Failed to set transfer info data structure!\n");
856 856
         }
857 857
 #else
858 858
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, older_progress)) {
859
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
859
+            logg("!downloadFile: Failed to set progress function!\n");
860 860
         }
861 861
         /* pass the struct pointer into the progress function */
862 862
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &prog)) {
863
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
863
+            logg("!downloadFile: Failed to set progress data structure!\n");
864 864
         }
865 865
 #endif
866 866
 
867 867
         if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L)) {
868
-            logg("!create_curl_handle: Failed to set SSL CTX function!\n");
868
+            logg("!downloadFile: Failed to disable progress function!\n");
869 869
         }
870 870
     }
871 871
 
... ...
@@ -929,11 +929,11 @@ static fc_error_t downloadFile(
929 929
 
930 930
     /* Send all data to this function  */
931 931
     if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteFileCallback)) {
932
-        logg("!remote_cvdhead: Failed to set write-data fwrite callback function for curl session.\n");
932
+        logg("!downloadFile: Failed to set write-data fwrite callback function for curl session.\n");
933 933
     }
934 934
 
935 935
     if (CURLE_OK != curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&receivedFile)) {
936
-        logg("!remote_cvdhead: Failed to set write-data file handle for curl session.\n");
936
+        logg("!downloadFile: Failed to set write-data file handle for curl session.\n");
937 937
     }
938 938
 
939 939
     logg("*downloadFile: Download source:      %s\n", url);
... ...
@@ -47,7 +47,7 @@ if test "X$have_curl" = "Xyes"; then
47 47
         CURL_LIBS="-lcurl"
48 48
     fi
49 49
     save_LDFLAGS="$LDFLAGS"
50
-    LDFLAGS="$CURL_LDFLAGS $CURL_LIBS"
50
+    LDFLAGS="$CURL_LDFLAGS $CURL_LIBS $SSL_LDFLAGS $SSL_LIBS"
51 51
 
52 52
     dnl Following section modified from libcurl, Copyright (C) 2006, David Shaw, license under COPYING.curl
53 53
     AC_PROG_AWK
... ...
@@ -61,9 +61,9 @@ if test "X$have_curl" = "Xyes"; then
61 61
     curl_version=`echo $awk_curl_version | $curl_version_parse`
62 62
     dnl end of section
63 63
 
64
-    AM_COND_IF([BUILD_CLAMONACC], 
64
+    AM_COND_IF([BUILD_CLAMONACC],
65 65
                     dnl if version greater than (7.45)
66
-                    [if test $curl_version -ge 470272 ; then 
66
+                    [if test $curl_version -ge 470272 ; then
67 67
                         $enable_clamonacc="yes"
68 68
                     else
69 69
                         AC_MSG_ERROR([m4_normalize([
... ...
@@ -214,7 +214,7 @@ void cert_store_unload(void)
214 214
 #if OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0+ */
215 215
 static cl_error_t x509_cert_name_cmp(X509 *cert_a, X509 *cert_b, int *cmp_out)
216 216
 {
217
-    int rc = CL_EMEM;
217
+    cl_error_t status = CL_EMEM;
218 218
 
219 219
     X509_NAME *a = NULL;
220 220
     X509_NAME *b = NULL;
... ...
@@ -233,13 +233,24 @@ static cl_error_t x509_cert_name_cmp(X509 *cert_a, X509 *cert_b, int *cmp_out)
233 233
     if (!bio_out_b)
234 234
         goto done;
235 235
 
236
-    rc = X509_NAME_print_ex(bio_out_a, a, 0, XN_FLAG_SEP_SPLUS_SPC);
236
+    a = X509_get_subject_name(cert_a);
237
+
238
+    if (-1 == X509_NAME_print_ex(bio_out_a, a, 0, XN_FLAG_SEP_SPLUS_SPC)) {
239
+        mprintf("!Failed to print x509 certificate name!\n");
240
+        goto done;
241
+    }
237 242
     BIO_get_mem_ptr(bio_out_a, &biomem_a);
238 243
 
239
-    rc = X509_NAME_print_ex(bio_out_b, b, 0, XN_FLAG_SEP_SPLUS_SPC);
244
+    b = X509_get_subject_name(cert_b);
245
+
246
+    if (-1 == X509_NAME_print_ex(bio_out_b, b, 0, XN_FLAG_SEP_SPLUS_SPC)) {
247
+        mprintf("!Failed to print x509 certificate name!\n");
248
+        goto done;
249
+    }
240 250
     BIO_get_mem_ptr(bio_out_b, &biomem_b);
241 251
 
242 252
     *cmp_out = strncmp(biomem_a->data, biomem_b->data, MIN(biomem_a->length, biomem_b->length));
253
+    status   = CL_SUCCESS;
243 254
 
244 255
 done:
245 256
     if (NULL != bio_out_a)
... ...
@@ -247,19 +258,20 @@ done:
247 247
     if (NULL != bio_out_b)
248 248
         BIO_free(bio_out_b);
249 249
 
250
-    return !rc;
250
+    return status;
251 251
 }
252 252
 
253 253
 cl_error_t x509_get_cert_name(X509 *cert, char **name)
254 254
 {
255
-    int rc = CL_EMEM;
255
+    cl_error_t status = CL_EMEM;
256 256
 
257 257
     X509_NAME *a = NULL;
258 258
     BIO *bio_out = NULL;
259 259
     BUF_MEM *biomem;
260
+    char *cert_name = NULL;
260 261
 
261 262
     if (NULL == cert || NULL == name) {
262
-        rc = CL_EARG;
263
+        status = CL_EARG;
263 264
         goto done;
264 265
     }
265 266
 
... ...
@@ -269,21 +281,31 @@ cl_error_t x509_get_cert_name(X509 *cert, char **name)
269 269
     if (!bio_out)
270 270
         goto done;
271 271
 
272
-    rc = X509_NAME_print_ex(bio_out, a, 0, XN_FLAG_SEP_SPLUS_SPC);
272
+    a = X509_get_subject_name(cert);
273
+
274
+    if (-1 == X509_NAME_print_ex(bio_out, a, 0, XN_FLAG_SEP_SPLUS_SPC)) {
275
+        mprintf("!Failed to print x509 certificate name!\n");
276
+        goto done;
277
+    }
273 278
     BIO_get_mem_ptr(bio_out, &biomem);
274 279
 
275
-    *name = malloc(biomem->length + 1);
276
-    if (!name)
280
+    cert_name = malloc(biomem->length + 1);
281
+    if (!cert_name) {
282
+        mprintf("!Failed to allocate memory for certificate name biomem structure!\n");
277 283
         goto done;
284
+    }
285
+
286
+    memcpy(cert_name, biomem->data, biomem->length);
287
+    cert_name[biomem->length] = '\0';
278 288
 
279
-    memcpy(*name, biomem->data, biomem->length);
280
-    *name[biomem->length] = '\0';
289
+    *name  = cert_name;
290
+    status = CL_SUCCESS;
281 291
 
282 292
 done:
283 293
     if (NULL != bio_out)
284 294
         BIO_free(bio_out);
285 295
 
286
-    return !rc;
296
+    return status;
287 297
 }
288 298
 #endif
289 299