MD4 support for GNUS

Johan Vromans jv at mh.nl
Sun May 12 00:31:32 AEST 1991


This file defines the functions to have automatic validation and
insertion of MD4 signatures using GNUS.

See the recent postings in comp.sources.misc for a discussion of MD4.

#!/bin/sh
# This is 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/11/1991 14:27 UTC by jv at pronto
# Source directory /u1/users/jv
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   4010 -r--r--r-- md4.el
#
# ============= md4.el ==============
if test -f 'md4.el' -a X"$1" != X"-c"; then
	echo 'x - skipping md4.el (File already exists)'
else
echo 'x - extracting md4.el (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'md4.el' &&
X;; @(#)@ md4 1.1 - MD4 support for GNUS
X;;
X;; This file defines functions to calculate a MD4 signature, add
X;; it to outgoing postings, and validate it on incoming postings.
X;;
X;; It uses "gnus-Inews-article-hook", called by GNUS just before passing
X;; the articel to inews, to install the signature.
X;;
X;; "gnus-Article-prepare-hook" is used to validate the signature on
X;; an article if you read it.
X;;
X;; This file, if useful, is covered by the GPL.
X;;
X;;	Johan Vromans <jv at mh.nl>
X
X;; Customizations
X
X(defvar md4-command "md4" "*Where to find md4")
X
X(defvar md4-signature-header "X-Md4-Signature")
X
X(defvar md4-insertion t
X  "*Controls MD4 signature insertion. If nil, no signature is
X  calculated nor inserted.")
X
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
X;; Hook definitions and insertions.
X
X(add-hook 'gnus-Inews-article-hook 'md4-add-signature)
X(add-hook 'gnus-Article-prepare-hook 'md4-validate-signature)
X;;
X;; Calcuates the MD4 signature for the article to be posted, which
X;; is assumed to be in the current buffer.
X;;
X(defun md4-add-signature ()
X  "Adds a MD4-signature to the article being posted. Must be called
Xfrom 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 (file-exists-p
X	   (setq sigfile
X		 (or gnus-signature-file (expand-file-name "~/.signature"))))
X	  (progn
X	    (insert "-- \n")		; that is what I get inserted...
X	    (insert-file sigfile))
X	(setq sigfile nil))
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
X;;
X;; Validate MD4 signature. A message is shown with the result.
X;; If the signature does not match, buffer "*MD4 Buffer*" holds more
X;; information.
X;;
X(defun md4-validate-signature ()
X  "Checks a MD4-signature in the article being read. May be called
Xfrom 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
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 4010 -eq "$Wc_c" ||
	echo 'md4.el: original size 4010, current size' "$Wc_c"
fi
exit 0
-- 
Johan Vromans				       jv at 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" -------------------------



More information about the Alt.sources mailing list