annotate lisp/gnus/starttls.el @ 112199:6c6130ccdefd

New arg RETURN-ACTION for compose-mail, and related functions. * lisp/mail/sendmail.el (mail-return-action): New var. (mail-mode): Make it buffer-local. (mail-bury): Obey it. Move special Rmail window handling to rmail-mail-return. (mail, mail-setup): New arg RETURN-ACTION. (sendmail-user-agent-compose): Move from simple.el. * lisp/simple.el (sendmail-user-agent-compose): Move to sendmail.el. (compose-mail): New arg RETURN-ACTION. (compose-mail-other-window, compose-mail-other-frame): Likewise. * lisp/gnus/gnus-msg.el (gnus-msg-mail): New arg RETURN-ACTION. Pass it to message-mail. * lisp/gnus/message.el (message-mail): New arg RETURN-ACTION. (message-return-action): New var. (message-bury): Use it. (message-mode): Make it buffer-local. (message-send-and-exit): Always call message-bury. (message-tool-bar-gnome): Tweak tool-bar items. Add :vert-only tags. * lisp/mail/rmail.el (rmail-mail-return): New function. (rmail-start-mail): Pass it to compose-mail. * lisp/mh-e/mh-comp.el (mh-user-agent-compose): New arg RETURN-ACTION.
author Chong Yidong <cyd@stupidchicken.com>
date Wed, 12 Jan 2011 23:23:41 -0500
parents e07971bb896c
children 417b1e4d63cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; starttls.el --- STARTTLS functions
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
74548
ce127a46b1ca Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68633
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Author: Daiki Ueno <ueno@unixuser.org>
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
7 ;; Author: Simon Josefsson <simon@josefsson.org>
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; Created: 1999/11/20
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
9 ;; Keywords: TLS, SSL, OpenSSL, GNUTLS, mail, news
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
11 ;; This file is part of GNU Emacs.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
12
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
21 ;; GNU General Public License for more details.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94662
f42ef85caf91 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
25
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; This module defines some utility functions for STARTTLS profiles.
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;; [RFC 2595] "Using TLS with IMAP, POP3 and ACAP"
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; by Chris Newman <chris.newman@innosoft.com> (1999/06)
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
33 ;; This file now contains a combination of the two previous
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
34 ;; implementations both called "starttls.el". The first one is Daiki
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
35 ;; Ueno's starttls.el which uses his own "starttls" command line tool,
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
36 ;; and the second one is Simon Josefsson's starttls.el which uses
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
37 ;; "gnutls-cli" from GNUTLS.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
38 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
39 ;; If "starttls" is available, it is prefered by the code over
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
40 ;; "gnutls-cli", for backwards compatibility. Use
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
41 ;; `starttls-use-gnutls' to toggle between implementations if you have
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
42 ;; both tools installed. It is recommended to use GNUTLS, though, as
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
43 ;; it performs more verification of the certificates.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
44
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
45 ;; The GNUTLS support requires GNUTLS 0.9.90 (released 2003-10-08) or
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
46 ;; later, from <http://www.gnu.org/software/gnutls/>, or "starttls"
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
47 ;; from <ftp://ftp.opaopa.org/pub/elisp/>.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
48
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
49 ;; Usage is similar to `open-network-stream'. For example:
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
50 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
51 ;; (when (setq tmp (starttls-open-stream
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
52 ;; "test" (current-buffer) "yxa.extundo.com" 25))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
53 ;; (accept-process-output tmp 15)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
54 ;; (process-send-string tmp "STARTTLS\n")
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
55 ;; (accept-process-output tmp 15)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
56 ;; (message "STARTTLS output:\n%s" (starttls-negotiate tmp))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
57 ;; (process-send-string tmp "EHLO foo\n"))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
58
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
59 ;; An example run yields the following output:
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
60 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
61 ;; 220 yxa.extundo.com ESMTP Sendmail 8.12.11/8.12.11/Debian-3; Wed, 26 May 2004 19:12:29 +0200; (No UCE/UBE) logging access from: c494102a.s-bi.bostream.se(OK)-c494102a.s-bi.bostream.se [217.215.27.65]
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
62 ;; 220 2.0.0 Ready to start TLS
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
63 ;; 250-yxa.extundo.com Hello c494102a.s-bi.bostream.se [217.215.27.65], pleased to meet you
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
64 ;; 250-ENHANCEDSTATUSCODES
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
65 ;; 250-PIPELINING
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
66 ;; 250-EXPN
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
67 ;; 250-VERB
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
68 ;; 250-8BITMIME
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
69 ;; 250-SIZE
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
70 ;; 250-DSN
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
71 ;; 250-ETRN
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
72 ;; 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
73 ;; 250-DELIVERBY
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
74 ;; 250 HELP
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
75 ;; nil
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
76 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
77 ;; With the message buffer containing:
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
78 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
79 ;; STARTTLS output:
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
80 ;; *** Starting TLS handshake
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
81 ;; - Server's trusted authorities:
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
82 ;; [0]: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
83 ;; - Certificate type: X.509
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
84 ;; - Got a certificate list of 2 certificates.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
85 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
86 ;; - Certificate[0] info:
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
87 ;; # The hostname in the certificate matches 'yxa.extundo.com'.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
88 ;; # valid since: Wed May 26 12:16:00 CEST 2004
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
89 ;; # expires at: Wed Jul 26 12:16:00 CEST 2023
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
90 ;; # serial number: 04
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
91 ;; # fingerprint: 7c 04 4b c1 fa 26 9b 5d 90 22 52 3c 65 3d 85 3a
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
92 ;; # version: #1
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
93 ;; # public key algorithm: RSA
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
94 ;; # Modulus: 1024 bits
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
95 ;; # Subject's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=Mail server,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
96 ;; # Issuer's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
97 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
98 ;; - Certificate[1] info:
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
99 ;; # valid since: Sun May 23 11:35:00 CEST 2004
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
100 ;; # expires at: Sun Jul 23 11:35:00 CEST 2023
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
101 ;; # serial number: 00
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
102 ;; # fingerprint: fc 76 d8 63 1a c9 0b 3b fa 40 fe ed 47 7a 58 ae
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
103 ;; # version: #3
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
104 ;; # public key algorithm: RSA
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
105 ;; # Modulus: 1024 bits
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
106 ;; # Subject's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
107 ;; # Issuer's DN: C=SE,ST=Stockholm,L=Stockholm,O=YXA,OU=CA,CN=yxa.extundo.com,EMAIL=staff@yxa.extundo.com
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
108 ;;
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
109 ;; - Peer's certificate issuer is unknown
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
110 ;; - Peer's certificate is NOT trusted
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
111 ;; - Version: TLS 1.0
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
112 ;; - Key Exchange: RSA
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
113 ;; - Cipher: ARCFOUR 128
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
114 ;; - MAC: SHA
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
115 ;; - Compression: NULL
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
116
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
117 ;;; Code:
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
118
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
119 (defgroup starttls nil
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
120 "Support for `Transport Layer Security' protocol."
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
121 :version "21.1"
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
122 :group 'mail)
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
123
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
124 (defcustom starttls-gnutls-program "gnutls-cli"
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
125 "Name of GNUTLS command line tool.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
126 This program is used when GNUTLS is used, i.e. when
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
127 `starttls-use-gnutls' is non-nil."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
128 :version "22.1"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
129 :type 'string
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
130 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
131
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
132 (defcustom starttls-program "starttls"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
133 "The program to run in a subprocess to open an TLSv1 connection.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
134 This program is used when the `starttls' command is used,
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
135 i.e. when `starttls-use-gnutls' is nil."
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
136 :type 'string
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
137 :group 'starttls)
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
138
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
139 (defcustom starttls-use-gnutls (not (executable-find starttls-program))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
140 "*Whether to use GNUTLS instead of the `starttls' command."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
141 :version "22.1"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
142 :type 'boolean
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
143 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
144
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
145 (defcustom starttls-extra-args nil
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
146 "Extra arguments to `starttls-program'.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
147 These apply when the `starttls' command is used, i.e. when
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
148 `starttls-use-gnutls' is nil."
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
149 :type '(repeat string)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
150 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
151
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
152 (defcustom starttls-extra-arguments nil
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
153 "Extra arguments to `starttls-program'.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
154 These apply when GNUTLS is used, i.e. when `starttls-use-gnutls' is non-nil.
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
155
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
156 For example, non-TLS compliant servers may require
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
157 '(\"--protocols\" \"ssl3\"). Invoke \"gnutls-cli --help\" to
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
158 find out which parameters are available."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
159 :version "22.1"
34220
3984e8b6d0c5 Fix header and customization.
Dave Love <fx@gnu.org>
parents: 34219
diff changeset
160 :type '(repeat string)
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
161 :group 'starttls)
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
162
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
163 (defcustom starttls-process-connection-type nil
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
164 "*Value for `process-connection-type' to use when starting STARTTLS process."
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
165 :version "22.1"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
166 :type 'boolean
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
167 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
168
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
169 (defcustom starttls-connect "- Simple Client Mode:\n\n"
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
170 "*Regular expression indicating successful connection.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
171 The default is what GNUTLS's \"gnutls-cli\" outputs."
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
172 ;; GNUTLS cli.c:main() prints this string when it is starting to run
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
173 ;; in the application read/write phase. If the logic, or the string
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
174 ;; itself, is modified, this must be updated.
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
175 :version "22.1"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
176 :type 'regexp
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
177 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
178
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
179 (defcustom starttls-failure "\\*\\*\\* Handshake has failed"
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
180 "*Regular expression indicating failed TLS handshake.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
181 The default is what GNUTLS's \"gnutls-cli\" outputs."
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
182 ;; GNUTLS cli.c:do_handshake() prints this string on failure. If the
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
183 ;; logic, or the string itself, is modified, this must be updated.
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
184 :version "22.1"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
185 :type 'regexp
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
186 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
187
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
188 (defcustom starttls-success "- Compression: "
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
189 "*Regular expression indicating completed TLS handshakes.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
190 The default is what GNUTLS's \"gnutls-cli\" outputs."
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
191 ;; GNUTLS cli.c:do_handshake() calls, on success,
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
192 ;; common.c:print_info(), that unconditionally print this string
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
193 ;; last. If that logic, or the string itself, is modified, this
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
194 ;; must be updated.
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 57856
diff changeset
195 :version "22.1"
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
196 :type 'regexp
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
197 :group 'starttls)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
198
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
199 (defun starttls-negotiate-gnutls (process)
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
200 "Negotiate TLS on PROCESS opened by `open-starttls-stream'.
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
201 This should typically only be done once. It typically returns a
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
202 multi-line informational message with information about the
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
203 handshake, or nil on failure."
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
204 (let (buffer info old-max done-ok done-bad)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
205 (if (null (setq buffer (process-buffer process)))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
206 ;; XXX How to remove/extract the TLS negotiation junk?
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
207 (signal-process (process-id process) 'SIGALRM)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
208 (with-current-buffer buffer
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
209 (save-excursion
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
210 (setq old-max (goto-char (point-max)))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
211 (signal-process (process-id process) 'SIGALRM)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
212 (while (and (processp process)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
213 (eq (process-status process) 'run)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
214 (save-excursion
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
215 (goto-char old-max)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
216 (not (or (setq done-ok (re-search-forward
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
217 starttls-success nil t))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
218 (setq done-bad (re-search-forward
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
219 starttls-failure nil t))))))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
220 (accept-process-output process 1 100)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
221 (sit-for 0.1))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
222 (setq info (buffer-substring-no-properties old-max (point-max)))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
223 (delete-region old-max (point-max))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
224 (if (or (and done-ok (not done-bad))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
225 ;; Prevent mitm that fake success msg after failure msg.
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
226 (and done-ok done-bad (< done-ok done-bad)))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
227 info
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
228 (message "STARTTLS negotiation failed: %s" info)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
229 nil))))))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
230
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
231 (defun starttls-negotiate (process)
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
232 (if starttls-use-gnutls
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
233 (starttls-negotiate-gnutls process)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
234 (signal-process (process-id process) 'SIGALRM)))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
235
62960
31ebc6690b8b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-348
Miles Bader <miles@gnu.org>
parents: 62943
diff changeset
236 (eval-and-compile
31ebc6690b8b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-348
Miles Bader <miles@gnu.org>
parents: 62943
diff changeset
237 (if (fboundp 'set-process-query-on-exit-flag)
31ebc6690b8b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-348
Miles Bader <miles@gnu.org>
parents: 62943
diff changeset
238 (defalias 'starttls-set-process-query-on-exit-flag
31ebc6690b8b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-348
Miles Bader <miles@gnu.org>
parents: 62943
diff changeset
239 'set-process-query-on-exit-flag)
62943
11d53dd5abd9 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents: 59996
diff changeset
240 (defalias 'starttls-set-process-query-on-exit-flag
62960
31ebc6690b8b Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-348
Miles Bader <miles@gnu.org>
parents: 62943
diff changeset
241 'process-kill-without-query)))
62943
11d53dd5abd9 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents: 59996
diff changeset
242
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
243 (defun starttls-open-stream-gnutls (name buffer host port)
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
244 (message "Opening STARTTLS connection to `%s:%s'..." host port)
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
245 (let* (done
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
246 (old-max (with-current-buffer buffer (point-max)))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
247 (process-connection-type starttls-process-connection-type)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
248 (process (apply #'start-process name buffer
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
249 starttls-gnutls-program "-s" host
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
250 "-p" (if (integerp port)
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
251 (int-to-string port)
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
252 port)
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
253 starttls-extra-arguments)))
62943
11d53dd5abd9 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents: 59996
diff changeset
254 (starttls-set-process-query-on-exit-flag process nil)
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
255 (while (and (processp process)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
256 (eq (process-status process) 'run)
110410
f2e111723c3a Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110102
diff changeset
257 (with-current-buffer buffer
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
258 (goto-char old-max)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
259 (not (setq done (re-search-forward
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
260 starttls-connect nil t)))))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
261 (accept-process-output process 0 100)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
262 (sit-for 0.1))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
263 (if done
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
264 (with-current-buffer buffer
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
265 (delete-region old-max done))
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
266 (delete-process process)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
267 (setq process nil))
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
268 (message "Opening STARTTLS connection to `%s:%s'...%s"
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
269 host port (if done "done" "failed"))
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
270 process))
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
271
110555
e07971bb896c Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110410
diff changeset
272 ;;;###autoload
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
273 (defun starttls-open-stream (name buffer host port)
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
274 "Open a TLS connection for a port to a host.
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
275 Returns a subprocess object to represent the connection.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
276 Input and output work as for subprocesses; `delete-process' closes it.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
277 Args are NAME BUFFER HOST PORT.
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
278 NAME is name for process. It is modified if necessary to make it unique.
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
279 BUFFER is the buffer (or `buffer-name') to associate with the process.
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
280 Process output goes at end of that buffer, unless you specify
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
281 an output stream or filter function to handle the output.
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
282 BUFFER may be also nil, meaning that this process is not associated
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
283 with any buffer
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
284 Third arg is name of the host to connect to, or its IP address.
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
285 Fourth arg PORT is an integer specifying a port to connect to.
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
286 If `starttls-use-gnutls' is nil, this may also be a service name, but
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
287 GNUTLS requires a port number."
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
288 (if starttls-use-gnutls
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
289 (starttls-open-stream-gnutls name buffer host port)
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
290 (message "Opening STARTTLS connection to `%s:%s'" host (format "%s" port))
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
291 (let* ((process-connection-type starttls-process-connection-type)
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
292 (process (apply #'start-process
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
293 name buffer starttls-program
67643
1c477099d3ac Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-676
Miles Bader <miles@gnu.org>
parents: 64754
diff changeset
294 host (format "%s" port)
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
295 starttls-extra-args)))
62943
11d53dd5abd9 Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-345
Miles Bader <miles@gnu.org>
parents: 59996
diff changeset
296 (starttls-set-process-query-on-exit-flag process nil)
55783
cbd20e241bd5 starttls.el: Merge with my GNUTLS based starttls.el.
Simon Josefsson <jas@extundo.com>
parents: 52401
diff changeset
297 process)))
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
298
99402
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
299 (defun starttls-any-program-available ()
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
300 (let ((program (if starttls-use-gnutls
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
301 starttls-gnutls-program
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
302 starttls-program)))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
303 (condition-case ()
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
304 (progn
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
305 (call-process program)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
306 program)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
307 (error (progn
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
308 (message "No STARTTLS program was available (tried '%s')"
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
309 program)
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
310 nil)))))
d0dc678bbb96 Merge from gnus--devo--0
Miles Bader <miles@gnu.org>
parents: 94662
diff changeset
311
34219
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
312 (provide 'starttls)
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
313
d940776a9d6d *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
314 ;;; starttls.el ends here