* sasl.el (sasl-make-authenticator): Allocate a freshly generated
[elisp/flim.git] / sasl-cram.el
1 ;;; sasl-cram.el --- CRAM-MD5 module for the SASL client framework
2
3 ;; Copyright (C) 2000 Daiki Ueno
4
5 ;; Author: Kenichi OKADA <okada@opaopa.org>
6 ;;      Daiki Ueno <ueno@unixuser.org>
7 ;; Keywords: SASL, CRAM-MD5
8
9 ;; This file is part of FLIM (Faithful Library about Internet Message).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 (require 'sasl)
29 (require 'hmac-md5)
30
31 (defvar sasl-cram-md5-authenticator nil)
32
33 (defconst sasl-cram-md5-continuations
34   '(ignore                              ;no initial response
35     sasl-cram-md5-response))
36
37 (defun sasl-cram-md5-response (principal challenge)
38   (let ((passphrase
39          (sasl-read-passphrase
40           (format "CRAM-MD5 passphrase for %s: "
41                   (sasl-principal-name-internal principal)))))
42     (unwind-protect
43         (concat (sasl-principal-name-internal principal) " "
44                 (encode-hex-string
45                  (hmac-md5 (nth 1 challenge) passphrase)))
46       (fillarray passphrase 0))))
47
48 (put 'sasl-cram 'sasl-authenticator
49      (sasl-make-authenticator "CRAM-MD5" sasl-cram-md5-continuations))
50
51 (provide 'sasl-cram)
52
53 ;;; sasl-cram.el ends here