Skip to content

Commit 1189acd

Browse files
author
Hujer
committed
fix yatb with openssl 1.1.1
1 parent 8011dd4 commit 1189acd

11 files changed

+91
-21
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ CPPFLAGS = -W -Wall -O2 -I/usr/local/ssl/include -Iinclude
44
.cc.o :
55
g++ -c $(CPPFLAGS) $< -o $@
66

7-
include/tls_dh.h :
8-
openssl dhparam -noout -C 2048 >>include/tls_dh.h
9-
107
all:
118
@echo "To compile yatb type"
129
@echo " - 'make linux' (linux-debug,linux-static,linux-debug-static) to compile under linux"
@@ -15,6 +12,9 @@ all:
1512
@echo " - or 'make solaris' (solaris-debug,solaris-static,solaris-debug-static) to compile under solaris"
1613
@echo " - or 'make clean'"
1714

15+
include/tls_dh.h :
16+
openssl dhparam -noout -C 2048 >>include/tls_dh.h
17+
1818
linux: include/tls_dh.h src/fpwhitelist.o src/whitelist.o src/iplist.o src/yatb.o src/forward.o src/counter.o src/controlthread.o src/datathread.o src/config.o src/tls.o src/stringlist.o src/tools.o src/lock.o src/blowcrypt.o src/bnccheck.o src/getfp.o
1919
g++ src/fpwhitelist.o src/whitelist.o src/iplist.o src/yatb.o src/forward.o src/counter.o src/config.o src/controlthread.o src/datathread.o src/tls.o src/stringlist.o src/tools.o src/lock.o -lssl -lpthread -lcrypto -o bin/yatb; strip bin/yatb
2020
g++ src/blowcrypt.o src/config.o src/lock.o src/counter.o src/tools.o -o bin/blowcrypt -lssl -lcrypto -lpthread; strip bin/blowcrypt

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ _____
2020

2121
Now copy a cert file (ftpd-dsa.pem) to bin directory
2222
Also copy yatb.conf.dist to bin dir
23-
If you have a rsa cert, you will need a dh file
24-
(can be generated with 'openssl dhparam -out dh1024.pem -2 1024')
2523

2624
Encrypting config file
2725
______________________

include/controlthread.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CControlThread
3636
void mainloop(void);
3737

3838
int Read(int ,SSL *,string &);
39+
int TryRead(int ,SSL *,string &);
3940
int Write(int ,string ,SSL *);
4041

4142
int trytls(void);

simple.conf

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
[ Debug ]
2+
#debug=1;
3+
#log_to_screen=1;
4+
#debug_logfile=log.txt;
5+
#command_logfile=clog.txt;
6+
#syslog=0;
7+
18
[ Connection ]
2-
listen_port=31000;
3-
site_ip=192.168.1.254;
4-
site_port=11000;
9+
listen_ip=127.0.0.1;
10+
listen_port=2222;
11+
site_ip=127.0.0.1;
12+
site_port=3333;
513
traffic_bnc=1;
614

715
[ SSL ]
8-
cert_path=dsa.pem;
16+
cert_path=ecdsa.pem;
17+
18+
[ Advanced ]
19+
#add_to_passive_port=5;
20+
#port_range_start=28001;
21+
#port_range_end=30000;
22+
#use_port_range=1;

src/config.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CConfig::CConfig()
2929
month_limit = 0;
3030

3131
// section [SSL]
32-
cert_path = "ftpd-dsa.pem";
32+
cert_path = "ftpd-rsa.pem";
3333
crypted_cert = 0;
3434
enforce_tls = 0;
3535
enforce_tls_fxp = 0;

src/controlthread.cc

+52-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ CControlThread::~CControlThread()
174174
}
175175

176176
debugmsg(username, "[controlthread] free ssl error queue");
177+
#if (OPENSSL_VERSION_NUMBER < 0x10100000)
177178
ERR_remove_state(0);
179+
#endif
178180
}
179181

180182

@@ -521,7 +523,9 @@ void CControlThread::mainloop(void)
521523
{
522524
debugmsg(username, "[controlthread] start read from site");
523525
string s;
524-
if(!Read(site_sock,sitessl,s))
526+
int res = TryRead(site_sock,sitessl,s);
527+
if (res==2) {debugmsg(username, "[controlthread] start read from site - empty"); continue;}
528+
if(!res)
525529
{
526530
return;
527531
}
@@ -917,7 +921,9 @@ void CControlThread::mainloop(void)
917921
{
918922
debugmsg(username, "[controlthread] start read from client");
919923
string s;
920-
if(!Read(client_sock,clientssl,s))
924+
int res=TryRead(client_sock,clientssl,s);
925+
if (res == 2) continue;
926+
if(!res)
921927
{
922928
return;
923929
}
@@ -2326,6 +2332,49 @@ int CControlThread::Read(int sock,SSL *ssl,string &s)
23262332
return 1;
23272333
}
23282334

2335+
int CControlThread::TryRead(int sock,SSL *ssl,string &s)
2336+
{
2337+
rwlock.Lock();
2338+
if(sock == client_sock)
2339+
{
2340+
debugmsg(username,"[TryControlRead] read from client");
2341+
}
2342+
else if(sock == site_sock)
2343+
{
2344+
debugmsg(username,"[TryControlRead] read from site");
2345+
}
2346+
2347+
int res=control_read(sock ,ssl,s);
2348+
//nothing to read
2349+
if (res==2) {
2350+
rwlock.UnLock();
2351+
return 2;
2352+
}
2353+
if(!res)
2354+
{
2355+
debugmsg(username,"[TryControlRead] read failed");
2356+
rwlock.UnLock();
2357+
return 0;
2358+
}
2359+
if(sock == client_sock)
2360+
{
2361+
localcounter.addrecvd(s.length());
2362+
totalcounter.addrecvd(s.length());
2363+
daycounter.addrecvd(s.length());
2364+
weekcounter.addrecvd(s.length());
2365+
monthcounter.addrecvd(s.length());
2366+
debugmsg(username,"\n" + s);
2367+
cmddebugmsg(username,">> " + s);
2368+
}
2369+
else if(sock == site_sock)
2370+
{
2371+
debugmsg(username,"\n" + s);
2372+
cmddebugmsg(username,"<< " + s);
2373+
}
2374+
rwlock.UnLock();
2375+
return 1;
2376+
}
2377+
23292378

23302379
int CControlThread::Write(int sock,string s,SSL *ssl)
23312380
{
@@ -2340,7 +2389,7 @@ int CControlThread::Write(int sock,string s,SSL *ssl)
23402389
}
23412390

23422391
//------------- hotfix start ---------------
2343-
if(sock == client_sock && config.traffic_bnc)
2392+
if(sock == client_sock && config.traffic_bnc && !config.debug)
23442393
{
23452394
if(s.find(_site_ip,0) != string::npos)
23462395
{

src/datathread.cc

+2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ void CDataThread::closeconnection(void)
150150
}
151151

152152
debugmsg(username, "[closeconnection] free ssl error queue");
153+
#if (OPENSSL_VERSION_NUMBER < 0x10100000)
153154
ERR_remove_state(0);
155+
#endif
154156
}
155157
debugmsg(username, "[closeconnection] end");
156158
}

src/tls.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,11 @@ int ssl_setup()
847847

848848
SSL_CTX_set_default_verify_paths(connectsslctx);
849849
SSL_CTX_set_options(connectsslctx,SSL_OP_ALL);
850-
SSL_CTX_set_mode(connectsslctx,SSL_MODE_AUTO_RETRY);
850+
SSL_CTX_clear_mode(connectsslctx,SSL_MODE_AUTO_RETRY);
851851

852852
SSL_CTX_set_default_verify_paths(clientsslctx);
853853
SSL_CTX_set_options(clientsslctx, SSL_OP_SINGLE_DH_USE | SSL_OP_SINGLE_ECDH_USE | SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 /*SSL_OP_ALL*/);
854-
SSL_CTX_set_mode(clientsslctx,SSL_MODE_AUTO_RETRY);
854+
SSL_CTX_clear_mode(clientsslctx,SSL_MODE_AUTO_RETRY);
855855

856856
string certfile = "certtmp";
857857

src/tools.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,12 @@ int control_read(int sock,SSL *sslcon,string &str)
14241424
int err = SSL_get_error(sslcon,rc);
14251425

14261426
if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE || err == SSL_ERROR_WANT_X509_LOOKUP)
1427-
{
1428-
debugmsg("CONTROLREAD","want read/write error");
1427+
{
1428+
// if (trying) {
1429+
delete [] buffer;
1430+
return 2;
1431+
// }
1432+
/* debugmsg("CONTROLREAD","want read/write error");
14291433
fd_set data_writefds;
14301434
FD_ZERO(&data_writefds);
14311435
FD_SET(sock,&data_writefds);
@@ -1449,7 +1453,7 @@ int control_read(int sock,SSL *sslcon,string &str)
14491453
delete [] buffer;
14501454
return 0;
14511455
}
1452-
}
1456+
*/ }
14531457
else
14541458
{
14551459
debugmsg("CONTROLWRITE","SSL error",errno);
@@ -1529,7 +1533,7 @@ int SslConnect(int &sock,SSL **ssl,SSL_CTX **sslctx,int &shouldquit,string ciphe
15291533
}
15301534
SSL_CTX_set_default_verify_paths(*sslctx);
15311535
SSL_CTX_set_options(*sslctx,SSL_OP_ALL);
1532-
SSL_CTX_set_mode(*sslctx,SSL_MODE_AUTO_RETRY);
1536+
SSL_CTX_clear_mode(*sslctx,SSL_MODE_AUTO_RETRY);
15331537
SSL_CTX_set_session_cache_mode(*sslctx,SSL_SESS_CACHE_OFF);
15341538
}
15351539
*ssl = SSL_new(*sslctx);

src/yatb.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include "fpwhitelist.h"
1313

1414
#ifndef SOLARIS
15-
#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
15+
#if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
16+
#define SOLARIS
17+
#endif
1618
#endif
1719

1820

yatb.conf.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ retry_count=10;
113113
ssl_ascii_cache=0;
114114
disable_noop=0;
115115
speed_write=0;
116-
allow_noentry_connect=0;
116+
allow_noentry_connect=0;

0 commit comments

Comments
 (0)