Newsgroups: alt.security.pgp,gnu.emacs.vm.info
From: mwarren@oracle.com (Mark Warren)
Subject: Re: Signing messages with headers only.
Organization: Oracle Corporation, Belmont, CA
Date: Thu, 31 Dec 1992 20:19:07 GMT
X-Disclaimer: This message was written by an unauthenticated user
              at Oracle Corporation.  The opinions expressed are those
              of the user and not necessarily those of Oracle.


There is a package md4.el (included below) to do message fingerprint
verification. Perhaps this combined with the -b option of pgp could be
used to create an automatic signature generation/checking for use in
emacs and vm (this is probably of limited value for elm/mh and
rn/nn/trn users). Hopefully someone will have already hacked together
a package.

Thanks,

Mark

From alt.security.pgp:
In article <1992Dec30.175147.17244@netcom.com> jef@netcom.com (Jef Poskanzer) writes:

   amanda@intercon.com (Amanda Walker):
   }-----BEGIN PRIVACY-ENHANCED MESSAGE-----
   }jef@netcom.com (Jef Poskanzer) writes:
   }> Note, since posting this I've fetched RIPEM, and found that it
   }> doesn't have this headers-only option either.
   }
   }If I understand this correctly, I believe it does; that is to say, RIPEM
   }can indeed produce a signed message, where the body remains in the clear.
   }You just have to use the "-m mic-clear" option.  For example, this article
   }was produced by piping the body through "ripem -e -m mic-clear".
   }-----END PRIVACY-ENHANCED MESSAGE-----

   Yeah, I noticed that feature.  PGP has the equivalent.  What neither
   has is a mode to sign using *headers only*.  As in, up there at the
   top with my X-Face, without all that ---BEGIN arglebargle messing up
   the message.
   ---
   Jef

	      Jef Poskanzer  jef@netcom.com  jef@well.sf.ca.us
	"You striving, bickering, foolishly brave humans." -- Apollo

======================================================================

;; md4.el -- MD4 support for GNUS
;;
;; SCCS Status     : @(#)@ md4	1.5
;; Author          : Johan Vromans
;; Created On      : Sat May 11 09:10:04 1991
;; Last Modified By: Dave Brennan
;; Last Modified On: Mon Jul  6 16:42:14 1992
;; Update Count    : 13
;; Status          : OK
;;
;; LCD Archive Entry:
;; md4|Johan Vromans|jv@mh.nl|
;; MD4 support for GNUS|
;; 92-06-16|1.5|~/misc/md4.el.Z|
;;
;; 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>

;; HISTORY 
;; 16-Jun-1992		Johan Vromans	
;;    Added LCD entry.
;; 22-May-1991		Johan Vromans	
;;    Enhanced comments and improved customization.
;;    Added provide 'md4 and require 'add-hook.
;;    Normalized .signature file inclusion.

(provide 'md4)
;;(or (fboundp 'add-hook)
;;    (require 'add-hook))	; by Dan LaLiberte <liberte@cs.uiuc.edu>

;; 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 "md5"
  "*Where to find the md4 program. This program should be in your PATH.")

(defvar md4-insertion t
  "*Controls MD4 signature insertion. If nil, no signature is inserted.")

(defvar md4-validation 1
  "*Controls MD4 signature validation. If nil, no validation is
  performed. If t, validation is performed, and failures are reported.
  Any other value causes validation to be performed, and failures as
  well as successes to be reported.")

;; 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.

(defvar md4-signature-separator "-- \n"
  "*If your news posting system appends your .signature file for you, 
  then set this variable to the separator string used. In this case, 
  the signature will be added on behalf of the calculation of the MD4
  checksum, and removed before the article is transferred to the news
  system.
  In general, set it to "--\\n" or "-- \\n" for classic B-news or C-news.")

;;
;; End of customizations
;;

(defvar md4-signature-header "X-Md4-Signature")

;; Hook definitions and insertions.
;;
;; Commented out these two lines since I don't have the package add-hook yet
;; maw 9/28/92
;; (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 ()
  "Adds a MD4-signature to the article being posted. Must be called
from gnus-Inews-article-hook."
  (interactive)

  (if (null md4-insertion)
      nil
    (let (start-of-body end-of-body sigfile)

      ;; .signature handling. may be system specific
      (goto-char (point-max))
      (setq end-of-body (point-marker))
      (if (not gnus-signature-file)	;skip if gnus-sig set
	  (if (file-exists-p
	       (setq sigfile (expand-file-name "~/.signature")))
	      (progn
		(insert md4-signature-separator)
		(insert-file sigfile))
	    (setq sigfile nil)))	;signal 'no file'

      (goto-char (point-min))
      (search-forward "\n\n")
      (setq start-of-body (point-marker))	; remember where
      
      ;; Run md4 and add the signature.
      (forward-line -1)
      (insert md4-signature-header ": ")
      (insert (md4-signature-region start-of-body (point-max)))
      (insert "\n")

      (if sigfile
	  (delete-region end-of-body (point-max)))
      )))

;;
;; 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 ()
  "Checks a MD4-signature in the article being read. May be called
from gnus-article-prepare-hook."
  (interactive)

  (if (null md4-validation)
      nil
    (let (start-of-body)
      (goto-char (point-min))
      (search-forward "\n\n")
      (setq start-of-body (point-marker))	; remember where

      ;; Check if a signature header is present
      (goto-char (point-min))
      (if (search-forward 
	   (concat "\n" md4-signature-header ": ")
	   start-of-body t)
	  (let (signature (here (point)))
	    (forward-line 1)
	    (setq signature (buffer-substring here (1- (point))))

	    ;; Validate
	    (if (string= 
		 signature
		 (md4-signature-region start-of-body (point-max)))
		(progn
		  (if (not (equal md4-validation t))
		      (message "MD4 signature valid."))
		  (bury-buffer md4-buffer))
	      (beep)
	      (save-excursion
		(set-buffer md4-buffer)
		(goto-char (point-min))
		(insert (message "MD4 signature mismatch!")
			"\nPosted:     " signature
			"\nCalculated: ")
		(goto-char (point-min))))
	    )))))

(defun md4-signature-region (start end)
  "Calculates MD4 signature."

  ;; Get buffer and clear it
  (setq md4-buffer (get-buffer-create "*MD4 Buffer*"))
  (save-excursion
    (set-buffer md4-buffer)
    (erase-buffer))

  ;; Run md4
  (call-process-region start end
		       md4-command nil md4-buffer nil)

  ;; Verify normal result
  (save-excursion
    (set-buffer md4-buffer)
    (if (= (buffer-size) 33)
	(buffer-substring (point-min) (1- (point-max)))
      (error "Unexpected result from %s: %s" md4-command
	     (buffer-substring (point-min) (point-max))))))
--
Mark Warren                      300 Oracle Parkway, office #423, mail #659304
warren@us.oracle.com                                  Redwood Shores, CA 94065
(415) 506-4639 Voice or 506-7292 Fax         Friends don't let friends run DOS
--
The X-Face header is my picture! Get `faces' from iuvax.cs.indiana.edu
----------------------------------------------------------------------
Newsgroups: alt.security,sci.crypt,talk.politics.guns,talk.politics.misc,alt.security.pgp