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

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