Commit cc14523440c99ff970e9a002f600133deab4b5dd

Authored by Jay Berkenbilt
1 parent d0a53cd3

Update autoconf to support crypto selection

autoconf.mk.in
@@ -30,6 +30,7 @@ STRIP=@STRIP@ @@ -30,6 +30,7 @@ STRIP=@STRIP@
30 OBJDUMP=@OBJDUMP@ 30 OBJDUMP=@OBJDUMP@
31 GENDEPS=@GENDEPS@ 31 GENDEPS=@GENDEPS@
32 LIBTOOL=@LIBTOOL@ 32 LIBTOOL=@LIBTOOL@
  33 +USE_CRYPTO_NATIVE=@USE_CRYPTO_NATIVE@
33 DOCBOOKX_DTD=@DOCBOOKX_DTD@ 34 DOCBOOKX_DTD=@DOCBOOKX_DTD@
34 FOP=@FOP@ 35 FOP=@FOP@
35 XSLTPROC=@XSLTPROC@ 36 XSLTPROC=@XSLTPROC@
autofiles.sums
1 -0e7c13071bce1494783a7da2be2b8805a9c03118e62126162ae551034882d420 configure.ac 1 +2b5c5a808c353b8df9e28e8cfb1e7d37114a2cad37eaede5bfe4354acae804d0 configure.ac
2 d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4 2 d3f9ee6f6f0846888d9a10fd3dad2e4b1258be84205426cf04d7cef02d61dad7 aclocal.m4
3 -39b7c25e5553cb231b408de5f22b86386e96fb109e2c44371f57c33d4d285725 libqpdf/qpdf/qpdf-config.h.in 3 +7fc840fce5d372e92aa676e0040213a0f239cc8c01b6d6ef53c82043ceda571a libqpdf/qpdf/qpdf-config.h.in
4 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4 4 5297971a0ef90bcd5563eb3f7127a032bb76d3ae2af7258bf13479caf8983a60 m4/ax_cxx_compile_stdcxx.m4
5 35bc5c645dc42d47f2daeea06f8f3e767c8a1aee6a35eb2b4854fd2ce66c3413 m4/ax_random_device.m4 5 35bc5c645dc42d47f2daeea06f8f3e767c8a1aee6a35eb2b4854fd2ce66c3413 m4/ax_random_device.m4
6 37f8897d5f68d7d484e5457832a8f190ddb7507fa2a467cb7ee2be40a4364643 m4/libtool.m4 6 37f8897d5f68d7d484e5457832a8f190ddb7507fa2a467cb7ee2be40a4364643 m4/libtool.m4
configure
@@ -642,6 +642,8 @@ DOCBOOK_FO @@ -642,6 +642,8 @@ DOCBOOK_FO
642 DOCBOOK_XHTML 642 DOCBOOK_XHTML
643 SHOW_FAILED_TEST_OUTPUT 643 SHOW_FAILED_TEST_OUTPUT
644 QPDF_SKIP_TEST_COMPARE_IMAGES 644 QPDF_SKIP_TEST_COMPARE_IMAGES
  645 +DEFAULT_CRYPTO
  646 +USE_CRYPTO_NATIVE
645 CXXWFLAGS 647 CXXWFLAGS
646 WFLAGS 648 WFLAGS
647 BUILDRULES 649 BUILDRULES
@@ -776,6 +778,9 @@ enable_ld_version_script @@ -776,6 +778,9 @@ enable_ld_version_script
776 with_buildrules 778 with_buildrules
777 enable_werror 779 enable_werror
778 enable_int_warnings 780 enable_int_warnings
  781 +enable_implicit_crypto
  782 +enable_crypto_native
  783 +with_default_crypto
779 enable_test_compare_images 784 enable_test_compare_images
780 enable_show_failed_test_output 785 enable_show_failed_test_output
781 with_docbook_xsl 786 with_docbook_xsl
@@ -1456,6 +1461,11 @@ Optional Features: @@ -1456,6 +1461,11 @@ Optional Features:
1456 --enable-werror whether to treat warnings as errors (default is no) 1461 --enable-werror whether to treat warnings as errors (default is no)
1457 --enable-int-warnings whether to turn on integer type warnings (default is 1462 --enable-int-warnings whether to turn on integer type warnings (default is
1458 yes) 1463 yes)
  1464 + --enable-implicit-crypto
  1465 + whether to enable available crypto providers that
  1466 + are not explicitly requested; true by default
  1467 + --enable-crypto-native whether to include support for native crypto
  1468 + provider
1459 --enable-test-compare-images 1469 --enable-test-compare-images
1460 whether to compare images in test suite; disabled by 1470 whether to compare images in test suite; disabled by
1461 default, enabling requires ghostscript and tiffcmp 1471 default, enabling requires ghostscript and tiffcmp
@@ -1491,6 +1501,9 @@ Optional Packages: @@ -1491,6 +1501,9 @@ Optional Packages:
1491 QPDF_LARGE_FILE_TEST_PATH environment variable to 1501 QPDF_LARGE_FILE_TEST_PATH environment variable to
1492 the path before running the test suite. 1502 the path before running the test suite.
1493 --with-buildrules=rules which build rules to use; see README.md 1503 --with-buildrules=rules which build rules to use; see README.md
  1504 + --with-default-crypto=provider
  1505 + which crypto provider to use by default; see
  1506 + README.md
1494 --with-docbook-xsl=DIR location of docbook 4.x xml stylesheets 1507 --with-docbook-xsl=DIR location of docbook 4.x xml stylesheets
1495 --with-docbookx-dtd=FILE 1508 --with-docbookx-dtd=FILE
1496 location of docbook 4.x xml DTD 1509 location of docbook 4.x xml DTD
@@ -17569,6 +17582,84 @@ $as_echo "no" >&6; } @@ -17569,6 +17582,84 @@ $as_echo "no" >&6; }
17569 fi 17582 fi
17570 17583
17571 17584
  17585 +
  17586 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for whether to use implicit crypto" >&5
  17587 +$as_echo_n "checking for whether to use implicit crypto... " >&6; }
  17588 +# Check whether --enable-implicit-crypto was given.
  17589 +if test "${enable_implicit_crypto+set}" = set; then :
  17590 + enableval=$enable_implicit_crypto; if test "$enableval" = "yes"; then
  17591 + IMPLICIT_CRYPTO=1
  17592 + else
  17593 + IMPLICIT_CRYPTO=0
  17594 + fi
  17595 +else
  17596 + IMPLICIT_CRYPTO=1
  17597 +fi
  17598 +
  17599 +if test "$IMPLICIT_CRYPTO" = "1"; then
  17600 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
  17601 +$as_echo "yes" >&6; }
  17602 +else
  17603 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
  17604 +$as_echo "no" >&6; }
  17605 +fi
  17606 +
  17607 +
  17608 +
  17609 +# Check whether --enable-crypto-native was given.
  17610 +if test "${enable_crypto_native+set}" = set; then :
  17611 + enableval=$enable_crypto_native; if test "$enableval" = "yes"; then
  17612 + USE_CRYPTO_NATIVE=1
  17613 + else
  17614 + USE_CRYPTO_NATIVE=0
  17615 + fi
  17616 +else
  17617 + USE_CRYPTO_NATIVE=$IMPLICIT_CRYPTO
  17618 +fi
  17619 +
  17620 +if test "$USE_CRYPTO_NATIVE" = "1"; then
  17621 +
  17622 +$as_echo "#define USE_CRYPTO_NATIVE 1" >>confdefs.h
  17623 +
  17624 + DEFAULT_CRYPTO=native
  17625 +fi
  17626 +
  17627 +
  17628 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking which crypto to use by default" >&5
  17629 +$as_echo_n "checking which crypto to use by default... " >&6; }
  17630 +
  17631 +
  17632 +# Check whether --with-default-crypto was given.
  17633 +if test "${with_default_crypto+set}" = set; then :
  17634 + withval=$with_default_crypto; DEFAULT_CRYPTO=$withval
  17635 +fi
  17636 +
  17637 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $DEFAULT_CRYPTO" >&5
  17638 +$as_echo "$DEFAULT_CRYPTO" >&6; }
  17639 +
  17640 +cat >>confdefs.h <<_ACEOF
  17641 +#define DEFAULT_CRYPTO "$DEFAULT_CRYPTO"
  17642 +_ACEOF
  17643 +
  17644 +
  17645 +
  17646 +bad_crypto=0
  17647 +case "$DEFAULT_CRYPTO" in
  17648 + "native")
  17649 + if test "$USE_CRYPTO_NATIVE" != "1"; then
  17650 + bad_crypto=1
  17651 + fi
  17652 + ;;
  17653 + *)
  17654 + bad_crypto=1
  17655 + ;;
  17656 +esac
  17657 +if test "$bad_crypto" = "1"; then
  17658 + as_fn_error $? "Unsupported default crypto: $DEFAULT_CRYPTO" "$LINENO" 5
  17659 +fi
  17660 +
  17661 +
  17662 +
17572 # Check whether --enable-test-compare-images was given. 17663 # Check whether --enable-test-compare-images was given.
17573 if test "${enable_test_compare_images+set}" = set; then : 17664 if test "${enable_test_compare_images+set}" = set; then :
17574 enableval=$enable_test_compare_images; if test "$enableval" = "no"; then 17665 enableval=$enable_test_compare_images; if test "$enableval" = "no"; then
configure.ac
@@ -465,6 +465,78 @@ else @@ -465,6 +465,78 @@ else
465 AC_MSG_RESULT(no) 465 AC_MSG_RESULT(no)
466 fi 466 fi
467 467
  468 +dnl BEGIN CRYPTO
  469 +
  470 +dnl By default, we build in support for every crypto provider that we
  471 +dnl can. If implicit crypto is disabled, we don't build support for
  472 +dnl any crypto that is not explicitly enabled. Test for various crypto
  473 +dnl providers in increasing order of priority. The last one found
  474 +dnl becomes the default unless a default is explicitly specified.
  475 +
  476 +AC_MSG_CHECKING(for whether to use implicit crypto)
  477 +AC_ARG_ENABLE(implicit-crypto,
  478 + AS_HELP_STRING([--enable-implicit-crypto],
  479 + [whether to enable available crypto providers that are not explicitly requested; true by default]),
  480 + [if test "$enableval" = "yes"; then
  481 + IMPLICIT_CRYPTO=1
  482 + else
  483 + IMPLICIT_CRYPTO=0
  484 + fi],
  485 + [IMPLICIT_CRYPTO=1])
  486 +if test "$IMPLICIT_CRYPTO" = "1"; then
  487 + AC_MSG_RESULT(yes)
  488 +else
  489 + AC_MSG_RESULT(no)
  490 +fi
  491 +
  492 +dnl Native crypto is always available unless explicitly disabled.
  493 +
  494 +AC_SUBST(USE_CRYPTO_NATIVE)
  495 +AC_ARG_ENABLE(crypto-native,
  496 + AS_HELP_STRING([--enable-crypto-native],
  497 + [whether to include support for native crypto provider]),
  498 + [if test "$enableval" = "yes"; then
  499 + USE_CRYPTO_NATIVE=1
  500 + else
  501 + USE_CRYPTO_NATIVE=0
  502 + fi],
  503 + [USE_CRYPTO_NATIVE=$IMPLICIT_CRYPTO])
  504 +if test "$USE_CRYPTO_NATIVE" = "1"; then
  505 + AC_DEFINE([USE_CRYPTO_NATIVE], 1, [Whether to use the native crypto provider])
  506 + DEFAULT_CRYPTO=native
  507 +fi
  508 +
  509 +dnl Allow the default crypto provider to be specified explicitly.
  510 +
  511 +AC_MSG_CHECKING(which crypto to use by default)
  512 +AC_SUBST(DEFAULT_CRYPTO)
  513 +AC_ARG_WITH(default-crypto,
  514 + AS_HELP_STRING([--with-default-crypto=provider],
  515 + [which crypto provider to use by default; see README.md]),
  516 + [DEFAULT_CRYPTO=$withval],
  517 + [])
  518 +AC_MSG_RESULT($DEFAULT_CRYPTO)
  519 +AC_DEFINE_UNQUOTED([DEFAULT_CRYPTO], "$DEFAULT_CRYPTO", [Default crypto provider])
  520 +
  521 +dnl Make sure the default crypto provider is actually being built.
  522 +
  523 +bad_crypto=0
  524 +case "$DEFAULT_CRYPTO" in
  525 + "native")
  526 + if test "$USE_CRYPTO_NATIVE" != "1"; then
  527 + bad_crypto=1
  528 + fi
  529 + ;;
  530 + *)
  531 + bad_crypto=1
  532 + ;;
  533 +esac
  534 +if test "$bad_crypto" = "1"; then
  535 + AC_MSG_ERROR(Unsupported default crypto: $DEFAULT_CRYPTO)
  536 +fi
  537 +
  538 +dnl END CRYPTO
  539 +
468 AC_SUBST(QPDF_SKIP_TEST_COMPARE_IMAGES) 540 AC_SUBST(QPDF_SKIP_TEST_COMPARE_IMAGES)
469 AC_ARG_ENABLE(test-compare-images, 541 AC_ARG_ENABLE(test-compare-images,
470 AS_HELP_STRING([--enable-test-compare-images], 542 AS_HELP_STRING([--enable-test-compare-images],
libqpdf/QPDFCryptoProvider.cc
1 #include <qpdf/QPDFCryptoProvider.hh> 1 #include <qpdf/QPDFCryptoProvider.hh>
  2 +#include <qpdf/qpdf-config.h>
2 #include <stdexcept> 3 #include <stdexcept>
3 4
4 -#include <qpdf/QPDFCrypto_native.hh> 5 +#ifdef USE_CRYPTO_NATIVE
  6 +# include <qpdf/QPDFCrypto_native.hh>
  7 +#endif
5 8
6 std::shared_ptr<QPDFCryptoImpl> 9 std::shared_ptr<QPDFCryptoImpl>
7 QPDFCryptoProvider::getImpl() 10 QPDFCryptoProvider::getImpl()
@@ -37,8 +40,10 @@ QPDFCryptoProvider::setDefaultProvider(std::string const&amp; name) @@ -37,8 +40,10 @@ QPDFCryptoProvider::setDefaultProvider(std::string const&amp; name)
37 QPDFCryptoProvider::QPDFCryptoProvider() : 40 QPDFCryptoProvider::QPDFCryptoProvider() :
38 m(std::make_shared<Members>()) 41 m(std::make_shared<Members>())
39 { 42 {
  43 +#ifdef USE_CRYPTO_NATIVE
40 registerImpl_internal<QPDFCrypto_native>("native"); 44 registerImpl_internal<QPDFCrypto_native>("native");
41 - setDefaultProvider_internal("native"); 45 +#endif
  46 + setDefaultProvider_internal(DEFAULT_CRYPTO);
42 } 47 }
43 48
44 QPDFCryptoProvider& 49 QPDFCryptoProvider&
libqpdf/build.mk
@@ -90,7 +90,9 @@ SRCS_libqpdf = \ @@ -90,7 +90,9 @@ SRCS_libqpdf = \
90 libqpdf/SparseOHArray.cc \ 90 libqpdf/SparseOHArray.cc \
91 libqpdf/qpdf-c.cc 91 libqpdf/qpdf-c.cc
92 92
  93 +ifeq ($(USE_CRYPTO_NATIVE), 1)
93 SRCS_libqpdf += $(CRYPTO_NATIVE) 94 SRCS_libqpdf += $(CRYPTO_NATIVE)
  95 +endif
94 96
95 # ----- 97 # -----
96 98
libqpdf/qpdf/qpdf-config.h.in
@@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
3 /* Whether to avoid use of HANDLE in Windows */ 3 /* Whether to avoid use of HANDLE in Windows */
4 #undef AVOID_WINDOWS_HANDLE 4 #undef AVOID_WINDOWS_HANDLE
5 5
  6 +/* Default crypto provider */
  7 +#undef DEFAULT_CRYPTO
  8 +
6 /* define if the compiler supports basic C++11 syntax */ 9 /* define if the compiler supports basic C++11 syntax */
7 #undef HAVE_CXX11 10 #undef HAVE_CXX11
8 11
@@ -81,6 +84,9 @@ @@ -81,6 +84,9 @@
81 /* Define to 1 if you have the ANSI C header files. */ 84 /* Define to 1 if you have the ANSI C header files. */
82 #undef STDC_HEADERS 85 #undef STDC_HEADERS
83 86
  87 +/* Whether to use the native crypto provider */
  88 +#undef USE_CRYPTO_NATIVE
  89 +
84 /* Whether to use insecure random numbers */ 90 /* Whether to use insecure random numbers */
85 #undef USE_INSECURE_RANDOM 91 #undef USE_INSECURE_RANDOM
86 92