home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3409 < prev    next >
Encoding:
Internet Message Format  |  1991-05-24  |  10.5 KB

  1. From: jv@mh.nl (Johan Vromans)
  2. Newsgroups: alt.sources,gnu.emacs.gnus,gnu.emacs.sources
  3. Subject: MD4 support for GNU Emacs GNUS version 1.4
  4. Message-ID: <1991May22.142150.6490@pronto.mh.nl>
  5. Date: 22 May 91 14:21:50 GMT
  6.  
  7.  
  8. This release 
  9.   * includes instructions for use
  10.   * corrects the inclusion of the .signature file
  11.   * provides the necessary 'add-hook' function
  12.   * includes a decent README
  13.  
  14. ---- Cut Here and feed the following to sh ----
  15. #!/bin/sh
  16. # This is md4, a shell archive (produced by shar 3.49)
  17. # To extract the files from this archive, save it to a file, remove
  18. # everything above the "!/bin/sh" line above, and type "sh file_name".
  19. #
  20. # made 05/22/1991 12:18 UTC by jv@mh.nl
  21. # Source directory /u1/users/jv/elisp/src/md4
  22. #
  23. # existing files will NOT be overwritten unless -c is specified
  24. #
  25. # This shar contains:
  26. # length  mode       name
  27. # ------ ---------- ------------------------------------------
  28. #   1318 -rw-r--r-- README
  29. #   5865 -r--r--r-- md4.el
  30. #    647 -rw-r--r-- add-hook.el
  31. #
  32. if test -r _shar_seq_.tmp; then
  33.     echo 'Must unpack archives in sequence!'
  34.     echo Please unpack part `cat _shar_seq_.tmp` next
  35.     exit 1
  36. fi
  37. # ============= README ==============
  38. if test -f 'README' -a X"$1" != X"-c"; then
  39.     echo 'x - skipping README (File already exists)'
  40.     rm -f _shar_wnt_.tmp
  41. else
  42. > _shar_wnt_.tmp
  43. echo 'x - extracting README (Text)'
  44. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  45. This is MD4 signature support for the GNU Emacs GNUS newsreader.
  46. X
  47. MD4 can be used to apply a fingerprint on an article posted to USENET that,
  48. when run through a verification tool, will tell you whether an article has 
  49. been corrupted. It does not detect or prevent complete replacement of the
  50. article. Think of MD4 as a super-strong checksum.
  51. X
  52. This package allows for automatic insertion of the MD4 signature in
  53. news articles posted with GNUS, and the automatic verification of MD4
  54. signatures in articles when retrieved. The main source file, 'md4.el'
  55. is heavily commented on usage and customization.
  56. X
  57. As stated in RFC1186:
  58. X   This  note describes the MD4 message digest algorithm.  The algorithm
  59. X   takes as input an input message of arbitrary length and produces as
  60. X   output a 128-bit "fingerprint" or "message digest" of the input.  It
  61. X   is conjectured that it is computationally infeasible to produce two
  62. X   messages having the same message digest, or to produce any message
  63. X   having a given prespecified target message digest.  The MD4 algorithm
  64. X   is thus ideal for digital signature applications, where a large file
  65. X   must be "compressed" in a secure manner before being signed with the
  66. X   RSA public-key cryptosystem.
  67. X
  68. Please read RFC1186 for more details about MD4.
  69. X
  70. Have fun,
  71. X
  72. X    Johan Vromans <jv@mh.nl>
  73. SHAR_EOF
  74. chmod 0644 README ||
  75. echo 'restore of README failed'
  76. Wc_c="`wc -c < 'README'`"
  77. test 1318 -eq "$Wc_c" ||
  78.     echo 'README: original size 1318, current size' "$Wc_c"
  79. rm -f _shar_wnt_.tmp
  80. fi
  81. # ============= md4.el ==============
  82. if test -f 'md4.el' -a X"$1" != X"-c"; then
  83.     echo 'x - skipping md4.el (File already exists)'
  84.     rm -f _shar_wnt_.tmp
  85. else
  86. > _shar_wnt_.tmp
  87. echo 'x - extracting md4.el (Text)'
  88. sed 's/^X//' << 'SHAR_EOF' > 'md4.el' &&
  89. ;; md4.el -- MD4 support for GNUS
  90. ;;
  91. ;; SCCS Status     : @(#)@ md4    1.4
  92. ;; Author          : Johan Vromans
  93. ;; Created On      : Sat May 11 09:10:04 1991
  94. ;; Last Modified By: Johan Vromans
  95. ;; Last Modified On: Wed May 22 13:36:56 1991
  96. ;; Update Count    : 11
  97. ;; Status          : OK
  98. ;;
  99. ;; This file defines functions to calculate a MD4 signature, add
  100. ;; it to outgoing postings, and validate it on incoming postings.
  101. ;;
  102. ;; It uses "gnus-Inews-article-hook", called by GNUS just before passing
  103. ;; the articel to inews, to install the signature.
  104. ;;
  105. ;; "gnus-Article-prepare-hook" is used to validate the signature on
  106. ;; an article if you read it.
  107. ;;
  108. ;; Advised usage: load this file after loading gnus, e.g. from the
  109. ;; gnus-Startup-hook.
  110. ;; You also can do this explicitly:
  111. ;;
  112. ;;      (load "gnus" nil t)
  113. ;;    (load "md4" t nil)    ; optional
  114. ;;    (gnus)
  115. ;;
  116. ;; This file, if useful, is covered by the GPL.
  117. ;;
  118. ;;    Johan Vromans <jv@mh.nl>
  119. X
  120. ;; HISTORY 
  121. ;; 22-May-1991        Johan Vromans    
  122. ;;    Enhanced comments and improved customization.
  123. ;;    Added provide 'md4 and require 'add-hook.
  124. ;;    Normalized .signature file inclusion.
  125. X
  126. (provide 'md4)
  127. (or (fboundp 'add-hook)
  128. X    (require 'add-hook))    ; by Dan LaLiberte <liberte@cs.uiuc.edu>
  129. X
  130. ;; Customizations
  131. ;;
  132. ;; This function only uses program md4; it doesn't need md4hash nor 
  133. ;; md4check.
  134. ;; The md4 programs can be retrieved from your nearest comp.sources.misc
  135. ;; archive site. Contact the moderator of comp.sources.misc for details.
  136. ;;
  137. (defvar md4-command "md4"
  138. X  "*Where to find the md4 program. This program should be in your PATH.")
  139. X
  140. (defvar md4-insertion t
  141. X  "*Controls MD4 signature insertion. If nil, no signature is inserted.")
  142. X
  143. (defvar md4-validation 1
  144. X  "*Controls MD4 signature validation. If nil, no validation is
  145. X  performed. If t, validation is performed, and failures are reported.
  146. X  Any other value causes validation to be performed, and failures as
  147. X  well as successes to be reported.")
  148. X
  149. ;; If the variable gnus-signature-file is not null, GNUS will append
  150. ;; this file to the article before posting. If null, your .signature
  151. ;; is supposed to be added by your news system. In this case, the md4
  152. ;; calculation will temporary insert the signature to make sure a
  153. ;; correct checksum is calculated.
  154. ;; You may have to change the md4-signature-separator if needed.
  155. X
  156. (defvar md4-signature-separator "-- \n"
  157. X  "*If your news posting system appends your .signature file for you, 
  158. X  then set this variable to the separator string used. In this case, 
  159. X  the signature will be added on behalf of the calculation of the MD4
  160. X  checksum, and removed before the article is transferred to the news
  161. X  system.
  162. X  In general, set it to "--\\n" or "-- \\n" for classic B-news or C-news.")
  163. X
  164. ;;
  165. ;; End of customizations
  166. ;;
  167. X
  168. (defvar md4-signature-header "X-Md4-Signature")
  169. X
  170. ;; Hook definitions and insertions.
  171. X
  172. (add-hook 'gnus-Inews-article-hook 'md4-add-signature)
  173. (add-hook 'gnus-Article-prepare-hook 'md4-validate-signature)
  174. ;;
  175. ;; Calcuates the MD4 signature for the article to be posted, which
  176. ;; is assumed to be in the current buffer.
  177. ;;
  178. (defun md4-add-signature ()
  179. X  "Adds a MD4-signature to the article being posted. Must be called
  180. from gnus-Inews-article-hook."
  181. X  (interactive)
  182. X
  183. X  (if (null md4-insertion)
  184. X      nil
  185. X    (let (start-of-body end-of-body sigfile)
  186. X
  187. X      ;; .signature handling. may be system specific
  188. X      (goto-char (point-max))
  189. X      (setq end-of-body (point-marker))
  190. X      (if (not gnus-signature-file)    ;skip if gnus-sig set
  191. X      (if (file-exists-p
  192. X           (setq sigfile (expand-file-name "~/.signature")))
  193. X          (progn
  194. X        (insert md4-signature-separator)
  195. X        (insert-file sigfile))
  196. X        (setq sigfile nil)))    ;signal 'no file'
  197. X
  198. X      (goto-char (point-min))
  199. X      (search-forward "\n\n")
  200. X      (setq start-of-body (point-marker))    ; remember where
  201. X      
  202. X      ;; Run md4 and add the signature.
  203. X      (forward-line -1)
  204. X      (insert md4-signature-header ": ")
  205. X      (insert (md4-signature-region start-of-body (point-max)))
  206. X      (insert "\n")
  207. X
  208. X      (if sigfile
  209. X      (delete-region end-of-body (point-max)))
  210. X      )))
  211. X
  212. ;;
  213. ;; Validate MD4 signature. A message is shown with the result.
  214. ;; If the signature does not match, buffer "*MD4 Buffer*" holds more
  215. ;; information.
  216. ;;
  217. (defun md4-validate-signature ()
  218. X  "Checks a MD4-signature in the article being read. May be called
  219. from gnus-article-prepare-hook."
  220. X  (interactive)
  221. X
  222. X  (if (null md4-validation)
  223. X      nil
  224. X    (let (start-of-body)
  225. X      (goto-char (point-min))
  226. X      (search-forward "\n\n")
  227. X      (setq start-of-body (point-marker))    ; remember where
  228. X
  229. X      ;; Check if a signature header is present
  230. X      (goto-char (point-min))
  231. X      (if (search-forward 
  232. X       (concat "\n" md4-signature-header ": ")
  233. X       start-of-body t)
  234. X      (let (signature (here (point)))
  235. X        (forward-line 1)
  236. X        (setq signature (buffer-substring here (1- (point))))
  237. X
  238. X        ;; Validate
  239. X        (if (string= 
  240. X         signature
  241. X         (md4-signature-region start-of-body (point-max)))
  242. X        (progn
  243. X          (if (not (equal md4-validation t))
  244. X              (message "MD4 signature valid."))
  245. X          (bury-buffer md4-buffer))
  246. X          (beep)
  247. X          (save-excursion
  248. X        (set-buffer md4-buffer)
  249. X        (goto-char (point-min))
  250. X        (insert (message "MD4 signature mismatch!")
  251. X            "\nPosted:     " signature
  252. X            "\nCalculated: ")
  253. X        (goto-char (point-min))))
  254. X        )))))
  255. X
  256. (defun md4-signature-region (start end)
  257. X  "Calculates MD4 signature."
  258. X
  259. X  ;; Get buffer and clear it
  260. X  (setq md4-buffer (get-buffer-create "*MD4 Buffer*"))
  261. X  (save-excursion
  262. X    (set-buffer md4-buffer)
  263. X    (erase-buffer))
  264. X
  265. X  ;; Run md4
  266. X  (call-process-region start end
  267. X               md4-command nil md4-buffer nil)
  268. X
  269. X  ;; Verify normal result
  270. X  (save-excursion
  271. X    (set-buffer md4-buffer)
  272. X    (if (= (buffer-size) 33)
  273. X    (buffer-substring (point-min) (1- (point-max)))
  274. X      (error "Unexpected result from %s: %s" md4-command
  275. X         (buffer-substring (point-min) (point-max))))))
  276. SHAR_EOF
  277. chmod 0444 md4.el ||
  278. echo 'restore of md4.el failed'
  279. Wc_c="`wc -c < 'md4.el'`"
  280. test 5865 -eq "$Wc_c" ||
  281.     echo 'md4.el: original size 5865, current size' "$Wc_c"
  282. rm -f _shar_wnt_.tmp
  283. fi
  284. # ============= add-hook.el ==============
  285. if test -f 'add-hook.el' -a X"$1" != X"-c"; then
  286.     echo 'x - skipping add-hook.el (File already exists)'
  287.     rm -f _shar_wnt_.tmp
  288. else
  289. > _shar_wnt_.tmp
  290. echo 'x - extracting add-hook.el (Text)'
  291. sed 's/^X//' << 'SHAR_EOF' > 'add-hook.el' &&
  292. ;; add-hook function by Dan LaLiberte <liberte@cs.uiuc.edu>
  293. X
  294. (provide 'add-hook)
  295. X
  296. (defun add-hook (hook-var hook-function)
  297. X  "Prepend to the value of HOOK-VAR the function HOOK-FUNCTION, if it
  298. is not already an element.
  299. hook-var's value may be a single function or a list of functions."
  300. X  (if (boundp hook-var)
  301. X      (let ((value (symbol-value hook-var)))
  302. X    (if (and (listp value) (not (eq (car value) 'lambda)))
  303. X        (and (not (memq hook-function value))
  304. X         (set hook-var
  305. X              (cons hook-function value)))
  306. X      (and (not (eq hook-function value))
  307. X           (set hook-var
  308. X            (list hook-function value)))))
  309. X    (set hook-var hook-function)
  310. X    ))
  311. SHAR_EOF
  312. chmod 0644 add-hook.el ||
  313. echo 'restore of add-hook.el failed'
  314. Wc_c="`wc -c < 'add-hook.el'`"
  315. test 647 -eq "$Wc_c" ||
  316.     echo 'add-hook.el: original size 647, current size' "$Wc_c"
  317. rm -f _shar_wnt_.tmp
  318. fi
  319. exit 0
  320. -- 
  321. Johan Vromans                       jv@mh.nl via internet backbones
  322. Multihouse Automatisering bv               uucp: ..!{uunet,hp4nl}!mh.nl!jv
  323. Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
  324. ------------------------ "Arms are made for hugging" -------------------------
  325.