Skip to content

Commit

Permalink
Don't rely on the OpenSSL version to detect ALPN
Browse files Browse the repository at this point in the history
A vendor may back-port the feature to an older release, so we might as
well look for the presence of one of its basic functions. This includes
NPN since the code uses them in tandem, and keeps the ability to exclude
NPN with the OPENSSL_NO_NEXTPROTONEG macro since OpenSSL itself relies
on that internally.

Except that currently Hitch won't build when OPENSSL_NO_NEXTPROTONEG is
defined, which was already the case before this change.
  • Loading branch information
dridi committed Jul 15, 2019
1 parent f485aca commit 0013787
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ fi
AC_CHECK_HEADERS([linux/futex.h])
AM_CONDITIONAL([HAVE_LINUX_FUTEX], [test $ac_cv_header_linux_futex_h = yes])

HITCH_CHECK_FUNC([SSL_get0_alpn_selected], [$SSL_LIBS], [
AC_DEFINE([OPENSSL_WITH_ALPN], [1], [OpenSSL supports ALPN])
])

HITCH_CHECK_FUNC([SSL_get0_next_proto_negotiated], [$SSL_LIBS], [
AC_DEFINE([OPENSSL_WITH_NPN], [1], [OpenSSL supports NPN])
])

SH_TESTS="$(cd $srcdir/src && echo tests/test*.sh)"
AC_SUBST(SH_TESTS)

Expand Down
17 changes: 13 additions & 4 deletions hitch.m4
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
# HITCH_SEARCH_LIBS(VAR, LIBS, FUNC, NOTFOUND)
# --------------------------------------------
AC_DEFUN([HITCH_SEARCH_LIBS], [
hitch_save_LIBS="${LIBS}"
hitch_save_LIBS=$LIBS
LIBS=""
AC_SEARCH_LIBS([$3], [$2], [], [$4])
AC_SUBST([$1_LIBS], [$LIBS])
LIBS="${hitch_save_LIBS}"
LIBS=$hitch_save_LIBS
])

# HITCH_CHECK_FUNC(FUNC, LIBS, FOUND, NOTFOUND)
# --------------------------------------------
AC_DEFUN([HITCH_CHECK_FUNC], [
hitch_save_LIBS=$LIBS
LIBS="$2"
AC_CHECK_FUNC([$1], [$3], [$4])
LIBS=$hitch_save_LIBS
])

# _HITCH_CHECK_FLAG(VAR, FLAG)
------------------------------
AC_DEFUN([_HITCH_CHECK_FLAG], [
AC_MSG_CHECKING([whether the compiler accepts $2])
_cflags="$CFLAGS"
hitch_save_CFLAGS=$CFLAGS
CFLAGS="[$]$1 $2 $CFLAGS"
AC_RUN_IFELSE(
[AC_LANG_SOURCE([int main(void) { return (0); }])],
[AC_MSG_RESULT([yes]); $1="[$]$1 $2"],
[AC_MSG_RESULT([no])])
CFLAGS="$_cflags"
CFLAGS=$hitch_save_CFLAGS
])

# HITCH_CHECK_FLAGS(VAR, FLAGS)
Expand Down
13 changes: 3 additions & 10 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@

#include "foreign/uthash.h"

/* Is NPN available? See openssl/opensslv.h for explanation. */
#ifndef OPENSSL_NO_NEXTPROTONEG
# if OPENSSL_VERSION_NUMBER >= 0x1000100fL
# define OPENSSL_WITH_NPN
# endif
#endif

/* Is ALPN available? See openssl/opensslv.h for explanation. */
#if OPENSSL_VERSION_NUMBER >= 0x1000200fL
# define OPENSSL_WITH_ALPN
/* This macro disables NPN even in openssl/ssl.h */
#ifdef OPENSSL_NO_NEXTPROTONEG
# undef OPENSSL_WITH_NPN
#endif

#ifdef OPENSSL_WITH_ALPN
Expand Down

0 comments on commit 0013787

Please sign in to comment.