diff --git a/Makefile.tgl b/Makefile.tgl index 88e0bf4..3294e8a 100644 --- a/Makefile.tgl +++ b/Makefile.tgl @@ -1,11 +1,11 @@ -TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tgl-net.o ${OBJ}/tgl-timers.o ${OBJ}/tg-mime-types.o ${OBJ}/mtproto-utils.o +TGL_OBJECTS=${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/tgl.o ${OBJ}/updates.o ${OBJ}/tgl-net.o ${OBJ}/tgl-timers.o ${OBJ}/tg-mime-types.o ${OBJ}/mtproto-utils.o ${OBJ}/crypto/bn_openssl.o ${OBJ}/crypto/bn_altern.o ${OBJ}/crypto/rsa_pem_openssl.o ${OBJ}/crypto/rsa_pem_altern.o ${OBJ}/crypto/md5_openssl.o ${OBJ}/crypto/md5_altern.o ${OBJ}/crypto/sha_openssl.o ${OBJ}/crypto/sha_altern.o ${OBJ}/crypto/aes_openssl.o ${OBJ}/crypto/aes_altern.o TGL_OBJECTS_AUTO=${OBJ}/auto/auto-skip.o ${OBJ}/auto/auto-fetch.o ${OBJ}/auto/auto-store.o ${OBJ}/auto/auto-autocomplete.o ${OBJ}/auto/auto-types.o ${OBJ}/auto/auto-fetch-ds.o ${OBJ}/auto/auto-free-ds.o ${OBJ}/auto/auto-store-ds.o ${OBJ}/auto/auto-print-ds.o TLD_OBJECTS=${OBJ}/dump-tl-file.o GENERATE_OBJECTS=${OBJ}/generate.o -TGL_COMMON_OBJECTS=${OBJ}/tools.o +TGL_COMMON_OBJECTS=${OBJ}/tools.o ${OBJ}/crypto/rand_openssl.o ${OBJ}/crypto/rand_altern.o ${OBJ}/crypto/err_openssl.o ${OBJ}/crypto/err_altern.o TGL_OBJ_C=${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS} .SUFFIXES: diff --git a/config.h.in b/config.h.in index bb5f2d6..a98b0d8 100644 --- a/config.h.in +++ b/config.h.in @@ -36,6 +36,9 @@ /* Define to 1 if you have the `event' library (-levent). */ #undef HAVE_LIBEVENT +/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */ +#undef HAVE_LIBGCRYPT + /* Define to 1 if you have the `jansson' library (-ljansson). */ #undef HAVE_LIBJANSSON @@ -158,6 +161,10 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS +/* avoid OpenSSL entirely, use libgcrypt instead (this can't read *.pub files, + though.) */ +#undef TGL_AVOID_OPENSSL + /* use json */ #undef USE_JSON diff --git a/configure b/configure index 02941e3..8223fc6 100755 --- a/configure +++ b/configure @@ -695,6 +695,7 @@ SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking +enable_openssl with_openssl with_zlib enable_libconfig @@ -1326,6 +1327,8 @@ Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-openssl disables OpenSSL, and don't link against it + (this can't read *.pub files, though.) --enable-libconfig/--disable-libconfig --enable-extf/--disable-extf --enable-liblua/--disable-liblua @@ -4129,6 +4132,60 @@ EXTRA_LIBS="" # OPENSSL_LIBS to the -l directives required # OPENSSL_LDFLAGS to the -L or -R flags required +# Check whether --enable-openssl was given. +if test "${enable_openssl+set}" = set; then : + enableval=$enable_openssl; + if test "x$enableval" = "xno" ; then + +$as_echo "#define TGL_AVOID_OPENSSL 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcry_md_open in -lgcrypt" >&5 +$as_echo_n "checking for gcry_md_open in -lgcrypt... " >&6; } +if ${ac_cv_lib_gcrypt_gcry_md_open+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lgcrypt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char gcry_md_open (); +int +main () +{ +return gcry_md_open (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_gcrypt_gcry_md_open=yes +else + ac_cv_lib_gcrypt_gcry_md_open=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gcrypt_gcry_md_open" >&5 +$as_echo "$ac_cv_lib_gcrypt_gcry_md_open" >&6; } +if test "x$ac_cv_lib_gcrypt_gcry_md_open" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBGCRYPT 1 +_ACEOF + + LIBS="-lgcrypt $LIBS" + +fi + + else + # Don't be annoying, so don't inform the user about --disable-openssl found=false @@ -4267,7 +4324,7 @@ else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - as_fn_error $? "No openssl found" "$LINENO" 5 + as_fn_error $? "No openssl found." "$LINENO" 5 fi rm -f core conftest.err conftest.$ac_objext \ @@ -4280,6 +4337,164 @@ rm -f core conftest.err conftest.$ac_objext \ + fi + +else + + + found=false + +# Check whether --with-openssl was given. +if test "${with_openssl+set}" = set; then : + withval=$with_openssl; + case "$withval" in + "" | y | ye | yes | n | no) + as_fn_error $? "Invalid --with-openssl value" "$LINENO" 5 + ;; + *) ssldirs="$withval" + ;; + esac + +else + + # if pkg-config is installed and openssl has installed a .pc file, + # then use that information and don't search ssldirs + # Extract the first word of "pkg-config", so it can be a program name with args. +set dummy pkg-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_PKG_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $PKG_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + ;; +esac +fi +PKG_CONFIG=$ac_cv_path_PKG_CONFIG +if test -n "$PKG_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5 +$as_echo "$PKG_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + 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 + + +fi + + + + # note that we #include , so the OpenSSL headers have to be in + # an 'openssl' subdirectory + + if ! $found; then + OPENSSL_INCLUDES= + for ssldir in $ssldirs; do + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openssl/ssl.h in $ssldir" >&5 +$as_echo_n "checking for openssl/ssl.h in $ssldir... " >&6; } + 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 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + break + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + 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 + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiling and linking against OpenSSL works" >&5 +$as_echo_n "checking whether compiling and linking against OpenSSL works... " >&6; } + echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \ + "OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&5 + + save_LIBS="$LIBS" + save_LDFLAGS="$LDFLAGS" + save_CPPFLAGS="$CPPFLAGS" + LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS" + LIBS="$OPENSSL_LIBS $LIBS" + CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +SSL_new(NULL) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + as_fn_error $? "No openssl found. With --disable-openssl, libtgl will use libgcrypt instead." "$LINENO" 5 + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" + + + + + + +fi + # # Handle user hints # diff --git a/configure.ac b/configure.ac index a2c09e5..20bdd74 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,19 @@ EXTRA_LIBS="" # OPENSSL_LIBS to the -l directives required # OPENSSL_LDFLAGS to the -L or -R flags required -AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found])]) +AC_ARG_ENABLE(openssl,[ --disable-openssl disables OpenSSL, and don't link against it + (this can't read *.pub files, though.)], + [ + if test "x$enableval" = "xno" ; then + AC_DEFINE([TGL_AVOID_OPENSSL],[1],[avoid OpenSSL entirely, use libgcrypt instead (this can't read *.pub files, though.)]) + AC_CHECK_LIB([gcrypt], [gcry_md_open]) + else + # Don't be annoying, so don't inform the user about --disable-openssl + AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found.])]) + fi + ],[ + AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found. With --disable-openssl, libtgl will use libgcrypt instead.])]) + ]) AX_CHECK_ZLIB(, [AC_MSG_ERROR([No zlib found])]) AC_CHECK_LIB([readline], [rl_save_prompt], [ EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; ], [AC_MSG_ERROR([no libreadline found])]) diff --git a/interface.c b/interface.c index f052f4a..09c9388 100644 --- a/interface.c +++ b/interface.c @@ -93,6 +93,8 @@ #include "auto/auto-types.h" #include "auto/auto-free-ds.h" +#include + #define ALLOW_MULT 1 char *default_prompt = "> "; diff --git a/loop.c b/loop.c index 9f1606e..a7fffaa 100644 --- a/loop.c +++ b/loop.c @@ -637,11 +637,7 @@ void read_secret_chat (int fd, int v) { assert (read (fd, &state, 4) == 4); assert (read (fd, &key_fingerprint, 8) == 8); assert (read (fd, &key, 256) == 256); - if (v >= 2) { - assert (read (fd, sha, 20) == 20); - } else { - SHA1 ((void *)key, 256, sha); - } + assert (read (fd, sha, 20) == 20); int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0; if (v >= 1) { assert (read (fd, &in_seq_no, 4) == 4); diff --git a/main.c b/main.c index d97ce22..34d0f16 100644 --- a/main.c +++ b/main.c @@ -973,6 +973,8 @@ int main (int argc, char **argv) { #endif tgl_set_rsa_key (TLS, "tg-server.pub"); + #include "tgl/mtproto-key.c" + tgl_set_rsa_key_direct (TLS, _mtproto_default_e, _mtproto_default_key_len, _mtproto_default_key); get_terminal_attributes (); diff --git a/tgl b/tgl index 5faeb3e..e985863 160000 --- a/tgl +++ b/tgl @@ -1 +1 @@ -Subproject commit 5faeb3e0bed7237fef33b77855ba3be408ef712d +Subproject commit e9858634ec18db8ae7a6fe70daa00af1b3970772