Debian Codegraph @

mew-auth.el

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 ;;; mew-auth.el
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Aug 17, 1999
5
6 ;;; Code:
7
8 (require 'mew)
9
10 (defun mew-auth-select (grt lst)
11 (mew-auth-select2 (mew-split grt mew-sp) lst))
12
13 (defun mew-auth-select2 (auths lst)
14 (let (n preference strongest)
15 (dolist (auth auths)
16 (setq n (mew-member-case-equal auth lst))
17 (cond
18 ((null n) ())
19 ((null preference)
20 (setq preference n)
21 (setq strongest auth))
22 ((< n preference)
23 (setq preference n)
24 (setq strongest auth))))
25 strongest))
26
27 (defun mew-md5-raw (str)
28 (let* ((md5str (mew-md5 str))
29 (len (length md5str))
30 (md5raw (make-string (/ len 2) 0))
31 (i 0) (j 0))
32 (while (< i len)
33 (aset md5raw j (+ (* (mew-hexchar-to-int (aref md5str i)) 16)
34 (mew-hexchar-to-int (aref md5str (1+ i)))))
35 (setq i (+ i 2))
36 (setq j (1+ j)))
37 md5raw))
38
39 ;; (mew-hmac-md5 "what do ya want for nothing?" "Jefe")
40 ;; -> 0x750c783e6ab0b503eaa86e310a5db738
41
42 (defun mew-hmac-md5 (message key)
43 "HMAC-MD5 defined in RFC 2104"
44 (let* ((keylen (length key))
45 (ipad 54) ;; 0x36
46 (opad 92) ;; 0x5c
47 (ikey (make-string 64 0))
48 okey digest)
49 (when (< keylen 64)
50 (dotimes (i keylen)
51 (aset ikey i (aref key i))))
52 (setq okey (copy-sequence ikey))
53 (dotimes (i 64)
54 (aset ikey i (logxor (aref ikey i) ipad))
55 (aset okey i (logxor (aref okey i) opad)))
56 (setq digest (mew-md5-raw (concat ikey message)))
57 (mew-md5 (concat okey digest))))
58
59 (defun mew-cram-md5 (user passwd b64-challenge)
60 "CRAM-MD5 defined in RFC 2195"
61 (let* ((challenge (mew-base64-decode-string b64-challenge))
62 (response (mew-hmac-md5 challenge passwd)))
63 (mew-base64-encode-string (format "%s %s" user response))))
64
65 ;;
66
67 (defun mew-keyed-md5 (key passwd)
68 (mew-md5 (concat key passwd)))
69
70 (provide 'mew-auth)
71
72 ;;; Copyright Notice:
73
74 ;; Copyright (C) 2000-2015 Mew developing team.
75 ;; All rights reserved.
76
77 ;; Redistribution and use in source and binary forms, with or without
78 ;; modification, are permitted provided that the following conditions
79 ;; are met:
80 ;;
81 ;; 1. Redistributions of source code must retain the above copyright
82 ;; notice, this list of conditions and the following disclaimer.
83 ;; 2. Redistributions in binary form must reproduce the above copyright
84 ;; notice, this list of conditions and the following disclaimer in the
85 ;; documentation and/or other materials provided with the distribution.
86 ;; 3. Neither the name of the team nor the names of its contributors
87 ;; may be used to endorse or promote products derived from this software
88 ;; without specific prior written permission.
89 ;;
90 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
91 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
93 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
94 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
95 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
96 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
97 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
98 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
99 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
100 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
101
102 ;;; mew-auth.el ends here