Skip to content

Commit

Permalink
Add BearSSL vtls implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelforney committed Nov 17, 2019
1 parent 2e9b725 commit 84b966b
Show file tree
Hide file tree
Showing 17 changed files with 1,038 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CMake/FindBearSSL.cmake
@@ -0,0 +1,9 @@
find_path(BEARSSL_INCLUDE_DIRS bearssl.h)

find_library(BEARSSL_LIBRARY bearssl)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BEARSSL DEFAULT_MSG
BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY)

mark_as_advanced(BEARSSL_INCLUDE_DIRS BEARSSL_LIBRARY)
11 changes: 11 additions & 0 deletions CMakeLists.txt
Expand Up @@ -295,6 +295,7 @@ if(WIN32)
CMAKE_USE_WINSSL OFF)
endif()
option(CMAKE_USE_MBEDTLS "Enable mbedTLS for SSL/TLS" OFF)
option(CMAKE_USE_BEARSSL "Enable BearSSL for SSL/TLS" OFF)

set(openssl_default ON)
if(WIN32 OR CMAKE_USE_SECTRANSP OR CMAKE_USE_WINSSL OR CMAKE_USE_MBEDTLS)
Expand All @@ -307,6 +308,7 @@ count_true(enabled_ssl_options_count
CMAKE_USE_SECTRANSP
CMAKE_USE_OPENSSL
CMAKE_USE_MBEDTLS
CMAKE_USE_BEARSSL
)
if(enabled_ssl_options_count GREATER "1")
set(CURL_WITH_MULTI_SSL ON)
Expand Down Expand Up @@ -379,6 +381,14 @@ if(CMAKE_USE_MBEDTLS)
include_directories(${MBEDTLS_INCLUDE_DIRS})
endif()

if(CMAKE_USE_BEARSSL)
find_package(BearSSL REQUIRED)
set(SSL_ENABLED ON)
set(USE_BEARSSL ON)
list(APPEND CURL_LIBS ${BEARSSL_LIBRARY})
include_directories(${BEARSSL_INCLUDE_DIRS})
endif()

option(USE_NGHTTP2 "Use Nghttp2 library" OFF)
if(USE_NGHTTP2)
find_package(NGHTTP2 REQUIRED)
Expand Down Expand Up @@ -1251,6 +1261,7 @@ _add_if("WinSSL" SSL_ENABLED AND USE_WINDOWS_SSPI)
_add_if("OpenSSL" SSL_ENABLED AND USE_OPENSSL)
_add_if("Secure Transport" SSL_ENABLED AND USE_SECTRANSP)
_add_if("mbedTLS" SSL_ENABLED AND USE_MBEDTLS)
_add_if("BearSSL" SSL_ENABLED AND USE_BEARSSL)
if(_items)
list(SORT _items)
endif()
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Expand Up @@ -30,8 +30,8 @@ CMAKE_DIST = CMakeLists.txt CMake/CMakeConfigurableFile.in \
CMake/Macros.cmake \
CMake/CurlSymbolHiding.cmake CMake/FindCARES.cmake \
CMake/FindLibSSH2.cmake CMake/FindNGHTTP2.cmake \
CMake/FindMbedTLS.cmake CMake/cmake_uninstall.cmake.in \
CMake/curl-config.cmake.in
CMake/FindMbedTLS.cmake CMake/FindBearSSL.cmake \
CMake/cmake_uninstall.cmake.in CMake/curl-config.cmake.in

VC6_LIBTMPL = projects/Windows/VC6/lib/libcurl.tmpl
VC6_LIBDSP = projects/Windows/VC6/lib/libcurl.dsp.dist
Expand Down
98 changes: 95 additions & 3 deletions configure.ac
Expand Up @@ -156,7 +156,7 @@ AC_SUBST(PKGADD_VENDOR)

dnl
dnl initialize all the info variables
curl_ssl_msg="no (--with-{ssl,gnutls,nss,mbedtls,wolfssl,schannel,secure-transport,mesalink,amissl} )"
curl_ssl_msg="no (--with-{ssl,gnutls,nss,mbedtls,wolfssl,schannel,secure-transport,mesalink,amissl,bearssl} )"
curl_ssh_msg="no (--with-libssh2)"
curl_zlib_msg="no (--with-zlib)"
curl_brotli_msg="no (--with-brotli)"
Expand Down Expand Up @@ -2399,6 +2399,98 @@ if test -z "$ssl_backends" -o "x$OPT_MESALINK" != xno; then
test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
fi

dnl ----------------------------------------------------
dnl check for BearSSL
dnl ----------------------------------------------------

OPT_BEARSSL=no

_cppflags=$CPPFLAGS
_ldflags=$LDFLAGS
AC_ARG_WITH(bearssl,dnl
AC_HELP_STRING([--with-bearssl=PATH],[where to look for BearSSL, PATH points to the installation root])
AC_HELP_STRING([--without-bearssl], [disable BearSSL detection]),
OPT_BEARSSL=$withval)

if test -z "$ssl_backends" -o "x$OPT_BEARSSL" != xno; then
ssl_msg=

if test X"$OPT_BEARSSL" != Xno; then

if test "$OPT_BEARSSL" = "yes"; then
OPT_BEARSSL=""
fi

if test -z "$OPT_BEARSSL" ; then
dnl check for lib first without setting any new path

AC_CHECK_LIB(bearssl, br_ssl_client_init_full,
dnl libbearssl found, set the variable
[
AC_DEFINE(USE_BEARSSL, 1, [if BearSSL is enabled])
AC_SUBST(USE_BEARSSL, [1])
BEARSSL_ENABLED=1
USE_BEARSSL="yes"
ssl_msg="BearSSL"
test bearssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
], [], -lbearssl)
fi

addld=""
addlib=""
addcflags=""
bearssllib=""

if test "x$USE_BEARSSL" != "xyes"; then
dnl add the path and test again
addld=-L$OPT_BEARSSL/lib$libsuff
addcflags=-I$OPT_BEARSSL/include
bearssllib=$OPT_BEARSSL/lib$libsuff

LDFLAGS="$LDFLAGS $addld"
if test "$addcflags" != "-I/usr/include"; then
CPPFLAGS="$CPPFLAGS $addcflags"
fi

AC_CHECK_LIB(bearssl, br_ssl_client_init_full,
[
AC_DEFINE(USE_BEARSSL, 1, [if BearSSL is enabled])
AC_SUBST(USE_BEARSSL, [1])
BEARSSL_ENABLED=1
USE_BEARSSL="yes"
ssl_msg="BearSSL"
test bearssl != "$DEFAULT_SSL_BACKEND" || VALID_DEFAULT_SSL_BACKEND=yes
],
[
CPPFLAGS=$_cppflags
LDFLAGS=$_ldflags
], -lbearssl)
fi

if test "x$USE_BEARSSL" = "xyes"; then
AC_MSG_NOTICE([detected BearSSL])
check_for_ca_bundle=1

LIBS="-lbearssl $LIBS"

if test -n "$bearssllib"; then
dnl when shared libs were found in a path that the run-time
dnl linker doesn't search through, we need to add it to
dnl CURL_LIBRARY_PATH to prevent further configure tests to fail
dnl due to this
if test "x$cross_compiling" != "xyes"; then
CURL_LIBRARY_PATH="$CURL_LIBRARY_PATH:$bearssllib"
export CURL_LIBRARY_PATH
AC_MSG_NOTICE([Added $bearssllib to CURL_LIBRARY_PATH])
fi
fi
fi

fi dnl BearSSL not disabled

test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
fi

dnl ----------------------------------------------------
dnl NSS. Only check if GnuTLS and OpenSSL are not enabled
dnl ----------------------------------------------------
Expand Down Expand Up @@ -2529,10 +2621,10 @@ if test -z "$ssl_backends" -o "x$OPT_NSS" != xno; then
test -z "$ssl_msg" || ssl_backends="${ssl_backends:+$ssl_backends, }$ssl_msg"
fi

case "x$OPENSSL_ENABLED$GNUTLS_ENABLED$NSS_ENABLED$MBEDTLS_ENABLED$WOLFSSL_ENABLED$WINSSL_ENABLED$SECURETRANSPORT_ENABLED$MESALINK_ENABLED$AMISSL_ENABLED" in
case "x$OPENSSL_ENABLED$GNUTLS_ENABLED$NSS_ENABLED$MBEDTLS_ENABLED$WOLFSSL_ENABLED$WINSSL_ENABLED$SECURETRANSPORT_ENABLED$MESALINK_ENABLED$BEARSSL_ENABLED$AMISSL_ENABLED" in
x)
AC_MSG_WARN([SSL disabled, you will not be able to use HTTPS, FTPS, NTLM and more.])
AC_MSG_WARN([Use --with-ssl, --with-gnutls, --with-wolfssl, --with-mbedtls, --with-nss, --with-schannel, --with-secure-transport, --with-mesalink or --with-amissl to address this.])
AC_MSG_WARN([Use --with-ssl, --with-gnutls, --with-wolfssl, --with-mbedtls, --with-nss, --with-schannel, --with-secure-transport, --with-mesalink, --with-amissl or --with-bearssl to address this.])
;;
x1)
# one SSL backend is enabled
Expand Down
6 changes: 3 additions & 3 deletions docs/FAQ
Expand Up @@ -447,9 +447,9 @@ FAQ

curl can be built to use one of the following SSL alternatives: OpenSSL,
libressl, BoringSSL, GnuTLS, wolfSSL, NSS, mbedTLS, MesaLink, Secure
Transport (native iOS/OS X), Schannel (native Windows) or GSKit (native IBM
i). They all have their pros and cons, and we try to maintain a comparison
of them here: https://curl.haxx.se/docs/ssl-compared.html
Transport (native iOS/OS X), Schannel (native Windows), GSKit (native IBM
i), or BearSSL. They all have their pros and cons, and we try to maintain a
comparison of them here: https://curl.haxx.se/docs/ssl-compared.html

2.3 Where can I find a copy of LIBEAY32.DLL?

Expand Down
1 change: 1 addition & 0 deletions docs/INSTALL.md
Expand Up @@ -120,6 +120,7 @@ libressl.
- schannel: `--without-ssl --with-schannel`
- secure transport: `--without-ssl --with-secure-transport`
- MesaLink: `--without-ssl --with-mesalink`
- BearSSL: `--without-ssl --with-bearssl`

# Windows

Expand Down
5 changes: 5 additions & 0 deletions docs/LICENSE-MIXING.md
Expand Up @@ -75,6 +75,11 @@ not have the announcement clause that collides with GPL.
(May be used for SSL/TLS support) As an OpenSSL fork, it has the same
license as that.

## BearSSL

(May be used for SSL/TLS support) Uses an MIT license that is very liberal
and imposes no restrictions on any other library or part you may link with.

## c-ares

(Used for asynchronous name resolves) Uses an MIT license that is very
Expand Down
3 changes: 2 additions & 1 deletion docs/libcurl/curl_global_sslset.3
Expand Up @@ -43,7 +43,8 @@ typedef enum {
CURLSSLBACKEND_DARWINSSL = 9,
CURLSSLBACKEND_AXTLS = 10, /* deprecated */
CURLSSLBACKEND_MBEDTLS = 11,
CURLSSLBACKEND_MESALINK = 12
CURLSSLBACKEND_MESALINK = 12,
CURLSSLBACKEND_BEARSSL = 13
} curl_sslbackend;

.B "CURLsslset curl_global_sslset(curl_sslbackend " id,
Expand Down
1 change: 1 addition & 0 deletions docs/libcurl/symbols-in-versions
Expand Up @@ -718,6 +718,7 @@ CURLSSH_AUTH_NONE 7.16.1
CURLSSH_AUTH_PASSWORD 7.16.1
CURLSSH_AUTH_PUBLICKEY 7.16.1
CURLSSLBACKEND_AXTLS 7.38.0 7.61.0
CURLSSLBACKEND_BEARSSL 7.68.0
CURLSSLBACKEND_BORINGSSL 7.49.0
CURLSSLBACKEND_CYASSL 7.34.0
CURLSSLBACKEND_DARWINSSL 7.34.0 7.64.1
Expand Down
3 changes: 2 additions & 1 deletion include/curl/curl.h
Expand Up @@ -154,7 +154,8 @@ typedef enum {
CURLSSLBACKEND_SECURETRANSPORT = 9,
CURLSSLBACKEND_AXTLS = 10, /* never used since 7.63.0 */
CURLSSLBACKEND_MBEDTLS = 11,
CURLSSLBACKEND_MESALINK = 12
CURLSSLBACKEND_MESALINK = 12,
CURLSSLBACKEND_BEARSSL = 13
} curl_sslbackend;

/* aliases for library clones and renames */
Expand Down
5 changes: 3 additions & 2 deletions lib/Makefile.inc
Expand Up @@ -30,12 +30,13 @@ LIB_VAUTH_HFILES = vauth/vauth.h vauth/digest.h vauth/ntlm.h
LIB_VTLS_CFILES = vtls/openssl.c vtls/gtls.c vtls/vtls.c vtls/nss.c \
vtls/polarssl.c vtls/polarssl_threadlock.c \
vtls/wolfssl.c vtls/schannel.c vtls/schannel_verify.c \
vtls/sectransp.c vtls/gskit.c vtls/mbedtls.c vtls/mesalink.c
vtls/sectransp.c vtls/gskit.c vtls/mbedtls.c vtls/mesalink.c \
vtls/bearssl.c

LIB_VTLS_HFILES = vtls/openssl.h vtls/vtls.h vtls/gtls.h \
vtls/nssg.h vtls/polarssl.h vtls/polarssl_threadlock.h \
vtls/wolfssl.h vtls/schannel.h vtls/sectransp.h vtls/gskit.h \
vtls/mbedtls.h vtls/mesalink.h
vtls/mbedtls.h vtls/mesalink.h vtls/bearssl.h

LIB_VQUIC_CFILES = vquic/ngtcp2.c vquic/quiche.c

Expand Down
3 changes: 3 additions & 0 deletions lib/curl_config.h.cmake
Expand Up @@ -948,6 +948,9 @@ ${SIZEOF_TIME_T_CODE}
/* if mbedTLS is enabled */
#cmakedefine USE_MBEDTLS 1

/* if BearSSL is enabled */
#cmakedefine USE_BEARSSL 1

/* if libSSH2 is in use */
#cmakedefine USE_LIBSSH2 1

Expand Down
3 changes: 2 additions & 1 deletion lib/curl_setup.h
Expand Up @@ -644,7 +644,8 @@ int netware_init(void);
#if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_NSS) || \
defined(USE_MBEDTLS) || \
defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \
defined(USE_SECTRANSP) || defined(USE_GSKIT) || defined(USE_MESALINK)
defined(USE_SECTRANSP) || defined(USE_GSKIT) || defined(USE_MESALINK) || \
defined(USE_BEARSSL)
#define USE_SSL /* SSL support has been enabled */
#endif

Expand Down

0 comments on commit 84b966b

Please sign in to comment.