1 ;;; digest-md5.el --- Compute DIGEST-MD5.
3 ;; Copyright (C) 1999 Kenichi OKADA
5 ;; Author: Kenichi OKADA <okada@opaopa.org>
6 ;; Keywords: DIGEST-MD5, HMAC-MD5, SASL, IMAP, POP, ACAP
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or
13 ;; (at your option) any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 ;; This program is implemented from draft-leach-digest-sasl-05.txt.
31 ;; It is caller's responsibility to base64-decode challenges and
32 ;; base64-encode responses in IMAP4 AUTHENTICATE command.
34 ;; Passphrase should be longer than 16 bytes. (See RFC 2195)
38 ;; (digest-md5-digest-response "chris" "elwood.innosoft.com"
39 ;; "OA6MG9tEQGm2hh" "OA6MHXh6VqTrRk"
40 ;; "imap/elwood.innosoft.com"
41 ;; "d388dad90d4bbd760a152321f2143af7"
42 ;; 1 "auth" nil "utf-8")
43 ;; => "charset=utf-8,username=\"chris\",realm=\"elwood.innosoft.com\",nonce=\"OA6MG9tEQGm2hh\",nc=00000001,cnonce=\"OA6MHXh6VqTrRk\",digest-uri=\"imap/elwood.innosoft.com\",response=d388dad90d4bbd760a152321f2143af7,qop=auth"
51 (defvar digest-md5-parse-digest-challenge-syntax-table
52 (let ((table (make-syntax-table)))
53 (modify-syntax-entry ?= "." table)
54 (modify-syntax-entry ?, "." table)
56 "A syntax table for parsing sgml attributes.")
58 (defun digest-md5-parse-digest-challenge (digest-challenge)
59 ;; return a property list of
60 ;; (realm nonce qop-options stale maxbuf charset
61 ;; algorithm cipher-opts auth-param).
63 (set-syntax-table digest-md5-parse-digest-challenge-syntax-table)
64 (insert digest-challenge)
65 (goto-char (point-min))
67 (while (progn (forward-sexp) (not (eobp)))
72 (read (point-min-marker))
74 (error "Parse error in digest-challenge.")))))
76 (defun digest-md5-digest-uri (serv-type host &optional serv-name)
77 (concat serv-type "/" host
79 (null (string= host serv-name)))
80 (concat "/" serv-name))))
82 (defun digest-md5-cnonce ()
83 ;; It is RECOMMENDED that it
84 ;; contain at least 64 bits of entropy.
85 (concat (unique-id-m "") (unique-id-m "")))
87 (defun digest-md5-digest-response (username
90 &optional nonce-count qop
91 maxbuf charset cipher authzid)
94 (concat "charset=" charset ","))
95 "username=\"" username "\""
96 ",realm=\"" realm "\""
97 ",nonce=\"" nonce "\""
100 ",cnonce=\"" cnonce "\""
101 ",digest-uri=\"" digest-uri "\""
102 ",response=" response
104 (concat ",qop=" qop))
106 (concat ",maxbuf=" maxbuf))
108 (concat ",cipher=" cipher))
110 (concat ",authzid=\"" authzid "\""))))
113 (provide 'digest-md5)
115 ;;; digest-md5.el ends here