Skip to content

Commit a73ca70

Browse files
author
V V
committed
merged openssl switch
1 parent c6de6b2 commit a73ca70

File tree

8 files changed

+244
-10
lines changed

8 files changed

+244
-10
lines changed

‎Makefile.tgl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
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
1+
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
22

33
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
44

55

66
TLD_OBJECTS=${OBJ}/dump-tl-file.o
77
GENERATE_OBJECTS=${OBJ}/generate.o
8-
TGL_COMMON_OBJECTS=${OBJ}/tools.o
8+
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
99
TGL_OBJ_C=${GENERATE_OBJECTS} ${TGL_COMMON_OBJECTS} ${TGL_OBJECTS} ${TLD_OBJECTS}
1010

1111
.SUFFIXES:

‎config.h.in

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
/* Define to 1 if you have the `event' library (-levent). */
3737
#undef HAVE_LIBEVENT
3838

39+
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
40+
#undef HAVE_LIBGCRYPT
41+
3942
/* Define to 1 if you have the `jansson' library (-ljansson). */
4043
#undef HAVE_LIBJANSSON
4144

@@ -158,6 +161,10 @@
158161
/* Define to 1 if you have the ANSI C header files. */
159162
#undef STDC_HEADERS
160163

164+
/* avoid OpenSSL entirely, use libgcrypt instead (this can't read *.pub files,
165+
though.) */
166+
#undef TGL_AVOID_OPENSSL
167+
161168
/* use json */
162169
#undef USE_JSON
163170

‎configure

+216-1
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ SHELL'
695695
ac_subst_files=''
696696
ac_user_opts='
697697
enable_option_checking
698+
enable_openssl
698699
with_openssl
699700
with_zlib
700701
enable_libconfig
@@ -1326,6 +1327,8 @@ Optional Features:
13261327
--disable-option-checking ignore unrecognized --enable/--with options
13271328
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
13281329
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
1330+
--disable-openssl disables OpenSSL, and don't link against it
1331+
(this can't read *.pub files, though.)
13291332
--enable-libconfig/--disable-libconfig
13301333
--enable-extf/--disable-extf
13311334
--enable-liblua/--disable-liblua
@@ -4129,6 +4132,60 @@ EXTRA_LIBS=""
41294132
# OPENSSL_LIBS to the -l directives required
41304133
# OPENSSL_LDFLAGS to the -L or -R flags required
41314134

4135+
# Check whether --enable-openssl was given.
4136+
if test "${enable_openssl+set}" = set; then :
4137+
enableval=$enable_openssl;
4138+
if test "x$enableval" = "xno" ; then
4139+
4140+
$as_echo "#define TGL_AVOID_OPENSSL 1" >>confdefs.h
4141+
4142+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcry_md_open in -lgcrypt" >&5
4143+
$as_echo_n "checking for gcry_md_open in -lgcrypt... " >&6; }
4144+
if ${ac_cv_lib_gcrypt_gcry_md_open+:} false; then :
4145+
$as_echo_n "(cached) " >&6
4146+
else
4147+
ac_check_lib_save_LIBS=$LIBS
4148+
LIBS="-lgcrypt $LIBS"
4149+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4150+
/* end confdefs.h. */
4151+
4152+
/* Override any GCC internal prototype to avoid an error.
4153+
Use char because int might match the return type of a GCC
4154+
builtin and then its argument prototype would still apply. */
4155+
#ifdef __cplusplus
4156+
extern "C"
4157+
#endif
4158+
char gcry_md_open ();
4159+
int
4160+
main ()
4161+
{
4162+
return gcry_md_open ();
4163+
;
4164+
return 0;
4165+
}
4166+
_ACEOF
4167+
if ac_fn_c_try_link "$LINENO"; then :
4168+
ac_cv_lib_gcrypt_gcry_md_open=yes
4169+
else
4170+
ac_cv_lib_gcrypt_gcry_md_open=no
4171+
fi
4172+
rm -f core conftest.err conftest.$ac_objext \
4173+
conftest$ac_exeext conftest.$ac_ext
4174+
LIBS=$ac_check_lib_save_LIBS
4175+
fi
4176+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_gcrypt_gcry_md_open" >&5
4177+
$as_echo "$ac_cv_lib_gcrypt_gcry_md_open" >&6; }
4178+
if test "x$ac_cv_lib_gcrypt_gcry_md_open" = xyes; then :
4179+
cat >>confdefs.h <<_ACEOF
4180+
#define HAVE_LIBGCRYPT 1
4181+
_ACEOF
4182+
4183+
LIBS="-lgcrypt $LIBS"
4184+
4185+
fi
4186+
4187+
else
4188+
# Don't be annoying, so don't inform the user about --disable-openssl
41324189

41334190
found=false
41344191

@@ -4267,7 +4324,7 @@ else
42674324

42684325
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
42694326
$as_echo "no" >&6; }
4270-
as_fn_error $? "No openssl found" "$LINENO" 5
4327+
as_fn_error $? "No openssl found." "$LINENO" 5
42714328

42724329
fi
42734330
rm -f core conftest.err conftest.$ac_objext \
@@ -4280,6 +4337,164 @@ rm -f core conftest.err conftest.$ac_objext \
42804337

42814338

42824339

4340+
fi
4341+
4342+
else
4343+
4344+
4345+
found=false
4346+
4347+
# Check whether --with-openssl was given.
4348+
if test "${with_openssl+set}" = set; then :
4349+
withval=$with_openssl;
4350+
case "$withval" in
4351+
"" | y | ye | yes | n | no)
4352+
as_fn_error $? "Invalid --with-openssl value" "$LINENO" 5
4353+
;;
4354+
*) ssldirs="$withval"
4355+
;;
4356+
esac
4357+
4358+
else
4359+
4360+
# if pkg-config is installed and openssl has installed a .pc file,
4361+
# then use that information and don't search ssldirs
4362+
# Extract the first word of "pkg-config", so it can be a program name with args.
4363+
set dummy pkg-config; ac_word=$2
4364+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
4365+
$as_echo_n "checking for $ac_word... " >&6; }
4366+
if ${ac_cv_path_PKG_CONFIG+:} false; then :
4367+
$as_echo_n "(cached) " >&6
4368+
else
4369+
case $PKG_CONFIG in
4370+
[\\/]* | ?:[\\/]*)
4371+
ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
4372+
;;
4373+
*)
4374+
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
4375+
for as_dir in $PATH
4376+
do
4377+
IFS=$as_save_IFS
4378+
test -z "$as_dir" && as_dir=.
4379+
for ac_exec_ext in '' $ac_executable_extensions; do
4380+
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
4381+
ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
4382+
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
4383+
break 2
4384+
fi
4385+
done
4386+
done
4387+
IFS=$as_save_IFS
4388+
4389+
;;
4390+
esac
4391+
fi
4392+
PKG_CONFIG=$ac_cv_path_PKG_CONFIG
4393+
if test -n "$PKG_CONFIG"; then
4394+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
4395+
$as_echo "$PKG_CONFIG" >&6; }
4396+
else
4397+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
4398+
$as_echo "no" >&6; }
4399+
fi
4400+
4401+
4402+
if test x"$PKG_CONFIG" != x""; then
4403+
OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
4404+
if test $? = 0; then
4405+
OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
4406+
OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 2>/dev/null`
4407+
found=true
4408+
fi
4409+
fi
4410+
4411+
# no such luck; use some default ssldirs
4412+
if ! $found; then
4413+
ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
4414+
fi
4415+
4416+
4417+
fi
4418+
4419+
4420+
4421+
# note that we #include <openssl/foo.h>, so the OpenSSL headers have to be in
4422+
# an 'openssl' subdirectory
4423+
4424+
if ! $found; then
4425+
OPENSSL_INCLUDES=
4426+
for ssldir in $ssldirs; do
4427+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for openssl/ssl.h in $ssldir" >&5
4428+
$as_echo_n "checking for openssl/ssl.h in $ssldir... " >&6; }
4429+
if test -f "$ssldir/include/openssl/ssl.h"; then
4430+
OPENSSL_INCLUDES="-I$ssldir/include"
4431+
OPENSSL_LDFLAGS="-L$ssldir/lib"
4432+
OPENSSL_LIBS="-lssl -lcrypto"
4433+
found=true
4434+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
4435+
$as_echo "yes" >&6; }
4436+
break
4437+
else
4438+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
4439+
$as_echo "no" >&6; }
4440+
fi
4441+
done
4442+
4443+
# if the file wasn't found, well, go ahead and try the link anyway -- maybe
4444+
# it will just work!
4445+
fi
4446+
4447+
# try the preprocessor and linker with our new flags,
4448+
# being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
4449+
4450+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiling and linking against OpenSSL works" >&5
4451+
$as_echo_n "checking whether compiling and linking against OpenSSL works... " >&6; }
4452+
echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
4453+
"OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" >&5
4454+
4455+
save_LIBS="$LIBS"
4456+
save_LDFLAGS="$LDFLAGS"
4457+
save_CPPFLAGS="$CPPFLAGS"
4458+
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
4459+
LIBS="$OPENSSL_LIBS $LIBS"
4460+
CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
4461+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
4462+
/* end confdefs.h. */
4463+
#include <openssl/ssl.h>
4464+
int
4465+
main ()
4466+
{
4467+
SSL_new(NULL)
4468+
;
4469+
return 0;
4470+
}
4471+
_ACEOF
4472+
if ac_fn_c_try_link "$LINENO"; then :
4473+
4474+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
4475+
$as_echo "yes" >&6; }
4476+
4477+
4478+
else
4479+
4480+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
4481+
$as_echo "no" >&6; }
4482+
as_fn_error $? "No openssl found. With --disable-openssl, libtgl will use libgcrypt instead." "$LINENO" 5
4483+
4484+
fi
4485+
rm -f core conftest.err conftest.$ac_objext \
4486+
conftest$ac_exeext conftest.$ac_ext
4487+
CPPFLAGS="$save_CPPFLAGS"
4488+
LDFLAGS="$save_LDFLAGS"
4489+
LIBS="$save_LIBS"
4490+
4491+
4492+
4493+
4494+
4495+
4496+
fi
4497+
42834498
#
42844499
# Handle user hints
42854500
#

‎configure.ac

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ EXTRA_LIBS=""
3434
# OPENSSL_LIBS to the -l directives required
3535
# OPENSSL_LDFLAGS to the -L or -R flags required
3636

37-
AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found])])
37+
AC_ARG_ENABLE(openssl,[ --disable-openssl disables OpenSSL, and don't link against it
38+
(this can't read *.pub files, though.)],
39+
[
40+
if test "x$enableval" = "xno" ; then
41+
AC_DEFINE([TGL_AVOID_OPENSSL],[1],[avoid OpenSSL entirely, use libgcrypt instead (this can't read *.pub files, though.)])
42+
AC_CHECK_LIB([gcrypt], [gcry_md_open])
43+
else
44+
# Don't be annoying, so don't inform the user about --disable-openssl
45+
AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found.])])
46+
fi
47+
],[
48+
AX_CHECK_OPENSSL(,[AC_MSG_ERROR([No openssl found. With --disable-openssl, libtgl will use libgcrypt instead.])])
49+
])
3850
AX_CHECK_ZLIB(, [AC_MSG_ERROR([No zlib found])])
3951

4052
AC_CHECK_LIB([readline], [rl_save_prompt], [ EXTRA_LIBS="${EXTRA_LIBS} -lreadline" ; ], [AC_MSG_ERROR([no libreadline found])])

‎interface.c

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@
9393
#include "auto/auto-types.h"
9494
#include "auto/auto-free-ds.h"
9595

96+
#include <errno.h>
97+
9698
#define ALLOW_MULT 1
9799
char *default_prompt = "> ";
98100

‎loop.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,7 @@ void read_secret_chat (int fd, int v) {
637637
assert (read (fd, &state, 4) == 4);
638638
assert (read (fd, &key_fingerprint, 8) == 8);
639639
assert (read (fd, &key, 256) == 256);
640-
if (v >= 2) {
641-
assert (read (fd, sha, 20) == 20);
642-
} else {
643-
SHA1 ((void *)key, 256, sha);
644-
}
640+
assert (read (fd, sha, 20) == 20);
645641
int in_seq_no = 0, out_seq_no = 0, last_in_seq_no = 0;
646642
if (v >= 1) {
647643
assert (read (fd, &in_seq_no, 4) == 4);

‎main.c

+2
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ int main (int argc, char **argv) {
973973
#endif
974974
tgl_set_rsa_key (TLS, "tg-server.pub");
975975

976+
#include "tgl/mtproto-key.c"
977+
tgl_set_rsa_key_direct (TLS, _mtproto_default_e, _mtproto_default_key_len, _mtproto_default_key);
976978

977979
get_terminal_attributes ();
978980

0 commit comments

Comments
 (0)