Check-in [37d16cba38]
Bounty program for improvements to Tcl and certain Tcl packages.
Overview
Comment:Started work on mbedTLS backend
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | backend-mbedtls
Files: files | file ages | folders
SHA3-256: 37d16cba38e65e598e519912be001b2add22231dafb1b46dd057a6d6ec9ee644
User & Date: rkeene on 2019-11-12 17:49:02
Other Links: branch diff | manifest | tags
Context
2019-11-12
17:49
Started work on mbedTLS backend Leaf check-in: 37d16cba38 user: rkeene tags: backend-mbedtls
17:46
Makefile cleanup check-in: b9af6e4772 user: rkeene tags: trunk
Changes

Added aclocal/tcltls_mbedtls.m4 version [04069331bc].

            1  +AC_DEFUN([TCLTLS_SSL_MBEDTLS], [
            2  +	mbedtlsdir=''
            3  +	AC_ARG_WITH([mbedtls-dir],
            4  +		AS_HELP_STRING(
            5  +			[--with-mbedtls-dir=<dir>],
            6  +			[path to root directory of MbedTLS installation]
            7  +		), [
            8  +			mbedtlsdir="$withval"
            9  +		]
           10  +	)
           11  +
           12  +	if test -n "$mbedtlsdir"; then
           13  +		if test -e "$mbedtlsdir/libmbedtls.a" -o -e "$mbedtlsdir/libmbedtls.${AREXT}"; then
           14  +			TCLTLS_SSL_LIBS="-L$mbedtlsdir -lmbedtls -lmbedcrypto"
           15  +			mbedtlsdir="`AS_DIRNAME(["$mbedtlsdir"])`"
           16  +		else
           17  +			TCLTLS_SSL_LIBS="-L$mbedtlsdir/library -lmbedtls -lmbedcrypto"
           18  +		fi
           19  +		TCLTLS_SSL_CFLAGS="-I$mbedtlsdir/include -I${mbedtlsdir}/include/mbedtls"
           20  +		TCLTLS_SSL_CPPFLAGS="-I$mbedtlsdir/include -I${mbedtlsdir}/include/mbedtls"
           21  +	fi
           22  +
           23  +	AC_ARG_VAR([TCLTLS_SSL_LIBS], [libraries to pass to the linker for MbedTLS])
           24  +	AC_ARG_VAR([TCLTLS_SSL_CFLAGS], [C compiler flags for MbedTLS])
           25  +	AC_ARG_VAR([TCLTLS_SSL_CPPFLAGS], [C preprocessor flags for MbedTLS])
           26  +
           27  +	if test "$TCLEXT_BUILD" = "static"; then
           28  +		dnl If we are doing a static build, save the linker flags for other programs to consume
           29  +		rm -f tcltls.${AREXT}.linkadd
           30  +		AS_ECHO(["$TCLTLS_SSL_LIBS"]) > tcltls.${AREXT}.linkadd
           31  +	fi
           32  +
           33  +	dnl If we have been asked to statically link to the SSL library, specifically tell the linker to do so
           34  +	if test "$TCLEXT_TLS_STATIC_SSL" = 'yes'; then
           35  +		dnl Don't bother doing this if we aren't actually doing the runtime linking
           36  +		if test "$TCLEXT_BUILD" != "static"; then
           37  +			dnl Split the libraries into SSL and non-SSL libraries
           38  +			new_TCLTLS_SSL_LIBS_normal=''
           39  +			new_TCLTLS_SSL_LIBS_static=''
           40  +			for arg in $TCLTLS_SSL_LIBS; do
           41  +				case "${arg}" in
           42  +					-L*)
           43  +						new_TCLTLS_SSL_LIBS_normal="${new_TCLTLS_SSL_LIBS_normal} ${arg}"
           44  +						new_TCLTLS_SSL_LIBS_static="${new_TCLTLS_SSL_LIBS_static} ${arg}"
           45  +						;;
           46  +					-ldl|-lrt|-lc|-lpthread|-lm|-lcrypt|-lidn|-lresolv|-lgcc|-lgcc_s)
           47  +						new_TCLTLS_SSL_LIBS_normal="${new_TCLTLS_SSL_LIBS_normal} ${arg}"
           48  +						;;
           49  +					-l*)
           50  +						new_TCLTLS_SSL_LIBS_static="${new_TCLTLS_SSL_LIBS_static} ${arg}"
           51  +						;;
           52  +					*)
           53  +						new_TCLTLS_SSL_LIBS_normal="${new_TCLTLS_SSL_LIBS_normal} ${arg}"
           54  +						;;
           55  +				esac
           56  +			done
           57  +			SHOBJ_DO_STATIC_LINK_LIB([MbedTLS], [$new_TCLTLS_SSL_LIBS_static], [new_TCLTLS_SSL_LIBS_static])
           58  +			TCLTLS_SSL_LIBS="${new_TCLTLS_SSL_LIBS_normal} ${new_TCLTLS_SSL_LIBS_static}"
           59  +		fi
           60  +	fi
           61  +
           62  +	dnl Save compile-altering variables we are changing
           63  +	SAVE_LIBS="${LIBS}"
           64  +	SAVE_CFLAGS="${CFLAGS}"
           65  +	SAVE_CPPFLAGS="${CPPFLAGS}"
           66  +
           67  +	dnl Update compile-altering variables to include the MbedTLS libraries
           68  +	LIBS="${TCLTLS_SSL_LIBS} ${SAVE_LIBS} ${TCLTLS_SSL_LIBS}"
           69  +	CFLAGS="${TCLTLS_SSL_CFLAGS} ${SAVE_CFLAGS} ${TCLTLS_SSL_CFLAGS}"
           70  +	CPPFLAGS="${TCLTLS_SSL_CPPFLAGS} ${SAVE_CPPFLAGS} ${TCLTLS_SSL_CPPFLAGS}"
           71  +
           72  +	dnl Verify that basic functionality is there
           73  +	AC_LANG_PUSH(C)
           74  +	AC_MSG_CHECKING([if a basic MbedTLS program works])
           75  +	AC_LINK_IFELSE([AC_LANG_PROGRAM([
           76  +#define MBEDTLS_CONFIG_FILE <mbedtls/config.h>
           77  +#include MBEDTLS_CONFIG_FILE
           78  +		], [
           79  +    mbedtls_ssl_context *ctx;
           80  +    mbedtls_ssl_init(ctx);
           81  +    mbedtls_ssl_setup(ctx, (void *) 0);
           82  +    mbedtls_ssl_free(ctx);
           83  +		])], [
           84  +		AC_MSG_RESULT([yes])
           85  +	], [
           86  +		AC_MSG_RESULT([no])
           87  +		AC_MSG_ERROR([Unable to compile a basic program using MbedTLS])
           88  +	])
           89  +	AC_LANG_POP([C])
           90  +
           91  +dnl
           92  +dnl	AC_CHECK_FUNCS([TLS_method])
           93  +dnl	TCLTLS_SSL_OPENSSL_CHECK_PROTO_VER([tcltls_ssl_ssl2], [SSLv2_method], [sslv2], [NO_SSL2])
           94  +dnl	TCLTLS_SSL_OPENSSL_CHECK_PROTO_VER([tcltls_ssl_ssl3], [SSLv3_method], [sslv3], [NO_SSL3])
           95  +dnl	TCLTLS_SSL_OPENSSL_CHECK_PROTO_VER([tcltls_ssl_tls1_0], [TLSv1_method], [tlsv1.0], [NO_TLS1])
           96  +dnl	TCLTLS_SSL_OPENSSL_CHECK_PROTO_VER([tcltls_ssl_tls1_1], [TLSv1_1_method], [tlsv1.1], [NO_TLS1_1])
           97  +dnl	TCLTLS_SSL_OPENSSL_CHECK_PROTO_VER([tcltls_ssl_tls1_2], [TLSv1_2_method], [tlsv1.2], [NO_TLS1_2])
           98  +dnl	TCLTLS_SSL_OPENSSL_CHECK_PROTO_VER([tcltls_ssl_tls1_3], [], [tlsv1.3], [NO_TLS1_3], [SSL_OP_NO_TLSv1_3])
           99  +dnl
          100  +
          101  +	dnl Restore compile-altering variables
          102  +	LIBS="${SAVE_LIBS}"
          103  +	CFLAGS="${SAVE_CFLAGS}"
          104  +	CPPFLAGS="${SAVE_CPPFLAGS}"
          105  +])

Modified autogen.sh from [825e8c0a23] to [85a2a104f6].

    14     14   	http://chiselapp.com/user/rkeene/repository/autoconf/doc/trunk/shobj.m4
    15     15   	http://chiselapp.com/user/rkeene/repository/autoconf/doc/trunk/versionscript.m4
    16     16   	'http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_check_compile_flag.m4'
    17     17   )
    18     18   
    19     19   localFiles=(
    20     20   	aclocal/tcltls_openssl.m4
           21  +	aclocal/tcltls_mbedtls.m4
    21     22   )
    22     23   
    23     24   failed='0'
    24     25   for command in "${commands[@]}"; do
    25     26   	if [ ! -f "$(which "${command}" 2>/dev/null)" ]; then
    26     27   		echo "error: Unable to locate ${command}" >&2
    27     28   		failed='1'

Modified configure.ac from [6234df6904] to [c705e1d652].

    26     26   	AC_CHECK_TOOL([RANLIB], [ranlib], [:])
    27     27   	EXTENSION_TARGET="tcltls.${AREXT}"
    28     28   fi
    29     29   AC_SUBST(EXTENSION_TARGET)
    30     30   AC_SUBST(TCLEXT_BUILD)
    31     31   
    32     32   dnl Determine what SSL library to link with
    33         -AC_ARG_WITH([ssl], AS_HELP_STRING([--with-ssl=<name>], [name of ssl library to build against (openssl, libressl, nss, auto)]), [
           33  +AC_ARG_WITH([ssl], AS_HELP_STRING([--with-ssl=<name>], [name of ssl library to build against (openssl, libressl, mbedtls, auto)]), [
    34     34   	if test "$withval" = "no"; then
    35     35   		AC_MSG_ERROR([You may not specify --without-ssl])
    36     36   	fi
    37     37   
    38     38   	if test "$withval" = "yes"; then
    39     39   		AC_MSG_ERROR([If you specify --with-ssl then you must provide a value])
    40     40   	fi
................................................................................
   216    216   	tcltls_ssl_lib='openssl'
   217    217   fi
   218    218   
   219    219   AS_CASE([$tcltls_ssl_lib],
   220    220   	[openssl], [
   221    221   		TCLTLS_SSL_OPENSSL
   222    222   	],
   223         -	[nss], [
   224         -	 	TCLTLS_SSL_LIBS=""
   225         -		TCLTLS_SSL_CFLAGS=""
   226         -		TCLTLS_SSL_CPPFLAGS=""
          223  +	[mbedtls], [
          224  +		TCLTLS_SSL_MBEDTLS
   227    225   	],
   228    226   	[
   229    227   		AC_MSG_ERROR([Unsupported SSL library: $tcltls_ssl_lib])
   230    228   	]
   231    229   )
   232    230   dnl Determine how to use this SSL library
   233    231   AC_MSG_CHECKING([how to use $tcltls_ssl_lib])