Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: rework NSS and SSL #9831

Merged
merged 2 commits into from Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 24 additions & 22 deletions CMakeLists.txt
Expand Up @@ -177,16 +177,6 @@ set(HAVE_OPENLDAP ${OPENLDAP_FOUND})
message(STATUS "${OPENLDAP_LIBS}")
endif(${WITH_OPENLDAP})

option(WITH_OPENSSL "OPENSSL is here" ON)
if(${WITH_OPENSSL})
find_package(OpenSSL REQUIRED)
set(HAVE_OPENSSL ON)
#message(STATUS "${OPENSSL_LIBRARIES}")
else(${WITH_OPENSSL})
set(HAVE_OPENSSL OFF)
set(OPENSSL_LIBRARIES)
endif(${WITH_OPENSSL})

option(WITH_FUSE "Fuse is here" ON)
if(${WITH_FUSE})
find_package(fuse)
Expand Down Expand Up @@ -286,18 +276,30 @@ find_package(libuuid REQUIRED)
find_package(libcurl REQUIRED)

# nss or cryptopp?
# (dropped cryptopp support for now, feel free to add it back -sage)
find_package(NSS REQUIRED)
if(NSS_FOUND)
set(USE_NSS 1)
find_package(NSPR)
if(NSPR_FOUND)
set(CRYPTO_LIBS ${NSS_LIBRARIES} ${NSPR_LIBRARIES})
#MESSAGE(STATUS "${CRYPTO_LIBS}")
#MESSAGE(STATUS "${NSS_INCLUDE_DIR} ${NSPR_INCLUDE_DIR}")
endif(NSPR_FOUND)
endif(NSS_FOUND)

option(WITH_NSS "Use NSS crypto and SSL implementations" ON)
if (${WITH_NSS})
find_package(NSS REQUIRED)
set(USE_NSS 1)
find_package(NSPR REQUIRED)
set(CRYPTO_LIBS ${NSS_LIBRARIES} ${NSPR_LIBRARIES})
else ()
find_package(cryptopp REQUIRED)
set(CRYPTO_LIBS ${CRYPTOPP_LIBRARIES})
set(USE_CRYPTOPP 1)
endif (${WITH_NSS})

option(WITH_SSL "SSL build selected" ON)
if (${USE_NSS})
#nss
set(SSL_LIBRARIES ${NSS_LIBRARIES})
message(STATUS "SSL with NSS selected (Libs: ${SSL_LIBRARIES})")
else (${USE_NSS})
#openssl
find_package(OpenSSL REQUIRED)
set(HAVE_OPENSSL ON)
set(SSL_LIBRARIES ${OPENSSL_LIBRARIES})
message(STATUS "SSL with OpenSSL selected (Libs: ${SSL_LIBRARIES})")
endif(${USE_NSS})

option(WITH_XIO "Enable XIO messaging" OFF)
if(WITH_XIO)
Expand Down
67 changes: 38 additions & 29 deletions configure.ac
Expand Up @@ -398,13 +398,27 @@ AC_CHECK_LIB([m], [pow], [true], AC_MSG_FAILURE([libm not found]))
AC_CHECK_FUNCS([syncfs], AC_DEFINE([HAVE_SYS_SYNCFS], [1], [we have syncfs]), [])

# Find some crypto library for us to use, while letting user to decide which one to use.
AC_ARG_WITH([cryptopp],
[AS_HELP_STRING([--with-cryptopp], [Use cryptographic functions from cryptopp])],
AC_ARG_WITH([nss],
[AS_HELP_STRING([--with-nss], [Use cryptographic functions from nss])],
[],
[with_cryptopp=check])
have_cryptopp=no
# this looks clumsy but it's just if A then { success } else { if B then success }
AS_IF([test "x$with_cryptopp" != "xno"],
[with_nss=check])
have_nss=no
AS_IF([test "x$with_nss" != "xno"],
[PKG_CHECK_MODULES([NSS], [nss], [have_nss=yes], [true])])
# bail out if given explicit --with-nss
if test "x$have_nss" = "xno" -a "x$with_nss" != "xcheck" -a "x$with_nss" != "xno"; then
AC_MSG_FAILURE([--with-nss was given, but library was not found])
fi

if test "x$have_nss" = "xno"; then
AC_ARG_WITH([cryptopp],
[AS_HELP_STRING([--with-cryptopp], [Use cryptographic functions from cryptopp])],
[],
[with_cryptopp=check])

have_cryptopp=no
# this looks clumsy but it's just if A then { success } else { if B then success }
AS_IF([test "x$with_cryptopp" != "xno"],
[PKG_CHECK_MODULES([CRYPTOPP],
[libcrypto++],
[have_cryptopp=yes],
Expand All @@ -422,39 +436,34 @@ AS_IF([test "x$with_cryptopp" != "xno"],
CXXFLAGS="${SAVED_CXXFLAGS}"
AC_LANG_POP([C++])
])])
# bail out if given explicit --with-cryptopp
if test "x$have_cryptopp" = "xno" -a "x$with_cryptopp" != "xcheck" -a "x$with_cryptopp" != "xno"; then
# bail out if given explicit --with-cryptopp
if test "x$have_cryptopp" = "xno" -a "x$with_cryptopp" != "xcheck" -a "x$with_cryptopp" != "xno"; then
AC_MSG_FAILURE([--with-cryptopp was given, but library was not found])
fi
fi

AC_ARG_WITH([nss],
[AS_HELP_STRING([--with-nss], [Use cryptographic functions from nss])],
[],
[with_nss=check])
have_nss=no
AS_IF([test "x$with_nss" != "xno"],
[PKG_CHECK_MODULES([NSS], [nss], [have_nss=yes], [true])])
# bail out if given explicit --with-nss
if test "x$have_nss" = "xno" -a "x$with_nss" != "xcheck" -a "x$with_nss" != "xno"; then
AC_MSG_FAILURE([--with-nss was given, but library was not found])
fi

# now decide which crypto library to really use
if test "x$have_cryptopp" = "xyes"; then
AC_MSG_NOTICE([using cryptopp for cryptography])
AC_DEFINE([USE_CRYPTOPP], [1], [Define if using CryptoPP.])
AC_SUBST([CRYPTO_CFLAGS], [$CRYPTOPP_CFLAGS])
#AC_SUBST([CRYPTO_CXXFLAGS], [$CRYPTOPP_CXXFLAGS])
AM_CXXFLAGS="${AM_CXXFLAGS} ${CRYPTOPP_CXXFLAGS}"
AC_SUBST([CRYPTO_LIBS], [$CRYPTOPP_LIBS])
elif test "x$have_nss" = "xyes"; then
# now decide which crypto library to use
if test "x$have_nss" = "xyes"; then
AC_MSG_NOTICE([using nss for cryptography])
AC_DEFINE([USE_NSS], [1], [Define if using NSS.])
AC_SUBST([CRYPTO_CFLAGS], [$NSS_CFLAGS])
# this needs CFLAGS too in practise to get the includes right. ugly.
#AC_SUBST([CRYPTO_CXXFLAGS], [$NSS_CFLAGS $NSS_CXXFLAGS])
AM_CXXFLAGS="${AM_CXXFLAGS} ${NSS_CFLAGS} ${NSS_CXXFLAGS}"
AC_SUBST([CRYPTO_LIBS], [$NSS_LIBS])
AC_SUBST([SSL_LIBS], [$NSS_LIBS])
elif test "x$have_cryptopp" = "xyes"; then
AC_MSG_NOTICE([using cryptopp for cryptography])
AC_DEFINE([USE_CRYPTOPP], [1], [Define if using CryptoPP.])
AC_SUBST([CRYPTO_CFLAGS], [$CRYPTOPP_CFLAGS])
#AC_SUBST([CRYPTO_CXXFLAGS], [$CRYPTOPP_CXXFLAGS])
AM_CXXFLAGS="${AM_CXXFLAGS} ${CRYPTOPP_CXXFLAGS}"
AC_SUBST([CRYPTO_LIBS], [$CRYPTOPP_LIBS])
# OpenSSL -- defines OPENSSL_{INCLUDES,LIBS,LDFLAGS} on success
AX_CHECK_OPENSSL([],
[AC_MSG_FAILURE([CryptoPP build selected but OpenSSL not found])])
AC_SUBST([SSL_INCLUDES], [$OPENSSL_INCLUDES])
AC_SUBST([SSL_LIBS], [$OPENSSL_LIBS])
else
AC_MSG_FAILURE([no suitable crypto library found])
fi
Expand Down
124 changes: 124 additions & 0 deletions m4/ax_check_openssl.m4
@@ -0,0 +1,124 @@
# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
#
# DESCRIPTION
#
# Look for OpenSSL in a number of default spots, or in a user-selected
# spot (via --with-openssl). Sets
#
# OPENSSL_INCLUDES to the include directives required
# OPENSSL_LIBS to the -l directives required
# OPENSSL_LDFLAGS to the -L or -R flags required
#
# and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
#
# This macro sets OPENSSL_INCLUDES such that source files should use the
# openssl/ directory in include directives:
#
# #include <openssl/hmac.h>
#
# LICENSE
#
# Copyright (c) 2009,2010 Zmanda Inc. <http://www.zmanda.com/>
# Copyright (c) 2009,2010 Dustin J. Mitchell <dustin@zmanda.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 8

AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
AC_DEFUN([AX_CHECK_OPENSSL], [
found=false
AC_ARG_WITH([openssl],
[AS_HELP_STRING([--with-openssl=DIR],
[root of the OpenSSL directory])],
[
case "$withval" in
"" | y | ye | yes | n | no)
AC_MSG_ERROR([Invalid --with-openssl value])
;;
*) ssldirs="$withval"
;;
esac
], [
# if pkg-config is installed and openssl has installed a .pc file,
# then use that information and don't search ssldirs
AC_PATH_PROG([PKG_CONFIG], [pkg-config])
if test x"$PKG_CONFIG" != x""; then
OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
if test $? = 0; then
OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
found=true
fi
fi

# no such luck; use some default ssldirs
if ! $found; then
ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
fi
]
)


# note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
# an 'openssl' subdirectory

if ! $found; then
OPENSSL_INCLUDES=
for ssldir in $ssldirs; do
AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
if test -f "$ssldir/include/openssl/ssl.h"; then
OPENSSL_INCLUDES="-I$ssldir/include"
OPENSSL_LDFLAGS="-L$ssldir/lib"
OPENSSL_LIBS="-lssl -lcrypto"
found=true
AC_MSG_RESULT([yes])
break
else
AC_MSG_RESULT([no])
fi
done

# if the file wasn't found, well, go ahead and try the link anyway -- maybe
# it will just work!
fi

# try the preprocessor and linker with our new flags,
# being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS

AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
"OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&AS_MESSAGE_LOG_FD

save_LIBS="$LIBS"
save_LDFLAGS="$LDFLAGS"
save_CPPFLAGS="$CPPFLAGS"
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
LIBS="$OPENSSL_LIBS $LIBS"
CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <openssl/ssl.h>], [SSL_new(NULL)])],
[
AC_MSG_RESULT([yes])
$1
], [
AC_MSG_RESULT([no])
$2
])
CPPFLAGS="$save_CPPFLAGS"
LDFLAGS="$save_LDFLAGS"
LIBS="$save_LIBS"

AC_SUBST([OPENSSL_INCLUDES])
AC_SUBST([OPENSSL_LIBS])
AC_SUBST([OPENSSL_LDFLAGS])
])
20 changes: 10 additions & 10 deletions src/CMakeLists.txt
Expand Up @@ -1417,13 +1417,13 @@ if(${WITH_RADOSGW})
add_library(civetweb_common_objs OBJECT ${civetweb_common_files})
target_include_directories(civetweb_common_objs PUBLIC
"${CMAKE_SOURCE_DIR}/src/civetweb/include")
if(HAVE_OPENSSL)
set_property(TARGET civetweb_common_objs
APPEND PROPERTY COMPILE_DEFINITIONS NO_SSL_DL=1)
target_include_directories(civetweb_common_objs PUBLIC
"${OPENSSL_INCLUDE_DIR}")
else(HAVE_OPENSSL)
endif(HAVE_OPENSSL)
if(HAVE_SSL)
set_property(TARGET civetweb_common_objs
APPEND PROPERTY COMPILE_DEFINITIONS NO_SSL_DL=1)
target_include_directories(civetweb_common_objs PUBLIC
"${SSL_INCLUDE_DIR}")
else(HAVE_SSL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could dispense with this empty "else" block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's rather fussy

endif(HAVE_SSL)

add_library(rgw_a STATIC ${rgw_a_srcs})
target_link_libraries(rgw_a librados cls_rgw_client cls_refcount_client
Expand Down Expand Up @@ -1482,8 +1482,8 @@ if(${WITH_RADOSGW})
cls_rgw_client cls_lock_client cls_refcount_client
cls_log_client cls_statelog_client cls_timeindex_client
cls_version_client cls_replica_log_client cls_user_client
curl expat global fcgi resolv ${OPENSSL_LIBRARIES} ${BLKID_LIBRARIES} ${OPENLDAP_LIBS}
${ALLOC_LIBS})
curl expat global fcgi resolv ${SSL_LIBRARIES} ${BLKID_LIBRARIES}
${OPENLDAP_LIBS} ${ALLOC_LIBS})
# radosgw depends on cls libraries at runtime, but not as link dependencies
add_dependencies(radosgw cls_rgw cls_lock cls_refcount
cls_log cls_statelog cls_timeindex
Expand All @@ -1495,7 +1495,7 @@ if(${WITH_RADOSGW})
cls_rgw_client cls_lock_client cls_refcount_client
cls_log_client cls_statelog_client cls_timeindex_client
cls_version_client cls_replica_log_client cls_user_client
curl expat global fcgi resolv ${OPENSSL_LIBRARIES} ${BLKID_LIBRARIES})
curl expat global fcgi resolv ${SSL_LIBRARIES} ${BLKID_LIBRARIES})

install(TARGETS radosgw-admin DESTINATION bin)

Expand Down
4 changes: 2 additions & 2 deletions src/rgw/Makefile.am
Expand Up @@ -143,8 +143,8 @@ libcivetweb_la_SOURCES = \

libcivetweb_la_CXXFLAGS = ${CIVETWEB_INCLUDE} -fPIC -Woverloaded-virtual \
${AM_CXXFLAGS}
libcivetweb_la_CFLAGS = -I$(srcdir)/civetweb/include ${CIVETWEB_INCLUDE} -fPIC -DNO_SSL_DL
LIBCIVETWEB_DEPS += -lssl -lcrypto
libcivetweb_la_CFLAGS = -I$(srcdir)/civetweb/include ${CIVETWEB_INCLUDE} ${SSL_INCLUDES} -fPIC -DNO_SSL_DL
LIBCIVETWEB_DEPS += ${SSL_LIBS}

noinst_LTLIBRARIES += libcivetweb.la

Expand Down