From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Newsgroups: gmane.emacs.bugs Subject: bug#14380: 24.3; `network-stream-open-tls' fails in some imap servers on w32 Date: Fri, 10 May 2013 13:49:20 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1368190201 20846 80.91.229.3 (10 May 2013 12:50:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 May 2013 12:50:01 +0000 (UTC) To: 14380@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 10 14:50:01 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Uamlr-0002PN-U2 for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 May 2013 14:50:00 +0200 Original-Received: from localhost ([::1]:54962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uamlr-0005Gp-Bd for geb-bug-gnu-emacs@m.gmane.org; Fri, 10 May 2013 08:49:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uamlm-0005Gh-Ii for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:49:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uamlk-0002lx-VK for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:49:54 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:59557) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uamlk-0002ls-SM for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:49:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Uamlu-0000Vg-It for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: joaotavora@gmail.com (=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?=) Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 May 2013 12:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 14380 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13681901841885 (code B ref -1); Fri, 10 May 2013 12:50:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 May 2013 12:49:44 +0000 Original-Received: from localhost ([127.0.0.1]:35433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Uamlb-0000UD-5f for submit@debbugs.gnu.org; Fri, 10 May 2013 08:49:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38019) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UamlX-0000Tl-Gs for submit@debbugs.gnu.org; Fri, 10 May 2013 08:49:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UamlL-0002hg-UO for submit@debbugs.gnu.org; Fri, 10 May 2013 08:49:29 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:36305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamlL-0002hc-RD for submit@debbugs.gnu.org; Fri, 10 May 2013 08:49:27 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamlK-0005FZ-7u for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:49:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UamlI-0002h9-Dg for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:49:26 -0400 Original-Received: from mail3.siscog.pt ([195.23.29.18]:49771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamlI-0002gx-1b for bug-gnu-emacs@gnu.org; Fri, 10 May 2013 08:49:24 -0400 Original-Received: from smtps.lisboa.siscog (lximaps01.siscog.com [::ffff:194.100.100.99]) by mail3.siscog.pt with esmtp; Fri, 10 May 2013 13:49:21 +0100 id 0001E065.518CECD1.00001BC1 Original-Received: from BELMONTE (belmonte.siscog.com [194.100.100.149]) by smtps.lisboa.siscog (Postfix) with ESMTP id 1E0226D2AE for ; Fri, 10 May 2013 13:49:21 +0100 (WEST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:74119 Archived-At: Here's a emacs -Q recipe: $ emacs -Q M-x eval-expression RET (setq gnus-select-method '(nnimap "imaps.mycompany.com")) RET M-x gnus An error pops up: nnimap (imaps.mycompany.com) open error: ''gnutls-cli' is not recognized as an internal or external command, In the *Message* buffer, we can see at at least one tls command succeeded Opening connection to imaps.mycompany.com via tls... gnutls.c: [1] (Emacs) GnuTLS library not found Opening TLS connection to `imaps.mycompany.com'... Opening TLS connection with `gnutls-cli --insecure -p 993 imaps.mycompany.com'...failed Opening TLS connection with `gnutls-cli --insecure -p 993 imaps.mycompany.com --protocols ssl3'...failed Opening TLS connection with `openssl s_client -connect imaps.mycompany.com:993 -no_ssl2 -ign_eof'...done Opening TLS connection to `imaps.mycompany.com'...done nnimap (imaps.mycompany.com) open error: ''gnutls-cli' is not recognized as an internal or external command, '. Continue? (y or n) n This works fine, on the same server with linux. My analysis and possible fix is as follows: The problem is that `network-stream-open-tls' returns invalid information in its final form: (list stream (network-stream-get-response stream start eoc) (network-stream-command stream capability-command eoc) 'tls) This is turn is because code immediately preceding it ;; If we're using tls.el, we have to delete the output from ;; openssl/gnutls-cli. (when (and (null use-builtin-gnutls) eoc) (network-stream-get-response stream start eoc) (goto-char (point-min)) (when (re-search-forward eoc nil t) (goto-char (match-beginning 0)) (delete-region (point-min) (line-beginning-position)))) is not really doing what it says it's doing: it's not deleting enough input, and the search for capabilities actually returns the IMAP greeting. This in turn is related to the CRLF lineendings that the function `open-tls-stream' running under w32 only (in linux it doesn't happen) inserts in the process buffer before the end of the tls handshake. The code in `network-stream-open-tls' for getting rid of useless starting output deletes up to the first CRLF (and apparently it should do so just once, since other CRLF's are legitimate). But if fails and catches a very early CRLF which is still part of the now useless TLS handshake. The search performed by (network-stream-command stream capability-command eoc) doesn't work. That said, a reasonable way to fix this might be adding a line (delete-region (point-min) (point)) as the first form in the body of the `when'. This is because `open-tls-stream' apparently guarantees that point will be left where the tls handshake ended, as per its code snippet and comment: (if start-of-data ;; move point to start of client data (goto-char start-of-data)) Alternalively, make `open-tls-stream' do that itself in the end. I'm doing just that with. (defadvice open-tls-stream (after dont-forget-to-erase-buffer-up-to-point activate) (delete-region (point-min) (point))) Or maybe improve searches by `network-stream-get-response' or be smarter when deleting output. Here's the contents of the nnimap process buffer. Notice the CRLFs. 'gnutls-cli' is not recognized as an internal or external command, operable program or batch file. Process *nnimap* exited abnormally with code 1 'gnutls-cli' is not recognized as an internal or external command, operable program or batch file. Process *nnimap* exited abnormally with code 1 depth=0 C = PT, L = Lisboa, O = SISCOG.COM, OU = IMAP server, CN = *.siscog.com, emailAddress = suporte@siscog.pt verify error:num=18:self signed certificate verify return:1 depth=0 C = PT, L = Lisboa, O = SISCOG.COM, OU = IMAP server, CN = *.siscog.com, emailAddress = suporte@siscog.pt verify return:1 CONNECTED(00000003) --- Certificate chain 0 s:/C=PT/L=Lisboa/O=SISCOG.COM/OU=IMAP server/CN=*.siscog.com/emailAddress=suporte@siscog.pt i:/C=PT/L=Lisboa/O=SISCOG.COM/OU=IMAP server/CN=*.siscog.com/emailAddress=suporte@siscog.pt --- Server certificate -----BEGIN CERTIFICATE----- [elided] -----END CERTIFICATE----- subject=/C=PT/L=Lisboa/O=SISCOG.COM/OU=IMAP server/CN=*.siscog.com/emailAddress=suporte@siscog.pt issuer=/C=PT/L=Lisboa/O=SISCOG.COM/OU=IMAP server/CN=*.siscog.com/emailAddress=suporte@siscog.pt --- No client certificate CA names sent --- SSL handshake has read 1240 bytes and written 518 bytes --- New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA Server public key is 1024 bit Secure Renegotiation IS supported Compression: zlib compression Expansion: zlib compression SSL-Session: Protocol : TLSv1 Cipher : DHE-RSA-AES256-SHA Session-ID: 9334E31E9FD9A90C9D301227A2799EB8210AAC9FFD583B6597251744CB6EBFB3 Session-ID-ctx: Master-Key: 7A5A40FEFC3A3493C9AFC4B80BCB044FAC48C94E0B4DE6E35035866F90EC78FFDE18D1B40E93B125F4F3F73468A9D5F0 Key-Arg : None PSK identity: None PSK identity hint: None SRP username: None Compression: 1 (zlib compression) Start Time: 1368189548 Timeout : 300 (sec) Verify return code: 18 (self signed certificate) --- * OK Dovecot ready. In GNU Emacs 24.3.1 (i386-mingw-nt5.1.2600) of 2013-03-17 on MARVIN Windowing system distributor `Microsoft Corp.', version 5.1.2600 Configured using: `configure --with-gcc (4.7) --cflags -ID:/devel/emacs/libs/libXpm-3.5.8/include -ID:/devel/emacs/libs/libXpm-3.5.8/src -ID:/devel/emacs/libs/libpng-dev_1.4.3-1/include -ID:/devel/emacs/libs/zlib-dev_1.2.5-2/include -ID:/devel/emacs/libs/giflib-4.1.4-1/include -ID:/devel/emacs/libs/jpeg-6b-4/include -ID:/devel/emacs/libs/tiff-3.8.2-1/include -ID:/devel/emacs/libs/gnutls-3.0.9/include -ID:/devel/emacs/libs/libiconv-1.13.1-1-dev/include -ID:/devel/emacs/libs/libxml2-2.7.8/include/libxml2' Important settings: value of $LANG: C.UTF-8 locale-coding-system: cp1252 default enable-multibyte-characters: t