Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 6898
Collapse All | Expand All

(-)proftpd-1.2.6rc1.orig/Make.rules.in (-2 / +2 lines)
Lines 58-67 Link Here
58
#CFLAGS=-g -pedantic -DUSESHADOW -DDEBUG_NOFORK
58
#CFLAGS=-g -pedantic -DUSESHADOW -DDEBUG_NOFORK
59
59
60
OBJS=main.o timers.o sets.o pool.o dirtree.o support.o inet.o log.o \
60
OBJS=main.o timers.o sets.o pool.o dirtree.o support.o inet.o log.o \
61
     io.o ident.o data.o modules.o auth.o fs.o
61
     io.o ident.o data.o modules.o auth.o fs.o @TLS_OBJS@
62
BUILD_OBJS=src/main.o src/timers.o src/sets.o src/pool.o src/dirtree.o \
62
BUILD_OBJS=src/main.o src/timers.o src/sets.o src/pool.o src/dirtree.o \
63
           src/support.o src/inet.o src/log.o src/io.o src/ident.o \
63
           src/support.o src/inet.o src/log.o src/io.o src/ident.o \
64
           src/data.o src/modules.o src/auth.o src/fs.o
64
           src/data.o src/modules.o src/auth.o src/fs.o @TLS_BUILD_OBJS@
65
65
66
LIB_OBJS=getopt.o getopt1.o pr_fnmatch.o strsep.o vsnprintf.o glibc-glob.o \
66
LIB_OBJS=getopt.o getopt1.o pr_fnmatch.o strsep.o vsnprintf.o glibc-glob.o \
67
         glibc-mkstemp.o pwgrent.o
67
         glibc-mkstemp.o pwgrent.o
(-)proftpd-1.2.6rc1.orig/README.TLS (+147 lines)
Line 0 Link Here
1
TLS patch for proftpd-1.2.5 together with OpenSSL >= 0.9.4, based on the
2
"draft-murray-auth-ftp-ssl-09.txt" IETF draft.
3
Copyright (c) 2000 Peter 'Luna' Runestig <peter@runestig.com>
4
The verify_crl() function by Ralf S. Engelschall <rse@engelschall.com>
5
This product includes software developed by the OpenSSL Project
6
for use in the OpenSSL Toolkit. (http://www.openssl.org/)
7
This product includes cryptographic software written by
8
Eric Young (eay@cryptsoft.com)
9
10
Patching:
11
	$ tar xzf proftpd-1.2.5.tar.gz
12
	$ cd proftpd-1.2.5
13
	$ patch -p1 < ../proftpd-tls.current.patch
14
15
	Or just use the prepatched tarball.
16
17
Configuring:
18
	$ ./configure [--with-openssl-dir=DIR]
19
	
20
Building:
21
	$ make
22
23
Installation:
24
	$ make install
25
26
By default, proftpd looks for a single configuration file at
27
/usr/local/etc/proftpd.conf.  Copy sample-configurations/basic.conf to
28
/usr/local/etc/proftpd.conf and modify to suit your needs.  More advanced
29
configuration examples are also included.
30
31
The proftpd server tries to use these TLS related files by default:
32
ftpd-rsa.pem		RSA certificate, may include private key
33
ftpd-rsa-key.pem	RSA private key
34
ftpd-dsa.pem		DSA certificate, may include private key
35
ftpd-dsa-key.pem	DSA private key
36
ftpd-crl.pem		Certificate Revokation List
37
ftpd-dhparam.pem	DH Parameters (a set of DH params is compiled in)
38
39
These files is searched for in the following directorys (in this order):
40
* Current working directory of the process.
41
* Specified by the `X509_get_default_cert_dir_env()` environment variable
42
  (usually $SSL_CERT_DIR).
43
* `X509_get_default_cert_dir()`, usually (openssl-dir)/certs.
44
* `X509_get_default_private_dir()`, usually (openssl-dir/private.
45
46
Default CRL directory for the proftpd server is (openssl-dir)/crl.
47
48
If you don't have any "proper" certificate files (signed by some CA), you might
49
create a self-signed one using the ``openssl'' command:
50
$ openssl req -new -x509 -days 365 -nodes -out ftpd-rsa.pem -keyout ftpd-rsa-key.pem
51
This creates a cert which is valid 365 days, you might want to adjust that.
52
53
X509 client authentication
54
--------------------------
55
Support for user authentication is possible through the custom function
56
int x509_to_user(X509 *peer_cert, char *userid, int len) in the file
57
src/x509_to_user.c, and by a .tlslogin file in the user's home directory.
58
59
o  tls_userid_from_client_cert() is called and returns a user id or NULL.
60
   tls_userid_from_client_cert() calls the site specific function
61
   x509_to_user().
62
63
o  If the user name, set by the USER command, equals the user id mapped from the
64
   client cert, the user is logged right in.
65
66
o  If "USER" differ from the user id mapped from the client cert the function
67
   tls_is_user_valid() is called to check "USER"'s ~/.tlslogin file.
68
   That file, if it exist, contains one or more X509 certificates in PEM for-
69
   mat. If the client cert is present in the file, the user is logged right in.
70
71
o  If tls_userid_from_client_cert() can't map a user id from the client cert,
72
   tls_is_user_valid() is called to check "USER"'s  ~/.tlslogin file. If the
73
   client cert is present in the file, the user is logged right in.
74
75
Hash symlinks for certs: ln -s cert.pem `openssl x509 -hash -noout -in cert.pem`.0
76
Hash symlinks for CRLs:  ln -s crl.pem `openssl crl -hash -noout -in crl.pem`.r0
77
78
Default cipher list is "ALL:!EXP".
79
80
How to put together a  'cipher list string':
81
  Key Exchange Algorithms:
82
    "kRSA"      RSA key exchange
83
    "kDHr"      Diffie-Hellman key exchange (key from RSA cert)
84
    "kDHd"      Diffie-Hellman key exchange (key from DSA cert)
85
    "kEDH'      Ephemeral Diffie-Hellman key exchange (temporary key)
86
87
  Authentication Algorithm:
88
    "aNULL"     No authentication
89
    "aRSA"      RSA authentication
90
    "aDSS"      DSS authentication
91
    "aDH"       Diffie-Hellman authentication
92
93
  Cipher Encoding Algorithm:
94
    "eNULL"     No encodiing
95
    "DES"       DES encoding
96
    "3DES"      Triple DES encoding
97
    "RC4"       RC4 encoding
98
    "RC2"       RC2 encoding
99
    "IDEA"      IDEA encoding
100
101
  MAC Digest Algorithm:
102
    "MD5"       MD5 hash function
103
    "SHA1"      SHA1 hash function
104
    "SHA"       SHA hash function (should not be used)
105
106
  Aliases:
107
    "ALL"       all ciphers
108
    "SSLv2"     all SSL version 2.0 ciphers (should not be used)
109
    "SSLv3"     all SSL version 3.0 ciphers
110
    "EXP"       all export ciphers (40-bit)
111
    "EXPORT56"  all export ciphers (56-bit)
112
    "LOW"       all low strength ciphers (no export)
113
    "MEDIUM"    all ciphers with 128-bit encryption
114
    "HIGH"      all ciphers using greater than 128-bit encryption
115
    "RSA"       all ciphers using RSA key exchange
116
    "DH"        all ciphers using Diffie-Hellman key exchange
117
    "EDH"       all ciphers using Ephemeral Diffie-Hellman key exchange
118
    "ADH"       all ciphers using Anonymous Diffie-Hellman key exchange
119
    "DSS"       all ciphers using DSS authentication
120
    "NULL"      all ciphers using no encryption
121
122
Each item in the list may include a prefix modifier:
123
124
    "+"         move cipher(s) to the current location in the list
125
    "-"         remove cipher(s) from the list (may be added again by
126
                a subsequent list entry)
127
    "!"         kill cipher from the list (it may not be added again
128
                by a subsequent list entry)
129
130
If no modifier is specified the entry is added to the list at the current 
131
position.  "+" may also be used to combine tags to specify entries such as 
132
"RSA+RC4" describes all ciphers that use both RSA and RC4.
133
134
For example, all available ciphers not including ADH key exchange:
135
136
  ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
137
138
All algorithms including ADH and export but excluding patented algorithms: 
139
140
  HIGH:MEDIUM:LOW:EXPORT56:EXP:ADH:!kRSA:!aRSA:!RC4:!RC2:!IDEA
141
142
The OpenSSL command 
143
144
  openssl ciphers -v <list of ciphers> 
145
146
may be used to list all of the ciphers and the order described by a specific
147
<list of ciphers>.
(-)proftpd-1.2.6rc1.orig/acconfig.h (+6 lines)
Lines 18-23 Link Here
18
/* Define if you have BSD sendfile() semantics */
18
/* Define if you have BSD sendfile() semantics */
19
#undef HAVE_BSD_SENDFILE
19
#undef HAVE_BSD_SENDFILE
20
20
21
/* Define to build with SSL/TLS support */
22
#undef TLS
23
24
/* Define this symbol if support for OpenSSL zlib compression is enabled. */
25
#undef ZLIB
26
21
/* Define if you have Linux sendfile() semantics */
27
/* Define if you have Linux sendfile() semantics */
22
#undef HAVE_LINUX_SENDFILE
28
#undef HAVE_LINUX_SENDFILE
23
29
(-)proftpd-1.2.6rc1.orig/config.h.in (-1 / +7 lines)
Lines 19-24 Link Here
19
/* Define if you have BSD sendfile() semantics */
19
/* Define if you have BSD sendfile() semantics */
20
#undef HAVE_BSD_SENDFILE
20
#undef HAVE_BSD_SENDFILE
21
21
22
/* Define to build with SSL/TLS support */
23
#undef TLS
24
25
/* Define this symbol if support for OpenSSL zlib compression is enabled. */
26
#undef ZLIB
27
22
/* Define if you have Linux sendfile() semantics */
28
/* Define if you have Linux sendfile() semantics */
23
#undef HAVE_LINUX_SENDFILE
29
#undef HAVE_LINUX_SENDFILE
24
30
Lines 423-429 Link Here
423
/* Define if you have the <utmpx.h> header file.  */
429
/* Define if you have the <utmpx.h> header file.  */
424
#undef HAVE_UTMPX_H
430
#undef HAVE_UTMPX_H
425
431
426
/* Define if you have the "vmsdir.h" header file.  */
432
/* Define if you have the <vmsdir.h> header file.  */
427
#undef HAVE_VMSDIR_H
433
#undef HAVE_VMSDIR_H
428
434
429
/* Define if you have the bind library (-lbind).  */
435
/* Define if you have the bind library (-lbind).  */
(-)proftpd-1.2.6rc1.orig/configure (+242 lines)
Lines 838-843 Link Here
838
838
839
  --enable-shadow         force compilation of shadowed password support
839
  --enable-shadow         force compilation of shadowed password support
840
840
841
  --disable-tls           disable TLS security
842
  --enable-tls_zlib       enable use of OpenSSL zlib compression (EXPERIMENTAL)
841
843
842
Optional Packages:
844
Optional Packages:
843
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
845
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
Lines 854-859 Link Here
854
                          LIST is a ':' separated list of modules to add
856
                          LIST is a ':' separated list of modules to add
855
                          e.g. --with-modules=mod_pam:mod_readme
857
                          e.g. --with-modules=mod_pam:mod_readme
856
858
859
  --with-openssl-dir=DIR  specify location of the OpenSSL directory
857
860
858
Some influential environment variables:
861
Some influential environment variables:
859
  CC          C compiler command
862
  CC          C compiler command
Lines 3495-3500 Link Here
3495
fi
3498
fi
3496
3499
3497
3500
3501
# Check whether --with-openssl-dir or --without-openssl-dir was given.
3502
if test "${with_openssl_dir+set}" = set; then
3503
  withval="$with_openssl_dir"
3504
  OPENSSLDIR=$withval
3505
fi;
3506
if test -n "$OPENSSLDIR"; then
3507
    LIBS="$LIBS -L$OPENSSLDIR/lib"
3508
    CPPFLAGS="$CPPFLAGS -I$OPENSSLDIR/include"
3509
fi
3510
3511
# Check whether --enable-tls or --disable-tls was given.
3512
if test "${enable_tls+set}" = set; then
3513
  enableval="$enable_tls"
3514
3515
else
3516
  enable_tls=yes
3517
fi;
3518
# Check whether --enable-tls_zlib or --disable-tls_zlib was given.
3519
if test "${enable_tls_zlib+set}" = set; then
3520
  enableval="$enable_tls_zlib"
3521
3522
else
3523
  enable_tls_zlib=no
3524
fi;
3525
3526
3498
echo "$as_me:$LINENO: checking for set_auth_parameters in -lsecurity" >&5
3527
echo "$as_me:$LINENO: checking for set_auth_parameters in -lsecurity" >&5
3499
echo $ECHO_N "checking for set_auth_parameters in -lsecurity... $ECHO_C" >&6
3528
echo $ECHO_N "checking for set_auth_parameters in -lsecurity... $ECHO_C" >&6
3500
if test "${ac_cv_lib_security_set_auth_parameters+set}" = set; then
3529
if test "${ac_cv_lib_security_set_auth_parameters+set}" = set; then
Lines 10449-10454 Link Here
10449
  esac
10478
  esac
10450
fi
10479
fi
10451
10480
10481
if test "$enable_tls" = yes; then
10482
  # look for OpenSSL libraries
10483
  echo "$as_me:$LINENO: checking for X509_STORE_load_locations in -lcrypto" >&5
10484
echo $ECHO_N "checking for X509_STORE_load_locations in -lcrypto... $ECHO_C" >&6
10485
if test "${ac_cv_lib_crypto_X509_STORE_load_locations+set}" = set; then
10486
  echo $ECHO_N "(cached) $ECHO_C" >&6
10487
else
10488
  ac_check_lib_save_LIBS=$LIBS
10489
LIBS="-lcrypto  $LIBS"
10490
cat >conftest.$ac_ext <<_ACEOF
10491
#line $LINENO "configure"
10492
#include "confdefs.h"
10493
10494
/* Override any gcc2 internal prototype to avoid an error.  */
10495
#ifdef __cplusplus
10496
extern "C"
10497
#endif
10498
/* We use char because int might match the return type of a gcc2
10499
   builtin and then its argument prototype would still apply.  */
10500
char X509_STORE_load_locations ();
10501
#ifdef F77_DUMMY_MAIN
10502
#  ifdef __cplusplus
10503
     extern "C"
10504
#  endif
10505
   int F77_DUMMY_MAIN() { return 1; }
10506
#endif
10507
int
10508
main ()
10509
{
10510
X509_STORE_load_locations ();
10511
  ;
10512
  return 0;
10513
}
10514
_ACEOF
10515
rm -f conftest.$ac_objext conftest$ac_exeext
10516
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
10517
  (eval $ac_link) 2>&5
10518
  ac_status=$?
10519
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
10520
  (exit $ac_status); } &&
10521
         { ac_try='test -s conftest$ac_exeext'
10522
  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
10523
  (eval $ac_try) 2>&5
10524
  ac_status=$?
10525
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
10526
  (exit $ac_status); }; }; then
10527
  ac_cv_lib_crypto_X509_STORE_load_locations=yes
10528
else
10529
  echo "$as_me: failed program was:" >&5
10530
cat conftest.$ac_ext >&5
10531
ac_cv_lib_crypto_X509_STORE_load_locations=no
10532
fi
10533
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
10534
LIBS=$ac_check_lib_save_LIBS
10535
fi
10536
echo "$as_me:$LINENO: result: $ac_cv_lib_crypto_X509_STORE_load_locations" >&5
10537
echo "${ECHO_T}$ac_cv_lib_crypto_X509_STORE_load_locations" >&6
10538
if test $ac_cv_lib_crypto_X509_STORE_load_locations = yes; then
10539
  LIBTLS=-lcrypto
10540
else
10541
  { { echo "$as_me:$LINENO: error: Could not find OpenSSL library needed for SSL/TLS support. Try again using --with-openssl-dir=DIR" >&5
10542
echo "$as_me: error: Could not find OpenSSL library needed for SSL/TLS support. Try again using --with-openssl-dir=DIR" >&2;}
10543
   { (exit 1); exit 1; }; }
10544
fi
10545
10546
  echo "$as_me:$LINENO: checking for SSL_accept in -lssl" >&5
10547
echo $ECHO_N "checking for SSL_accept in -lssl... $ECHO_C" >&6
10548
if test "${ac_cv_lib_ssl_SSL_accept+set}" = set; then
10549
  echo $ECHO_N "(cached) $ECHO_C" >&6
10550
else
10551
  ac_check_lib_save_LIBS=$LIBS
10552
LIBS="-lssl -lcrypto $LIBS"
10553
cat >conftest.$ac_ext <<_ACEOF
10554
#line $LINENO "configure"
10555
#include "confdefs.h"
10556
10557
/* Override any gcc2 internal prototype to avoid an error.  */
10558
#ifdef __cplusplus
10559
extern "C"
10560
#endif
10561
/* We use char because int might match the return type of a gcc2
10562
   builtin and then its argument prototype would still apply.  */
10563
char SSL_accept ();
10564
#ifdef F77_DUMMY_MAIN
10565
#  ifdef __cplusplus
10566
     extern "C"
10567
#  endif
10568
   int F77_DUMMY_MAIN() { return 1; }
10569
#endif
10570
int
10571
main ()
10572
{
10573
SSL_accept ();
10574
  ;
10575
  return 0;
10576
}
10577
_ACEOF
10578
rm -f conftest.$ac_objext conftest$ac_exeext
10579
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
10580
  (eval $ac_link) 2>&5
10581
  ac_status=$?
10582
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
10583
  (exit $ac_status); } &&
10584
         { ac_try='test -s conftest$ac_exeext'
10585
  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
10586
  (eval $ac_try) 2>&5
10587
  ac_status=$?
10588
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
10589
  (exit $ac_status); }; }; then
10590
  ac_cv_lib_ssl_SSL_accept=yes
10591
else
10592
  echo "$as_me: failed program was:" >&5
10593
cat conftest.$ac_ext >&5
10594
ac_cv_lib_ssl_SSL_accept=no
10595
fi
10596
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
10597
LIBS=$ac_check_lib_save_LIBS
10598
fi
10599
echo "$as_me:$LINENO: result: $ac_cv_lib_ssl_SSL_accept" >&5
10600
echo "${ECHO_T}$ac_cv_lib_ssl_SSL_accept" >&6
10601
if test $ac_cv_lib_ssl_SSL_accept = yes; then
10602
  LIBTLS="-lssl $LIBTLS"
10603
else
10604
  { { echo "$as_me:$LINENO: error: Could not find OpenSSL library needed for SSL/TLS support. Try again using --with-openssl-dir=DIR" >&5
10605
echo "$as_me: error: Could not find OpenSSL library needed for SSL/TLS support. Try again using --with-openssl-dir=DIR" >&2;}
10606
   { (exit 1); exit 1; }; }
10607
fi
10608
10609
  ac_core_modules="$ac_core_modules mod_tls.o"
10610
  ac_build_core_modules="$ac_build_core_modules modules/mod_tls.o"
10611
  TLS_OBJS="tlsutil.o x509_to_user.o"
10612
  TLS_BUILD_OBJS="src/tlsutil.o src/x509_to_user.o"
10613
10614
10615
  cat >>confdefs.h <<\_ACEOF
10616
#define TLS 1
10617
_ACEOF
10618
10619
  if test "$enable_tls_zlib" = yes; then
10620
    echo "$as_me:$LINENO: checking for compress in -lz" >&5
10621
echo $ECHO_N "checking for compress in -lz... $ECHO_C" >&6
10622
if test "${ac_cv_lib_z_compress+set}" = set; then
10623
  echo $ECHO_N "(cached) $ECHO_C" >&6
10624
else
10625
  ac_check_lib_save_LIBS=$LIBS
10626
LIBS="-lz  $LIBS"
10627
cat >conftest.$ac_ext <<_ACEOF
10628
#line $LINENO "configure"
10629
#include "confdefs.h"
10630
10631
/* Override any gcc2 internal prototype to avoid an error.  */
10632
#ifdef __cplusplus
10633
extern "C"
10634
#endif
10635
/* We use char because int might match the return type of a gcc2
10636
   builtin and then its argument prototype would still apply.  */
10637
char compress ();
10638
#ifdef F77_DUMMY_MAIN
10639
#  ifdef __cplusplus
10640
     extern "C"
10641
#  endif
10642
   int F77_DUMMY_MAIN() { return 1; }
10643
#endif
10644
int
10645
main ()
10646
{
10647
compress ();
10648
  ;
10649
  return 0;
10650
}
10651
_ACEOF
10652
rm -f conftest.$ac_objext conftest$ac_exeext
10653
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
10654
  (eval $ac_link) 2>&5
10655
  ac_status=$?
10656
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
10657
  (exit $ac_status); } &&
10658
         { ac_try='test -s conftest$ac_exeext'
10659
  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
10660
  (eval $ac_try) 2>&5
10661
  ac_status=$?
10662
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
10663
  (exit $ac_status); }; }; then
10664
  ac_cv_lib_z_compress=yes
10665
else
10666
  echo "$as_me: failed program was:" >&5
10667
cat conftest.$ac_ext >&5
10668
ac_cv_lib_z_compress=no
10669
fi
10670
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
10671
LIBS=$ac_check_lib_save_LIBS
10672
fi
10673
echo "$as_me:$LINENO: result: $ac_cv_lib_z_compress" >&5
10674
echo "${ECHO_T}$ac_cv_lib_z_compress" >&6
10675
if test $ac_cv_lib_z_compress = yes; then
10676
  LIBS="$LIBS -lz"
10677
else
10678
  { { echo "$as_me:$LINENO: error: Could not find ZLIB library needed." >&5
10679
echo "$as_me: error: Could not find ZLIB library needed." >&2;}
10680
   { (exit 1); exit 1; }; }
10681
fi
10682
10683
    cat >>confdefs.h <<\_ACEOF
10684
#define ZLIB 1
10685
_ACEOF
10686
10687
  fi
10688
  LIBS="$LIBS $LIBTLS"
10689
fi
10690
10452
10691
10453
for ac_func in setproctitle
10692
for ac_func in setproctitle
10454
do
10693
do
Lines 11740-11749 Link Here
11740
s,@INSTALL_DATA@,$INSTALL_DATA,;t t
11979
s,@INSTALL_DATA@,$INSTALL_DATA,;t t
11741
s,@RANLIB@,$RANLIB,;t t
11980
s,@RANLIB@,$RANLIB,;t t
11742
s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
11981
s,@ac_ct_RANLIB@,$ac_ct_RANLIB,;t t
11982
s,@OPENSSLDIR@,$OPENSSLDIR,;t t
11743
s,@CPP@,$CPP,;t t
11983
s,@CPP@,$CPP,;t t
11744
s,@install_user@,$install_user,;t t
11984
s,@install_user@,$install_user,;t t
11745
s,@install_group@,$install_group,;t t
11985
s,@install_group@,$install_group,;t t
11746
s,@ALLOCA@,$ALLOCA,;t t
11986
s,@ALLOCA@,$ALLOCA,;t t
11987
s,@TLS_OBJS@,$TLS_OBJS,;t t
11988
s,@TLS_BUILD_OBJS@,$TLS_BUILD_OBJS,;t t
11747
s,@MODULES@,$MODULES,;t t
11989
s,@MODULES@,$MODULES,;t t
11748
s,@BUILD_MODULES@,$BUILD_MODULES,;t t
11990
s,@BUILD_MODULES@,$BUILD_MODULES,;t t
11749
s,@ADDL_DIRS@,$ADDL_DIRS,;t t
11991
s,@ADDL_DIRS@,$ADDL_DIRS,;t t
(-)proftpd-1.2.6rc1.orig/configure.in (+36 lines)
Lines 239-244 Link Here
239
  AC_DEFINE(HAVE__PW_STAYOPEN)
239
  AC_DEFINE(HAVE__PW_STAYOPEN)
240
fi
240
fi
241
241
242
dnl TLS options
243
AC_ARG_WITH(openssl-dir,
244
    [  --with-openssl-dir=DIR  specify location of the OpenSSL directory],
245
    OPENSSLDIR=$withval)
246
if test -n "$OPENSSLDIR"; then
247
    LIBS="$LIBS -L$OPENSSLDIR/lib"
248
    CPPFLAGS="$CPPFLAGS -I$OPENSSLDIR/include"
249
fi
250
AC_SUBST(OPENSSLDIR)
251
AC_ARG_ENABLE(tls, [  --disable-tls           disable TLS security],
252
             , enable_tls=yes)
253
AC_ARG_ENABLE(tls_zlib, [  --enable-tls_zlib       enable use of OpenSSL zlib compression (EXPERIMENTAL)],
254
	      , enable_tls_zlib=no)
255
242
AC_CHECK_LIB(security, set_auth_parameters)
256
AC_CHECK_LIB(security, set_auth_parameters)
243
AC_CHECK_HEADERS(sys/security.h)
257
AC_CHECK_HEADERS(sys/security.h)
244
AC_CHECK_HEADERS(krb.h)
258
AC_CHECK_HEADERS(krb.h)
Lines 536-541 Link Here
536
  esac
550
  esac
537
fi
551
fi
538
552
553
dnl TLS options
554
if test "$enable_tls" = yes; then
555
  # look for OpenSSL libraries
556
  AC_CHECK_LIB(crypto, X509_STORE_load_locations, LIBTLS=-lcrypto,
557
       AC_MSG_ERROR(Could not find OpenSSL library needed for SSL/TLS support. Try again using --with-openssl-dir=DIR))
558
  AC_CHECK_LIB(ssl, SSL_accept, LIBTLS="-lssl $LIBTLS",
559
       AC_MSG_ERROR(Could not find OpenSSL library needed for SSL/TLS support. Try again using --with-openssl-dir=DIR), -lcrypto)
560
  ac_core_modules="$ac_core_modules mod_tls.o"
561
  ac_build_core_modules="$ac_build_core_modules modules/mod_tls.o"
562
  TLS_OBJS="tlsutil.o x509_to_user.o"
563
  TLS_BUILD_OBJS="src/tlsutil.o src/x509_to_user.o"
564
  AC_SUBST(TLS_OBJS)
565
  AC_SUBST(TLS_BUILD_OBJS)
566
  AC_DEFINE(TLS)
567
  if test "$enable_tls_zlib" = yes; then
568
    AC_CHECK_LIB(z, compress, LIBS="$LIBS -lz",
569
	AC_MSG_ERROR(Could not find ZLIB library needed.))
570
    AC_DEFINE(ZLIB)
571
  fi
572
  LIBS="$LIBS $LIBTLS"
573
fi
574
539
dnl Check for various argv[] replacing functions on various OSs
575
dnl Check for various argv[] replacing functions on various OSs
540
AC_CHECK_FUNCS(setproctitle)
576
AC_CHECK_FUNCS(setproctitle)
541
AC_CHECK_HEADERS(libutil.h)
577
AC_CHECK_HEADERS(libutil.h)
(-)proftpd-1.2.6rc1.orig/contrib/dist/rpm/proftpd.spec.in (-2 / +35 lines)
Lines 1-21 Link Here
1
# $Id: proftpd.spec.in,v 1.14 2002/05/19 14:38:42 jwm Exp $
1
# $Id: proftpd.spec.in,v 1.14 2002/05/19 14:38:42 jwm Exp $
2
#
2
#
3
%define tls 1
4
%if %{tls}
5
%define TLSVERSION 20020711
6
%define TLSVERSIONRELEASE 1
7
%endif
8
%if %{tls}
9
Summary:	ProFTPD -- Professional FTP Server (TLS enabled).
10
%else
3
Summary:	ProFTPD -- Professional FTP Server.
11
Summary:	ProFTPD -- Professional FTP Server.
12
%endif
4
Name:		proftpd
13
Name:		proftpd
5
Version:	@VERSION@
14
Version:	@VERSION@
15
%if %{tls}
16
Release:	1.tls.%{TLSVERSION}.%{TLSVERSIONRELEASE}
17
%else
6
Release:	1
18
Release:	1
19
%endif
7
Copyright:	GPL
20
Copyright:	GPL
8
Group:		System Environment/Daemons
21
Group:		System Environment/Daemons
9
Packager:	Daniel Roesen <droesen@entire-systems.com>
22
Packager:	Daniel Roesen <droesen@entire-systems.com> and Dr. Peter Bieringer <pbieringer@aerasec.de> (TLS)
10
Vendor:		The ProFTPD Group
23
Vendor:		The ProFTPD Group
11
URL:		http://www.proftpd.org/
24
URL:		http://www.proftpd.org/
12
Source:		ftp://ftp.proftpd.org/distrib/%{name}-%{version}.tar.gz
25
Source:		ftp://ftp.proftpd.org/distrib/%{name}-%{version}.tar.gz
26
%if %{tls}
27
Patch0:		ftp://ftp.runestig.com/pub/%{name}-%{version}-tls.%{TLSVERSION}.patch.gz 
28
%endif
13
Prefix:		/usr
29
Prefix:		/usr
30
%if %{tls}
31
BuildRoot:	%{_builddir}/%{name}-%{version}-%{TLSVERSION}-root
32
Requires:	pam >= 0.72, openssl
33
%else
14
BuildRoot:	%{_builddir}/%{name}-%{version}-root
34
BuildRoot:	%{_builddir}/%{name}-%{version}-root
15
Requires:	pam >= 0.72
35
Requires:	pam >= 0.72
36
%endif
16
Provides:	ftpserver
37
Provides:	ftpserver
17
Prereq:		fileutils
38
Prereq:		fileutils
18
Obsoletes:	proftpd-core
39
Obsoletes:	proftpd-core
40
%if %{tls}
41
BuildPreReq:	openssl-devel
42
%endif
19
43
20
%description
44
%description
21
ProFTPD is an enhanced FTP server with a focus toward simplicity, security,
45
ProFTPD is an enhanced FTP server with a focus toward simplicity, security,
Lines 26-31 Link Here
26
50
27
There are two other packages you can use to setup for inetd or standalone
51
There are two other packages you can use to setup for inetd or standalone
28
operation.
52
operation.
53
%if %{tls}
54
This package is TLS enabled, used TLS patch version is: %{TLSVERSION}
55
%endif
29
56
30
%package standalone
57
%package standalone
31
Summary:	ProFTPD -- Setup for standalone operation.
58
Summary:	ProFTPD -- Setup for standalone operation.
Lines 39-45 Link Here
39
%package inetd
66
%package inetd
40
Summary:	ProFTPD -- Setup for inetd operation.
67
Summary:	ProFTPD -- Setup for inetd operation.
41
Group:		System Environment/Daemons
68
Group:		System Environment/Daemons
42
Requires:	proftpd
69
Requires:	proftpd-tls
43
Obsoletes:	proftpd-standalone
70
Obsoletes:	proftpd-standalone
44
71
45
%description inetd
72
%description inetd
Lines 47-52 Link Here
47
74
48
%prep
75
%prep
49
%setup -q
76
%setup -q
77
%if %{tls}
78
%patch0 -p1
79
%endif
50
  CFLAGS="$RPM_OPT_FLAGS" ./configure \
80
  CFLAGS="$RPM_OPT_FLAGS" ./configure \
51
	--prefix=%{prefix} \
81
	--prefix=%{prefix} \
52
	--sysconfdir=/etc \
82
	--sysconfdir=/etc \
Lines 178-183 Link Here
178
- Added use of %defattr to allow build of RPMs by non-root users
208
- Added use of %defattr to allow build of RPMs by non-root users
179
  For details see http://bugs.proftpd.org/show_bug.cgi?id=1580
209
  For details see http://bugs.proftpd.org/show_bug.cgi?id=1580
180
210
211
* Mon May 07 2001 Dr. Peter Bieringer <pbieringer@aerasec.de>
212
- Make "tls" usage switchable
213
181
* Mon Mar 05 2001 Daniel Roesen <droesen@entire-systems.com>
214
* Mon Mar 05 2001 Daniel Roesen <droesen@entire-systems.com>
182
- PAM >= 0.72 is now a requirement. Versions before are broken and
215
- PAM >= 0.72 is now a requirement. Versions before are broken and
183
  Red Hat provides a PAM update for all RH 6.x releases. See:
216
  Red Hat provides a PAM update for all RH 6.x releases. See:
(-)proftpd-1.2.6rc1.orig/doc/rfc/draft-murray-auth-ftp-ssl-09.txt (+1679 lines)
Line 0 Link Here
1
2
3
4
5
6
7
                                                    Paul Ford-Hutchinson
8
<draft-murray-auth-ftp-ssl-09.txt>                            IBM UK Ltd
9
                                                        Martin Carpenter
10
                                                            Verisign Inc
11
                                                              Tim Hudson
12
INTERNET-DRAFT (draft)                                 RSA Australia Ltd
13
                                                             Eric Murray
14
                                                        Wave Systems Inc
15
                                                          Volker Wiegand
16
                                                              SuSE Linux
17
18
                                                         2nd April, 2002
19
This document expires on 2nd October, 2002
20
21
22
                         Securing FTP with TLS
23
24
25
Status of this Memo
26
27
   This document is an Internet-Draft and is in full conformance with
28
   all provisions of Section 10 of RFC2026.
29
30
   Internet-Drafts are working documents of the Internet Engineering
31
   Task Force (IETF), its areas, and its working groups.  Note that
32
   other groups may also distribute working documents as Internet-
33
   Drafts.
34
35
   Internet-Drafts are draft documents valid for a maximum of six months
36
   and may be updated, replaced, or obsoleted by other documents at any
37
   time.  It is inappropriate to use Internet-Drafts as reference
38
   material or to cite them other than as "work in progress."
39
40
   The list of current Internet-Drafts can be accessed at
41
   http://www.ietf.org/1id-abstracts.txt
42
43
   The list of Internet-Draft Shadow Directories can be accessed at
44
   http://www.ietf.org/shadow.html
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 1]
59
60
61
62
63
64
Internet-Draft            Secure FTP using TLS           2nd April, 2002
65
66
67
Index
68
      1. .......... Abstract
69
      2. .......... Introduction
70
      3. .......... Audience
71
      4. .......... Session negotiation on the control port
72
      5. .......... Response to FEAT command
73
      6. .......... Data Connection Behaviour
74
      7. .......... Mechanisms for the AUTH Command
75
      8. .......... Data Connection Security
76
      9. .......... A discussion of negotiation behaviour
77
      10. ......... Who negotiates what, where and how
78
      11. ......... Timing Diagrams
79
      12. ......... Discussion of the REIN command
80
      13. ......... Discussion of the STAT and ABOR commands
81
      14. ......... Security Considerations
82
      15. ......... IANA Considerations
83
      16. ......... Other Parameters
84
      17. ......... Network Management
85
      18. ......... Internationalization
86
      19. ......... Scalability & Limits
87
      20. ......... Applicability
88
      21. ......... Acknowledgements
89
      22. ......... References
90
      23. ......... Authors' Contact Addresses
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 2]
119
120
121
122
123
124
Internet-Draft            Secure FTP using TLS           2nd April, 2002
125
126
127
1. Abstract
128
129
   This document describes a mechanism that can be used by FTP clients
130
   and servers to implement security and authentication using the TLS
131
   protocol defined by [RFC-2246] and the extensions to the FTP protocol
132
   defined by [RFC-2228].  It describes the subset of the extensions
133
   that are required and the parameters to be used; discusses some of
134
   the policy issues that clients and servers will need to take;
135
   considers some of the implications of those policies and discusses
136
   some expected behaviours of implementations to allow interoperation.
137
   This document is intended to provide TLS support for FTP in a similar
138
   way to that provided for SMTP in [RFC-2487] and HTTP in [RFC-2817].
139
140
   TLS is not the only mechanism for securing file transfer, however it
141
   does offer some of the following positive attributes:-
142
143
      - Flexible security levels.  TLS can support confidentiality,
144
      integrity, authentication or some combination of all of these.
145
      This allows clients and servers to dynamically, during a session,
146
      decide on the level of security required for a particular data
147
      transfer,
148
149
      - It is possible to use TLS identities to authenticate client
150
      users and not just client hosts.
151
152
      - Formalised public key management.  By use of well established
153
      client identity mechnisms (supported by TLS) during the
154
      authentication phase, certificate management may be built into a
155
      central function.  Whilst this may not be desirable for all uses
156
      of secured file transfer, it offers advantages in certain
157
      structured environments.
158
159
      - Co-existence and interoperation with authentication mechanisms
160
      that are already in place for the HTTPS protocol.  This allows web
161
      browsers to incorporate secure file transfer using the same
162
      infrastructure that has been set up to allow secure web browsing.
163
164
   The TLS protocol is a development of the Netscape Communication
165
   Corporation's SSL protocol and this document can be used to allow the
166
   FTP protocol to be used with either SSL or TLS.  The actual protocol
167
   used will be decided by the negotiation of the protected session by
168
   the TLS/SSL layer.  This document will only refer to the TLS
169
   protocol, however, it is understood that the Client and Server MAY
170
   actually be using SSL if they are so configured.
171
172
   Note that this specification is in accordance with the FTP RFC
173
   [RFC-959] and relies on the TLS protocol [RFC-2246] and the FTP
174
   security extensions [RFC-2228].
175
176
177
178
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 3]
179
180
181
182
183
184
Internet-Draft            Secure FTP using TLS           2nd April, 2002
185
186
187
2.  Introduction
188
189
   The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
190
    "SHALL NOT",  "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY" and
191
   "OPTIONAL" that appear in this document are to be interpreted as
192
   described in [RFC-2119].
193
194
   This document is an attempt to describe how three other documents
195
   should combined to provide a useful, interoperable, secure file
196
   transfer protocol.  Those documents are:-
197
198
199
      RFC 959 [RFC-959]
200
201
         The description of the Internet File Transfer Protocol
202
203
      RFC 2246 [RFC-2246]
204
205
         The description of the Transport Layer Security protocol
206
         (developed from the Netscape Secure Sockets Layer (SSL)
207
         protocol version 3.0).
208
209
      RFC 2228 [RFC-2228]
210
211
         Extensions to the FTP protocol to allow negotiation of security
212
         mechanisms to allow authentication, confidentiality and message
213
         integrity.
214
215
   The File Transfer Protocol (FTP) currently defined in [RFC-959] and
216
   in place on the Internet is an excellent mechanism for exchanging
217
   files.  The security extensions to FTP in [RFC-2228] offer a
218
   comprehensive set of commands and responses that can be used to add
219
   authentication, integrity and confidentiality to the FTP protocol.
220
   The TLS protocol is a popular (due to its wholesale adoption in the
221
   HTTP environment) mechanism for generally securing a socket
222
   connection.
223
   There are many ways in which these three protocols can be combined
224
   which would ensure that interoperation is impossible.  This document
225
   describes one method by which FTP can operate securely in such a way
226
   as to provide both flexibility and interoperation.  This necessitates
227
   a brief description of the actual negotiation mechanism ; a much more
228
   detailed description of the policies and practices that would be
229
   required and a discussion of the expected behaviours of clients and
230
   servers to allow either party to impose their security requirements
231
   on the FTP session.
232
233
234
3.  Audience
235
236
237
238
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 4]
239
240
241
242
243
244
Internet-Draft            Secure FTP using TLS           2nd April, 2002
245
246
247
   This document is aimed at developers who wish to implement TLS as a
248
   security mechanism to secure FTP clients and/or servers.
249
250
251
4.  Session negotiation on the control port
252
253
   The server listens on the normal FTP control port {FTP-PORT} and the
254
   session initiation is not secured at all.  Once the client wishes to
255
   secure the session, the AUTH command is sent and the server MAY then
256
   allow TLS negotiation to take place.
257
258
  4.1  Client wants a secured session
259
260
     If a client wishes to attempt to secure a session then it SHOULD,
261
     in accordance with [RFC-2228] send the AUTH command with the
262
     parameter requesting TLS {TLS-PARM}.
263
264
265
     The client then needs to behave according to its policies depending
266
     on the response received from the server and also the result of the
267
     TLS negotiation.  i.e. A client which receives an AUTH rejection
268
     MAY choose to continue with the session unprotected if it so
269
     desires.
270
271
  4.2  Server wants a secured session
272
273
     The FTP protocol does not allow a server to directly dictate client
274
     behaviour, however the same effect can be achieved by refusing to
275
     accept certain FTP commands until the session is secured to an
276
     acceptable level to the server.
277
278
   The server response to an 'AUTH TLS' command which it will honour, is
279
   '234'.
280
281
      Note. The '334' response as defined in [RFC-2228] implies that an
282
      ADAT exchange will folow.  This document does not use the ADAT
283
      command and so the '334' reply is incorrect.
284
285
   Note. The FTP protocol insists that a USER command be used to
286
   identify the entity attempting to use the ftp server.  Although the
287
   TLS negotiation may be providing authentication information the USER
288
   command must still be isssued by the client.  However, it will be a
289
   server implementation issue to decide which credentials to accept and
290
   what consistency checks to make between any client cert used and the
291
   parameter on the USER command.
292
293
5.  Response to the FEAT command
294
295
296
297
298
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 5]
299
300
301
302
303
304
Internet-Draft            Secure FTP using TLS           2nd April, 2002
305
306
307
   The FEAT command (introduced in [RFC-2389]) allows servers with
308
   additional features to advertise these to a client by responding to
309
   the FEAT command.  If a server supports the FEAT command then it MUST
310
   advertise supported AUTH, PBSZ and PROT commands in the reply as
311
   described in section 3.2 of [RFC-2389].  Additionally, the AUTH
312
   command should have a reply that identifies 'TLS' as one of the
313
   possible parameters to AUTH.  It is not necessary to identify the
314
   'TLS-C' synonym separately.
315
316
   Example reply (in same style is [RFC-2389])
317
      C> FEAT
318
      S> 211-Extensions supported
319
      S>  AUTH TLS
320
      S>  PBSZ
321
      S>  PROT
322
      S> 211 END
323
324
325
6. Data Connection Behaviour
326
327
   The Data Connection in the FTP model can be used in one of three
328
   ways.  (Note: these descriptions are not necessarily placed in exact
329
   chronological order, but do describe the steps required. - See
330
   diagrams later for clarification)
331
332
         i) Classic FTP client/server data exchange
333
334
         - The client obtains a port; sends the port number to the
335
         server; the server connects to the client.  The client issues a
336
         send or receive request to the server on the control connection
337
         and the data transfer commences on the data connection.
338
339
         ii) Firewall-Friendly client/server data exchange (as discussed
340
         in [RFC-1579]) using the PASV command to reverse the direction
341
         of the data connection.
342
343
         - The client requests that the server open a port; the server
344
         obtains a port and returns the address and port number to the
345
         client; the client connects to the server on this port.  The
346
         client issues a send or receive request on the control
347
         connection and the data transfer commences on the data
348
         connection.
349
350
         iii) Client initiated server/server data exchange (proxy or
351
         PASV connections)
352
353
         - The client requests that server A opens a port; server A
354
         obtains a port and returns it to the client; the client sends
355
356
357
358
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 6]
359
360
361
362
363
364
Internet-Draft            Secure FTP using TLS           2nd April, 2002
365
366
367
         this port number to server B.  Server B connects to server A.
368
         The client sends a send or receive request to server A and the
369
         complement to server B and the data transfer commences.  In
370
         this model server A is the proxy or PASV host and is a client
371
         for the Data Connection to server B.
372
373
   For i) and ii) the FTP client MUST be the TLS client and the FTP
374
   server MUST be the TLS server.
375
376
   That is to say, it does not matter which side initiates the
377
   connection with a connect() call or which side reacts to the
378
   connection via the accept() call; the FTP client as defined in
379
   [RFC-959] is always the TLS client as defined in [RFC-2246].
380
381
   In scenario iii) there is a problem in that neither server A nor
382
   server B is the TLS client given the fact that an FTP server must act
383
   as a TLS server for Firewall-Friendly FTP [RFC-1579].  Thus this is
384
   explicitly excluded in the security extensions document [RFC-2228],
385
   and in this document.
386
387
388
389
7. Mechanisms for the AUTH Command
390
391
   The AUTH command takes a single parameter to define the security
392
   mechanism to be negotiated.  As the SSL/TLS protocols self-negotiate
393
   their levels there is no need to distinguish SSL vs TLS in the
394
   application layer.  The proposed mechanism name for negotiating TLS
395
   will be the character string identified in {TLS-PARM}.  This will
396
   allow the client and server to negotiate TLS on the control
397
   connection without altering the protection of the data channel.  To
398
   protect the data channel as well, the PBSZ:PROT command sequence MUST
399
   be used.
400
401
   Note: The data connection state MAY be modified by the client issuing
402
   the PROT command with the new desired level of data channel
403
   protection and the server replying in the affirmative.  This data
404
   channel protection negotiation can happen at any point in the session
405
   (even straight after a PORT or PASV command) and as often as is
406
   required.
407
408
      See also Section 15, "IANA Considerations".
409
410
411
8. Data Connection Security
412
413
   The Data Connection security level is determined by the PROT command
414
415
416
417
418
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 7]
419
420
421
422
423
424
Internet-Draft            Secure FTP using TLS           2nd April, 2002
425
426
427
      The PROT command, as specified in [RFC-2228] allows client/server
428
      negotiation of the security level of the data connection.  Once a
429
      PROT command has been issued by the client and accepted by the
430
      server returning the '200' reply, the security of subsequent data
431
      connections MUST be at that level until another PROT command is
432
      issued and accepted; the session ends; a REIN command is issued;
433
      or the security of the session (via an AUTH command) is re-
434
      negotiated.
435
436
   Data Connection Security Negotiation (the PROT command)
437
438
      Note: In line with [RFC-2228], there is no facility for securing
439
      the Data connection with an insecure Control connection.
440
      Specifically, the PROT command MUST be preceded by a PBSZ command
441
      and a PBSZ command MUST be preceded by a successful security data
442
      exchange (the TLS negotiation in this case)
443
444
      The command defined in [RFC-2228] to negotiate data connection
445
      security is the PROT command.  As defined there are four values
446
      that the PROT command parameter can take.
447
448
          'C' - Clear - neither Integrity nor Privacy
449
450
          'S' - Safe - Integrity without Privacy
451
452
          'E' - Confidential - Privacy without Integrity
453
454
          'P' - Private - Integrity and Privacy
455
456
      As TLS negotiation encompasses (and exceeds) the Safe /
457
      Confidential / Private distinction, only Private (use TLS) and
458
      Clear (don't use TLS) are used.
459
460
      For TLS, the data connection can have one of two security levels.
461
462
         1)Clear (requested by 'PROT C')
463
464
         2)Private (requested by 'PROT P')
465
466
      With 'Clear' protection level, the data connection is made without
467
      TLS at all.  Thus the connection is unauthenticated and has no
468
      confidentiality or integrity.  This might be the desired behaviour
469
      for servers sending file lists, pre-encrypted data or non-
470
      sensitive data (e.g. for anonymous FTP servers).
471
472
      If the data connection security level is 'Private' then a TLS
473
      negotiation must take place on the data connection, to the
474
      satisfaction of the Client and Server prior to any data being
475
476
477
478
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 8]
479
480
481
482
483
484
Internet-Draft            Secure FTP using TLS           2nd April, 2002
485
486
487
      transmitted over the connection.  The TLS layers of the Client and
488
      Server will be responsible for negotiating the exact TLS Cipher
489
      Suites that will be used (and thus the eventual security of the
490
      connection).
491
492
493
      In addition, the PBSZ (protection buffer size) command, as
494
      detailed in [RFC-2228], is compulsory prior to any PROT command.
495
      This document also defines a data channel encapsulation mechanism
496
      for protected data buffers.  For FTP-TLS, which appears to the FTP
497
      application as a streaming protection mechanism, this is not
498
      required.  Thus the PBSZ command must still be issued, but must
499
      have a parameter of '0' to indicate that no buffering is taking
500
      place and the data connection should not be encapsulated.
501
       Note that PBSZ 0 is not in the grammar of [RFC-2228], section
502
      8.1, where it is stated:
503
         PBSZ <sp> <decimal-integer> <CRLF> <decimal-integer> ::= any
504
         decimal integer from 1 to (2^32)-1
505
      However it should be noted that using a value of '0' to mean a
506
      streaming protocol is a reasonable use of '0' for that parameter
507
      and is not ambiguous.
508
509
   Initial Data Connection Security
510
511
      The initial state of the data connection MUST be 'Clear' (this is
512
      the behaviour as indicated by [RFC-2228].)
513
514
515
9. A Discussion of Negotiation Behaviour
516
517
   9.1. The server's view of the control connection
518
519
      A server MAY have a policy statement somewhere that might:
520
521
         - Deny any command before TLS is negotiated (this might cause
522
         problems if a SITE or some such command is required prior to
523
         login)
524
         - Deny certain commands before TLS is negotiated (such as USER,
525
         PASS or ACCT)
526
         - Deny insecure USER commands for certain users (e.g. not
527
         ftp/anonymous)
528
         - Deny secure USER commands for certain users (e.g.
529
         ftp/anonymous)
530
         - Define the level(s) of TLS to be allowed
531
         - Define the CipherSuites allowed to be used (perhaps on a per
532
         host/domain/...  basis)
533
         - Allow TLS authentication as a substitute for local
534
         authentication.
535
536
537
538
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand    FORMFEED[Page 9]
539
540
541
542
543
544
Internet-Draft            Secure FTP using TLS           2nd April, 2002
545
546
547
         - Define data connection policies (see next section)
548
549
         It is possible that the TLS negotiation may not be completed
550
         satisfactorily for the server, in which case it can be one of
551
         these states.
552
553
            The TLS negotiation failed completely
554
555
         In this case, the control connection should still be up in
556
         unprotected mode and the server SHOULD issue an unprotected
557
         '421' reply to end the session.
558
559
            The TLS negotiation completed successfully, but the server
560
            decides that the session parameters are not acceptable (e.g.
561
            Distinguished Name in the client certificate is not
562
            permitted to use the server)
563
564
         In this case, the control connection should still be up in a
565
         protected state, so the server MAY either continue to refuse to
566
         service commands or issue a protected '421' reply and close the
567
         connection.
568
569
            The TLS negotiation failed during the TLS handshake
570
571
         In this case, the control connection is in an unknown state and
572
         the server SHOULD simply drop the control connection.
573
574
      Server code will be responsible for implementing the required
575
      policies and ensuring that the client is prevented from
576
      circumventing the chosen security by refusing to service those
577
      commands that are against policy.
578
579
   9.2. The server's view of the data connection
580
581
      The server can take one of four basic views of the data connection
582
583
         1 - Don't allow encryption at all (in which case the PROT
584
         command should not allow any value other than 'C' - if it is
585
         allowed at all)
586
         2 - Allow the client to choose protection or not
587
         3 - Insist on data protection (in which case the PROT command
588
         must be issued prior to the first attempted data transfer)
589
         4 - Decide on one of the above three for each and every data
590
         connection
591
592
      The server SHOULD only check the status of the data protection
593
      level (for options 3 and 4 above) on the actual command that will
594
      initiate the data transfer (and not on the PORT or PASV).  The
595
596
597
598
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 10]
599
600
601
602
603
604
Internet-Draft            Secure FTP using TLS           2nd April, 2002
605
606
607
      following commands, defined in [RFC-959] cause data connections to
608
      be opened and thus may be rejected (before any 1xx) message due to
609
      an incorrect PROT setting.
610
611
612
         STOR
613
         RETR
614
         NLST
615
         LIST
616
         STOU
617
         APPE
618
619
620
      The reply to indicate that the PROT setting is incorrect is
621
       '521 data connection cannot be opened with this PROT setting'
622
      If the protection level indicates that TLS is required, then it
623
      should be negotiated once the data connection is made.  Thus, the
624
      '150' reply only states that the command can be used given the
625
      current PROT level.  Should the server not like the TLS
626
      negotiation then it will close the data port immediately and
627
      follow the '150' command with a '522' reply indicating that the
628
      TLS negotiation failed or was unacceptable.  (Note: this means
629
      that the application can pass a standard list of CipherSuites to
630
      the TLS layer for negotiation and review the one negotiated for
631
      applicability in each instance).
632
633
      It is quite reasonable for the server to insist that the data
634
      connection uses a TLS cached session.  This might be a cache of a
635
      previous data connection or of the control connection.  If this is
636
      the reason for the the refusal to allow the data transfer then the
637
      '522' reply should indicate this.
638
      Note: this has an important impact on client design, but allows
639
      servers to minimise the cycles used during TLS negotiation by
640
      refusing to perform a full negotiation with a previously
641
      authenticated client.
642
643
      It should be noted that the TLS authentication of the server will
644
      be authentication of the server host itself and not a user on the
645
      server host.
646
647
   9.3. The client's view of the control connection
648
649
      In most cases it is likely that the client will be using TLS
650
      because the server would refuse to interact insecurely.  To allow
651
      for this, clients SHOULD be able to be flexible enough to manage
652
      the securing of a session at the appropriate time and still allow
653
      the user/server policies to dictate exactly when in the session
654
      the security is negotiated.
655
656
657
658
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 11]
659
660
661
662
663
664
Internet-Draft            Secure FTP using TLS           2nd April, 2002
665
666
667
      In the case where it is the client that is insisting on the
668
      securing of the session, it will need to ensure that the
669
      negotiations are all completed satisfactorily and will need to be
670
      able to inform the user sensibly should the server not support, or
671
      be prepared to use, the required security levels.
672
673
      Clients SHOULD be coded in such a manner as to allow the timing of
674
      the AUTH, PBSZ and PROT commands to be flexible and dictated by
675
      the server.  It is quite reasonable for a server to refuse certain
676
      commands prior to these commands, similarly it is quite possible
677
      that a SITE or quoted command might be needed by a server prior to
678
      the AUTH.  A client MUST allow a user to override the timing of
679
      these commands to suit a specific server.
680
      For example, a client SHOULD NOT insist on sending the AUTH as the
681
      first command in a session, nor should it insist on issuing a
682
      PBSZ, PROT pair directly after the AUTH.  This may well be the
683
      default behaviour, but must be overridable by a user.
684
685
      Note: The TLS negotiation may not be completed satisfactorily for
686
      the client, in which case it will be in one of these states:
687
688
            The TLS negotiation failed completely
689
690
            In this case, the control connection should still be up in
691
            unprotected mode and the client should issue an unprotected
692
            QUIT command to end the session.
693
694
            The TLS negotiation completed successfully, but the client
695
            decides that the session parameters are not acceptable (e.g.
696
            Distinguished Name in certificate is not the actual server
697
            expected)
698
699
            In this case, the control connection should still be up in a
700
            protected state, so the client should issue a protected QUIT
701
            command to end the session.
702
703
            The TLS negotiation failed during the TLS handshake
704
705
            In this case, the control connection is in an unknown state
706
            and the client should simply drop the control connection.
707
708
   9.4. The client's view of the data connection
709
710
   Client security policies
711
712
      Clients do not typically have 'policies' as such, instead they
713
      rely on the user defining their actions and, to a certain extent,
714
      are reactive to the server policy.  Thus a client will need to
715
716
717
718
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 12]
719
720
721
722
723
724
Internet-Draft            Secure FTP using TLS           2nd April, 2002
725
726
727
      have commands that will allow the user to switch the protection
728
      level of the data connection dynamically, however, there may be a
729
      general 'policy' that attempts all LIST and NLST commands on a
730
      Clear connection first (and automatically switches to Private if
731
      it fails).  In this case there would need to be a user command
732
      available to ensure that a given data transfer was not attempted
733
      on an insecure data connection.
734
735
      Clients also need to understand that the level of the PROT setting
736
      is only checked for a particular data transfer after that transfer
737
      has been requested.  Thus a refusal by the server to accept a
738
      particular data transfer should not be read by the client as a
739
      refusal to accept that data protection level in toto, as not only
740
      may other data transfers be acceptable at that protection level,
741
      but it is entirely possible that the same transfer may be accepted
742
      at the same protection level at a later point in the session.
743
744
      It should be noted that the TLS authentication of the client
745
      should be authentication of a user on the client host and not the
746
      client host itself.
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 13]
779
780
781
782
783
784
Internet-Draft            Secure FTP using TLS           2nd April, 2002
785
786
787
10. Who negotiates what, where and how
788
789
   10.1. Do we protect at all ?
790
791
      Client issues 'AUTH TLS', server accepts or rejects.
792
      If server needs AUTH, then it refuses to accept certain commands
793
      until it gets a successfully protected session.
794
795
   10.2. What level of protection do we use on the Control connection ?
796
797
      Decided entirely by the TLS CipherSuite negotiation.
798
799
   10.3. Do we protect data connections in general ?
800
801
      Client issues PROT command, server accepts or rejects.
802
803
804
   10.4. Is protection required for a particular data transfer ?
805
806
      A client would already have issued a PROT command if it required
807
      the connection to be protected.
808
      If a server needs to have the connection protected then it will
809
      reply to the STOR/RETR/NLST/... command with a '522' indicating
810
      that the current state of the data connection protection level is
811
      not sufficient for that data transfer at that time.
812
813
   10.5. What level of protection is required for a particular data
814
   transfer ?
815
816
      Decided entirely by the TLS CipherSuite negotiation.
817
818
   Thus it can be seen that, for flexibility, it is desirable for the
819
   FTP application to be able to interact with the TLS layer upon which
820
   it sits to define and discover the exact TLS CipherSuites that are to
821
   be/have been negotiated and make decisions accordingly.
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 14]
839
840
841
842
843
844
Internet-Draft            Secure FTP using TLS           2nd April, 2002
845
846
847
11. Timing Diagrams
848
849
   11.1. Establishing a protected session
850
851
           Client                                 Server
852
  control          data                   data               control
853
====================================================================
854
855
                                                             socket()
856
                                                             bind()
857
  socket()
858
  connect()  ----------------------------------------------> accept()
859
            <----------------------------------------------  220
860
  AUTH TLS   ---------------------------------------------->
861
            <----------------------------------------------  234
862
  TLSneg()  <----------------------------------------------> TLSneg()
863
  PBSZ 0     ---------------------------------------------->
864
            <----------------------------------------------  200
865
  PROT P     ---------------------------------------------->
866
            <----------------------------------------------  200
867
  USER fred  ---------------------------------------------->
868
            <----------------------------------------------  331
869
  PASS pass  ---------------------------------------------->
870
            <----------------------------------------------  230
871
872
Note 1: the order of the PBSZ/PROT pair and the USER/PASS pair (with
873
respect to each other) is not important (i.e. the USER/PASS can happen
874
prior to the PBSZ/PROT - or indeed the server can refuse to allow a
875
PBSZ/PROT pair until the USER/PASS pair has happened).
876
877
Note 2: the PASS command might not be required at all (if the USER
878
parameter and any client identity presented provide sufficient
879
authentication).  The server would indicate this by issuing a '232'
880
reply to the USER command instead of the '331' which requests a PASS
881
from the client.
882
883
Note 3: the AUTH command might not be the first command after the
884
receipt of the 220 welcome message.
885
886
887
888
889
890
891
892
893
894
895
896
897
898
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 15]
899
900
901
902
903
904
Internet-Draft            Secure FTP using TLS           2nd April, 2002
905
906
907
   11.2. A standard data transfer without protection.
908
909
           Client                                 Server
910
  control          data                   data               control
911
====================================================================
912
913
                   socket()
914
                   bind()
915
  PORT w,x,y,z,a,b ----------------------------------------->
916
      <----------------------------------------------------- 200
917
  STOR file ------------------------------------------------>
918
                                          socket()
919
                                          bind()
920
      <----------------------------------------------------- 150
921
                   accept() <-----------  connect()
922
                   write()   -----------> read()
923
                   close()   -----------> close()
924
      <----------------------------------------------------- 226
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 16]
959
960
961
962
963
964
Internet-Draft            Secure FTP using TLS           2nd April, 2002
965
966
967
   11.3. A firewall-friendly data transfer without protection
968
969
           Client                                 Server
970
  control          data                   data               control
971
====================================================================
972
973
  PASV -------------------------------------------------------->
974
                                          socket()
975
                                          bind()
976
      <------------------------------------------ 227 (w,x,y,z,a,b)
977
                   socket()
978
  STOR file --------------------------------------------------->
979
                   connect()  ----------> accept()
980
      <-------------------------------------------------------- 150
981
                   write()    ----------> read()
982
                   close()    ----------> close()
983
      <-------------------------------------------------------- 226
984
985
986
    Note: Implementors should be aware that then connect()/accept()
987
    function is performed prior to the receipt of the reply from the
988
    STOR command. This contrasts with situation when (non-firewall-
989
    friendly) PORT is used prior to the STOR, and the accept()/connect()
990
    is performed after the reply from the aforementioned STOR has been
991
    dealt with.
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 17]
1019
1020
1021
1022
1023
1024
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1025
1026
1027
   11.4. A standard data transfer with protection
1028
1029
           Client                                 Server
1030
  control          data                   data               control
1031
====================================================================
1032
1033
                   socket()
1034
                   bind()
1035
  PORT w,x,y,z,a,b -------------------------------------------->
1036
      <-------------------------------------------------------- 200
1037
  STOR file --------------------------------------------------->
1038
                                          socket()
1039
                                          bind()
1040
      <-------------------------------------------------------- 150
1041
                   accept()  <----------  connect()
1042
                   TLSneg()  <----------> TLSneg()
1043
                   TLSwrite() ----------> TLSread()
1044
                   TLSshutdown() -------> TLSshutdown()
1045
                   close()    ----------> close()
1046
      <-------------------------------------------------------- 226
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 18]
1079
1080
1081
1082
1083
1084
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1085
1086
1087
   11.5. A firewall-friendly data transfer with protection
1088
1089
           Client                                 Server
1090
  control          data                   data               control
1091
====================================================================
1092
1093
  PASV -------------------------------------------------------->
1094
                                          socket()
1095
                                          bind()
1096
      <------------------------------------------ 227 (w,x,y,z,a,b)
1097
                   socket()
1098
  STOR file --------------------------------------------------->
1099
                   connect()  ----------> accept()
1100
      <-------------------------------------------------------- 150
1101
                   TLSneg()   <---------> TLSneg()
1102
                   TLSwrite()  ---------> TLSread()
1103
                   TLSshutdown() -------> TLSshutdown()
1104
                   close()     ---------> close()
1105
      <-------------------------------------------------------- 226
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 19]
1139
1140
1141
1142
1143
1144
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1145
1146
1147
12. Discussion of the REIN command
1148
1149
   The REIN command, defined in [RFC-959], allows the user to reset the
1150
   state of the FTP session.  From [RFC-959]:
1151
      REINITIALIZE (REIN)
1152
         This command terminates a USER, flushing all I/O and account
1153
         information, except to allow any transfer in progress to be
1154
         completed.  All parameters are reset to the default settings
1155
         and the control connection is left open.  This is identical to
1156
         the state in which a user finds himself immediately after the
1157
         control connection is opened.  A USER command may be expected
1158
         to follow.
1159
   When this command is processed by the server,  the TLS session(s)
1160
   MUST be cleared and the control and data connections revert to
1161
   unprotected, clear communications.  It MAY be acceptable to use
1162
   cached TLS sessions for subsequent connections, however a server MUST
1163
   not mandate this.
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 20]
1199
1200
1201
1202
1203
1204
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1205
1206
1207
13. Discussion of the STAT and ABOR commands
1208
1209
   The ABOR and STAT commands and the use of TCP Urgent Pointers
1210
1211
      [RFC-959] describes the use of Telnet commands (IP and DM) and the
1212
      TCP Urgent pointer to indicate the transmission of commands on the
1213
      control channel during the execution of a data transfer.  FTP uses
1214
      the Telnet Interrupt Process and Data Mark commands in conjunction
1215
      with Urgent data to preface two commands: ABOR (Abort Transfer)
1216
      and STAT (Status request).
1217
1218
      The Urgent Pointer was used because in a Unix implementation the
1219
      receipt of a TCP packet marked as Urgent would result in the the
1220
      execution of the SIGURG interrupt handler.  This reliance on
1221
      interrupt handlers was necessary on systems which did not
1222
      implement select() or did not support multiple threads.  TLS does
1223
      not support the notion of Urgent data.
1224
1225
      When TLS is implemented as a security method in FTP the server
1226
      SHOULD NOT rely on the use of SIGURG to process input on the
1227
      control channel during data transfers.  The client MUST send all
1228
      data including Telnet commands across the TLS session.  The TLS
1229
      session will be corrupted if any data is sent on a socket while
1230
      TLS is active.
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 21]
1259
1260
1261
1262
1263
1264
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1265
1266
1267
14. Security Considerations
1268
1269
   This entire document deals with security considerations related to
1270
   the File Transfer Protocol.
1271
1272
   14.1. Verification of Authentication tokens
1273
1274
      14.1.1. Server Certificates
1275
1276
         Although it is entirely an implementation decision, it is
1277
         recommended that certificates used for server authentication of
1278
         the TLS session contain the server identification information
1279
         in a similar manner to those used for http servers.  (see
1280
         [RFC-2818])
1281
1282
         Similarly, it is recommended that the certificate used for
1283
         server authentication of Data connections is the same
1284
         certificate as that used for the corresponding Control
1285
         connection.
1286
1287
      14.1.2. Client Certificates
1288
1289
         - Deciding which client certificates to allow and defining
1290
         which fields define what authentication information is entirely
1291
         a server implementation issue.
1292
1293
         - It is also server implementation issue to decide if the
1294
         authentication token presented for the data connection must
1295
         match the one used for the corresponding control connection.
1296
1297
   14.2. Addressing FTP Security Considerations [RFC-2577]
1298
1299
      14.2.1. Bounce Attack
1300
1301
         A bounce attack should be harder in a secured FTP environment
1302
         because:
1303
1304
            - The FTP server that is being used to initiate a false
1305
            connection will always be a 'server' in the TLS context.
1306
            Therefore, only services that act as 'clients' in the TLS
1307
            context could be vulnerable.  This would be a counter-
1308
            intuitive way to implement TLS on a service.
1309
1310
            - The FTP server would detect that the authentication
1311
            credentials for the data connection are not the same as
1312
            those for the control connection, thus the server policies
1313
            COULD be set to drop the data connection.
1314
1315
1316
1317
1318
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 22]
1319
1320
1321
1322
1323
1324
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1325
1326
1327
            - Genuine users are less likely to initiate such attacks
1328
            when the authentication is strong and malicious users are
1329
            less likely to gain access to the FTP server if the
1330
            authentication is not easily subverted (password guessing,
1331
            network tracing, etc...)
1332
1333
      14.2.2. Restricting Access
1334
1335
         This document presents a strong mechanism for solving the issue
1336
         raised in this section.
1337
1338
      14.2.3. Protecting Passwords
1339
1340
         The twin solutions of strong authentication and data
1341
         confidentiality ensure that this is not an issue when TLS is
1342
         used to protect the control session.
1343
1344
      14.2.4. Privacy
1345
1346
         The TLS protocol ensures data confidentiality by encryption.
1347
         Privacy (e.g. access to download logs, user profile
1348
         information, etc...) is outside the scope of this document (and
1349
         [RFC-2577] presumably)
1350
1351
      14.2.5. Protecting Usernames
1352
1353
         This is not an issue when TLS is used as the primary
1354
         authentication mechanism.
1355
1356
      14.2.6. Port Stealing
1357
1358
         This proposal will do little for the Denial of Service element
1359
         of this section, however, strong authentication on the data
1360
         connection will prevent unauthorised connections retrieving or
1361
         submitting files.
1362
1363
      14.2.7. Software-Base Security Problems
1364
1365
         Nothing in this proposal will affect the discussion in this
1366
         section.
1367
1368
1369
15. IANA Considerations
1370
1371
   {FTP-PORT} - The port assigned to the FTP control connection is 21.
1372
1373
16. Other Parameters
1374
1375
1376
1377
1378
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 23]
1379
1380
1381
1382
1383
1384
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1385
1386
1387
   {TLS-PARM} - The parameter for the AUTH command to indicate that TLS
1388
   is required.  To request the TLS protocol in accordance with this
1389
   document, the client MUST use 'TLS'
1390
1391
      To maintain backward compatability with older versions of this
1392
      document, the server SHOULD accept 'TLS-C' as a synonym for 'TLS'
1393
1394
         Note - [RFC-2228] states that these parameters are case-
1395
         insensitive.
1396
1397
1398
17. Network Management
1399
1400
   NONE
1401
1402
1403
18. Internationalization
1404
1405
   NONE
1406
1407
1408
19. Scalability & Limits
1409
1410
   There are no issues other than those concerned with the ability of
1411
   the server to refuse to have a complete TLS negotiation for each and
1412
   every data connection, which will allow servers to retain throughput
1413
   whilst using cycles only when necessary.
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 24]
1439
1440
1441
1442
1443
1444
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1445
1446
1447
20. Applicability
1448
1449
   This mechanism is generally applicable as a mechanism for securing
1450
   the FTP protocol.  It is unlikely that anonymous FTP clients or
1451
   servers will require such security (although some might like the
1452
   authentication features without the confidentiality).
1453
1454
1455
21. Acknowledgements
1456
1457
   o Netscape Communications Corporation for the original SSL protocol.
1458
1459
   o Eric Young for the SSLeay libraries.
1460
1461
   o University of California, Berkley for the original implementations
1462
   of FTP and ftpd on which the initial implementation of these
1463
   extensions were layered.
1464
1465
   o IETF CAT working group.
1466
1467
   o IETF TLS working group.
1468
1469
   o IETF FTPEXT working group.
1470
1471
   o Jeff Altman for the ABOR and STAT discussion.
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 25]
1499
1500
1501
1502
1503
1504
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1505
1506
1507
22. References
1508
1509
   [RFC-959] J. Postel, "File Transfer Protocol"
1510
      RFC 959, October 1985.
1511
1512
   [RFC-1579] S. Bellovin, "Firewall-Friendly FTP"
1513
      RFC 1579, February 1994.
1514
1515
   [RFC-2119] S. Bradner, "Key words for use in RFCs to Indicate
1516
   Requirement Levels"
1517
      RFC 2119, March 1997.
1518
1519
   [RFC-2222] J. Myers, "Simple Authentication and Security Layer"
1520
      RFC 2222, October 1997.
1521
1522
   [RFC-2228] M. Horowitz, S. Lunt, "FTP Security Extensions"
1523
      RFC 2228, October 1997.
1524
1525
   [RFC-2246] T. Dierks, C. Allen, "The TLS Protocol Version 1.0"
1526
      RFC 2246, January 1999.
1527
1528
   [RFC-2389] P Hethmon, R.Elz, "Feature Negotiation Mechanism for the
1529
   File Transfer Protocol"
1530
      RFC 2389, August 1998.
1531
1532
   [RFC-2487] P Hoffman, "SMTP Service Extension for Secure SMTP over
1533
   TLS"
1534
      RFC 2487, January 1999.
1535
1536
   [RFC-2577] M Allman, S Ostermann, "FTP Security Considerations"
1537
      RFC 2577, May 1999.
1538
1539
   [RFC-2817] R. Khare, S. Lawrence, "Upgrading to TLS Within HTTP/1.1"
1540
      RFC 2817, May 2000.
1541
1542
   [RFC-2818] E. Rescorla,  "HTTP Over TLS"
1543
      RFC 2818, May 2000.
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 26]
1559
1560
1561
1562
1563
1564
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1565
1566
1567
23. Authors' Contact Addresses
1568
1569
The FTP-TLS draft information site is at http://www.ford-
1570
hutchinson.com/~fh-1-pfh/ftps-ext.html
1571
1572
1573
Please send comments to Paul Ford-Hutchinson at the address below
1574
1575
        Tim Hudson                  Paul Ford-Hutchinson
1576
           RSA Data Security           IBM UK Ltd
1577
             Australia Pty Ltd         PO Box 31
1578
                                       Birmingham Road
1579
                                       Warwick
1580
                                       United Kingdom
1581
  tel -   +61 7 3227 4444             +44 1926 462005
1582
  fax -   +61 7 3227 4400             +44 1926 496482
1583
email - tjh@rsasecurity.com.au    paulfordh@uk.ibm.com
1584
1585
        Martin Carpenter            Eric Murray
1586
           Verisign Ltd                Wave Systems Inc.
1587
email -  mcarpenter@verisign.com    ericm@lne.com
1588
1589
        Volker Wiegand
1590
           SuSE Linux
1591
email -  wiegand@suse.de
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 27]
1619
1620
1621
1622
1623
1624
Internet-Draft            Secure FTP using TLS           2nd April, 2002
1625
1626
1627
   The IETF takes no position regarding the validity or scope of any
1628
   intellectual property or other rights that might be claimed to
1629
   pertain to the implementation or use of the technology described in
1630
   this document or the extent to which any license under such rights
1631
   might or might not be available; neither does it represent that it
1632
   has made any effort to identify any such rights.  Information on the
1633
   IETF's procedures with respect to rights in standards-track and
1634
   standards-related documentation can be found in BCP-11.  Copies of
1635
   claims of rights made available for publication and any assurances of
1636
   licenses to be made available, or the result of an attempt made to
1637
   obtain a general license or permission for the use of such
1638
   proprietary rights by implementors or users of this specification can
1639
   be obtained from the IETF Secretariat.
1640
1641
   The IETF invites any interested party to bring to its attention any
1642
   copyrights, patents or patent applications, or other proprietary
1643
   rights which may cover technology that may be required to practice
1644
   this standard.  Please address the information to the IETF Executive
1645
   Director.
1646
1647
Copyright (C) The Internet Society (2002).  All Rights Reserved.
1648
1649
   This document and translations of it may be copied and furnished to
1650
   others, and derivative works that comment on or otherwise explain it
1651
   or assist in its implementation may be prepared, copied, published
1652
   and distributed, in whole or in part, without restriction of any
1653
   kind, provided that the above copyright notice and this paragraph are
1654
   included on all such copies and derivative works.  However, this
1655
   document itself may not be modified in any way, such as by removing
1656
   the copyright notice or references to the Internet Society or other
1657
   Internet organizations, except as needed for the purpose of
1658
   developing Internet standards in which case the procedures for
1659
   copyrights defined in the Internet Standards process must be
1660
   followed, or as required to translate it into languages other than
1661
   English.
1662
1663
   The limited permissions granted above are perpetual and will not be
1664
   revoked by the Internet Society or its successors or assigns.
1665
1666
   This document and the information contained herein is provided on an
1667
   "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
1668
   TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
1669
   BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
1670
   HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
1671
   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1672
1673
This document expires on 2nd October, 2002
1674
1675
1676
1677
1678
Ford-Hutchinson, Carpenter, Hudson, Murray & Wiegand   FORMFEED[Page 28]
1679
(-)proftpd-1.2.6rc1.orig/include/conf.h (+4 lines)
Lines 33-38 Link Here
33
33
34
#include "version.h"
34
#include "version.h"
35
#include "config.h"
35
#include "config.h"
36
#if defined(TLS) && defined(HAVE_SENDFILE)
37
/* using sendfile() together with TLS breaks things! */
38
#undef HAVE_SENDFILE
39
#endif
36
40
37
#include "default_paths.h"
41
#include "default_paths.h"
38
42
(-)proftpd-1.2.6rc1.orig/include/ftp.h (+4 lines)
Lines 102-107 Link Here
102
#define R_226	"226"		/* Closing data connection.  File transfer/abort successful */
102
#define R_226	"226"		/* Closing data connection.  File transfer/abort successful */
103
#define R_227	"227"		/* Entering passive mode (h1,h2,h3,h4,p1,p2) */
103
#define R_227	"227"		/* Entering passive mode (h1,h2,h3,h4,p1,p2) */
104
#define R_230	"230"		/* User logged in, proceed */
104
#define R_230	"230"		/* User logged in, proceed */
105
#define R_232	"232"		/* User logged in, authorized by security data exchange */
105
#define R_250	"250"		/* Requested file action okay, completed. */
106
#define R_250	"250"		/* Requested file action okay, completed. */
106
#define R_257	"257"		/* "PATHNAME" created. */
107
#define R_257	"257"		/* "PATHNAME" created. */
107
#define R_331	"331"		/* User name okay, need password. */
108
#define R_331	"331"		/* User name okay, need password. */
Lines 110-115 Link Here
110
#define R_421	"421"		/* Service not available, closing control connection (service is about to be shutdown) */
111
#define R_421	"421"		/* Service not available, closing control connection (service is about to be shutdown) */
111
#define R_425	"425"		/* Can't open data connection */
112
#define R_425	"425"		/* Can't open data connection */
112
#define R_426	"426"		/* Connection closed; transfer aborted */
113
#define R_426	"426"		/* Connection closed; transfer aborted */
114
#define R_431	"431"		/* Can't accept specified protection level, maybe some resource unavailable */
113
#define R_450	"450"		/* Requested file action not taken (file unavailable; busy) */
115
#define R_450	"450"		/* Requested file action not taken (file unavailable; busy) */
114
#define R_451	"451"		/* Requested action aborted; local error in processing */
116
#define R_451	"451"		/* Requested action aborted; local error in processing */
115
#define R_452	"452"		/* Requested action not taken; insufficient storage space */
117
#define R_452	"452"		/* Requested action not taken; insufficient storage space */
Lines 120-125 Link Here
120
#define R_504	"504"		/* Command not implemented for that parameter */
122
#define R_504	"504"		/* Command not implemented for that parameter */
121
#define R_530	"530"		/* Not logged in */
123
#define R_530	"530"		/* Not logged in */
122
#define R_532	"532"		/* Need account for storing files */
124
#define R_532	"532"		/* Need account for storing files */
125
#define R_534	"534"		/* Request denied for policy reasons */
126
#define R_536	"536"		/* Current security mechanism doesn't support the specified protection level */
123
#define R_550	"550"		/* Requested action not taken. No access, etc */
127
#define R_550	"550"		/* Requested action not taken. No access, etc */
124
#define R_551	"551"		/* Requested action not taken, page type unknown */
128
#define R_551	"551"		/* Requested action not taken, page type unknown */
125
#define R_552	"552"		/* Requested file action aborted, exceeding storage allocation */
129
#define R_552	"552"		/* Requested file action aborted, exceeding storage allocation */
(-)proftpd-1.2.6rc1.orig/include/io.h (+7 lines)
Lines 32-37 Link Here
32
#ifndef __IO_H
32
#ifndef __IO_H
33
#define __IO_H
33
#define __IO_H
34
34
35
#ifdef TLS
36
#include <openssl/ssl.h>
37
#endif
38
35
#define IO_READ		0
39
#define IO_READ		0
36
#define IO_WRITE	1
40
#define IO_WRITE	1
37
41
Lines 81-86 Link Here
81
  IOBUF *buf;
85
  IOBUF *buf;
82
  IOREQ *req;				/* Request buffer */
86
  IOREQ *req;				/* Request buffer */
83
  int  bufsize;				/* Default size of request buffer */
87
  int  bufsize;				/* Default size of request buffer */
88
#ifdef TLS
89
  SSL 	*tls_session;			/* OpenSSL SSL pointer */
90
#endif
84
};
91
};
85
92
86
struct IO_Buffer {
93
struct IO_Buffer {
(-)proftpd-1.2.6rc1.orig/include/tls_dh.h (+187 lines)
Line 0 Link Here
1
static unsigned char dh512_p[]={
2
	0xC0,0xC5,0x23,0x8D,0x3A,0xB3,0xA3,0x63,0x57,0xC0,0xD3,0xFE,
3
	0xD4,0xC2,0x8F,0x17,0x0E,0x7A,0xDB,0x8E,0x3B,0xB6,0xA5,0xC2,
4
	0x60,0x7D,0xE7,0x03,0xCC,0xA3,0x10,0xCC,0x82,0x39,0x3C,0x68,
5
	0xA0,0x82,0x9C,0x7A,0x4A,0x96,0x8C,0xB0,0x1A,0xB4,0xB8,0xA0,
6
	0x9E,0x64,0x9D,0x40,0x77,0x8A,0x9C,0x97,0x96,0x69,0x3D,0xCA,
7
	0xA8,0x25,0xAE,0xAB,
8
	};
9
static unsigned char dh512_g[]={
10
	0x02,
11
	};
12
13
DH *get_dh512()
14
	{
15
	DH *dh;
16
17
	if ((dh=DH_new()) == NULL) return(NULL);
18
	dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
19
	dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
20
	if ((dh->p == NULL) || (dh->g == NULL))
21
		return(NULL);
22
	return(dh);
23
	}
24
/*	
25
-----BEGIN DH PARAMETERS-----
26
MEYCQQDAxSONOrOjY1fA0/7Uwo8XDnrbjju2pcJgfecDzKMQzII5PGiggpx6SpaM
27
sBq0uKCeZJ1Ad4qcl5ZpPcqoJa6rAgEC
28
-----END DH PARAMETERS-----
29
*/
30
static unsigned char dh768_p[]={
31
	0xB3,0x95,0x74,0xCE,0x0B,0xFD,0xAB,0xC3,0x53,0x9B,0x0B,0xFD,
32
	0x6E,0xB2,0x64,0x64,0x02,0xDD,0xFF,0x2E,0x77,0xEB,0x0D,0x6C,
33
	0xCE,0x04,0x2C,0x8E,0x5A,0xA7,0x96,0x45,0x54,0xA6,0x2F,0xBC,
34
	0xF9,0x77,0x1C,0x50,0x66,0x8E,0x48,0xA8,0x34,0xF0,0x81,0xDD,
35
	0x5B,0x5A,0xD4,0xA6,0x13,0x89,0x60,0x46,0x05,0x65,0x57,0x2C,
36
	0x1E,0x94,0x57,0x3C,0x3E,0x38,0xA6,0xFE,0x7B,0x03,0x7D,0x16,
37
	0x46,0xF6,0xB3,0x21,0x3C,0x44,0xF1,0xF1,0x90,0xCE,0x40,0x93,
38
	0x4B,0xE6,0xD6,0x0E,0x20,0x85,0xDA,0x9B,0x3F,0x5C,0x1F,0xDB,
39
	};
40
static unsigned char dh768_g[]={
41
	0x02,
42
	};
43
44
DH *get_dh768()
45
	{
46
	DH *dh;
47
48
	if ((dh=DH_new()) == NULL) return(NULL);
49
	dh->p=BN_bin2bn(dh768_p,sizeof(dh768_p),NULL);
50
	dh->g=BN_bin2bn(dh768_g,sizeof(dh768_g),NULL);
51
	if ((dh->p == NULL) || (dh->g == NULL))
52
		return(NULL);
53
	return(dh);
54
	}
55
/*
56
-----BEGIN DH PARAMETERS-----
57
MGYCYQCzlXTOC/2rw1ObC/1usmRkAt3/LnfrDWzOBCyOWqeWRVSmL7z5dxxQZo5I
58
qDTwgd1bWtSmE4lgRgVlVywelFc8Pjim/nsDfRZG9rMhPETx8ZDOQJNL5tYOIIXa
59
mz9cH9sCAQI=
60
-----END DH PARAMETERS-----
61
*/
62
static unsigned char dh1024_p[]={
63
	0xC1,0xD8,0x9C,0x90,0xB1,0x58,0x7C,0xE1,0x56,0x70,0xD7,0x61,
64
	0x6C,0x00,0xE6,0xE7,0x99,0x04,0x9F,0x86,0xD9,0xB4,0x11,0x09,
65
	0x23,0x18,0xAA,0x19,0xCA,0x49,0x7C,0xA8,0x9D,0xF7,0x43,0x3A,
66
	0xAF,0xC3,0x1F,0x0E,0xAE,0xBB,0xF2,0xEA,0x5B,0x62,0xA1,0x5F,
67
	0x7C,0x26,0xA8,0xB4,0x5D,0x2A,0x25,0xAB,0x88,0x70,0x27,0x06,
68
	0xD0,0xF5,0x01,0xD9,0x6A,0x1F,0x48,0x2D,0x9C,0xEC,0xFE,0xA8,
69
	0x45,0x97,0x1D,0xC0,0x8A,0xFF,0xE5,0xE1,0x79,0xDF,0x85,0x31,
70
	0xFC,0x58,0x91,0x35,0xE8,0xC7,0xDA,0x55,0x7B,0xAA,0xDD,0xC2,
71
	0x0A,0x94,0x34,0xF7,0xB4,0x4A,0x91,0x3B,0x1E,0x16,0x89,0x2A,
72
	0x04,0x47,0x5D,0xE9,0x42,0x47,0x5E,0x30,0x61,0xE8,0x42,0xC1,
73
	0x23,0xC7,0x97,0x78,0x63,0x36,0x9D,0x3B,
74
	};
75
static unsigned char dh1024_g[]={
76
	0x02,
77
	};
78
79
DH *get_dh1024()
80
	{
81
	DH *dh;
82
83
	if ((dh=DH_new()) == NULL) return(NULL);
84
	dh->p=BN_bin2bn(dh1024_p,sizeof(dh1024_p),NULL);
85
	dh->g=BN_bin2bn(dh1024_g,sizeof(dh1024_g),NULL);
86
	if ((dh->p == NULL) || (dh->g == NULL))
87
		return(NULL);
88
	return(dh);
89
	}
90
/*
91
-----BEGIN DH PARAMETERS-----
92
MIGHAoGBAMHYnJCxWHzhVnDXYWwA5ueZBJ+G2bQRCSMYqhnKSXyonfdDOq/DHw6u
93
u/LqW2KhX3wmqLRdKiWriHAnBtD1AdlqH0gtnOz+qEWXHcCK/+Xhed+FMfxYkTXo
94
x9pVe6rdwgqUNPe0SpE7HhaJKgRHXelCR14wYehCwSPHl3hjNp07AgEC
95
-----END DH PARAMETERS-----
96
*/
97
static unsigned char dh1536_p[]={
98
	0xDA,0x68,0x25,0x7F,0x9D,0xB5,0x3F,0x42,0x05,0xBC,0x79,0x65,
99
	0x6F,0x19,0x6A,0x6F,0x70,0x11,0x91,0xF2,0x08,0x48,0x2B,0xE2,
100
	0x0C,0x15,0xD9,0x31,0xE7,0x3A,0x50,0x32,0x9F,0xFB,0xD6,0x56,
101
	0xFA,0xB4,0xA9,0x5F,0x22,0x17,0x52,0x72,0x2C,0xE3,0x5D,0xA1,
102
	0xA8,0xEF,0x16,0x42,0x35,0xC6,0xD9,0x64,0xC1,0xB3,0xB3,0x4C,
103
	0x09,0x90,0xF4,0x49,0xEF,0xDE,0x64,0x99,0xFF,0x3C,0x37,0x0A,
104
	0x91,0xA4,0x9E,0x38,0x27,0xF2,0x96,0x13,0x1E,0x15,0xA2,0x52,
105
	0xF1,0x54,0x0C,0xED,0x5C,0x38,0xC4,0xEC,0xFF,0xE2,0xFA,0x0A,
106
	0x41,0xBB,0x48,0x5D,0xD3,0x54,0xA1,0xEB,0xBD,0x1F,0x68,0xED,
107
	0x2A,0x49,0x7F,0x68,0x52,0xB3,0xA0,0x77,0x3E,0x19,0xFB,0x44,
108
	0xCD,0x4B,0x21,0x3E,0x3B,0xBA,0xF6,0xA2,0x36,0x37,0xE5,0xFA,
109
	0x95,0xB0,0x7D,0x7B,0x58,0x96,0xC4,0xC9,0xC0,0xCF,0xD9,0x3F,
110
	0xA3,0x42,0x0B,0xD7,0xBE,0x1A,0xA8,0xB5,0x57,0x58,0xF4,0x04,
111
	0x97,0x54,0xB0,0x59,0x23,0x5F,0x98,0x09,0x90,0xC0,0x49,0x85,
112
	0x40,0x23,0x2D,0x21,0x3E,0xB0,0x07,0x06,0x07,0x32,0xFB,0xB9,
113
	0x91,0x40,0x92,0x09,0xED,0x07,0x80,0x05,0x14,0x5B,0xC1,0x9B,
114
	};
115
static unsigned char dh1536_g[]={
116
	0x02,
117
	};
118
119
DH *get_dh1536()
120
	{
121
	DH *dh;
122
123
	if ((dh=DH_new()) == NULL) return(NULL);
124
	dh->p=BN_bin2bn(dh1536_p,sizeof(dh1536_p),NULL);
125
	dh->g=BN_bin2bn(dh1536_g,sizeof(dh1536_g),NULL);
126
	if ((dh->p == NULL) || (dh->g == NULL))
127
		return(NULL);
128
	return(dh);
129
	}
130
/*
131
-----BEGIN DH PARAMETERS-----
132
MIHHAoHBANpoJX+dtT9CBbx5ZW8Zam9wEZHyCEgr4gwV2THnOlAyn/vWVvq0qV8i
133
F1JyLONdoajvFkI1xtlkwbOzTAmQ9Env3mSZ/zw3CpGknjgn8pYTHhWiUvFUDO1c
134
OMTs/+L6CkG7SF3TVKHrvR9o7SpJf2hSs6B3Phn7RM1LIT47uvaiNjfl+pWwfXtY
135
lsTJwM/ZP6NCC9e+Gqi1V1j0BJdUsFkjX5gJkMBJhUAjLSE+sAcGBzL7uZFAkgnt
136
B4AFFFvBmwIBAg==
137
-----END DH PARAMETERS-----
138
*/
139
static unsigned char dh2048_p[]={
140
	0xD0,0xE6,0xFF,0x1F,0x39,0xE0,0xCC,0x85,0xAC,0xA4,0xE6,0xDD,
141
	0x06,0xE5,0x2D,0xBF,0xEA,0x64,0x2E,0xC7,0x99,0x8A,0x0F,0xCB,
142
	0x3C,0x9D,0xEE,0xAC,0x61,0xFF,0x69,0x31,0x71,0xFE,0x2F,0x7B,
143
	0x65,0x95,0xA0,0xA4,0x59,0xB8,0xE3,0x66,0x5B,0x3F,0xD8,0x42,
144
	0x99,0x4F,0x09,0x44,0xC5,0x8D,0x8B,0x5D,0x16,0xAA,0x05,0x6E,
145
	0x8B,0x11,0x59,0x1F,0xD7,0x11,0x84,0x87,0x4D,0xBE,0xBB,0xBA,
146
	0x9A,0xF0,0xC3,0xE2,0x0E,0xB8,0x0F,0xFD,0x08,0xB1,0x48,0x98,
147
	0xDE,0x89,0xDA,0x00,0x15,0x04,0xA4,0x51,0xBE,0x5B,0x60,0x0A,
148
	0x0E,0x20,0xAC,0xC5,0x83,0x5D,0xC4,0x0F,0xA3,0x8E,0x11,0x66,
149
	0x2C,0xD3,0x61,0x5F,0x16,0x83,0xAA,0xCF,0x52,0x9C,0x7D,0x75,
150
	0xEA,0xCA,0x67,0xA3,0xAB,0x58,0x9F,0x67,0x17,0xA0,0x54,0x3A,
151
	0x2B,0xCA,0xB5,0x03,0x7E,0x50,0xBD,0x99,0x1E,0xEF,0xB2,0x8F,
152
	0xB4,0xFB,0xD2,0x2D,0x6A,0xA9,0xA2,0xC0,0xD4,0xD2,0x68,0x6C,
153
	0x21,0x71,0x78,0x75,0x82,0x4C,0xD8,0xE8,0x2C,0x0B,0xC9,0x3F,
154
	0xF6,0xF0,0x64,0xD9,0x6E,0x76,0xCB,0xBB,0x99,0xFB,0xBC,0x15,
155
	0x54,0x7B,0x7F,0x97,0x36,0x8F,0x0B,0x1C,0xFF,0xDD,0x28,0x99,
156
	0xE5,0x3A,0xAD,0xCD,0x84,0xAB,0xA1,0xEF,0xB2,0x21,0xEA,0xD6,
157
	0x49,0x22,0x6A,0x30,0x6A,0x63,0x2E,0x52,0x79,0xCF,0xBC,0xC2,
158
	0xB6,0x2E,0xA5,0x5D,0xB3,0xDA,0xC2,0xDD,0x02,0xEA,0x26,0x2F,
159
	0x3B,0x0A,0x12,0xBB,0xA2,0xEF,0x2B,0xFA,0xCC,0x25,0x63,0x1B,
160
	0xC3,0x00,0x18,0x8F,0x36,0xB7,0x30,0x5A,0x55,0x1A,0xE0,0x12,
161
	0xA1,0xD2,0x9C,0x93,
162
	};
163
static unsigned char dh2048_g[]={
164
	0x02,
165
	};
166
167
DH *get_dh2048()
168
	{
169
	DH *dh;
170
171
	if ((dh=DH_new()) == NULL) return(NULL);
172
	dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
173
	dh->g=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
174
	if ((dh->p == NULL) || (dh->g == NULL))
175
		return(NULL);
176
	return(dh);
177
	}
178
/*
179
-----BEGIN DH PARAMETERS-----
180
MIIBCAKCAQEA0Ob/HzngzIWspObdBuUtv+pkLseZig/LPJ3urGH/aTFx/i97ZZWg
181
pFm442ZbP9hCmU8JRMWNi10WqgVuixFZH9cRhIdNvru6mvDD4g64D/0IsUiY3ona
182
ABUEpFG+W2AKDiCsxYNdxA+jjhFmLNNhXxaDqs9SnH116spno6tYn2cXoFQ6K8q1
183
A35QvZke77KPtPvSLWqposDU0mhsIXF4dYJM2OgsC8k/9vBk2W52y7uZ+7wVVHt/
184
lzaPCxz/3SiZ5TqtzYSroe+yIerWSSJqMGpjLlJ5z7zCti6lXbPawt0C6iYvOwoS
185
u6LvK/rMJWMbwwAYjza3MFpVGuASodKckwIBAg==
186
-----END DH PARAMETERS-----
187
*/
(-)proftpd-1.2.6rc1.orig/include/tlsutil.h (+65 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 1999 - 2002 Peter 'Luna' Runestig <peter@runestig.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modifi-
6
 * cation, are permitted provided that the following conditions are met:
7
 *
8
 *    o Redistributions of source code must retain the above copyright notice,
9
 *      this list of conditions and the following disclaimer.
10
 *
11
 *    o Redistributions in binary form must reproduce the above copyright no-
12
 *      tice, this list of conditions and the following disclaimer in the do-
13
 *      cumentation and/or other materials provided with the distribution.
14
 *
15
 *    o The names of the contributors may not be used to endorse or promote
16
 *      products derived from this software without specific prior written
17
 *      permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LI-
23
 * ABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN-
24
 * TIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV-
26
 * ER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI-
27
 * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#ifndef _TLSUTIL_H_
32
#define _TLSUTIL_H_
33
34
extern int	tls_on_data;
35
extern int	tls_on_ctrl;
36
extern int 	tls_implicit;
37
extern int	tls_no_verify;
38
extern int	tls_dont_request_cert;
39
extern int	tls_required;
40
extern int	tls_init_error;
41
extern char 	*tls_rsa_key_file;
42
extern char	*tls_rsa_cert_file;
43
extern char 	*tls_dsa_key_file;
44
extern char	*tls_dsa_cert_file;
45
extern char	*tls_crl_file;
46
extern char	*tls_dhparam_file;
47
extern char	*tls_cipher_list;
48
49
int	tls_init(void);
50
int	tls_accept(conn_t *conn, int data_connection);
51
void	tls_cleanup(void);
52
void	tls_close_session(SSL *ssl);
53
int	tls_recv(int s, void *buf, size_t len, int flags);
54
int	tls_send(int s, const void *msg, size_t len, int flags);
55
ssize_t	tls_read(SSL *ssl, void *buf, size_t count);
56
ssize_t	tls_write(SSL *ssl, const void *buf, size_t count);
57
int	tls_pending(SSL *ssl);
58
void	tls_optarg(char *optarg);
59
char	*tls_userid_from_client_cert();
60
int	tls_is_user_valid(char *user);
61
void	tls_set_file_defaults(void);
62
int	tls_setup_session_cache(void);
63
64
65
#endif
(-)proftpd-1.2.6rc1.orig/modules/mod_auth.c (-4 / +44 lines)
Lines 67-72 Link Here
67
  return 0;
67
  return 0;
68
}
68
}
69
69
70
#ifdef TLS
71
static int tls_logged_in = 0;
72
MODRET cmd_pass(cmd_rec *cmd);
73
#include "tlsutil.h"
74
#endif
75
70
/* check_auth is hooked into the main server's auth_hook function,
76
/* check_auth is hooked into the main server's auth_hook function,
71
 * so that we can deny all commands until authentication is complete.
77
 * so that we can deny all commands until authentication is complete.
72
 */
78
 */
Lines 173-178 Link Here
173
  char *cpw = NULL;
179
  char *cpw = NULL;
174
  config_rec *c;
180
  config_rec *c;
175
181
182
#ifdef TLS
183
  if (tls_logged_in)
184
    return 0;
185
#endif
186
   
176
  if (conf) {
187
  if (conf) {
177
    c = find_config(conf,CONF_PARAM,"UserPassword",FALSE);
188
    c = find_config(conf,CONF_PARAM,"UserPassword",FALSE);
178
189
Lines 1015-1020 Link Here
1015
  if(c && c->subset)
1026
  if(c && c->subset)
1016
    resolve_anonymous_dirs(c->subset);
1027
    resolve_anonymous_dirs(c->subset);
1017
1028
1029
#if TLS
1030
  if (tls_logged_in)
1031
    log_auth(LOG_NOTICE, "USER %s: TLS/X509 authentication login successful.",
1032
	origuser);
1033
  else
1034
#endif /* TLS */
1018
  log_auth(LOG_NOTICE, "%s %s: Login successful.",
1035
  log_auth(LOG_NOTICE, "%s %s: Login successful.",
1019
	   (c != NULL) ? "ANON" : "USER",
1036
	   (c != NULL) ? "ANON" : "USER",
1020
	   origuser);
1037
	   origuser);
Lines 1573-1578 Link Here
1573
  config_rec *c;
1590
  config_rec *c;
1574
  char *user, *origuser;
1591
  char *user, *origuser;
1575
  int failnopwprompt = 0, aclp, i;
1592
  int failnopwprompt = 0, aclp, i;
1593
#ifdef TLS
1594
  char *tls_user = NULL;
1595
#endif
1576
1596
1577
  if(logged_in)
1597
  if(logged_in)
1578
    return ERROR_MSG(cmd,R_503,"You are already logged in!");
1598
    return ERROR_MSG(cmd,R_503,"You are already logged in!");
Lines 1580-1585 Link Here
1580
  if(cmd->argc < 2)
1600
  if(cmd->argc < 2)
1581
    return ERROR_MSG(cmd,R_500,"'USER': command requires a parameter.");
1601
    return ERROR_MSG(cmd,R_500,"'USER': command requires a parameter.");
1582
1602
1603
#ifdef TLS
1604
  if (tls_required && !tls_on_ctrl)
1605
    return ERROR_MSG(cmd, R_534,
1606
	   "Server policy denies USER command on insecure connection.");
1607
#endif
1608
  
1583
  user = cmd->arg;
1609
  user = cmd->arg;
1584
1610
1585
  remove_config(cmd->server->conf, C_USER, FALSE);
1611
  remove_config(cmd->server->conf, C_USER, FALSE);
Lines 1652-1657 Link Here
1652
  if(c && user && get_param_int(c->subset, "AnonRequirePassword", FALSE) != 1)
1678
  if(c && user && get_param_int(c->subset, "AnonRequirePassword", FALSE) != 1)
1653
    nopass++;
1679
    nopass++;
1654
  
1680
  
1681
#ifdef TLS
1682
  tls_user = tls_userid_from_client_cert();
1683
  if ((tls_user && !strcmp(user, tls_user)) || tls_is_user_valid(user)) {
1684
    /* user is X509-authenticated */
1685
    tls_logged_in = 1;
1686
    return cmd_pass(cmd);
1687
  }
1688
#endif
1689
1655
  if(nopass)
1690
  if(nopass)
1656
    add_response(R_331, "Anonymous login ok, send your complete email "
1691
    add_response(R_331, "Anonymous login ok, send your complete email "
1657
		 "address as your password.");
1692
		 "address as your password.");
Lines 1680-1686 Link Here
1680
  char *display = NULL;
1715
  char *display = NULL;
1681
  char *user, *grantmsg;
1716
  char *user, *grantmsg;
1682
  int res = 0;
1717
  int res = 0;
1683
  
1718
  char *reply_code = R_230;
1719
1684
  if(logged_in)
1720
  if(logged_in)
1685
    return ERROR_MSG(cmd, R_503, "You are already logged in!");
1721
    return ERROR_MSG(cmd, R_503, "You are already logged in!");
1686
  
1722
  
Lines 1695-1700 Link Here
1695
  
1731
  
1696
  _auth_check_count(cmd, user);
1732
  _auth_check_count(cmd, user);
1697
  
1733
  
1734
#ifdef TLS
1735
  if (tls_logged_in)
1736
    reply_code = R_232;
1737
#endif
1698
  if((res = _setup_environment(cmd->tmp_pool,user,cmd->arg)) == 1) {
1738
  if((res = _setup_environment(cmd->tmp_pool,user,cmd->arg)) == 1) {
1699
    add_config_param_set(&cmd->server->conf,"authenticated",1,(void*)1);
1739
    add_config_param_set(&cmd->server->conf,"authenticated",1,(void*)1);
1700
    set_auth_check(NULL);
1740
    set_auth_check(NULL);
Lines 1713-1733 Link Here
1713
				      "DisplayLogin", FALSE);
1753
				      "DisplayLogin", FALSE);
1714
1754
1715
    if(display)
1755
    if(display)
1716
      core_display_file(R_230, display, NULL);
1756
      core_display_file(reply_code, display, NULL);
1717
    
1757
    
1718
    if ((grantmsg = (char *)get_param_ptr((session.anon_config ?
1758
    if ((grantmsg = (char *)get_param_ptr((session.anon_config ?
1719
        session.anon_config->subset : cmd->server->conf),
1759
        session.anon_config->subset : cmd->server->conf),
1720
        "AccessGrantMsg",FALSE)) != NULL) {
1760
        "AccessGrantMsg",FALSE)) != NULL) {
1721
      grantmsg = sreplace(cmd->tmp_pool, grantmsg, "%u", user, NULL);
1761
      grantmsg = sreplace(cmd->tmp_pool, grantmsg, "%u", user, NULL);
1722
1762
1723
      add_response(R_230, "%s", grantmsg);
1763
      add_response(reply_code, "%s", grantmsg);
1724
1764
1725
    } else {
1765
    } else {
1726
1766
1727
      if (session.flags & SF_ANON)
1767
      if (session.flags & SF_ANON)
1728
        add_response(R_230, "Anonymous access granted, restrictions apply.");
1768
        add_response(R_230, "Anonymous access granted, restrictions apply.");
1729
      else
1769
      else
1730
        add_response(R_230, "User %s logged in.", user);
1770
        add_response(reply_code, "User %s logged in.", user);
1731
    }
1771
    }
1732
    
1772
    
1733
    logged_in = 1;
1773
    logged_in = 1;
(-)proftpd-1.2.6rc1.orig/modules/mod_tls.c (+483 lines)
Line 0 Link Here
1
/*
2
 * ProFTPD - FTP server daemon
3
 * Copyright (c) 1997, 1998 Public Flood Software
4
 *  
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
18
 */
19
/*
20
 * AUTH/TLS module for ProFTPD, based on the mod_sample.c file.
21
 *
22
 * Copyright (c) 2000 - 2002 Peter 'Luna' Runestig <peter@runestig.com>
23
 * All rights reserved.
24
 *
25
 * Redistribution and use in source and binary forms, with or without modifi-
26
 * cation, are permitted provided that the following conditions are met:
27
 *
28
 *    o Redistributions of source code must retain the above copyright notice,
29
 *      this list of conditions and the following disclaimer.
30
 *
31
 *    o Redistributions in binary form must reproduce the above copyright no-
32
 *      tice, this list of conditions and the following disclaimer in the do-
33
 *      cumentation and/or other materials provided with the distribution.
34
 *
35
 *    o The names of the contributors may not be used to endorse or promote
36
 *      products derived from this software without specific prior written
37
 *      permission.
38
 *
39
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LI-
43
 * ABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN-
44
 * TIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV-
46
 * ER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI-
47
 * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
48
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49
 */
50
51
#include "conf.h"
52
#include <privs.h>
53
#include "tlsutil.h"
54
55
extern session_t session;
56
57
#define CHECK_TLS_INIT_ERROR()  if (tls_init_error) {			\
58
    char errmsg[256];            					\
59
    snprintf(errmsg, sizeof(errmsg),					\
60
	     "Local error code %d was returned from tls_init()", 	\
61
	     tls_init_error);						\
62
    return ERROR_MSG(cmd, R_431, errmsg); }
63
64
/* This sample configuration directive handler will get called
65
 * whenever the "FooBarDirective" directive is encountered in the
66
 * configuration file.
67
 */
68
69
MODRET set_rsacertfile(cmd_rec *cmd)
70
{
71
    config_rec *c;
72
73
    /* The CHECK_ARGS macro checks the number of arguments passed to the
74
     * directive against what we want.  Note that this is *one* less than
75
     * cmd->argc, because cmd->argc includes cmd->argv[0] (the directive
76
     * itself).  If CHECK_ARGS fails, a generic error is sent to the user
77
     */
78
    CHECK_ARGS(cmd, 1);
79
80
    /* The CHECK_CONF macro makes sure that this directive is not being
81
     * "used" in the wrong context (i.e. if the directive is only available
82
     * or applicable inside certain contexts).  In this case, we are allowing
83
     * the directive inside of <Anonymous> and <Limit>, but nowhere else.
84
     * If this macro fails a generic error is logged and the handler aborts.
85
     */
86
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
87
88
    /* add_config_param adds a configuration paramater to our current
89
     * configuration context.
90
     */
91
    c = add_config_param_str("TlsRsaCertFile", 1, cmd->argv[1]);
92
93
    /* By adding the CF_MERGEDOWN flag to the parameter we just created
94
     * we are telling proftpd that this parameter should be copied and
95
     * "merged" into all "lower" contexts until it either hits a
96
     * parameter w/ the same name or bottoms out.
97
     *
98
     * Example _without_ CF_MERGEDOWN:
99
     *
100
     * <VirtualHost>
101
     *      |----------\
102
     *             <Anonymous>
103
     *                 | - FooBarDirective  <------- Config places it here
104
     *                 |-----------\
105
     *                         <Directory>  <------- Doesn't apply here
106
     *                             |-------------\
107
     *                                        <Limit> <--- Or here.....
108
     *
109
     * Now, if we specify CF_MERGDOWN, the tree ends up looking like:
110
     *
111
     * <VirtualHost>
112
     *      |----------\
113
     *             <Anonymous>
114
     *                 | - FooBarDirective  <------- Config places it here
115
     *                 |-----------\
116
     *                         <Directory>  <------- Now, it DOES apply here
117
     *                             | - FooBarDirective
118
     *                             |-------------\
119
     *                                        <Limit> <-------- And here ...
120
     *                                           | - FooBarDirective
121
     *
122
     */
123
    c->flags |= CF_MERGEDOWN;
124
125
    /* Tell proftpd that we handled the request w/ no problems.
126
     */
127
    return HANDLED(cmd);
128
}
129
130
MODRET set_rsakeyfile(cmd_rec *cmd)
131
{
132
    config_rec *c;
133
134
    CHECK_ARGS(cmd, 1);
135
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
136
137
    c = add_config_param_str("TlsRsaKeyFile", 1, cmd->argv[1]);
138
    c->flags |= CF_MERGEDOWN;
139
    return HANDLED(cmd);
140
}
141
142
MODRET set_dsacertfile(cmd_rec *cmd)
143
{
144
    config_rec *c;
145
146
    CHECK_ARGS(cmd, 1);
147
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
148
149
    c = add_config_param_str("TlsDsaCertFile", 1, cmd->argv[1]);
150
    c->flags |= CF_MERGEDOWN;
151
    return HANDLED(cmd);
152
}
153
154
MODRET set_dsakeyfile(cmd_rec *cmd)
155
{
156
    config_rec *c;
157
158
    CHECK_ARGS(cmd, 1);
159
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
160
161
    c = add_config_param_str("TlsDsaKeyFile", 1, cmd->argv[1]);
162
    c->flags |= CF_MERGEDOWN;
163
    return HANDLED(cmd);
164
}
165
166
MODRET set_crlfile(cmd_rec *cmd)
167
{
168
    config_rec *c;
169
170
    CHECK_ARGS(cmd, 1);
171
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
172
173
    c = add_config_param_str("TlsCrlFile", 1, cmd->argv[1]);
174
    c->flags |= CF_MERGEDOWN;
175
    return HANDLED(cmd);
176
}
177
178
MODRET set_dhparamfile(cmd_rec *cmd)
179
{
180
    config_rec *c;
181
182
    CHECK_ARGS(cmd, 1);
183
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
184
185
    c = add_config_param_str("TlsDhParamFile", 1, cmd->argv[1]);
186
    c->flags |= CF_MERGEDOWN;
187
    return HANDLED(cmd);
188
}
189
190
MODRET set_cipherlist(cmd_rec *cmd)
191
{
192
    config_rec *c;
193
194
    CHECK_ARGS(cmd, 1);
195
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
196
197
    c = add_config_param_str("TlsCipherList", 1, cmd->argv[1]);
198
    c->flags |= CF_MERGEDOWN;
199
    return HANDLED(cmd);
200
}
201
202
MODRET set_no_verify(cmd_rec *cmd)
203
{
204
    config_rec *c;
205
    int b;
206
207
    CHECK_ARGS(cmd, 1);
208
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
209
210
    if ((b = get_boolean(cmd, 1)) == -1)
211
	CONF_ERROR(cmd, "expected boolean argument.");
212
    c = add_config_param("TlsCertsOk", 1, (void *) b);
213
    c->flags |= CF_MERGEDOWN;
214
    return HANDLED(cmd);
215
}
216
217
MODRET set_dont_request_cert(cmd_rec *cmd)
218
{
219
    config_rec *c;
220
    int b;
221
222
    CHECK_ARGS(cmd, 1);
223
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
224
225
    if ((b = get_boolean(cmd, 1)) == -1)
226
	CONF_ERROR(cmd, "expected boolean argument.");
227
    c = add_config_param("TlsDontRequestCert", 1, (void *) b);
228
    c->flags |= CF_MERGEDOWN;
229
    return HANDLED(cmd);
230
}
231
232
MODRET set_required(cmd_rec *cmd)
233
{
234
    config_rec *c;
235
    int b;
236
237
    CHECK_ARGS(cmd, 1);
238
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
239
240
    if ((b = get_boolean(cmd, 1)) == -1)
241
	CONF_ERROR(cmd, "expected boolean argument.");
242
    c = add_config_param("TlsRequired", 1, (void *) b);
243
    c->flags |= CF_MERGEDOWN;
244
    return HANDLED(cmd);
245
}
246
247
MODRET set_implicit(cmd_rec *cmd)
248
{
249
    config_rec *c;
250
    int b;
251
252
    CHECK_ARGS(cmd, 1);
253
    CHECK_CONF(cmd, CONF_ROOT | CONF_VIRTUAL | CONF_GLOBAL);
254
255
    if ((b = get_boolean(cmd, 1)) == -1)
256
	CONF_ERROR(cmd, "expected boolean argument.");
257
    c = add_config_param("TlsImplicit", 1, (void *) b);
258
    c->flags |= CF_MERGEDOWN;
259
    return HANDLED(cmd);
260
}
261
262
MODRET cmd_auth(cmd_rec *cmd)
263
{
264
    char *cp;
265
    
266
    if (tls_implicit)
267
	return ERROR_MSG(cmd, R_504, "The AUTH command is not supported on an implicit TLS connection");
268
    if (cmd->argc < 2)
269
	return ERROR_MSG(cmd, R_504, "The AUTH command needs at least one argument");
270
271
    /* convert to upper case */
272
    cp = cmd->argv[1];
273
    while (*cp) {
274
	*cp = toupper(*cp);
275
	cp++;
276
    }
277
    
278
    if (!strcmp(cmd->argv[1], "TLS") || !strcmp(cmd->argv[1], "TLS-C")) {
279
	CHECK_TLS_INIT_ERROR();
280
	send_response("234", "AUTH TLS successful");
281
	if (tls_accept(session.c, FALSE)) {
282
	    /* exit if we fail */
283
	    send_response_async(R_421,
284
	        "Failed TLS negotiation on control channel, disconnected");
285
	    main_exit((void*) LOG_ERR,
286
		"Failed TLS negotiation on control channel, disconnected.",
287
		(void*) 0, NULL);
288
	}
289
    }
290
    else if (!strcmp(cmd->argv[1], "SSL") || !strcmp(cmd->argv[1], "TLS-P")) {
291
	CHECK_TLS_INIT_ERROR();
292
	send_response("234", "AUTH SSL successful");
293
	if (tls_accept(session.c, FALSE)) {
294
	    /* exit if we fail */
295
	    send_response_async(R_421,
296
		"Failed TLS negotiation on control channel, disconnected");
297
	    main_exit((void*) LOG_ERR,
298
		"Failed TLS negotiation on control channel, disconnected.",
299
		(void*) 0, NULL);
300
	}
301
	tls_on_data = 1;
302
    }
303
    else {
304
	char errmsg[255];
305
	snprintf(errmsg, sizeof(errmsg), "AUTH %s unsupported", cmd->argv[1]);
306
	return ERROR_MSG(cmd, R_504, errmsg);
307
    }
308
    
309
    return HANDLED(cmd);
310
}
311
312
static int pbsz_ok = 0;
313
314
MODRET cmd_pbsz(cmd_rec *cmd)
315
{
316
    if (cmd->argc < 2)
317
	return ERROR_MSG(cmd, R_501, "PBSZ command needs at least one argument");
318
    if (!tls_on_ctrl)
319
	return ERROR_MSG(cmd, R_503, "You can't issue PBSZ on an insecure control connection");
320
321
    /* we expect "PBSZ 0" */
322
    CHECK_TLS_INIT_ERROR();
323
    if (!strcmp(cmd->argv[1], "0"))
324
	send_response("200", "PBSZ 0 successful");
325
    else
326
	send_response("200", "PBSZ=0 successful");
327
    pbsz_ok = 1;
328
    
329
    return HANDLED(cmd);
330
}
331
332
MODRET cmd_prot(cmd_rec *cmd)
333
{
334
    if (cmd->argc < 2)
335
	return ERROR_MSG(cmd, R_504, "PROT command needs at least one argument");
336
    if (!pbsz_ok)
337
	return ERROR_MSG(cmd, R_503, "You must issue the PBSZ command prior to PROT");
338
339
    /* only PROT C or PROT P is valid in respect to SSL/TLS */
340
    if (!strcmp(cmd->argv[1], "C")) {
341
	CHECK_TLS_INIT_ERROR();
342
	send_response("200", "Protection set to Clear");
343
	tls_on_data = 0;
344
    }
345
    else if (!strcmp(cmd->argv[1], "P")) {
346
	CHECK_TLS_INIT_ERROR();
347
	send_response("200", "Protection set to Private");
348
	tls_on_data = 1;
349
    }
350
    else if (!strcmp(cmd->argv[1], "S") || !strcmp(cmd->argv[1], "E")) {
351
	char errmsg[255];
352
	snprintf(errmsg, sizeof(errmsg), "PROT %s unsupported", cmd->argv[1]);
353
	return ERROR_MSG(cmd, R_536, errmsg);
354
    }
355
    else {
356
	char errmsg[255];
357
	snprintf(errmsg, sizeof(errmsg), "PROT %s unsupported", cmd->argv[1]);
358
	return ERROR_MSG(cmd, R_504, errmsg);
359
    }
360
    
361
    return HANDLED(cmd);
362
}
363
364
/* There are three tables which act as the "glue" between proftpd and
365
 * a module.  None of the tables are _required_ (however having none would
366
 * make the module fairly useless).
367
 */
368
369
/* The first table is the "configuration directive" table.  It specifies
370
 * handler routines in the module which will be used during configuration
371
 * file parsing.
372
 */
373
374
static conftable mod_tls_config[] = {
375
    { "TlsRsaCertFile",		set_rsacertfile,     	NULL },
376
    { "TlsRsaKeyFile",		set_rsakeyfile,      	NULL },
377
    { "TlsDsaCertFile",		set_dsacertfile,     	NULL },
378
    { "TlsDsaKeyFile",		set_dsakeyfile,      	NULL },
379
    { "TlsCrlFile",		set_crlfile,         	NULL },
380
    { "TlsDhParamFile",		set_dhparamfile,     	NULL },
381
    { "TlsCipherList",		set_cipherlist,      	NULL },
382
    { "TlsCertsOk",		set_no_verify,	     	NULL },
383
    { "TlsDontRequestCert",	set_dont_request_cert,	NULL },
384
    { "TlsRequired",		set_required,	     	NULL },
385
    { "TlsImplicit",		set_implicit,	     	NULL },
386
    { NULL , NULL, NULL}
387
};
388
389
/* Each module can supply up to two initialization routines (via
390
 * the module structure at the bottom of this file).  The first
391
 * init function is called immediately after the module is loaded,
392
 * while the second is called after proftpd is connected to a client,
393
 * and the main proftpd server (if not in inetd mode) has forked off.
394
 * The second init function's purpose is to let the module perform
395
 * any necessary work once a client is connected and proftpd is ready
396
 * to service the new client.  In inetd mode, the "child init" function
397
 * will be called immediately after proftpd is loaded, because proftpd
398
 * is _always_ in "child mode" when run from inetd.  Note that both
399
 * of these initialization routines are optional.  If you don't need
400
 * them (or only need one), simply set the function pointer to NULL
401
 * in the module structure.
402
 */
403
404
static int mod_tls_init()
405
{
406
    return 0;
407
}
408
409
#define PROCESS_PARAM_STR(x, y)	{						\
410
    char *str = (char *) get_param_ptr(CURRENT_CONF, x, FALSE);			\
411
    if (str) {									\
412
	if (y)									\
413
	    free(y);								\
414
	y = strdup(str);							\
415
    }										\
416
}
417
418
#define PROCESS_PARAM_INT(x, y) {						\
419
    long i = get_param_int(CURRENT_CONF, x, FALSE);				\
420
    if (i != -1)								\
421
	y = i;									\
422
}
423
424
static int mod_tls_child_init()
425
{
426
    PROCESS_PARAM_STR("TlsRsaCertFile", tls_rsa_cert_file);
427
    PROCESS_PARAM_STR("TlsRsaKeyFile", tls_rsa_key_file);
428
    PROCESS_PARAM_STR("TlsDsaCertFile", tls_dsa_cert_file);
429
    PROCESS_PARAM_STR("TlsDsaKeyFile", tls_dsa_key_file);
430
    PROCESS_PARAM_STR("TlsCrlFile", tls_crl_file);
431
    PROCESS_PARAM_STR("TlsDhParamFile", tls_dhparam_file);
432
    PROCESS_PARAM_STR("TlsCipherList", tls_cipher_list);
433
    PROCESS_PARAM_INT("TlsCertsOk", tls_no_verify);
434
    PROCESS_PARAM_INT("TlsDontRequestCert", tls_dont_request_cert);
435
    PROCESS_PARAM_INT("TlsRequired", tls_required);
436
    PROCESS_PARAM_INT("TlsImplicit", tls_implicit);
437
    
438
    return tls_init_error = tls_init();
439
}
440
441
/* command table ...
442
 * first  : command "type" (see the doc/API for more info)
443
 *
444
 * second : command "name", or the actual null-terminated ascii text
445
 *          sent by a client (in uppercase) for this command.  see
446
 *          include/ftp.h for macros which define all rfced FTP protocol
447
 *          commands.  Can also be the special macro C_ANY, which receives
448
 *          ALL commands.
449
 *
450
 * third  : command "group" (used for access control via Limit directives),
451
 *          this can be either G_DIRS (for commands related to directory
452
 *          listing), G_READ (for commands related to reading files), 
453
 *          G_WRITE (for commands related to file writing), or the
454
 *          special G_NONE for those commands against which the
455
 *          special <Limit READ|WRITE|DIRS> will not be applied.
456
 *
457
 * fourth : function pointer to your handler
458
 *
459
 * fifth  : TRUE if the command cannot be used before authentication
460
 *          (via USER/PASS), otherwise FALSE.
461
 *
462
 * sixth  : TRUE if the command can be sent during a file transfer
463
 *          (note: as of 1.1.5, this is obsolete)
464
 *
465
 */
466
467
cmdtable mod_tls_commands[] = {
468
    { CMD,	"AUTH",	G_NONE,	cmd_auth,	FALSE, FALSE },
469
    { CMD,	"PBSZ",	G_NONE,	cmd_pbsz,	FALSE, FALSE },
470
    { CMD,	"PROT",	G_NONE,	cmd_prot,	FALSE, FALSE },
471
    { 0,		NULL }
472
};
473
474
module tls_module = {
475
    NULL,NULL,		/* Always NULL */
476
    0x20,		/* API Version 2.0 */
477
    "tls",
478
    mod_tls_config,	/* Configuration handler table */
479
    mod_tls_commands,	/* Command handler table */
480
    NULL,		/* No authentication handler table */
481
    mod_tls_init,	/* Initialization function */
482
    mod_tls_child_init	/* Post-fork "child mode" init */
483
};
(-)proftpd-1.2.6rc1.orig/sample-configurations/basic.conf (-1 / +28 lines)
Lines 3-12 Link Here
3
# and a single anonymous login.  It assumes that you have a user/group
3
# and a single anonymous login.  It assumes that you have a user/group
4
# "nobody" and "ftp" for normal operation and anon.
4
# "nobody" and "ftp" for normal operation and anon.
5
5
6
ServerName			"ProFTPD Default Installation"
6
ServerName			"ProFTPD-TLS Default Installation"
7
# ServerType is either "standalone" or "inetd"
7
ServerType			standalone
8
ServerType			standalone
8
DefaultServer			on
9
DefaultServer			on
9
10
11
# If you want .message files to work with browsers, you probably
12
# want to uncomment the next line
13
#MultilineRFC2228		on
14
15
# These are the TLS related options, default values
16
#TlsRsaCertFile			ftpd-rsa.pem
17
#TlsRsaKeyFile			ftpd-rsa-key.pem
18
#TlsDsaCertFile			ftpd-dsa.pem
19
#TlsDsaKeyFile			ftpd-dsa-key.pem
20
#TlsCrlFile			ftpd-crl.pem
21
#TlsDhParamFile			ftpd-dhparam.pem
22
#TlsCipherList			ALL:!ADH
23
#TlsRequired			off
24
# don't verify any peer certificates
25
#TlsCertsOk			off
26
# Some ftp clients (e.g. SmartFTP) uses a broken SSL/TLS implementation that
27
# aborts the SSL/TLS handshake, if the server sends a "CertificateRequest" and
28
# the client don't have any certificate. This behaviour violates both the SSLv3
29
# and TLSv1 spec (it's actually old SSLv2 behaviour). To be able to use those
30
# clients without client certs, you must set the following option to "on".
31
#TlsDontRequestCert		off
32
# Set the following to "on" if you want to use implicit SSL/TLS. It's not the
33
# recommended way do to SSL/TLS ftp, but some user's want it anyway. Remember
34
# to make proftpd listen to the proper ``ftps'' port also.
35
#TlsImplicit			off
36
10
# Port 21 is the standard FTP port.
37
# Port 21 is the standard FTP port.
11
Port				21
38
Port				21
12
# Umask 022 is a good standard umask to prevent new dirs and files
39
# Umask 022 is a good standard umask to prevent new dirs and files
(-)proftpd-1.2.6rc1.orig/src/data.c (+29 lines)
Lines 41-46 Link Here
41
#include <sys/uio.h>
41
#include <sys/uio.h>
42
#endif /* HAVE_SYS_UIO_H */
42
#endif /* HAVE_SYS_UIO_H */
43
43
44
#ifdef TLS
45
#include <openssl/ssl.h>
46
#include "tlsutil.h"
47
#endif
48
44
/* local macro */
49
/* local macro */
45
50
46
#define MODE_STRING	(session.flags & (SF_ASCII|SF_ASCII_OVERRIDE) ? \
51
#define MODE_STRING	(session.flags & (SF_ASCII|SF_ASCII_OVERRIDE) ? \
Lines 199-204 Link Here
199
       */
204
       */
200
      send_response(R_150, "FILE: %s", reason);
205
      send_response(R_150, "FILE: %s", reason);
201
    }
206
    }
207
#ifdef TLS
208
  /* start TLS handshake if appropriate */
209
  if (tls_on_data)
210
    if (tls_accept(c, TRUE)) {
211
      /* exit if we fail */
212
      send_response_async(R_421,
213
	  "Failed TLS negotiation on data channel, disconnected");
214
      main_exit((void*) LOG_ERR,
215
	  "Failed TLS negotiation on data channel, disconnected.", (void*) 0,
216
	  NULL);
217
    }
218
#endif
202
    
219
    
203
    return 0;
220
    return 0;
204
  }
221
  }
Lines 289-294 Link Here
289
      send_response(R_150, "FILE: %s", reason);
306
      send_response(R_150, "FILE: %s", reason);
290
    }
307
    }
291
    
308
    
309
#ifdef TLS
310
  /* start TLS handshake if appropriate */
311
  if (tls_on_data)
312
    if (tls_accept(c, TRUE)) {
313
      /* exit if we fail */
314
      send_response_async(R_421,
315
	  "Failed TLS negotiation on data channel, disconnected");
316
      main_exit((void*) LOG_ERR,
317
	  "Failed TLS negotiation on data channel, disconnected.", (void*) 0,
318
	  NULL);
319
    }
320
#endif
292
    inet_close(session.pool,session.d);
321
    inet_close(session.pool,session.d);
293
    inet_setnonblock(session.pool,session.d);
322
    inet_setnonblock(session.pool,session.d);
294
    session.d = c;
323
    session.d = c;
(-)proftpd-1.2.6rc1.orig/src/io.c (+34 lines)
Lines 27-32 Link Here
27
27
28
#include <signal.h>
28
#include <signal.h>
29
29
30
#ifdef TLS
31
#include <openssl/ssl.h>
32
#include "tlsutil.h"
33
#endif
34
30
#ifndef IAC
35
#ifndef IAC
31
#define IAC	255
36
#define IAC	255
32
#endif
37
#endif
Lines 102-107 Link Here
102
107
103
  f->fd = fd;
108
  f->fd = fd;
104
  f->mode = mode;
109
  f->mode = mode;
110
#ifdef TLS
111
  f->tls_session = NULL;
112
#endif
105
113
106
  return f;
114
  return f;
107
}
115
}
Lines 116-121 Link Here
116
124
117
  res = close(f->fd);
125
  res = close(f->fd);
118
  f->fd = -1;
126
  f->fd = -1;
127
#ifdef TLS
128
  /* only close the READ IOFILE since they come in pairs with the same SSL */
129
  if (f->mode == IO_READ)
130
    tls_close_session(f->tls_session);
131
#endif
119
132
120
  destroy_pool(f->pool);
133
  destroy_pool(f->pool);
121
  return res;
134
  return res;
Lines 248-253 Link Here
248
    tv.tv_sec = ((f->flags & IO_INTR) ? f->restart_secs : 60);
261
    tv.tv_sec = ((f->flags & IO_INTR) ? f->restart_secs : 60);
249
    tv.tv_usec = 0;
262
    tv.tv_usec = 0;
250
263
264
#ifdef TLS
265
    /* check if there some data "hidden" left in the OpenSSL system */
266
    if (tls_pending(f->tls_session))
267
	res = 1;
268
    else
269
#endif
251
    res = select(f->fd + 1,rfds,wfds,NULL,&tv);
270
    res = select(f->fd + 1,rfds,wfds,NULL,&tv);
252
    switch(res) {
271
    switch(res) {
253
    case -1:
272
    case -1:
Lines 305-310 Link Here
305
        do {
324
        do {
306
          run_schedule();
325
          run_schedule();
307
          handle_signals();
326
          handle_signals();
327
#ifdef TLS
328
	  if (f->tls_session)
329
	    written = tls_write(f->tls_session,buf,size);
330
	  else
331
#endif
308
          written = write(f->fd,buf,size);
332
          written = write(f->fd,buf,size);
309
        } while(written == -1 && errno == EINTR);
333
        } while(written == -1 && errno == EINTR);
310
        break;
334
        break;
Lines 361-366 Link Here
361
  while(size) {
385
  while(size) {
362
    do {
386
    do {
363
      handle_signals();
387
      handle_signals();
388
#ifdef TLS
389
      if (f->tls_session)
390
	written = tls_write(f->tls_session,buf,size);
391
      else
392
#endif
364
      written = write(f->fd, buf, size);
393
      written = write(f->fd, buf, size);
365
    } while (written == -1 && errno == EINTR);
394
    } while (written == -1 && errno == EINTR);
366
    
395
    
Lines 414-419 Link Here
414
        do {
443
        do {
415
          run_schedule();
444
          run_schedule();
416
          handle_signals();
445
          handle_signals();
446
#ifdef TLS
447
	  if (f->tls_session)
448
	    bread = tls_read(f->tls_session,buf,size);
449
	  else
450
#endif
417
          bread = read(f->fd, buf, size);
451
          bread = read(f->fd, buf, size);
418
        } while(bread == -1 && errno == EINTR);
452
        } while(bread == -1 && errno == EINTR);
419
        break;
453
        break;
(-)proftpd-1.2.6rc1.orig/src/main.c (+26 lines)
Lines 71-76 Link Here
71
71
72
#include "privs.h"
72
#include "privs.h"
73
73
74
#ifdef TLS
75
#include <openssl/ssl.h>
76
#include "tlsutil.h"
77
#endif
78
74
/* From mod_core.c
79
/* From mod_core.c
75
 */
80
 */
76
extern int core_display_file(const char *numeric, const char *fn, const char *fs);
81
extern int core_display_file(const char *numeric, const char *fn, const char *fs);
Lines 647-652 Link Here
647
void end_login(int exitcode)
652
void end_login(int exitcode)
648
{
653
{
649
  end_login_noexit();
654
  end_login_noexit();
655
#ifdef TLS
656
  if (session.c)
657
    tls_close_session(session.c->inf->tls_session);
658
  if (is_master)
659
    tls_cleanup();
660
#endif
650
  _exit(exitcode);
661
  _exit(exitcode);
651
}
662
}
652
663
Lines 1593-1598 Link Here
1593
                    inet_ntoa(*session.c->remote_ipaddr),
1604
                    inet_ntoa(*session.c->remote_ipaddr),
1594
                    session.c->remote_port);
1605
                    session.c->remote_port);
1595
1606
1607
#ifdef TLS
1608
  /* start TLS handshake if we use implicit TLS */
1609
  if (tls_implicit) {
1610
      if (tls_accept(conn, FALSE)) {
1611
	  /* exit if we fail */
1612
	  send_response_async(R_421,
1613
	      "Failed TLS negotiation on control channel, disconnected");
1614
	  main_exit((void*) LOG_ERR,
1615
	      "Failed TLS negotiation on control channel, disconnected.",
1616
	      (void*) 0, NULL);
1617
      } else
1618
	  tls_on_data = 1;
1619
  }
1620
#endif
1621
1596
  /* xfer_set_data_port(conn->local_ipaddr,conn->local_port-1); */
1622
  /* xfer_set_data_port(conn->local_ipaddr,conn->local_port-1); */
1597
  cmd_loop(serv,conn);
1623
  cmd_loop(serv,conn);
1598
}
1624
}
(-)proftpd-1.2.6rc1.orig/src/tlsutil.c (+889 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 1999 - 2002 Peter 'Luna' Runestig <peter@runestig.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modifi-
6
 * cation, are permitted provided that the following conditions are met:
7
 *
8
 *   o  Redistributions of source code must retain the above copyright notice,
9
 *      this list of conditions and the following disclaimer.
10
 *
11
 *   o  Redistributions in binary form must reproduce the above copyright no-
12
 *      tice, this list of conditions and the following disclaimer in the do-
13
 *      cumentation and/or other materials provided with the distribution.
14
 *
15
 *   o  The names of the contributors may not be used to endorse or promote
16
 *      products derived from this software without specific prior written
17
 *      permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LI-
23
 * ABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN-
24
 * TIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV-
26
 * ER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI-
27
 * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#ifndef lint
32
static char copyright[] =
33
"@(#) Copyright (c) Peter 'Luna' Runestig 1999 - 2002 <peter@runestig.com>.\n";
34
#endif /* not lint */
35
36
/* ProFTPD special includes */
37
#include "conf.h"
38
#include <privs.h>
39
40
#include <string.h>
41
#include <errno.h>
42
#include <sys/time.h>
43
#include <sys/types.h>
44
#include <sys/socket.h>
45
#include <sys/poll.h>
46
#include <openssl/ssl.h>
47
#include <openssl/x509v3.h>
48
#include <openssl/err.h>
49
#include <openssl/rand.h>
50
#include "tls_dh.h"
51
#include "io.h"
52
#include "inet.h"
53
54
#if OPENSSL_VERSION_NUMBER < 0x00905100
55
/* ASN1_BIT_STRING_cmp was renamed in 0.9.5 */
56
#define M_ASN1_BIT_STRING_cmp ASN1_BIT_STRING_cmp
57
#endif
58
59
#define DEFRSACERTFILE		"ftpd-rsa.pem"
60
#define DEFRSAKEYFILE		"ftpd-rsa-key.pem" 
61
#define DEFDSACERTFILE		"ftpd-dsa.pem"
62
#define DEFDSAKEYFILE		"ftpd-dsa-key.pem" 
63
#define DEFCRLFILE		"ftpd-crl.pem"
64
#define DEFDHPARAMFILE		"ftpd-dhparam.pem"
65
#define DEFAULTCIPHERLIST       "ALL:!ADH"
66
67
/* define if you want to check for OpenSSL-related memory leaks */
68
/*#define DEBUG_OPENSSL_MEM*/
69
70
int x509_to_user(X509 *peer_cert, char *userid, int len);
71
static char *file_fullpath(char *fn);
72
73
int	tls_on_ctrl = 0;
74
int	tls_on_data = 0;
75
int 	tls_implicit = 0;
76
int	tls_init_error = 0;
77
int	tls_no_verify = 0;
78
int	tls_dont_request_cert = 0;
79
int	tls_required = 0;
80
char 	*tls_rsa_key_file = NULL;
81
char	*tls_rsa_cert_file = NULL;
82
char 	*tls_dsa_key_file = NULL;
83
char	*tls_dsa_cert_file = NULL;
84
char	*tls_crl_file = NULL;
85
char	*tls_crl_dir = NULL;
86
char	*tls_dhparam_file = NULL;
87
char	*tls_rand_file = NULL;
88
char	*tls_cipher_list = NULL;
89
static SSL *first_ssl = NULL;
90
static SSL_CTX	*ssl_ctx = NULL;
91
static X509_STORE *crl_store = NULL;
92
static DH *tmp_dh = NULL;
93
static RSA *tmp_rsa = NULL;
94
95
/* we need this so we don't mix static and malloc'ed strings */
96
void tls_set_file_defaults(void)
97
{
98
    if (!tls_rsa_key_file)
99
    	tls_rsa_key_file = strdup(DEFRSAKEYFILE);
100
    if (!tls_rsa_cert_file)
101
    	tls_rsa_cert_file = strdup(DEFRSACERTFILE);
102
    if (!tls_dsa_key_file)
103
    	tls_dsa_key_file = strdup(DEFDSAKEYFILE);
104
    if (!tls_dsa_cert_file)
105
    	tls_dsa_cert_file = strdup(DEFDSACERTFILE);
106
    if (!tls_crl_file)
107
    	tls_crl_file = strdup(DEFCRLFILE);
108
    if (!tls_crl_dir && (tls_crl_dir = malloc(strlen(X509_get_default_cert_area()) + 5)))
109
    	sprintf(tls_crl_dir, "%s/crl", X509_get_default_cert_area());
110
    if (!tls_dhparam_file)
111
    	tls_dhparam_file = strdup(DEFDHPARAMFILE);
112
    if (!tls_cipher_list)
113
    	tls_cipher_list = strdup(DEFAULTCIPHERLIST);
114
}
115
116
/* if we are using OpenSSL 0.9.6 or newer, we want to use X509_NAME_print_ex()
117
 * instead of X509_NAME_oneline().
118
 */
119
static char *x509_name_oneline(X509_NAME *n, char *buf, int len)
120
{
121
#if OPENSSL_VERSION_NUMBER < 0x000906000
122
    return X509_NAME_oneline(n, buf, len);
123
#else
124
    BIO *mem = BIO_new(BIO_s_mem());
125
    char *data = NULL;
126
    int data_len = 0, ok;
127
    
128
    ok = X509_NAME_print_ex(mem, n, 0, XN_FLAG_ONELINE);
129
    if (ok)
130
	data_len = BIO_get_mem_data(mem, &data);
131
    if (data) {
132
	/* the 'data' returned is not '\0' terminated */
133
	if (buf) {
134
	    memcpy(buf, data, data_len < len ? data_len : len);
135
	    buf[data_len < len ? data_len : len - 1] = 0;
136
	    BIO_free(mem);
137
	    return buf;
138
	} else {
139
	    char *b = malloc(data_len + 1);
140
	    if (b) {
141
		memcpy(b, data, data_len);
142
		b[data_len] = 0;
143
	    }
144
	    BIO_free(mem);
145
	    return b;
146
	}
147
    } else {
148
	BIO_free(mem);
149
	return NULL;
150
    }
151
#endif /* OPENSSL_VERSION_NUMBER >= 0x000906000 */
152
}
153
154
char *tls_get_subject_name()
155
{
156
    static char name[256];
157
    X509 *cert;
158
159
    if ((cert = SSL_get_peer_certificate(first_ssl))) {
160
	x509_name_oneline(X509_get_subject_name(cert), name, sizeof(name));
161
	X509_free(cert);
162
	return name;
163
    } else
164
	return NULL;
165
}
166
167
static DH *tmp_dh_cb(SSL *ssl, int is_export, int keylength)
168
{
169
    FILE *fp;
170
171
    if (!tmp_dh) {
172
    	/* first try any 'tls_dhparam_file', else use built-in dh params */
173
    	if (tls_dhparam_file && (fp = fopen(tls_dhparam_file, "r"))) {
174
	    tmp_dh = PEM_read_DHparams(fp, NULL, NULL, NULL);
175
	    fclose(fp);
176
	    if (tmp_dh)
177
	    	return tmp_dh;
178
	}
179
	switch (keylength) {
180
	    case 512:	return tmp_dh = get_dh512();
181
	    case 768:	return tmp_dh = get_dh768();
182
	    case 1024:	return tmp_dh = get_dh1024();
183
	    case 1536:	return tmp_dh = get_dh1536();
184
	    case 2048:	return tmp_dh = get_dh2048();
185
	    default:	return tmp_dh = get_dh1024();
186
	}
187
    }
188
    else
189
    	return tmp_dh;
190
}
191
192
static RSA *tmp_rsa_cb(SSL *ssl, int is_export, int keylength)
193
{
194
    if (!tmp_rsa)
195
	tmp_rsa = RSA_generate_key(keylength, RSA_F4, NULL, NULL);
196
    return tmp_rsa;
197
}
198
199
/* check_file() expands 'file' to an existing full path or NULL if not found */
200
static void check_file(char **file)
201
{
202
    char *p;
203
    
204
    if (*file) {
205
    	p = file_fullpath(*file);
206
	if (p == *file)	/* same pointer returned from file_fullpath() */
207
	    return;
208
	free(*file);
209
	if (p) {
210
	    *file = malloc(strlen(p) + 1);
211
	    strcpy(*file, p);
212
	}
213
	else
214
	    *file = NULL;
215
    }
216
}
217
218
/* this one is (very much!) based on work by Ralf S. Engelschall <rse@engelschall.com>.
219
 * comments by Ralf.
220
 */
221
static int verify_crl(int ok, X509_STORE_CTX *ctx)
222
{
223
    X509_OBJECT obj;
224
    X509_NAME *subject;
225
    X509_NAME *issuer;
226
    X509 *xs;
227
    X509_CRL *crl;
228
    X509_REVOKED *revoked;
229
    X509_STORE_CTX store_ctx;
230
    long serial;
231
    int i, n, rc;
232
    char *cp;
233
234
    /*
235
     * Unless a revocation store for CRLs was created we
236
     * cannot do any CRL-based verification, of course.
237
     */
238
    if (!crl_store)
239
        return ok;
240
241
    /*
242
     * Determine certificate ingredients in advance
243
     */
244
    xs      = X509_STORE_CTX_get_current_cert(ctx);
245
    subject = X509_get_subject_name(xs);
246
    issuer  = X509_get_issuer_name(xs);
247
248
    /*
249
     * OpenSSL provides the general mechanism to deal with CRLs but does not
250
     * use them automatically when verifying certificates, so we do it
251
     * explicitly here. We will check the CRL for the currently checked
252
     * certificate, if there is such a CRL in the store.
253
     *
254
     * We come through this procedure for each certificate in the certificate
255
     * chain, starting with the root-CA's certificate. At each step we've to
256
     * both verify the signature on the CRL (to make sure it's a valid CRL)
257
     * and it's revocation list (to make sure the current certificate isn't
258
     * revoked).  But because to check the signature on the CRL we need the
259
     * public key of the issuing CA certificate (which was already processed
260
     * one round before), we've a little problem. But we can both solve it and
261
     * at the same time optimize the processing by using the following
262
     * verification scheme (idea and code snippets borrowed from the GLOBUS
263
     * project):
264
     *
265
     * 1. We'll check the signature of a CRL in each step when we find a CRL
266
     *    through the _subject_ name of the current certificate. This CRL
267
     *    itself will be needed the first time in the next round, of course.
268
     *    But we do the signature processing one round before this where the
269
     *    public key of the CA is available.
270
     *
271
     * 2. We'll check the revocation list of a CRL in each step when
272
     *    we find a CRL through the _issuer_ name of the current certificate.
273
     *    This CRLs signature was then already verified one round before.
274
     *
275
     * This verification scheme allows a CA to revoke its own certificate as
276
     * well, of course.
277
     */
278
279
    /*
280
     * Try to retrieve a CRL corresponding to the _subject_ of
281
     * the current certificate in order to verify it's integrity.
282
     */
283
    memset((char *)&obj, 0, sizeof(obj));
284
    X509_STORE_CTX_init(&store_ctx, crl_store, NULL, NULL);
285
    rc = X509_STORE_get_by_subject(&store_ctx, X509_LU_CRL, subject, &obj);
286
    X509_STORE_CTX_cleanup(&store_ctx);
287
    crl = obj.data.crl;
288
    if (rc > 0 && crl != NULL) {
289
        /*
290
         * Verify the signature on this CRL
291
         */
292
        if (X509_CRL_verify(crl, X509_get_pubkey(xs)) <= 0) {
293
            log_pri(LOG_ERR, "Invalid signature on CRL!");
294
            X509_STORE_CTX_set_error(ctx, X509_V_ERR_CRL_SIGNATURE_FAILURE);
295
            X509_OBJECT_free_contents(&obj);
296
            return 0;
297
        }
298
299
        /*
300
         * Check date of CRL to make sure it's not expired
301
         */
302
        i = X509_cmp_current_time(X509_CRL_get_nextUpdate(crl));
303
        if (i == 0) {
304
            log_pri(LOG_ERR, "Found CRL has invalid nextUpdate field.");
305
            X509_STORE_CTX_set_error(ctx, X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD);
306
            X509_OBJECT_free_contents(&obj);
307
            return 0;
308
        }
309
        if (i < 0) {
310
            log_pri(LOG_ERR, "Found CRL is expired - revoking all certificates until you get updated CRL.");
311
            X509_STORE_CTX_set_error(ctx, X509_V_ERR_CRL_HAS_EXPIRED);
312
            X509_OBJECT_free_contents(&obj);
313
            return 0;
314
        }
315
        X509_OBJECT_free_contents(&obj);
316
    }
317
318
    /*
319
     * Try to retrieve a CRL corresponding to the _issuer_ of
320
     * the current certificate in order to check for revocation.
321
     */
322
    memset((char *)&obj, 0, sizeof(obj));
323
    X509_STORE_CTX_init(&store_ctx, crl_store, NULL, NULL);
324
    rc = X509_STORE_get_by_subject(&store_ctx, X509_LU_CRL, issuer, &obj);
325
    X509_STORE_CTX_cleanup(&store_ctx);
326
    crl = obj.data.crl;
327
    if (rc > 0 && crl != NULL) {
328
        /*
329
         * Check if the current certificate is revoked by this CRL
330
         */
331
        n = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
332
        for (i = 0; i < n; i++) {
333
            revoked = sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
334
            if (ASN1_INTEGER_cmp(revoked->serialNumber, X509_get_serialNumber(xs)) == 0) {
335
336
                serial = ASN1_INTEGER_get(revoked->serialNumber);
337
                cp = x509_name_oneline(issuer, NULL, 0);
338
                log_pri(LOG_ERR, "Certificate with serial %ld (0x%lX) revoked per CRL from issuer %s",
339
                        serial, serial, cp ? cp : "(ERROR)");
340
                if (cp) free(cp);
341
342
                X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);
343
                X509_OBJECT_free_contents(&obj);
344
                return 0;
345
            }
346
        }
347
        X509_OBJECT_free_contents(&obj);
348
    }
349
    return ok;
350
}
351
352
static int verify_callback(int ok, X509_STORE_CTX *ctx)
353
{
354
    /* TODO: Make up my mind on what to accept or not.*/
355
    /* we can configure the server to skip the peer's cert verification */
356
    if (tls_no_verify)
357
    	return 1;
358
359
    ok = verify_crl(ok, ctx);
360
    if (!ok) {
361
    	switch (ctx->error) {
362
	    case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
363
	    	log_pri(LOG_ERR, "Error: Client's certificate is self signed.");
364
		ok = 0;
365
		break;
366
	    case X509_V_ERR_CERT_HAS_EXPIRED:
367
	    	log_pri(LOG_ERR, "Error: Client's certificate has expired.");
368
		ok = 0;
369
		break;
370
	    case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
371
	    	log_pri(LOG_ERR, "Error: Client's certificate issuer's certificate isn't available locally.");
372
		ok = 0;
373
		break;
374
	    case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
375
	    	log_pri(LOG_ERR, "Error: Unable to verify leaf signature.");
376
		ok = 0;
377
		break;
378
	    case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
379
		/* XXX this is strange. we get this error for certain clients (ie Jeff's kftp) when
380
		 * all is ok. I think it's because the client is actually sending the whole CA
381
		 * cert. this must be figured out, but we let it pass for now. if the CA cert isn't
382
		 * available locally, we will fail anyway.
383
		 */
384
	    	log_pri(LOG_NOTICE, "Warning: Self signed certificate in chain.");
385
		ok = 1;
386
		break;
387
	    case X509_V_ERR_CERT_REVOKED:
388
	    	log_pri(LOG_ERR, "Error: Certificate revoked.");
389
		ok = 0;
390
		break;
391
	    default:
392
	    	log_pri(LOG_ERR,
393
		    "Error %d while verifying the client's certificate.", ctx->error);
394
		ok = 0;
395
	    	break;
396
	}
397
    }
398
    return ok;
399
}
400
401
static int seed_PRNG(void)
402
{
403
    char stackdata[1024];
404
    static char rand_file[300];
405
    FILE *fh;
406
    
407
#if OPENSSL_VERSION_NUMBER >= 0x00905100
408
    if (RAND_status())
409
	return 0;     /* PRNG already good seeded */
410
#endif
411
    /* if the device '/dev/urandom' is present, OpenSSL uses it by default.
412
     * check if it's present, else we have to make random data ourselfs.
413
     */
414
    if ((fh = fopen("/dev/urandom", "r"))) {
415
	fclose(fh);
416
	return 0;
417
    }
418
    /* the ftpd's rand file is (openssl-dir)/.rnd */
419
    sprintf(rand_file, "%s/.rnd", X509_get_default_cert_area());
420
    tls_rand_file = rand_file;
421
    if (!RAND_load_file(rand_file, 1024)) {
422
	/* no .rnd file found, create new seed */
423
	unsigned int c;
424
	c = time(NULL);
425
	RAND_seed(&c, sizeof(c));
426
	c = getpid();
427
	RAND_seed(&c, sizeof(c));
428
	RAND_seed(stackdata, sizeof(stackdata));
429
    }
430
#if OPENSSL_VERSION_NUMBER >= 0x00905100
431
    if (!RAND_status())
432
	return 2;   /* PRNG still badly seeded */
433
#endif
434
    return 0;
435
}
436
437
int tls_init(void)
438
{
439
    int err;
440
	
441
#ifdef DEBUG_OPENSSL_MEM
442
    CRYPTO_malloc_debug_init();
443
    CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
444
#endif /* DEBUG_OPENSSL_MEM */
445
    SSL_load_error_strings();
446
    SSL_library_init();
447
#ifdef ZLIB
448
    {
449
	COMP_METHOD *cm = COMP_zlib();
450
	if (cm != NULL && cm->type != NID_undef) {
451
	    SSL_COMP_add_compression_method(0xe0, cm); /* Eric Young's ZLIB ID */
452
	}
453
    }
454
#endif /* ZLIB */
455
    ssl_ctx = SSL_CTX_new(SSLv23_method());
456
    if (!ssl_ctx) {
457
	log_pri(LOG_ERR, "SSL_CTX_new() %s",
458
		(char *)ERR_error_string(ERR_get_error(), NULL));
459
	return 1;
460
    }
461
    SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
462
    if (!tls_dont_request_cert)
463
	SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER, verify_callback);
464
    SSL_CTX_set_default_verify_paths(ssl_ctx);
465
    /* set up session caching  */
466
    SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_SERVER);
467
    SSL_CTX_set_session_id_context(ssl_ctx, "1", 1);
468
469
    /* let's find out which files are available */
470
    tls_set_file_defaults();
471
#ifdef PRIVS_ROOT
472
    PRIVS_ROOT	/* ProFTPD must regain root privs here to read the key file(s) */
473
#endif
474
    check_file(&tls_rsa_cert_file);
475
    check_file(&tls_rsa_key_file);
476
    check_file(&tls_dsa_cert_file);
477
    check_file(&tls_dsa_key_file);
478
    check_file(&tls_crl_file);
479
    check_file(&tls_dhparam_file);
480
    if (!tls_rsa_cert_file && !tls_dsa_cert_file) {
481
    	log_pri(LOG_ERR, "No certificate files found!");
482
	return 2;
483
    }
484
    if (!tls_rsa_key_file)
485
    	tls_rsa_key_file = tls_rsa_cert_file;
486
    if (!tls_dsa_key_file)
487
    	tls_dsa_key_file = tls_dsa_cert_file;
488
    
489
    if (tls_rsa_cert_file) {
490
	err = SSL_CTX_use_certificate_file(ssl_ctx, tls_rsa_cert_file, X509_FILETYPE_PEM);
491
	if (err <= 0) {
492
	    log_pri(LOG_ERR, "SSL_CTX_use_certificate_file(%s) %s", tls_rsa_cert_file,
493
		(char *)ERR_error_string(ERR_get_error(), NULL));
494
	    return 3;
495
	}
496
	SSL_CTX_set_tmp_rsa_callback(ssl_ctx, tmp_rsa_cb);
497
    }
498
    if (tls_rsa_key_file) {
499
	err = SSL_CTX_use_PrivateKey_file(ssl_ctx, tls_rsa_key_file, X509_FILETYPE_PEM);
500
	if (err <= 0) {
501
	    log_pri(LOG_ERR, "SSL_CTX_use_PrivateKey_file(%s) %s", tls_rsa_key_file,
502
	    	(char *)ERR_error_string(ERR_get_error(), NULL));
503
	    return 4;
504
	}
505
    }
506
    if (tls_dsa_cert_file) {
507
	err = SSL_CTX_use_certificate_file(ssl_ctx, tls_dsa_cert_file, X509_FILETYPE_PEM);
508
	if (err <= 0) {
509
	    log_pri(LOG_ERR, "SSL_CTX_use_certificate_file(%s) %s", tls_dsa_cert_file,
510
		(char *)ERR_error_string(ERR_get_error(), NULL));
511
	    return 5;
512
	}
513
    }
514
    if (tls_dsa_key_file) {
515
	err = SSL_CTX_use_PrivateKey_file(ssl_ctx, tls_dsa_key_file, X509_FILETYPE_PEM);
516
	if (err <= 0) {
517
	    log_pri(LOG_ERR, "SSL_CTX_use_PrivateKey_file(%s) %s", tls_dsa_key_file,
518
	    	(char *)ERR_error_string(ERR_get_error(), NULL));
519
	    return 6;
520
	}
521
    }
522
#ifdef PRIVS_RELINQUISH
523
    PRIVS_RELINQUISH	/* ProFTPD dropping root privs again */
524
#endif
525
526
    SSL_CTX_set_tmp_dh_callback(ssl_ctx, tmp_dh_cb);
527
528
    /* set up the CRL */
529
    if ((tls_crl_file || tls_crl_dir) && (crl_store = X509_STORE_new()))
530
	X509_STORE_load_locations(crl_store, tls_crl_file, tls_crl_dir);
531
532
    if (tls_cipher_list)
533
	SSL_CTX_set_cipher_list(ssl_ctx, tls_cipher_list);
534
    else
535
	log_pri(LOG_NOTICE, "NULL tls_cipher_list!");
536
    if (seed_PRNG())
537
	log_pri(LOG_NOTICE, "Wasn't able to properly seed the PRNG!");
538
    return 0;
539
}
540
541
char *tls_userid_from_client_cert()
542
{
543
    static char cn[256];
544
    static char *r = cn;
545
    static int again = 0;
546
    int err;
547
    X509 *client_cert;
548
549
    if (!tls_on_ctrl || !first_ssl)
550
    	return NULL;
551
    if (again)
552
    	return r;
553
    again = 1;
554
    if ((client_cert = SSL_get_peer_certificate(first_ssl))) {
555
    	/* call the custom function */
556
	err = x509_to_user(client_cert, cn, sizeof(cn));
557
	X509_free(client_cert);
558
	if (err)
559
	    return r = NULL;
560
	else
561
	    return r;
562
    }
563
    else
564
	return r = NULL;
565
}
566
567
int tls_is_user_valid(char *user)
568
/* check if clients cert is in "user"'s ~/.tlslogin file */
569
{
570
    char buf[512];
571
    int r = 0;
572
    FILE *fp = NULL;
573
    X509 *client_cert = NULL, *file_cert;
574
    struct passwd *pwd;
575
576
    if (!tls_on_ctrl || !first_ssl || !user)
577
	return 0;
578
#ifdef PRIVS_ROOT
579
    PRIVS_ROOT	/* ProFTPD must regain root privs here to read the .tlslogin file */
580
#endif
581
    if (!(pwd = getpwnam(user)))
582
    	goto cleanup;
583
    snprintf(buf, sizeof(buf), "%s/.tlslogin", pwd->pw_dir);
584
    if (!(fp = fopen(buf, "r")))
585
    	goto cleanup;
586
    if (!(client_cert = SSL_get_peer_certificate(first_ssl)))
587
    	goto cleanup;
588
    while ((file_cert = PEM_read_X509(fp, NULL, NULL, NULL))) {
589
	if (!M_ASN1_BIT_STRING_cmp(client_cert->signature, file_cert->signature))
590
	    r = 1;
591
	X509_free(file_cert);
592
	if (r) break;
593
    }
594
  cleanup:
595
    if (client_cert)
596
	X509_free(client_cert);
597
    if (fp)
598
	fclose(fp);
599
#ifdef PRIVS_RELINQUISH
600
    PRIVS_RELINQUISH	/* ProFTPD dropping root privs again */
601
#endif
602
    return r;
603
}
604
605
void tls_close_session(SSL *ssl)
606
{
607
    if (!ssl)
608
	return;
609
    SSL_shutdown(ssl);
610
    SSL_free(ssl);
611
}
612
613
int tls_accept(conn_t *conn, int data_connection)
614
{
615
    int err;
616
    SSL *ssl;
617
    static int logged_data_connection = 0;
618
619
    if (!ssl_ctx) {
620
	log_pri(LOG_ERR, "tls_accept() called when ssl_ctx == NULL!");
621
	return 1;
622
    }
623
    ssl = SSL_new(ssl_ctx);
624
    if (!ssl) {
625
	log_pri(LOG_ERR, "SSL_new() %s", (char *)ERR_error_string(ERR_get_error(), NULL));
626
	return 2;
627
    }
628
629
    if (!first_ssl)
630
	first_ssl = ssl;
631
    SSL_set_fd(ssl, conn->rfd); /* it works with either rfd or wfd (I hope ;-) */
632
    
633
  retry:
634
    err = SSL_accept(ssl);
635
    if (err < 1) {
636
	int ssl_err = SSL_get_error(ssl, err);
637
	if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE)
638
	    goto retry;
639
	log_pri(LOG_ERR, "SSL_accept(): (%d) %s", ssl_err,
640
		(char *)ERR_error_string(ERR_get_error(), NULL));
641
	tls_close_session(ssl);
642
	return 3;
643
    }
644
    conn->inf->tls_session = conn->outf->tls_session = ssl;
645
    tls_on_ctrl = 1;
646
    
647
    if (data_connection) {
648
	/* only log first TLS data connection, otherwise there might be lots of logging */
649
	if (!logged_data_connection) {
650
	    log_pri(LOG_NOTICE, "TLS data connection using cipher %s (%d bits)",
651
		    SSL_get_cipher(ssl), SSL_get_cipher_bits(ssl, NULL));
652
	    logged_data_connection = 1;
653
	}
654
    } else {
655
	char *subject = tls_get_subject_name();
656
	log_pri(LOG_NOTICE, "TLS connection using cipher %s (%d bits)",
657
		SSL_get_cipher(ssl), SSL_get_cipher_bits(ssl, NULL));
658
	if (subject)
659
	    log_pri(LOG_NOTICE, "Client: %s", subject);
660
    }
661
    return 0;
662
}
663
664
void tls_cleanup(void)
665
{
666
    if (crl_store) {
667
    	X509_STORE_free(crl_store);
668
	crl_store = NULL;
669
    }
670
    if (ssl_ctx) {
671
	SSL_CTX_free(ssl_ctx);
672
	ssl_ctx = NULL;
673
    }
674
    if (tmp_dh) {
675
	DH_free(tmp_dh);
676
	tmp_dh = NULL;
677
    }
678
    if (tmp_rsa) {
679
	RSA_free(tmp_rsa);
680
	tmp_rsa = NULL;
681
    }
682
    ERR_free_strings();
683
    ERR_remove_state(0);
684
    EVP_cleanup();	/* release the stuff allocated by SSL_library_init() */
685
    if (tls_rsa_key_file) {
686
    	if (tls_rsa_key_file != tls_rsa_cert_file)
687
	    free(tls_rsa_key_file);
688
	tls_rsa_key_file = NULL;
689
    }
690
    if (tls_rsa_cert_file) {
691
    	free(tls_rsa_cert_file);
692
	tls_rsa_cert_file = NULL;
693
    }
694
    if (tls_dsa_key_file) {
695
    	if (tls_dsa_key_file != tls_dsa_cert_file)
696
	    free(tls_dsa_key_file);
697
	tls_dsa_key_file = NULL;
698
    }
699
    if (tls_dsa_cert_file) {
700
    	free(tls_dsa_cert_file);
701
	tls_dsa_cert_file = NULL;
702
    }
703
    if (tls_dhparam_file) {
704
    	free(tls_dhparam_file);
705
	tls_dhparam_file = NULL;
706
    }
707
    if (tls_crl_file) {
708
    	free(tls_crl_file);
709
	tls_crl_file = NULL;
710
    }
711
    if (tls_crl_dir) {
712
    	free(tls_crl_dir);
713
	tls_crl_dir = NULL;
714
    }
715
    if (tls_cipher_list) {
716
    	free(tls_cipher_list);
717
	tls_cipher_list = NULL;
718
    }
719
    if (tls_rand_file)
720
	/* tls_rand_file is not malloc()'ed */
721
	RAND_write_file(tls_rand_file);
722
#ifdef DEBUG_OPENSSL_MEM
723
    {
724
    char fname[] = "/tmp/proftpd_memleak_XXXXXX";
725
    int fd;
726
    if ((fd = mkstemp(fname)) != -1) {
727
    	FILE *f = fdopen(fd, "w");
728
        if (f) {
729
	    CRYPTO_mem_leaks_fp(f);
730
	    fclose(f);
731
	}
732
    }
733
    }
734
#endif /* DEBUG_OPENSSL_MEM */
735
}
736
737
static void handle_ssl_error(int error, int line)
738
{
739
    switch (error) {
740
    	case SSL_ERROR_NONE:
741
	    return;
742
	case SSL_ERROR_SSL:
743
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_SSL on line %d!", line);
744
	    break;
745
	case SSL_ERROR_WANT_READ:
746
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_WANT_READ on line %d!", line);
747
	    break;
748
	case SSL_ERROR_WANT_WRITE:
749
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_WANT_WRITE on line %d!", line);
750
	    break;
751
	case SSL_ERROR_WANT_X509_LOOKUP:
752
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_WANT_X509_LOOKUP on line %d!", line);
753
	    break;
754
	case SSL_ERROR_SYSCALL:
755
	    /* ProFTPD is sloppy in checking the return value/errno status from
756
	     * read()/write(), so we must double-check here so we don't generate
757
	     * unnecessary fuzz...
758
	     */
759
	    if (errno == ECONNRESET) /* peer hung up */
760
		return;
761
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_SYSCALL on line %d!", line);
762
	    break;
763
	case SSL_ERROR_ZERO_RETURN:
764
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_ZERO_RETURN on line %d!", line);
765
	    break;
766
	case SSL_ERROR_WANT_CONNECT:
767
	    log_pri(LOG_ERR, "Panic: SSL_ERROR_WANT_CONNECT on line %d!", line);
768
	    break;
769
	default:
770
	    log_pri(LOG_ERR, "Panic: SSL_ERROR %d on line %d!", error, line);
771
	    break;
772
    }
773
    /* if we reply something here, we might just trigger another handle_ssl_error()
774
     * call and loop endlessly...
775
     */
776
    main_exit((void*) LOG_ERR,
777
	      "Unexpected OpenSSL error, disconnected.", (void*) 0, NULL);
778
    /* NOTREACHED */
779
}
780
781
static int select_read(int rfd)
782
/* timeout = 20 seconds */
783
{
784
    fd_set rfds;
785
    struct timeval tv;
786
787
    FD_ZERO(&rfds);
788
    FD_SET(rfd, &rfds);
789
    tv.tv_sec = 20;
790
    tv.tv_usec = 0;
791
    return select(rfd + 1, &rfds, NULL, NULL, &tv);
792
}
793
794
ssize_t tls_read(SSL *ssl, void *buf, size_t count)
795
{
796
    ssize_t c;
797
798
  retry:
799
    c = SSL_read(ssl, buf, count);
800
    if (c < 0) {
801
	int err = SSL_get_error(ssl, c);
802
	/* read(2) returns only the generic error number -1 */
803
	c = -1;
804
	switch (err) {
805
	    case SSL_ERROR_WANT_READ:
806
		/* OpenSSL needs more data from the wire to finish the current block,
807
		 * so we wait a little while for it. */
808
		err = select_read(SSL_get_fd(ssl));
809
		if (err > 0)
810
		    goto retry;
811
		else if (err == 0)
812
		    /* still missing data after timeout. simulate an EINTR and return. */
813
		    errno = EINTR;
814
		/* if err < 0, i.e. some error from the select(), everything is already
815
		 * in place; errno is properly set and this function returns -1. */
816
		break;
817
	    default:
818
		handle_ssl_error(err, __LINE__);
819
		break;
820
	}
821
    }
822
    return c;
823
}
824
825
ssize_t tls_write(SSL *ssl, const void *buf, size_t count)
826
{
827
    ssize_t c;
828
829
    c = SSL_write(ssl, buf, count);
830
    if (c < 0) {
831
	int err = SSL_get_error(ssl, c);
832
	/* write(2) returns only the generic error number -1 */
833
	c = -1;
834
	switch (err) {
835
	    case SSL_ERROR_WANT_WRITE:
836
		/* simulate an EINTR in case OpenSSL wants to write more */
837
		errno = EINTR;
838
		break;
839
	    default:
840
		handle_ssl_error(err, __LINE__);
841
		break;
842
	}
843
    }
844
    return c;
845
}
846
847
int tls_pending(SSL *ssl)
848
{
849
    if (ssl)
850
        return SSL_pending(ssl);
851
    else 
852
        return 0;
853
}
854
855
char *file_fullpath(char *fn)
856
{
857
    static char fp[256];
858
    FILE *file;
859
    char *dir;
860
    
861
    /* check if it is a full path already */
862
    if (strchr(fn, '/')) {
863
	if ((file = fopen(fn, "r"))) {
864
	    fclose(file);
865
	    return fn;
866
	}
867
	else
868
	    return NULL;
869
    }
870
    /* check if it is in current dir */
871
    if ((file = fopen(fn, "r"))) {
872
    	fclose(file);
873
	return fn;
874
    }
875
    if (!(dir = getenv(X509_get_default_cert_dir_env())))	/* $SSL_CERT_DIR */
876
    	dir = (char *)X509_get_default_cert_dir();
877
    snprintf(fp, sizeof(fp), "%s/%s", dir, fn);
878
    if ((file = fopen(fp, "r"))) {
879
    	fclose(file);
880
	return fp;
881
    }
882
    dir = (char *)X509_get_default_private_dir();
883
    snprintf(fp, sizeof(fp), "%s/%s", dir, fn);
884
    if ((file = fopen(fp, "r"))) {
885
    	fclose(file);
886
	return fp;
887
    }
888
    return NULL;
889
}
(-)proftpd-1.2.6rc1.orig/src/x509_to_user.c (+43 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 1999, 2000 Peter 'Luna' Runestig <peter@runestig.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modifi-
6
 * cation, are permitted provided that the following conditions are met:
7
 *
8
 *   o  Redistributions of source code must retain the above copyright notice,
9
 *      this list of conditions and the following disclaimer.
10
 *
11
 *   o  Redistributions in binary form must reproduce the above copyright no-
12
 *      tice, this list of conditions and the following disclaimer in the do-
13
 *      cumentation and/or other materials provided with the distribution.
14
 *
15
 *   o  The names of the contributors may not be used to endorse or promote
16
 *      products derived from this software without specific prior written
17
 *      permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LI-
23
 * ABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN-
24
 * TIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV-
26
 * ER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI-
27
 * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#include <openssl/ssl.h>
32
33
/* x509_to_user() returns 0 if valid userid in 'userid', else 1 */
34
int x509_to_user(X509 *peer_cert, char *userid, int len)
35
{
36
37
    if (!(peer_cert && userid))
38
    	return 1;
39
40
    /* TODO: insert cert => userid translation code here */
41
	
42
    return 1;
43
}
(-)proftpd-1.2.6rc1.orig/src/x509_to_user.c.samp1 (+49 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 1999, 2000 Peter 'Luna' Runestig <peter@runestig.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modifi-
6
 * cation, are permitted provided that the following conditions are met:
7
 *
8
 *   o  Redistributions of source code must retain the above copyright notice,
9
 *      this list of conditions and the following disclaimer.
10
 *
11
 *   o  Redistributions in binary form must reproduce the above copyright no-
12
 *      tice, this list of conditions and the following disclaimer in the do-
13
 *      cumentation and/or other materials provided with the distribution.
14
 *
15
 *   o  The names of the contributors may not be used to endorse or promote
16
 *      products derived from this software without specific prior written
17
 *      permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LI-
23
 * ABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN-
24
 * TIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV-
26
 * ER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI-
27
 * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#include <openssl/ssl.h>
32
33
/* sample that returns a userid in cert's subj UID */
34
/* x509_to_user() returns 0 if valid userid in 'userid', else 1 */
35
int x509_to_user(X509 *peer_cert, char *userid, int len)
36
{
37
    int err;
38
    
39
    if (!(peer_cert && userid))
40
    	return 1;
41
42
    /* userid is in cert subject /UID */
43
    err = X509_NAME_get_text_by_NID(X509_get_subject_name(peer_cert),
44
		NID_uniqueIdentifier, userid, len);
45
    if (err > 0)
46
    	return 0;
47
    else
48
	return 1;
49
}
(-)proftpd-1.2.6rc1.orig/src/x509_to_user.c.samp2 (+104 lines)
Line 0 Link Here
1
/*
2
 * Copyright (c) 1999, 2000 Peter 'Luna' Runestig <peter@runestig.com>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modifi-
6
 * cation, are permitted provided that the following conditions are met:
7
 *
8
 *   o  Redistributions of source code must retain the above copyright notice,
9
 *      this list of conditions and the following disclaimer.
10
 *
11
 *   o  Redistributions in binary form must reproduce the above copyright no-
12
 *      tice, this list of conditions and the following disclaimer in the do-
13
 *      cumentation and/or other materials provided with the distribution.
14
 *
15
 *   o  The names of the contributors may not be used to endorse or promote
16
 *      products derived from this software without specific prior written
17
 *      permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LI-
23
 * ABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUEN-
24
 * TIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEV-
26
 * ER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI-
27
 * LITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28
 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#include <stdio.h>
32
#include <unistd.h>
33
#include <sys/time.h>
34
#include <openssl/ssl.h>
35
36
/* sample that uses SafeGossip's "Certificate Mapping Server"  */
37
38
char *trim(char *s)
39
{
40
	while (isspace(*s))
41
		memmove(s, s + 1, strlen(s + 1) + 1);
42
	while (isspace(s[strlen(s) - 1]))
43
		s[strlen(s) - 1] = 0;
44
	return s;
45
}
46
47
/* x509_to_user() returns 0 if valid userid in 'userid', else 1 */
48
int x509_to_user(X509 *peer_cert, char *userid, int len)
49
{
50
    int pin[2], pout[2], err;
51
    FILE *pfp;
52
    pid_t pid;
53
    fd_set rfds;
54
    struct timeval tv;
55
    
56
    if (!(peer_cert && userid))
57
    	return 1;
58
59
    /* '/usr/sbin/authcert' reads a cert from stdin and writes the userid to stdout. */
60
    if (pipe(pin))
61
    	return 1;
62
    if (pipe(pout))
63
    	return 1;
64
    pid = fork();
65
    if (pid == -1)
66
    	return 1;
67
    else if (pid == 0) {
68
    	/* child */
69
	dup2(pin[0], 0);
70
	close(pin[0]); close(pin[1]);
71
	dup2(pout[1], 1);
72
	execl("/usr/sbin/authcert", "authcert", NULL);
73
	/* normally not reached */
74
	exit(2);
75
    }
76
77
    /* write PEM-formatted cert to subprocess' stdin */
78
    if (!(pfp = fdopen(pin[1], "w")))
79
    	return 1;
80
    PEM_write_X509(pfp, peer_cert);
81
    fclose(pfp);
82
    close(pin[0]);
83
    
84
    /* wait for userid from pout[0] */
85
    FD_ZERO(&rfds);
86
    FD_SET(pout[0], &rfds);
87
    tv.tv_sec = 20;
88
    tv.tv_usec = 0;
89
    err = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
90
    
91
    if (err < 1) {
92
    	close(pout[0]); close(pout[1]);
93
    	return 1;
94
    }
95
    err = read(pout[0], userid, len - 1);
96
    close(pout[0]); close(pout[1]);
97
    if (err) {
98
    	userid[err] = 0;
99
	trim(userid);
100
	return 0;
101
    }
102
    else
103
    	return 1;
104
}

Return to bug 6898