annotate lisp/net/sasl.el @ 105139:549ca02e98fe

elint stuff
author Glenn Morris <rgm@gnu.org>
date Tue, 22 Sep 2009 02:31:54 +0000
parents a9dc0e7c3f2b
children 1d1d5d9bd884
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
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 96406
diff changeset
3 ;; Copyright (C) 2000, 2007, 2008, 2009 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
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
86997
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
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; (at your option) any later version.
86997
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
94677
91e5880a36c1 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
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 ;; This module provides common interface functions to share several
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 ;; SASL mechanism drivers. The toplevel is designed to be mostly
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 ;; compatible with [Java-SASL].
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 ;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 ;; [SASL] J. Myers, "Simple Authentication and Security Layer (SASL)",
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 ;; RFC 2222, October 1997.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 ;;
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 ;; [Java-SASL] R. Weltman & R. Lee, "The Java SASL Application Program
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 ;; Interface", draft-weltman-java-sasl-03.txt, March 2000.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 ;;; Code:
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 (defvar sasl-mechanisms
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 '("CRAM-MD5" "DIGEST-MD5" "PLAIN" "LOGIN" "ANONYMOUS"
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 "NTLM" "SCRAM-MD5"))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 (defvar sasl-mechanism-alist
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 '(("CRAM-MD5" sasl-cram)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 ("DIGEST-MD5" sasl-digest)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 ("PLAIN" sasl-plain)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 ("LOGIN" sasl-login)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 ("ANONYMOUS" sasl-anonymous)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 ("NTLM" sasl-ntlm)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 ("SCRAM-MD5" sasl-scram)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 (defvar sasl-unique-id-function #'sasl-unique-id-function)
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 (put 'sasl-error 'error-message "SASL error")
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 (put 'sasl-error 'error-conditions '(sasl-error error))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 (defun sasl-error (datum)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 (signal 'sasl-error (list datum)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 ;;; @ SASL client
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
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 (defun sasl-make-client (mechanism name service server)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 "Return a newly allocated SASL client.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 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
64 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
65 (vector mechanism name service server (make-symbol "sasl-client-properties")))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67 (defun sasl-client-mechanism (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 "Return the authentication mechanism driver of CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 (aref client 0))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 (defun sasl-client-name (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72 "Return the authorization name of CLIENT, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 (aref client 1))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 (defun sasl-client-service (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 "Return the service name of CLIENT, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 (aref client 2))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79 (defun sasl-client-server (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 "Return the server name of CLIENT, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 (aref client 3))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 (defun sasl-client-set-properties (client plist)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 "Destructively set the properties of CLIENT.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 The second argument PLIST is the new property list."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 (setplist (aref client 4) plist))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
88 (defun sasl-client-set-property (client property value)
96406
ce3cca778d10 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 94677
diff changeset
89 "Add the given PROPERTY/VALUE to CLIENT."
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 (put (aref client 4) property value))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 (defun sasl-client-property (client property)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 "Return the value of the PROPERTY of CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 (get (aref client 4) property))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96 (defun sasl-client-properties (client)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 "Return the properties of CLIENT."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 (symbol-plist (aref client 4)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 ;;; @ SASL mechanism
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
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 (defun sasl-make-mechanism (name steps)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 "Make an authentication mechanism.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
105 NAME is a IANA registered SASL mechanism name.
96406
ce3cca778d10 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 94677
diff changeset
106 STEPS is list of continuation functions."
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
107 (vector name
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108 (mapcar
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 (lambda (step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 (let ((symbol (make-symbol (symbol-name step))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 (fset symbol (symbol-function step))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 symbol))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 steps)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 (defun sasl-mechanism-name (mechanism)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
116 "Return name of MECHANISM, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
117 (aref mechanism 0))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
118
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119 (defun sasl-mechanism-steps (mechanism)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 "Return the authentication steps of MECHANISM, a list of functions."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 (aref mechanism 1))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 (defun sasl-find-mechanism (mechanisms)
96406
ce3cca778d10 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 94677
diff changeset
124 "Retrieve an appropriate mechanism object from MECHANISMS hints."
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
125 (let* ((sasl-mechanisms sasl-mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
126 (mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
127 (catch 'done
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
128 (while sasl-mechanisms
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
129 (if (member (car sasl-mechanisms) mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
130 (throw 'done (nth 1 (assoc (car sasl-mechanisms)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
131 sasl-mechanism-alist))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
132 (setq sasl-mechanisms (cdr sasl-mechanisms))))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
133 (if mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
134 (require mechanism))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
135 (get mechanism 'sasl-mechanism)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
136
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
137 ;;; @ SASL authentication step
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
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
140 (defun sasl-step-data (step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
141 "Return the data which STEP holds, a string."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
142 (aref step 1))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
143
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
144 (defun sasl-step-set-data (step data)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
145 "Store DATA string to STEP."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
146 (aset step 1 data))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
147
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
148 (defun sasl-next-step (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
149 "Evaluate the challenge and prepare an appropriate next response.
96406
ce3cca778d10 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 94677
diff changeset
150 The data type of the value and 2nd argument STEP is nil or opaque
ce3cca778d10 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 94677
diff changeset
151 authentication step which holds the reference to the next action and
ce3cca778d10 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 94677
diff changeset
152 the current challenge. At the first time STEP should be set to nil."
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
153 (let* ((steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
154 (sasl-mechanism-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
155 (sasl-client-mechanism client)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
156 (function
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
157 (if (vectorp step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
158 (nth 1 (memq (aref step 0) steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159 (car steps))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 (if function
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (vector function (funcall function client step)))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163 (defvar sasl-read-passphrase nil)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 (defun sasl-read-passphrase (prompt)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 (if (not sasl-read-passphrase)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166 (if (functionp 'read-passwd)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 (setq sasl-read-passphrase 'read-passwd)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 (if (load "passwd" t)
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 (autoload 'ange-ftp-read-passwd "ange-ftp")
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 (setq sasl-read-passphrase 'ange-ftp-read-passwd))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 (funcall sasl-read-passphrase prompt))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 (defun sasl-unique-id ()
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 "Compute a data string which must be different each time.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 It contain at least 64 bits of entropy."
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 (concat (funcall sasl-unique-id-function)(funcall sasl-unique-id-function)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 (defvar sasl-unique-id-char nil)
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 ;; stolen (and renamed) from message.el
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
182 (defun sasl-unique-id-function ()
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
183 ;; Don't use microseconds from (current-time), they may be unsupported.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
184 ;; Instead we use this randomly inited counter.
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
185 (setq sasl-unique-id-char
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
186 (% (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
187 ;; (current-time) returns 16-bit ints,
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
188 ;; 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
189 (* 25 25)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
190 (let ((tm (current-time)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
191 (concat
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
192 (sasl-unique-id-number-base36
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
193 (+ (car tm)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
194 (lsh (% sasl-unique-id-char 25) 16)) 4)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
195 (sasl-unique-id-number-base36
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
196 (+ (nth 1 tm)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
197 (lsh (/ sasl-unique-id-char 25) 16)) 4))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 (defun sasl-unique-id-number-base36 (num len)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 (if (if (< len 0)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 (<= num 0)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 (= len 0))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 ""
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
204 (concat (sasl-unique-id-number-base36 (/ num 36) (1- len))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
205 (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206 (% num 36))))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 ;;; PLAIN (RFC2595 Section 6)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 (defconst sasl-plain-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 '(sasl-plain-response))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 (defun sasl-plain-response (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 (let ((passphrase
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214 (sasl-read-passphrase
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 (format "PLAIN passphrase for %s: " (sasl-client-name client))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 (authenticator-name
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 (sasl-client-property
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 client 'authenticator-name))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 (name (sasl-client-name client)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 (unwind-protect
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 (if (and authenticator-name
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 (not (string= authenticator-name name)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223 (concat authenticator-name "\0" name "\0" passphrase)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 (concat "\0" name "\0" passphrase))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 (fillarray passphrase 0))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
227 (put 'sasl-plain 'sasl-mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
228 (sasl-make-mechanism "PLAIN" sasl-plain-steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
229
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
230 (provide 'sasl-plain)
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 ;;; LOGIN (No specification exists)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
233 (defconst sasl-login-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
234 '(ignore ;no initial response
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
235 sasl-login-response-1
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
236 sasl-login-response-2))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
237
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
238 (defun sasl-login-response-1 (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
239 ;;; (unless (string-match "^Username:" (sasl-step-data step))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
240 ;;; (sasl-error (format "Unexpected response: %s" (sasl-step-data step))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
241 (sasl-client-name client))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
242
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
243 (defun sasl-login-response-2 (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
244 ;;; (unless (string-match "^Password:" (sasl-step-data step))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
245 ;;; (sasl-error (format "Unexpected response: %s" (sasl-step-data step))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
246 (sasl-read-passphrase
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
247 (format "LOGIN passphrase for %s: " (sasl-client-name client))))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
248
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
249 (put 'sasl-login 'sasl-mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
250 (sasl-make-mechanism "LOGIN" sasl-login-steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
251
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
252 (provide 'sasl-login)
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 ;;; ANONYMOUS (RFC2245)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
255 (defconst sasl-anonymous-steps
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
256 '(ignore ;no initial response
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
257 sasl-anonymous-response))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
258
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
259 (defun sasl-anonymous-response (client step)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
260 (or (sasl-client-property client 'trace)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
261 (sasl-client-name client)))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
262
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
263 (put 'sasl-anonymous 'sasl-mechanism
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
264 (sasl-make-mechanism "ANONYMOUS" sasl-anonymous-steps))
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
265
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
266 (provide 'sasl-anonymous)
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)
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
269
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87665
diff changeset
270 ;; arch-tag: 8b3326fa-4978-4fda-93e2-cb2c6255f887
86997
529f678278ec Move here from ../gnus.
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
271 ;;; sasl.el ends here