annotate lisp/net/sasl.el @ 92745:871ad7e118ff

(menu-bar-update-buffers-maxbuf): Remove. (menu-bar-select-buffer): Remove. (menu-bar-select-frame): Make non-interactive and take a frame arg. (menu-bar-update-buffers): Don't use buffer-names or frame names as events.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 11 Mar 2008 17:44:39 +0000
parents b9e8ab94c460
children 1e3a407766b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 ;;; sasl.el --- SASL client framework
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2
87665
b9e8ab94c460 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86997
diff changeset
3 ;; Copyright (C) 2000, 2007, 2008 Free Software Foundation, Inc.
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 ;; Author: Daiki Ueno <ueno@unixuser.org>
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 ;; Keywords: SASL
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 3, or (at your option)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 ;; any later version.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02110-1301, USA.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;; This module provides common interface functions to share several
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;; SASL mechanism drivers. The toplevel is designed to be mostly
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;; compatible with [Java-SASL].
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 ;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 ;; [SASL] J. Myers, "Simple Authentication and Security Layer (SASL)",
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 ;; RFC 2222, October 1997.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 ;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 ;; [Java-SASL] R. Weltman & R. Lee, "The Java SASL Application Program
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 ;; Interface", draft-weltman-java-sasl-03.txt, March 2000.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 ;;; Code:
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 (defvar sasl-mechanisms
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 '("CRAM-MD5" "DIGEST-MD5" "PLAIN" "LOGIN" "ANONYMOUS"
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 "NTLM" "SCRAM-MD5"))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 (defvar sasl-mechanism-alist
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 '(("CRAM-MD5" sasl-cram)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 ("DIGEST-MD5" sasl-digest)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 ("PLAIN" sasl-plain)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ("LOGIN" sasl-login)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ("ANONYMOUS" sasl-anonymous)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 ("NTLM" sasl-ntlm)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 ("SCRAM-MD5" sasl-scram)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 (defvar sasl-unique-id-function #'sasl-unique-id-function)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 (put 'sasl-error 'error-message "SASL error")
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 (put 'sasl-error 'error-conditions '(sasl-error error))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 (defun sasl-error (datum)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 (signal 'sasl-error (list datum)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 ;;; @ SASL client
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 ;;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 (defun sasl-make-client (mechanism name service server)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 "Return a newly allocated SASL client.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 NAME is name of the authorization. SERVICE is name of the service desired.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 SERVER is the fully qualified host name of the server to authenticate to."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 (vector mechanism name service server (make-symbol "sasl-client-properties")))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 (defun sasl-client-mechanism (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 "Return the authentication mechanism driver of CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 (aref client 0))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (defun sasl-client-name (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 "Return the authorization name of CLIENT, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (aref client 1))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (defun sasl-client-service (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 "Return the service name of CLIENT, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (aref client 2))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 (defun sasl-client-server (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 "Return the server name of CLIENT, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 (aref client 3))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 (defun sasl-client-set-properties (client plist)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 "Destructively set the properties of CLIENT.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 The second argument PLIST is the new property list."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 (setplist (aref client 4) plist))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
89
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 (defun sasl-client-set-property (client property value)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91 "Add the given property/value to CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 (put (aref client 4) property value))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 (defun sasl-client-property (client property)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 "Return the value of the PROPERTY of CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 (get (aref client 4) property))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 (defun sasl-client-properties (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 "Return the properties of CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 (symbol-plist (aref client 4)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 ;;; @ SASL mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 ;;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 (defun sasl-make-mechanism (name steps)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
106 "Make an authentication mechanism.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 NAME is a IANA registered SASL mechanism name.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 STEPS is list of continuation function."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 (vector name
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 (mapcar
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (lambda (step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 (let ((symbol (make-symbol (symbol-name step))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 (fset symbol (symbol-function step))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 symbol))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 steps)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 (defun sasl-mechanism-name (mechanism)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118 "Return name of MECHANISM, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 (aref mechanism 0))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 (defun sasl-mechanism-steps (mechanism)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 "Return the authentication steps of MECHANISM, a list of functions."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 (aref mechanism 1))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 (defun sasl-find-mechanism (mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 "Retrieve an apropriate mechanism object from MECHANISMS hints."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 (let* ((sasl-mechanisms sasl-mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 (mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 (catch 'done
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 (while sasl-mechanisms
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 (if (member (car sasl-mechanisms) mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 (throw 'done (nth 1 (assoc (car sasl-mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 sasl-mechanism-alist))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 (setq sasl-mechanisms (cdr sasl-mechanisms))))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 (if mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136 (require mechanism))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 (get mechanism 'sasl-mechanism)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
138
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
139 ;;; @ SASL authentication step
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 ;;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (defun sasl-step-data (step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143 "Return the data which STEP holds, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 (aref step 1))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 (defun sasl-step-set-data (step data)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147 "Store DATA string to STEP."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 (aset step 1 data))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
150 (defun sasl-next-step (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
151 "Evaluate the challenge and prepare an appropriate next response.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
152 The data type of the value and optional 2nd argument STEP is nil or
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 opaque authentication step which holds the reference to the next action
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 and the current challenge. At the first time STEP should be set to nil."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 (let* ((steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 (sasl-mechanism-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 (sasl-client-mechanism client)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 (function
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 (if (vectorp step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 (nth 1 (memq (aref step 0) steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (car steps))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 (if function
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 (vector function (funcall function client step)))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 (defvar sasl-read-passphrase nil)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 (defun sasl-read-passphrase (prompt)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 (if (not sasl-read-passphrase)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 (if (functionp 'read-passwd)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 (setq sasl-read-passphrase 'read-passwd)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170 (if (load "passwd" t)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 (setq sasl-read-passphrase 'read-passwd)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 (autoload 'ange-ftp-read-passwd "ange-ftp")
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 (setq sasl-read-passphrase 'ange-ftp-read-passwd))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 (funcall sasl-read-passphrase prompt))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 (defun sasl-unique-id ()
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 "Compute a data string which must be different each time.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 It contain at least 64 bits of entropy."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 (concat (funcall sasl-unique-id-function)(funcall sasl-unique-id-function)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181 (defvar sasl-unique-id-char nil)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 ;; stolen (and renamed) from message.el
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 (defun sasl-unique-id-function ()
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 ;; Don't use microseconds from (current-time), they may be unsupported.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 ;; Instead we use this randomly inited counter.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
187 (setq sasl-unique-id-char
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 (% (1+ (or sasl-unique-id-char (logand (random t) (1- (lsh 1 20)))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189 ;; (current-time) returns 16-bit ints,
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 ;; and 2^16*25 just fits into 4 digits i base 36.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 (* 25 25)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 (let ((tm (current-time)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 (concat
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (sasl-unique-id-number-base36
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 (+ (car tm)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 (lsh (% sasl-unique-id-char 25) 16)) 4)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 (sasl-unique-id-number-base36
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198 (+ (nth 1 tm)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 (lsh (/ sasl-unique-id-char 25) 16)) 4))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 (defun sasl-unique-id-number-base36 (num len)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 (if (if (< len 0)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 (<= num 0)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 (= len 0))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 ""
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 (concat (sasl-unique-id-number-base36 (/ num 36) (1- len))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 (% num 36))))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 ;;; PLAIN (RFC2595 Section 6)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 (defconst sasl-plain-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 '(sasl-plain-response))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 (defun sasl-plain-response (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 (let ((passphrase
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 (sasl-read-passphrase
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 (format "PLAIN passphrase for %s: " (sasl-client-name client))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (authenticator-name
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (sasl-client-property
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 client 'authenticator-name))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 (name (sasl-client-name client)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 (unwind-protect
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 (if (and authenticator-name
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 (not (string= authenticator-name name)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 (concat authenticator-name "\0" name "\0" passphrase)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 (concat "\0" name "\0" passphrase))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 (fillarray passphrase 0))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229 (put 'sasl-plain 'sasl-mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230 (sasl-make-mechanism "PLAIN" sasl-plain-steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
231
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
232 (provide 'sasl-plain)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234 ;;; LOGIN (No specification exists)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 (defconst sasl-login-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 '(ignore ;no initial response
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237 sasl-login-response-1
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238 sasl-login-response-2))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 (defun sasl-login-response-1 (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
241 ;;; (unless (string-match "^Username:" (sasl-step-data step))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242 ;;; (sasl-error (format "Unexpected response: %s" (sasl-step-data step))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
243 (sasl-client-name client))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 (defun sasl-login-response-2 (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 ;;; (unless (string-match "^Password:" (sasl-step-data step))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 ;;; (sasl-error (format "Unexpected response: %s" (sasl-step-data step))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
248 (sasl-read-passphrase
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
249 (format "LOGIN passphrase for %s: " (sasl-client-name client))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251 (put 'sasl-login 'sasl-mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 (sasl-make-mechanism "LOGIN" sasl-login-steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
253
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
254 (provide 'sasl-login)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 ;;; ANONYMOUS (RFC2245)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 (defconst sasl-anonymous-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258 '(ignore ;no initial response
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 sasl-anonymous-response))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 (defun sasl-anonymous-response (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262 (or (sasl-client-property client 'trace)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 (sasl-client-name client)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265 (put 'sasl-anonymous 'sasl-mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 (sasl-make-mechanism "ANONYMOUS" sasl-anonymous-steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
267
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
268 (provide 'sasl-anonymous)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
270 (provide 'sasl)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
272 ;;; arch-tag: 8b3326fa-4978-4fda-93e2-cb2c6255f887
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
273 ;;; sasl.el ends here