home *** CD-ROM | disk | FTP | other *** search
- From: jv@mh.nl (Johan Vromans)
- Newsgroups: alt.sources,gnu.emacs.gnus,gnu.emacs.sources
- Subject: MD4 support for GNU Emacs GNUS version 1.4
- Message-ID: <1991May22.142150.6490@pronto.mh.nl>
- Date: 22 May 91 14:21:50 GMT
-
-
- This release
- * includes instructions for use
- * corrects the inclusion of the .signature file
- * provides the necessary 'add-hook' function
- * includes a decent README
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # This is md4, a shell archive (produced by shar 3.49)
- # To extract the files from this archive, save it to a file, remove
- # everything above the "!/bin/sh" line above, and type "sh file_name".
- #
- # made 05/22/1991 12:18 UTC by jv@mh.nl
- # Source directory /u1/users/jv/elisp/src/md4
- #
- # existing files will NOT be overwritten unless -c is specified
- #
- # This shar contains:
- # length mode name
- # ------ ---------- ------------------------------------------
- # 1318 -rw-r--r-- README
- # 5865 -r--r--r-- md4.el
- # 647 -rw-r--r-- add-hook.el
- #
- if test -r _shar_seq_.tmp; then
- echo 'Must unpack archives in sequence!'
- echo Please unpack part `cat _shar_seq_.tmp` next
- exit 1
- fi
- # ============= README ==============
- if test -f 'README' -a X"$1" != X"-c"; then
- echo 'x - skipping README (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting README (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'README' &&
- This is MD4 signature support for the GNU Emacs GNUS newsreader.
- X
- MD4 can be used to apply a fingerprint on an article posted to USENET that,
- when run through a verification tool, will tell you whether an article has
- been corrupted. It does not detect or prevent complete replacement of the
- article. Think of MD4 as a super-strong checksum.
- X
- This package allows for automatic insertion of the MD4 signature in
- news articles posted with GNUS, and the automatic verification of MD4
- signatures in articles when retrieved. The main source file, 'md4.el'
- is heavily commented on usage and customization.
- X
- As stated in RFC1186:
- X
- X This note describes the MD4 message digest algorithm. The algorithm
- X takes as input an input message of arbitrary length and produces as
- X output a 128-bit "fingerprint" or "message digest" of the input. It
- X is conjectured that it is computationally infeasible to produce two
- X messages having the same message digest, or to produce any message
- X having a given prespecified target message digest. The MD4 algorithm
- X is thus ideal for digital signature applications, where a large file
- X must be "compressed" in a secure manner before being signed with the
- X RSA public-key cryptosystem.
- X
- Please read RFC1186 for more details about MD4.
- X
- Have fun,
- X
- X Johan Vromans <jv@mh.nl>
- SHAR_EOF
- chmod 0644 README ||
- echo 'restore of README failed'
- Wc_c="`wc -c < 'README'`"
- test 1318 -eq "$Wc_c" ||
- echo 'README: original size 1318, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= md4.el ==============
- if test -f 'md4.el' -a X"$1" != X"-c"; then
- echo 'x - skipping md4.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting md4.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'md4.el' &&
- ;; md4.el -- MD4 support for GNUS
- ;;
- ;; SCCS Status : @(#)@ md4 1.4
- ;; Author : Johan Vromans
- ;; Created On : Sat May 11 09:10:04 1991
- ;; Last Modified By: Johan Vromans
- ;; Last Modified On: Wed May 22 13:36:56 1991
- ;; Update Count : 11
- ;; Status : OK
- ;;
- ;; This file defines functions to calculate a MD4 signature, add
- ;; it to outgoing postings, and validate it on incoming postings.
- ;;
- ;; It uses "gnus-Inews-article-hook", called by GNUS just before passing
- ;; the articel to inews, to install the signature.
- ;;
- ;; "gnus-Article-prepare-hook" is used to validate the signature on
- ;; an article if you read it.
- ;;
- ;; Advised usage: load this file after loading gnus, e.g. from the
- ;; gnus-Startup-hook.
- ;; You also can do this explicitly:
- ;;
- ;; (load "gnus" nil t)
- ;; (load "md4" t nil) ; optional
- ;; (gnus)
- ;;
- ;; This file, if useful, is covered by the GPL.
- ;;
- ;; Johan Vromans <jv@mh.nl>
- X
- ;; HISTORY
- ;; 22-May-1991 Johan Vromans
- ;; Enhanced comments and improved customization.
- ;; Added provide 'md4 and require 'add-hook.
- ;; Normalized .signature file inclusion.
- X
- (provide 'md4)
- (or (fboundp 'add-hook)
- X (require 'add-hook)) ; by Dan LaLiberte <liberte@cs.uiuc.edu>
- X
- ;; Customizations
- ;;
- ;; This function only uses program md4; it doesn't need md4hash nor
- ;; md4check.
- ;; The md4 programs can be retrieved from your nearest comp.sources.misc
- ;; archive site. Contact the moderator of comp.sources.misc for details.
- ;;
- (defvar md4-command "md4"
- X "*Where to find the md4 program. This program should be in your PATH.")
- X
- (defvar md4-insertion t
- X "*Controls MD4 signature insertion. If nil, no signature is inserted.")
- X
- (defvar md4-validation 1
- X "*Controls MD4 signature validation. If nil, no validation is
- X performed. If t, validation is performed, and failures are reported.
- X Any other value causes validation to be performed, and failures as
- X well as successes to be reported.")
- X
- ;; If the variable gnus-signature-file is not null, GNUS will append
- ;; this file to the article before posting. If null, your .signature
- ;; is supposed to be added by your news system. In this case, the md4
- ;; calculation will temporary insert the signature to make sure a
- ;; correct checksum is calculated.
- ;; You may have to change the md4-signature-separator if needed.
- X
- (defvar md4-signature-separator "-- \n"
- X "*If your news posting system appends your .signature file for you,
- X then set this variable to the separator string used. In this case,
- X the signature will be added on behalf of the calculation of the MD4
- X checksum, and removed before the article is transferred to the news
- X system.
- X In general, set it to "--\\n" or "-- \\n" for classic B-news or C-news.")
- X
- ;;
- ;; End of customizations
- ;;
- X
- (defvar md4-signature-header "X-Md4-Signature")
- X
- ;; Hook definitions and insertions.
- X
- (add-hook 'gnus-Inews-article-hook 'md4-add-signature)
- (add-hook 'gnus-Article-prepare-hook 'md4-validate-signature)
- ;;
- ;; Calcuates the MD4 signature for the article to be posted, which
- ;; is assumed to be in the current buffer.
- ;;
- (defun md4-add-signature ()
- X "Adds a MD4-signature to the article being posted. Must be called
- from gnus-Inews-article-hook."
- X (interactive)
- X
- X (if (null md4-insertion)
- X nil
- X (let (start-of-body end-of-body sigfile)
- X
- X ;; .signature handling. may be system specific
- X (goto-char (point-max))
- X (setq end-of-body (point-marker))
- X (if (not gnus-signature-file) ;skip if gnus-sig set
- X (if (file-exists-p
- X (setq sigfile (expand-file-name "~/.signature")))
- X (progn
- X (insert md4-signature-separator)
- X (insert-file sigfile))
- X (setq sigfile nil))) ;signal 'no file'
- X
- X (goto-char (point-min))
- X (search-forward "\n\n")
- X (setq start-of-body (point-marker)) ; remember where
- X
- X ;; Run md4 and add the signature.
- X (forward-line -1)
- X (insert md4-signature-header ": ")
- X (insert (md4-signature-region start-of-body (point-max)))
- X (insert "\n")
- X
- X (if sigfile
- X (delete-region end-of-body (point-max)))
- X )))
- X
- ;;
- ;; Validate MD4 signature. A message is shown with the result.
- ;; If the signature does not match, buffer "*MD4 Buffer*" holds more
- ;; information.
- ;;
- (defun md4-validate-signature ()
- X "Checks a MD4-signature in the article being read. May be called
- from gnus-article-prepare-hook."
- X (interactive)
- X
- X (if (null md4-validation)
- X nil
- X (let (start-of-body)
- X (goto-char (point-min))
- X (search-forward "\n\n")
- X (setq start-of-body (point-marker)) ; remember where
- X
- X ;; Check if a signature header is present
- X (goto-char (point-min))
- X (if (search-forward
- X (concat "\n" md4-signature-header ": ")
- X start-of-body t)
- X (let (signature (here (point)))
- X (forward-line 1)
- X (setq signature (buffer-substring here (1- (point))))
- X
- X ;; Validate
- X (if (string=
- X signature
- X (md4-signature-region start-of-body (point-max)))
- X (progn
- X (if (not (equal md4-validation t))
- X (message "MD4 signature valid."))
- X (bury-buffer md4-buffer))
- X (beep)
- X (save-excursion
- X (set-buffer md4-buffer)
- X (goto-char (point-min))
- X (insert (message "MD4 signature mismatch!")
- X "\nPosted: " signature
- X "\nCalculated: ")
- X (goto-char (point-min))))
- X )))))
- X
- (defun md4-signature-region (start end)
- X "Calculates MD4 signature."
- X
- X ;; Get buffer and clear it
- X (setq md4-buffer (get-buffer-create "*MD4 Buffer*"))
- X (save-excursion
- X (set-buffer md4-buffer)
- X (erase-buffer))
- X
- X ;; Run md4
- X (call-process-region start end
- X md4-command nil md4-buffer nil)
- X
- X ;; Verify normal result
- X (save-excursion
- X (set-buffer md4-buffer)
- X (if (= (buffer-size) 33)
- X (buffer-substring (point-min) (1- (point-max)))
- X (error "Unexpected result from %s: %s" md4-command
- X (buffer-substring (point-min) (point-max))))))
- SHAR_EOF
- chmod 0444 md4.el ||
- echo 'restore of md4.el failed'
- Wc_c="`wc -c < 'md4.el'`"
- test 5865 -eq "$Wc_c" ||
- echo 'md4.el: original size 5865, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= add-hook.el ==============
- if test -f 'add-hook.el' -a X"$1" != X"-c"; then
- echo 'x - skipping add-hook.el (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting add-hook.el (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'add-hook.el' &&
- ;; add-hook function by Dan LaLiberte <liberte@cs.uiuc.edu>
- X
- (provide 'add-hook)
- X
- (defun add-hook (hook-var hook-function)
- X "Prepend to the value of HOOK-VAR the function HOOK-FUNCTION, if it
- is not already an element.
- hook-var's value may be a single function or a list of functions."
- X (if (boundp hook-var)
- X (let ((value (symbol-value hook-var)))
- X (if (and (listp value) (not (eq (car value) 'lambda)))
- X (and (not (memq hook-function value))
- X (set hook-var
- X (cons hook-function value)))
- X (and (not (eq hook-function value))
- X (set hook-var
- X (list hook-function value)))))
- X (set hook-var hook-function)
- X ))
- SHAR_EOF
- chmod 0644 add-hook.el ||
- echo 'restore of add-hook.el failed'
- Wc_c="`wc -c < 'add-hook.el'`"
- test 647 -eq "$Wc_c" ||
- echo 'add-hook.el: original size 647, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- exit 0
- --
- Johan Vromans jv@mh.nl via internet backbones
- Multihouse Automatisering bv uucp: ..!{uunet,hp4nl}!mh.nl!jv
- Doesburgweg 7, 2803 PL Gouda, The Netherlands phone/fax: +31 1820 62911/62500
- ------------------------ "Arms are made for hugging" -------------------------
-