Blame SOURCES/fetchmail-6.3.24-ssl-backport.patch

820307
diff -up fetchmail-6.3.24/configure.ac.orig fetchmail-6.3.24/configure.ac
820307
--- fetchmail-6.3.24/configure.ac.orig	2012-12-23 16:40:43.000000000 +0100
820307
+++ fetchmail-6.3.24/configure.ac	2017-03-07 12:35:18.961038361 +0100
820307
@@ -803,6 +803,7 @@ fi
820307
 
820307
 case "$LIBS" in *-lssl*)
820307
 	AC_CHECK_DECLS([SSLv2_client_method],,,[#include <openssl/ssl.h>])
820307
+	AC_CHECK_DECLS([SSLv3_client_method],,,[#include <openssl/ssl.h>])
820307
 	;;
820307
 esac
820307
 
820307
diff -up fetchmail-6.3.24/fetchmail.c.orig fetchmail-6.3.24/fetchmail.c
820307
--- fetchmail-6.3.24/fetchmail.c.orig	2012-12-14 00:56:41.000000000 +0100
820307
+++ fetchmail-6.3.24/fetchmail.c	2017-03-07 12:35:18.962038368 +0100
820307
@@ -263,6 +263,12 @@ int main(int argc, char **argv)
820307
 #ifdef SSL_ENABLE
820307
 	"+SSL"
820307
 #endif
820307
+#if HAVE_DECL_SSLV2_CLIENT_METHOD + 0 == 0
820307
+ 	"-SSLv2"
820307
+#endif
820307
+#if HAVE_DECL_SSLV3_CLIENT_METHOD + 0 == 0
820307
+ 	"-SSLv3"
820307
+#endif
820307
 #ifdef OPIE_ENABLE
820307
 	"+OPIE"
820307
 #endif /* OPIE_ENABLE */
820307
diff -up fetchmail-6.3.24/fetchmail.h.orig fetchmail-6.3.24/fetchmail.h
820307
--- fetchmail-6.3.24/fetchmail.h.orig	2012-12-14 00:56:41.000000000 +0100
820307
+++ fetchmail-6.3.24/fetchmail.h	2017-03-07 12:35:18.962038368 +0100
820307
@@ -771,9 +771,9 @@ int servport(const char *service);
820307
 int fm_getaddrinfo(const char *node, const char *serv, const struct addrinfo *hints, struct addrinfo **res);
820307
 void fm_freeaddrinfo(struct addrinfo *ai);
820307
 
820307
-/* prototypes from tls.c */
820307
-int maybe_tls(struct query *ctl);
820307
-int must_tls(struct query *ctl);
820307
+/* prototypes from starttls.c */
820307
+int maybe_starttls(struct query *ctl);
820307
+int must_starttls(struct query *ctl);
820307
 
820307
 /* prototype from rfc822valid.c */
820307
 int rfc822_valid_msgid(const unsigned char *);
820307
diff -up fetchmail-6.3.24/fetchmail.man.orig fetchmail-6.3.24/fetchmail.man
820307
--- fetchmail-6.3.24/fetchmail.man.orig	2012-12-13 22:50:38.000000000 +0100
820307
+++ fetchmail-6.3.24/fetchmail.man	2017-03-07 12:35:18.968038409 +0100
820307
@@ -412,23 +412,22 @@ from. The folder information is written
820307
 .B \-\-ssl
820307
 (Keyword: ssl)
820307
 .br
820307
-Causes the connection to the mail server to be encrypted
820307
-via SSL.  Connect to the server using the specified base protocol over a
820307
-connection secured by SSL. This option defeats opportunistic starttls
820307
-negotiation. It is highly recommended to use \-\-sslproto 'SSL3'
820307
-\-\-sslcertck to validate the certificates presented by the server and
820307
-defeat the obsolete SSLv2 negotiation. More information is available in
820307
-the \fIREADME.SSL\fP file that ships with fetchmail.
820307
-.IP
820307
-Note that fetchmail may still try to negotiate SSL through starttls even
820307
-if this option is omitted. You can use the \-\-sslproto option to defeat
820307
-this behavior or tell fetchmail to negotiate a particular SSL protocol.
820307
+Causes the connection to the mail server to be encrypted via SSL, by
820307
+negotiating SSL directly after connecting (SSL-wrapped mode).  It is
820307
+highly recommended to use \-\-sslcertck to validate the certificates
820307
+presented by the server.  Please see the description of \-\-sslproto
820307
+below!  More information is available in the \fIREADME.SSL\fP file that
820307
+ships with fetchmail.
820307
+.IP
820307
+Note that even if this option is omitted, fetchmail may still negotiate
820307
+SSL in-band for POP3 or IMAP, through the STLS or STARTTLS feature.  You
820307
+can use the \-\-sslproto option to modify that behavior.
820307
 .IP
820307
 If no port is specified, the connection is attempted to the well known
820307
 port of the SSL version of the base protocol.  This is generally a
820307
 different port than the port used by the base protocol.  For IMAP, this
820307
 is port 143 for the clear protocol and port 993 for the SSL secured
820307
-protocol, for POP3, it is port 110 for the clear text and port 995 for
820307
+protocol; for POP3, it is port 110 for the clear text and port 995 for
820307
 the encrypted variant.
820307
 .IP
820307
 If your system lacks the corresponding entries from /etc/services, see
820307
@@ -470,39 +469,77 @@ cause some complications in daemon mode.
820307
 .IP
820307
 Also see \-\-sslcert above.
820307
 .TP
820307
-.B \-\-sslproto <name>
820307
+.B \-\-sslproto <value>
820307
 (Keyword: sslproto)
820307
 .br
820307
-Forces an SSL/TLS protocol. Possible values are \fB''\fP,
820307
-\&'\fBSSL2\fP' (not supported on all systems),
820307
-\&'\fBSSL23\fP', (use of these two values is discouraged
820307
-and should only be used as a last resort) \&'\fBSSL3\fP', and
820307
-\&'\fBTLS1\fP'.  The default behaviour if this option is unset is: for
820307
-connections without \-\-ssl, use \&'\fBTLS1\fP' so that fetchmail will
820307
-opportunistically try STARTTLS negotiation with TLS1. You can configure
820307
-this option explicitly if the default handshake (TLS1 if \-\-ssl is not
820307
-used) does not work for your server.
820307
-.IP
820307
-Use this option with '\fBTLS1\fP' value to enforce a STARTTLS
820307
-connection. In this mode, it is highly recommended to also use
820307
-\-\-sslcertck (see below).  Note that this will then cause fetchmail
820307
-v6.3.19 to force STARTTLS negotiation even if it is not advertised by
820307
-the server.
820307
-.IP
820307
-To defeat opportunistic TLSv1 negotiation when the server advertises
820307
-STARTTLS or STLS, and use a cleartext connection use \fB''\fP.  This
820307
-option, even if the argument is the empty string, will also suppress the
820307
-diagnostic 'SERVER: opportunistic upgrade to TLS.' message in verbose
820307
-mode. The default is to try appropriate protocols depending on context.
820307
+This option has a dual use, out of historic fetchmail behaviour. It
820307
+controls both the SSL/TLS protocol version and, if \-\-ssl is not
820307
+specified, the STARTTLS behaviour (upgrading the protocol to an SSL or
820307
+TLS connection in-band). Some other options may however make TLS
820307
+mandatory.
820307
+.PP
820307
+Only if this option and \-\-ssl are both missing for a poll, there will
820307
+be opportunistic TLS for POP3 and IMAP, where fetchmail will attempt to
820307
+upgrade to TLSv1 or newer.
820307
+.PP
820307
+Recognized values for \-\-sslproto are given below. You should normally
820307
+chose one of the auto-negotiating options, i. e. '\fBauto\fP' or one of
820307
+the options ending in a plus (\fB+\fP) character. Note that depending
820307
+on OpenSSL library version and configuration, some options cause
820307
+run-time errors because the requested SSL or TLS versions are not
820307
+supported by the particular installed OpenSSL library.
820307
+.RS
820307
+.IP "\fB''\fP, the empty string"
820307
+Disable STARTTLS. If \-\-ssl is given for the same server, log an error
820307
+and pretend that '\fBauto\fP' had been used instead.
820307
+.IP '\fBauto\fP'
820307
+(default). Require TLS. Auto-negotiate TLSv1 or newer, disable SSLv3 downgrade.
820307
+(previous releases of fetchmail have auto-negotiated all protocols that
820307
+their OpenSSL library supported, including the broken SSLv3).
820307
+.IP "\&'\fBSSL23\fP'
820307
+see '\fBauto\fP'.
820307
+.IP \&'\fBSSL2\fP'
820307
+Require SSLv2 exactly. SSLv2 is broken, not supported on all systems, avoid it
820307
+if possible. This will make fetchmail negotiate SSLv2 only, and is the
820307
+only way to have fetchmail permit SSLv2.
820307
+.IP \&'\fBSSL3\fP'
820307
+Require SSLv3 exactly. SSLv3 is broken, not supported on all systems, avoid it
820307
+if possible. This will make fetchmail negotiate SSLv3 only, and is the
820307
+only way besides '\fBSSL3+\fP' to have fetchmail permit SSLv3.
820307
+.IP \&'\fBSSL3+\fP'
820307
+same as '\fBauto\fP', but permit SSLv3 as well. This is the only way
820307
+besides '\fBSSL3\fP' to have fetchmail permit SSLv3.
820307
+.IP \&'\fBTLS1\fP'
820307
+Require TLSv1. This does not negotiate TLSv1.1 or newer, and is
820307
+discouraged. Replace by TLS1+ unless the latter chokes your server.
820307
+.IP \&'\fBTLS1+\fP'
820307
+See '\fBauto\fP'.
820307
+.IP \&'\fBTLS1.1\fP'
820307
+Require TLS v1.1 exactly.
820307
+.IP \&'\fBTLS1.1+\fP'
820307
+Require TLS. Auto-negotiate TLSv1.1 or newer.
820307
+.IP \&'\fBTLS1.2\fP'
820307
+Require TLS v1.2 exactly.
820307
+.IP '\fBTLS1.2+\fP'
820307
+Require TLS. Auto-negotiate TLSv1.2 or newer.
820307
+.IP "Unrecognized parameters"
820307
+are treated the same as '\fBauto\fP'.
820307
+.RE
820307
+.IP
820307
+NOTE: you should hardly ever need to use anything other than '' (to
820307
+force an unencrypted connection) or 'auto' (to enforce TLS).
820307
 .TP
820307
 .B \-\-sslcertck
820307
 (Keyword: sslcertck)
820307
 .br
820307
-Causes fetchmail to strictly check the server certificate against a set of
820307
-local trusted certificates (see the \fBsslcertfile\fP and \fBsslcertpath\fP
820307
-options). If the server certificate cannot be obtained or is not signed by one
820307
-of the trusted ones (directly or indirectly), the SSL connection will fail,
820307
-regardless of the \fBsslfingerprint\fP option.
820307
+Causes fetchmail to require that SSL/TLS be used and disconnect if it
820307
+can not successfully negotiate SSL or TLS, or if it cannot successfully
820307
+verify and validate the certificate and follow it to a trust anchor (or
820307
+trusted root certificate). The trust anchors are given as a set of local
820307
+trusted certificates (see the \fBsslcertfile\fP and \fBsslcertpath\fP
820307
+options). If the server certificate cannot be obtained or is not signed
820307
+by one of the trusted ones (directly or indirectly), fetchmail will
820307
+disconnect, regardless of the \fBsslfingerprint\fP option.
820307
 .IP
820307
 Note that CRL (certificate revocation lists) are only supported in
820307
 OpenSSL 0.9.7 and newer! Your system clock should also be reasonably
820307
@@ -1202,31 +1239,33 @@ capability response. Specify a user opti
820307
 username and the part to the right as the NTLM domain.
820307
 
820307
 .SS Secure Socket Layers (SSL) and Transport Layer Security (TLS)
820307
+.PP All retrieval protocols can use SSL or TLS wrapping for the
820307
+transport. Additionally, POP3 and IMAP retrival can also negotiate
820307
+SSL/TLS by means of STARTTLS (or STLS).
820307
 .PP
820307
 Note that fetchmail currently uses the OpenSSL library, which is
820307
 severely underdocumented, so failures may occur just because the
820307
 programmers are not aware of OpenSSL's requirement of the day.
820307
 For instance, since v6.3.16, fetchmail calls
820307
 OpenSSL_add_all_algorithms(), which is necessary to support certificates
820307
-with SHA256 on OpenSSL 0.9.8 -- this information is deeply hidden in the
820307
-documentation and not at all obvious.  Please do not hesitate to report
820307
-subtle SSL failures.
820307
-.PP
820307
-You can access SSL encrypted services by specifying the \-\-ssl option.
820307
-You can also do this using the "ssl" user option in the .fetchmailrc
820307
-file. With SSL encryption enabled, queries are initiated over a
820307
-connection after negotiating an SSL session, and the connection fails if
820307
-SSL cannot be negotiated.  Some services, such as POP3 and IMAP, have
820307
+using SHA256 on OpenSSL 0.9.8 -- this information is deeply hidden in
820307
+the documentation and not at all obvious.  Please do not hesitate to
820307
+report subtle SSL failures.
820307
+.PP
820307
+You can access SSL encrypted services by specifying the options starting
820307
+with \-\-ssl, such as \-\-ssl, \-\-sslproto, \-\-sslcertck, and others.
820307
+You can also do this using the corresponding user options in the .fetchmailrc
820307
+file.  Some services, such as POP3 and IMAP, have
820307
 different well known ports defined for the SSL encrypted services.  The
820307
 encrypted ports will be selected automatically when SSL is enabled and
820307
-no explicit port is specified. The \-\-sslproto 'SSL3' option should be
820307
-used to select the SSLv3 protocol (default if unset: v2 or v3).  Also,
820307
-the \-\-sslcertck command line or sslcertck run control file option
820307
-should be used to force strict certificate checking - see below.
820307
+no explicit port is specified.   Also, the \-\-sslcertck command line or
820307
+sslcertck run control file option should be used to force strict
820307
+certificate checking - see below.
820307
 .PP
820307
 If SSL is not configured, fetchmail will usually opportunistically try to use
820307
-STARTTLS. STARTTLS can be enforced by using \-\-sslproto "TLS1". TLS
820307
-connections use the same port as the unencrypted version of the
820307
+STARTTLS. STARTTLS can be enforced by using \-\-sslproto\~auto and
820307
+defeated by using \-\-sslproto\~''.
820307
+TLS connections use the same port as the unencrypted version of the
820307
 protocol and negotiate TLS via special command. The \-\-sslcertck
820307
 command line or sslcertck run control file option should be used to
820307
 force strict certificate checking - see below.
820307
diff -up fetchmail-6.3.24/imap.c.orig fetchmail-6.3.24/imap.c
820307
--- fetchmail-6.3.24/imap.c.orig	2012-12-13 22:12:26.000000000 +0100
820307
+++ fetchmail-6.3.24/imap.c	2017-03-07 12:35:18.962038368 +0100
820307
@@ -405,6 +405,8 @@ static int imap_getauth(int sock, struct
820307
 /* apply for connection authorization */
820307
 {
820307
     int ok = 0;
820307
+    char *commonname;
820307
+
820307
     (void)greeting;
820307
 
820307
     /*
820307
@@ -429,25 +431,21 @@ static int imap_getauth(int sock, struct
820307
         return(PS_SUCCESS);
820307
     }
820307
 
820307
-#ifdef SSL_ENABLE
820307
-    if (maybe_tls(ctl)) {
820307
-	char *commonname;
820307
-
820307
-	commonname = ctl->server.pollname;
820307
-	if (ctl->server.via)
820307
-	    commonname = ctl->server.via;
820307
-	if (ctl->sslcommonname)
820307
-	    commonname = ctl->sslcommonname;
820307
+    commonname = ctl->server.pollname;
820307
+    if (ctl->server.via)
820307
+       commonname = ctl->server.via;
820307
+    if (ctl->sslcommonname)
820307
+       commonname = ctl->sslcommonname;
820307
 
820307
-	if (strstr(capabilities, "STARTTLS")
820307
-		|| must_tls(ctl)) /* if TLS is mandatory, ignore capabilities */
820307
+#ifdef SSL_ENABLE
820307
+    if (maybe_starttls(ctl)) {
820307
+       if ((strstr(capabilities, "STARTTLS") && maybe_starttls(ctl))
820307
+               || must_starttls(ctl)) /* if TLS is mandatory, ignore capabilities */
820307
 	{
820307
-	    /* Use "tls1" rather than ctl->sslproto because tls1 is the only
820307
-	     * protocol that will work with STARTTLS.  Don't need to worry
820307
-	     * whether TLS is mandatory or opportunistic unless SSLOpen() fails
820307
-	     * (see below). */
820307
+	    /* Don't need to worry whether TLS is mandatory or
820307
+	     * opportunistic unless SSLOpen() fails (see below). */
820307
 	    if (gen_transact(sock, "STARTTLS") == PS_SUCCESS
820307
-		    && (set_timeout(mytimeout), SSLOpen(sock, ctl->sslcert, ctl->sslkey, "tls1", ctl->sslcertck,
820307
+		    && (set_timeout(mytimeout), SSLOpen(sock, ctl->sslcert, ctl->sslkey, ctl->sslproto, ctl->sslcertck,
820307
 			ctl->sslcertfile, ctl->sslcertpath, ctl->sslfingerprint, commonname,
820307
 			ctl->server.pollname, &ctl->remotename)) != -1)
820307
 	    {
820307
@@ -470,7 +468,7 @@ static int imap_getauth(int sock, struct
820307
 		{
820307
 		    report(stdout, GT_("%s: upgrade to TLS succeeded.\n"), commonname);
820307
 		}
820307
-	    } else if (must_tls(ctl)) {
820307
+	    } else if (must_starttls(ctl)) {
820307
 		/* Config required TLS but we couldn't guarantee it, so we must
820307
 		 * stop. */
820307
 		set_timeout(0);
820307
@@ -492,6 +490,10 @@ static int imap_getauth(int sock, struct
820307
 		/* Usable.  Proceed with authenticating insecurely. */
820307
 	    }
820307
 	}
820307
+    } else {
820307
+	if (strstr(capabilities, "STARTTLS") && outlevel >= O_VERBOSE) {
820307
+	    report(stdout, GT_("%s: WARNING: server offered STARTTLS but sslproto '' given.\n"), commonname);
820307
+	}
820307
     }
820307
 #endif /* SSL_ENABLE */
820307
 
820307
diff -up fetchmail-6.3.24/Makefile.am.orig fetchmail-6.3.24/Makefile.am
820307
--- fetchmail-6.3.24/Makefile.am.orig	2012-12-23 16:40:57.000000000 +0100
820307
+++ fetchmail-6.3.24/Makefile.am	2017-03-07 12:35:18.962038368 +0100
820307
@@ -31,7 +31,7 @@ libfm_a_SOURCES=	xmalloc.c base64.c rfc8
820307
 			servport.c ntlm.h smbbyteorder.h smbdes.h smbmd4.h \
820307
 			smbencrypt.h smbdes.c smbencrypt.c smbmd4.c smbutil.c \
820307
 			libesmtp/gethostbyname.h libesmtp/gethostbyname.c \
820307
-			smbtypes.h fm_getaddrinfo.c tls.c rfc822valid.c \
820307
+			smbtypes.h fm_getaddrinfo.c starttls.c rfc822valid.c \
820307
 			xmalloc.h sdump.h sdump.c x509_name_match.c \
820307
 			fm_strl.h md5c.c
820307
 if NTLM_ENABLE
820307
diff -up fetchmail-6.3.24/Makefile.in.orig fetchmail-6.3.24/Makefile.in
820307
--- fetchmail-6.3.24/Makefile.in.orig	2012-12-23 17:29:56.000000000 +0100
820307
+++ fetchmail-6.3.24/Makefile.in	2017-03-07 12:35:18.963038375 +0100
820307
@@ -97,14 +97,14 @@ am__libfm_a_SOURCES_DIST = xmalloc.c bas
820307
 	rfc2047e.c servport.c ntlm.h smbbyteorder.h smbdes.h smbmd4.h \
820307
 	smbencrypt.h smbdes.c smbencrypt.c smbmd4.c smbutil.c \
820307
 	libesmtp/gethostbyname.h libesmtp/gethostbyname.c smbtypes.h \
820307
-	fm_getaddrinfo.c tls.c rfc822valid.c xmalloc.h sdump.h sdump.c \
820307
+	fm_getaddrinfo.c starttls.c rfc822valid.c xmalloc.h sdump.h sdump.c \
820307
 	x509_name_match.c fm_strl.h md5c.c ntlmsubr.c
820307
 @NTLM_ENABLE_TRUE@am__objects_1 = ntlmsubr.$(OBJEXT)
820307
 am_libfm_a_OBJECTS = xmalloc.$(OBJEXT) base64.$(OBJEXT) \
820307
 	rfc822.$(OBJEXT) report.$(OBJEXT) rfc2047e.$(OBJEXT) \
820307
 	servport.$(OBJEXT) smbdes.$(OBJEXT) smbencrypt.$(OBJEXT) \
820307
 	smbmd4.$(OBJEXT) smbutil.$(OBJEXT) gethostbyname.$(OBJEXT) \
820307
-	fm_getaddrinfo.$(OBJEXT) tls.$(OBJEXT) rfc822valid.$(OBJEXT) \
820307
+	fm_getaddrinfo.$(OBJEXT) starttls.$(OBJEXT) rfc822valid.$(OBJEXT) \
820307
 	sdump.$(OBJEXT) x509_name_match.$(OBJEXT) md5c.$(OBJEXT) \
820307
 	$(am__objects_1)
820307
 libfm_a_OBJECTS = $(am_libfm_a_OBJECTS)
820307
@@ -483,7 +483,7 @@ libfm_a_SOURCES = xmalloc.c base64.c rfc
820307
 	servport.c ntlm.h smbbyteorder.h smbdes.h smbmd4.h \
820307
 	smbencrypt.h smbdes.c smbencrypt.c smbmd4.c smbutil.c \
820307
 	libesmtp/gethostbyname.h libesmtp/gethostbyname.c smbtypes.h \
820307
-	fm_getaddrinfo.c tls.c rfc822valid.c xmalloc.h sdump.h sdump.c \
820307
+	fm_getaddrinfo.c starttls.c rfc822valid.c xmalloc.h sdump.h sdump.c \
820307
 	x509_name_match.c fm_strl.h md5c.c $(am__append_1)
820307
 libfm_a_LIBADD = $(EXTRAOBJ)
820307
 libfm_a_DEPENDENCIES = $(EXTRAOBJ)
820307
diff -up fetchmail-6.3.24/NEWS.orig fetchmail-6.3.24/NEWS
820307
--- fetchmail-6.3.24/NEWS.orig	2017-03-07 12:35:18.958038341 +0100
820307
+++ fetchmail-6.3.24/NEWS	2017-03-07 12:35:18.968038409 +0100
820307
@@ -56,6 +56,29 @@ removed from a 6.4.0 or newer release.)
820307
 
820307
 --------------------------------------------------------------------------------
820307
 
820307
+## SECURITY FIXES THAT AFFECT BEHAVIOUR AND MAY WANT RECONFIGURATION
820307
+* Fetchmail no longer attempts to negotiate SSLv3 by default,
820307
+  even with --sslproto ssl23. Fetchmail can now use SSLv3, or TLSv1.1 or a newer
820307
+  TLS version, with STLS/STARTTLS (it would previously force TLSv1.0).  If the
820307
+  OpenSSL version used at build and run-time supports these versions, -sslproto
820307
+  ssl3 can be used to enable this specific version.  Doing so is discouraged
820307
+  because these protocols are broken.
820307
+
820307
+  Along the lines suggested - as patch - by Kurt Roeckx, Debian Bug #768843.
820307
+
820307
+  While this change is supposed to be compatible with common configurations,
820307
+  users are advised to change all explicit --sslproto ssl2, --sslproto
820307
+  ssl3, --sslproto tls1 to --sslproto auto, so that they can enable TLSv1.1 and
820307
+  TLSv1.2 on systems with OpenSSL 1.0.1 or newer.
820307
+
820307
+  The --sslproto option now understands the values auto, tls1+, tls1.1+,
820307
+  tls1.2+ (case insensitively).
820307
+
820307
+## CHANGES
820307
+* Fetchmail now supports --sslproto auto and --sslproto tls1+ (same as ssl23).
820307
+* --sslproto tls1.1+ and tls1.2+ are now supported for auto-negotiation with a
820307
+  minimum specified TLS protocol version.
820307
+
820307
 fetchmail-6.3.24 (released 2012-12-23, 26108 LoC):
820307
 
820307
 # NOTE THAT THE RELEASE OF FUTURE FETCHMAIL 6.3.X VERSIONS IS UNCLEAR.
820307
diff -up fetchmail-6.3.24/pop3.c.orig fetchmail-6.3.24/pop3.c
820307
--- fetchmail-6.3.24/pop3.c.orig	2012-12-13 22:50:38.000000000 +0100
820307
+++ fetchmail-6.3.24/pop3.c	2017-03-07 12:35:18.963038375 +0100
820307
@@ -281,6 +281,7 @@ static int pop3_getauth(int sock, struct
820307
 #endif /* OPIE_ENABLE */
820307
 #ifdef SSL_ENABLE
820307
     flag connection_may_have_tls_errors = FALSE;
820307
+    char *commonname;
820307
 #endif /* SSL_ENABLE */
820307
 
820307
     done_capa = FALSE;
820307
@@ -393,7 +394,7 @@ static int pop3_getauth(int sock, struct
820307
 		(ctl->server.authenticate == A_KERBEROS_V5) ||
820307
 		(ctl->server.authenticate == A_OTP) ||
820307
 		(ctl->server.authenticate == A_CRAM_MD5) ||
820307
-		maybe_tls(ctl))
820307
+		maybe_starttls(ctl))
820307
 	{
820307
 	    if ((ok = capa_probe(sock)) != PS_SUCCESS)
820307
 		/* we are in STAGE_GETAUTH => failure is PS_AUTHFAIL! */
820307
@@ -406,12 +407,12 @@ static int pop3_getauth(int sock, struct
820307
 		    (ok == PS_SOCKET && !ctl->wehaveauthed))
820307
 		{
820307
 #ifdef SSL_ENABLE
820307
-		    if (must_tls(ctl)) {
820307
+		    if (must_starttls(ctl)) {
820307
 			/* fail with mandatory STLS without repoll */
820307
 			report(stderr, GT_("TLS is mandatory for this session, but server refused CAPA command.\n"));
820307
 			report(stderr, GT_("The CAPA command is however necessary for TLS.\n"));
820307
 			return ok;
820307
-		    } else if (maybe_tls(ctl)) {
820307
+		    } else if (maybe_starttls(ctl)) {
820307
 			/* defeat opportunistic STLS */
820307
 			xfree(ctl->sslproto);
820307
 			ctl->sslproto = xstrdup("");
820307
@@ -431,24 +432,19 @@ static int pop3_getauth(int sock, struct
820307
 	}
820307
 
820307
 #ifdef SSL_ENABLE
820307
-	if (maybe_tls(ctl)) {
820307
-	    char *commonname;
820307
+	commonname = ctl->server.pollname;
820307
+	if (ctl->server.via)
820307
+	    commonname = ctl->server.via;
820307
+	if (ctl->sslcommonname)
820307
+	   commonname = ctl->sslcommonname;
820307
 
820307
-	    commonname = ctl->server.pollname;
820307
-	    if (ctl->server.via)
820307
-		commonname = ctl->server.via;
820307
-	    if (ctl->sslcommonname)
820307
-		commonname = ctl->sslcommonname;
820307
-
820307
-	   if (has_stls
820307
-		   || must_tls(ctl)) /* if TLS is mandatory, ignore capabilities */
820307
+	if (maybe_starttls(ctl)) {
820307
+	   if (has_stls || must_starttls(ctl)) /* if TLS is mandatory, ignore capabilities */
820307
 	   {
820307
-	       /* Use "tls1" rather than ctl->sslproto because tls1 is the only
820307
-		* protocol that will work with STARTTLS.  Don't need to worry
820307
-		* whether TLS is mandatory or opportunistic unless SSLOpen() fails
820307
-		* (see below). */
820307
+	       /* Don't need to worry whether TLS is mandatory or
820307
+	        * opportunistic unless SSLOpen() fails (see below). */
820307
 	       if (gen_transact(sock, "STLS") == PS_SUCCESS
820307
-		       && (set_timeout(mytimeout), SSLOpen(sock, ctl->sslcert, ctl->sslkey, "tls1", ctl->sslcertck,
820307
+		       && (set_timeout(mytimeout), SSLOpen(sock, ctl->sslcert, ctl->sslkey, ctl->sslproto, ctl->sslcertck,
820307
 			   ctl->sslcertfile, ctl->sslcertpath, ctl->sslfingerprint, commonname,
820307
 			   ctl->server.pollname, &ctl->remotename)) != -1)
820307
 	       {
820307
@@ -475,7 +471,7 @@ static int pop3_getauth(int sock, struct
820307
 		   {
820307
 		       report(stdout, GT_("%s: upgrade to TLS succeeded.\n"), commonname);
820307
 		   }
820307
-	       } else if (must_tls(ctl)) {
820307
+	       } else if (must_starttls(ctl)) {
820307
 		   /* Config required TLS but we couldn't guarantee it, so we must
820307
 		    * stop. */
820307
 		   set_timeout(0);
820307
@@ -495,7 +491,11 @@ static int pop3_getauth(int sock, struct
820307
 		   }
820307
 	       }
820307
 	   }
820307
-	} /* maybe_tls() */
820307
+	} else { /* maybe_starttls() */
820307
+	    if (has_stls && outlevel >= O_VERBOSE) {
820307
+	        report(stdout, GT_("%s: WARNING: server offered STLS, but sslproto '' given.\n"), commonname);
820307
+	    }
820307
+	} /* maybe_starttls() */
820307
 #endif /* SSL_ENABLE */
820307
 
820307
 	/*
820307
diff -up fetchmail-6.3.24/README.SSL.orig fetchmail-6.3.24/README.SSL
820307
--- fetchmail-6.3.24/README.SSL.orig	2011-08-16 13:24:53.000000000 +0200
820307
+++ fetchmail-6.3.24/README.SSL	2017-03-07 12:35:18.963038375 +0100
820307
@@ -11,36 +11,48 @@ specific to fetchmail.
820307
 In case of troubles, mail the README.SSL-SERVER file to your ISP and 
820307
 have them check their server configuration against it.
820307
 
820307
-Unfortunately, fetchmail confuses SSL/TLS protocol levels with whether 
820307
-a service needs to use in-band negotiation (STLS/STARTTLS for POP3/IMAP4) or is 
820307
-totally SSL-wrapped on a separate port.  For compatibility reasons, this cannot 
820307
-be fixed in a bugfix release.
820307
+Unfortunately, fetchmail confuses SSL/TLS protocol levels with whether a
820307
+service needs to use in-band negotiation (STLS/STARTTLS for POP3/IMAP4)
820307
+or is totally SSL-wrapped on a separate port.  For compatibility
820307
+reasons, this cannot be fixed in a bugfix or minor release.
820307
 
820307
 	-- Matthias Andree, 2009-05-09
820307
 
820307
+Also, fetchmail 6.4.0 and newer releases (this is also true for this release,
820307
+as the changes were backported from upstream - noted by Red Hat) changed
820307
+some of the semantics as the result of a bug-fix, and will auto-negotiate
820307
+TLSv1 or newer only. If your server does not support this, you may have
820307
+to specify --sslproto ssl3.  This is in order to prefer the newer TLS
820307
+protocols, because SSLv2 and v3 are broken.
820307
+
820307
+       -- Matthias Andree, 2015-01-16
820307
+
820307
 
820307
 Quickstart
820307
 ----------
820307
 
820307
+Use an up-to-date release of OpenSSL 1.0.1 or newer, so as to get
820307
+TLSv1.2 support.
820307
+
820307
 For use of SSL or TLS with in-band negotiation on the regular service's port, 
820307
 i. e. with STLS or STARTTLS, use these command line options
820307
 
820307
-    --sslproto tls1 --sslcertck
820307
+    --sslproto auto --sslcertck
820307
 
820307
 or these options in the rcfile (after the respective "user"... options)
820307
 
820307
-      sslproto tls1   sslcertck
820307
+      sslproto auto   sslcertck
820307
 
820307
 
820307
 For use of SSL or TLS on a separate port, if the whole TCP connection is 
820307
-SSL-encrypted from the very beginning, use these command line options (in the 
820307
-rcfile, omit all leading "--"):
820307
+SSL-encrypted from the very beginning (SSL- or TLS-wrapped), use these
820307
+command line options (in the rcfile, omit all leading "--"):
820307
 
820307
-    --ssl --sslproto ssl3 --sslcertck
820307
+    --ssl --sslproto auto --sslcertck
820307
 
820307
 or these options in the rcfile (after the respective "user"... options)
820307
 
820307
-      ssl   sslproto ssl3   sslcertck
820307
+      ssl   sslproto auto   sslcertck
820307
 
820307
 
820307
 Background and use (long version :-))
820307
diff -up fetchmail-6.3.24/socket.c.orig fetchmail-6.3.24/socket.c
820307
--- fetchmail-6.3.24/socket.c.orig	2012-12-13 23:32:29.000000000 +0100
820307
+++ fetchmail-6.3.24/socket.c	2017-03-07 12:41:24.558502332 +0100
820307
@@ -844,6 +844,9 @@ int SSLOpen(int sock, char *mycert, char
820307
 {
820307
         struct stat randstat;
820307
         int i;
820307
+	/* disable SSLv2 and SSLv3 by default. SSLv2 can be enabled with '--sslproto ssl2'.
820307
+	   SSLv3 can be enabled with '--sslproto ssl3' or '--sslproto ssl3+' */
820307
+        int avoid_ssl_versions = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3;
820307
 	long sslopts = SSL_OP_ALL;
820307
 
820307
 	SSL_load_error_strings();
820307
@@ -873,28 +876,68 @@ int SSLOpen(int sock, char *mycert, char
820307
 
820307
 	/* Make sure a connection referring to an older context is not left */
820307
 	_ssl_context[sock] = NULL;
820307
-	if(myproto) {
820307
-		if(!strcasecmp("ssl2",myproto)) {
820307
+        if(myproto) {
820307
+                if(!strcasecmp("ssl2",myproto)) {
820307
 #if HAVE_DECL_SSLV2_CLIENT_METHOD + 0 > 0
820307
-			_ctx[sock] = SSL_CTX_new(SSLv2_client_method());
820307
+                        _ctx[sock] = SSL_CTX_new(SSLv2_client_method());
820307
 #else
820307
-			report(stderr, GT_("Your operating system does not support SSLv2.\n"));
820307
-			return -1;
820307
+                        report(stderr, GT_("Your OpenSSL version does not support SSLv2.\n"));
820307
+                        return -1;
820307
 #endif
820307
-		} else if(!strcasecmp("ssl3",myproto)) {
820307
-			_ctx[sock] = SSL_CTX_new(SSLv3_client_method());
820307
-		} else if(!strcasecmp("tls1",myproto)) {
820307
-			_ctx[sock] = SSL_CTX_new(TLSv1_client_method());
820307
-		} else if (!strcasecmp("ssl23",myproto)) {
820307
-			myproto = NULL;
820307
-		} else {
820307
-			fprintf(stderr,GT_("Invalid SSL protocol '%s' specified, using default (SSLv23).\n"), myproto);
820307
-			myproto = NULL;
820307
-		}
820307
-	}
820307
-	if(!myproto) {
820307
-		_ctx[sock] = SSL_CTX_new(SSLv23_client_method());
820307
-	}
820307
+                        avoid_ssl_versions &= ~SSL_OP_NO_SSLv2;
820307
+                } else if(!strcasecmp("ssl3",myproto)) {
820307
+#if HAVE_DECL_SSLV3_CLIENT_METHOD + 0 > 0
820307
+                        _ctx[sock] = SSL_CTX_new(SSLv3_client_method());
820307
+#else
820307
+                        report(stderr, GT_("Your OpenSSL version does not support SSLv3.\n"));
820307
+                        return -1;
820307
+#endif
820307
+                        avoid_ssl_versions &= ~SSL_OP_NO_SSLv3;
820307
+                } else if(!strcasecmp("ssl3+",myproto)) {
820307
+                        avoid_ssl_versions &= ~SSL_OP_NO_SSLv3;
820307
+                        myproto = NULL;
820307
+                } else if(!strcasecmp("tls1",myproto)) {
820307
+                        _ctx[sock] = SSL_CTX_new(TLSv1_client_method());
820307
+                } else if(!strcasecmp("tls1+",myproto)) {
820307
+                        myproto = NULL;
820307
+#if defined(TLS1_1_VERSION) && TLS_MAX_VERSION >= TLS1_1_VERSION
820307
+                } else if(!strcasecmp("tls1.1",myproto)) {
820307
+                        _ctx[sock] = SSL_CTX_new(TLSv1_1_client_method());
820307
+                } else if(!strcasecmp("tls1.1+",myproto)) {
820307
+                        myproto = NULL;
820307
+                        avoid_ssl_versions |= SSL_OP_NO_TLSv1;
820307
+#else
820307
+                } else if(!strcasecmp("tls1.1",myproto) || !strcasecmp("tls1.1+", myproto)) {
820307
+                        report(stderr, GT_("Your OpenSSL version does not support TLS v1.1.\n"));
820307
+                        return -1;
820307
+#endif
820307
+#if defined(TLS1_2_VERSION) && TLS_MAX_VERSION >= TLS1_2_VERSION
820307
+                } else if(!strcasecmp("tls1.2",myproto)) {
820307
+                        _ctx[sock] = SSL_CTX_new(TLSv1_2_client_method());
820307
+                } else if(!strcasecmp("tls1.2+",myproto)) {
820307
+                        myproto = NULL;
820307
+                        avoid_ssl_versions |= SSL_OP_NO_TLSv1;
820307
+                        avoid_ssl_versions |= SSL_OP_NO_TLSv1_1;
820307
+#else
820307
+                } else if(!strcasecmp("tls1.2",myproto) || !strcasecmp("tls1.2+", myproto)) {
820307
+                        report(stderr, GT_("Your OpenSSL version does not support TLS v1.2.\n"));
820307
+                        return -1;
820307
+#endif
820307
+                } else if (!strcasecmp("ssl23",myproto) || 0 == strcasecmp("auto",myproto)) {
820307
+                        myproto = NULL;
820307
+                } else {
820307
+                        report(stderr,GT_("Invalid SSL protocol '%s' specified, using default autoselect (SSL23).\n"), myproto);
820307
+                        myproto = NULL;
820307
+                }
820307
+        }
820307
+        // do not combine into an else { } as myproto may be nulled
820307
+        // above!
820307
+        if(!myproto) {
820307
+                // SSLv23 is a misnomer and will in fact use the best
820307
+                // available protocol, subject to SSL_OP_NO*
820307
+                // constraints.
820307
+                _ctx[sock] = SSL_CTX_new(SSLv23_client_method());
820307
+        }
820307
 	if(_ctx[sock] == NULL) {
820307
 		ERR_print_errors_fp(stderr);
820307
 		return(-1);
820307
@@ -906,7 +949,7 @@ int SSLOpen(int sock, char *mycert, char
820307
 		sslopts &= ~ SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
820307
 	}
820307
 
820307
-	SSL_CTX_set_options(_ctx[sock], sslopts);
820307
+	SSL_CTX_set_options(_ctx[sock], sslopts | avoid_ssl_versions);
820307
 
820307
 	if (certck) {
820307
 		SSL_CTX_set_verify(_ctx[sock], SSL_VERIFY_PEER, SSL_ck_verify_callback);
820307
@@ -985,6 +1028,24 @@ int SSLOpen(int sock, char *mycert, char
820307
 		return(-1);
820307
 	}
820307
 
820307
+	if (outlevel >= O_VERBOSE) {
820307
+	    SSL_CIPHER const *sc;
820307
+	    int bitsmax, bitsused;
820307
+
820307
+	    const char *ver;
820307
+
820307
+	    ver = SSL_get_version(_ssl_context[sock]);
820307
+
820307
+	    sc = SSL_get_current_cipher(_ssl_context[sock]);
820307
+	    if (!sc) {
820307
+		report (stderr, GT_("Cannot obtain current SSL/TLS cipher - no session established?\n"));
820307
+	    } else {
820307
+		bitsused = SSL_CIPHER_get_bits(sc, &bitsmax);
820307
+		report(stdout, GT_("SSL/TLS: using protocol %s, cipher %s, %d/%d secret/processed bits\n"),
820307
+		    ver, SSL_CIPHER_get_name(sc), bitsused, bitsmax);
820307
+		}
820307
+	}
820307
+
820307
 	/* Paranoia: was the callback not called as we expected? */
820307
 	if (!_depth0ck) {
820307
 		report(stderr, GT_("Certificate/fingerprint verification was somehow skipped!\n"));
820307
diff -up fetchmail-6.3.24/starttls.c.orig fetchmail-6.3.24/starttls.c
820307
--- fetchmail-6.3.24/starttls.c.orig	2017-03-07 12:35:18.964038382 +0100
820307
+++ fetchmail-6.3.24/starttls.c	2017-03-07 12:35:18.964038382 +0100
820307
@@ -0,0 +1,37 @@
820307
+/** \file tls.c - collect common TLS functionality
820307
+ * \author Matthias Andree
820307
+ * \date 2006
820307
+ */
820307
+
820307
+#include "fetchmail.h"
820307
+
820307
+#include <string.h>
820307
+
820307
+#ifdef HAVE_STRINGS_H
820307
+#include <strings.h>
820307
+#endif
820307
+
820307
+/** return true if user allowed opportunistic STARTTLS/STLS */
820307
+int maybe_starttls(struct query *ctl) {
820307
+#ifdef SSL_ENABLE
820307
+         /* opportunistic  or forced TLS */
820307
+    return (!ctl->sslproto || strlen(ctl->sslproto))
820307
+	&& !ctl->use_ssl;
820307
+#else
820307
+    (void)ctl;
820307
+    return 0;
820307
+#endif
820307
+}
820307
+
820307
+/** return true if user requires STARTTLS/STLS, note though that this
820307
+ * code must always use a logical AND with maybe_tls(). */
820307
+int must_starttls(struct query *ctl) {
820307
+#ifdef SSL_ENABLE
820307
+    return maybe_starttls(ctl)
820307
+	&& (ctl->sslfingerprint || ctl->sslcertck
820307
+		|| (ctl->sslproto && !strcasecmp(ctl->sslproto, "tls1")));
820307
+#else
820307
+    (void)ctl;
820307
+    return 0;
820307
+#endif
820307
+}
820307
diff -up fetchmail-6.3.24/tls.c.orig fetchmail-6.3.24/tls.c
820307
--- fetchmail-6.3.24/tls.c.orig	2012-12-13 22:12:27.000000000 +0100
820307
+++ fetchmail-6.3.24/tls.c	2017-03-07 12:35:18.964038382 +0100
820307
@@ -1,35 +0,0 @@
820307
-/** \file tls.c - collect common TLS functionality 
820307
- * \author Matthias Andree
820307
- * \date 2006
820307
- */
820307
-
820307
-#include "fetchmail.h"
820307
-
820307
-#ifdef HAVE_STRINGS_H
820307
-#include <strings.h>
820307
-#endif
820307
-
820307
-/** return true if user allowed TLS */
820307
-int maybe_tls(struct query *ctl) {
820307
-#ifdef SSL_ENABLE
820307
-         /* opportunistic  or forced TLS */
820307
-    return (!ctl->sslproto || !strcasecmp(ctl->sslproto,"tls1"))
820307
-	&& !ctl->use_ssl;
820307
-#else
820307
-    (void)ctl;
820307
-    return 0;
820307
-#endif
820307
-}
820307
-
820307
-/** return true if user requires TLS, note though that this code must
820307
- * always use a logical AND with maybe_tls(). */
820307
-int must_tls(struct query *ctl) {
820307
-#ifdef SSL_ENABLE
820307
-    return maybe_tls(ctl)
820307
-	&& (ctl->sslfingerprint || ctl->sslcertck
820307
-		|| (ctl->sslproto && !strcasecmp(ctl->sslproto, "tls1")));
820307
-#else
820307
-    (void)ctl;
820307
-    return 0;
820307
-#endif
820307
-}