home *** CD-ROM | disk | FTP | other *** search
- ;; @(#)@ md4 1.1 - MD4 support for GNUS
- ;;
- ;; 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.
- ;;
- ;; This file, if useful, is covered by the GPL.
- ;;
- ;; Johan Vromans <jv@mh.nl>
-
- ;; Customizations
-
- (defvar md4-command "md4" "*Where to find md4")
-
- (defvar md4-signature-header "X-Md4-Signature")
-
- (defvar md4-insertion t
- "*Controls MD4 signature insertion. If nil, no signature is
- calculated nor 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.")
-
- ;; Hook definitions and insertions.
-
- (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 (file-exists-p
- (setq sigfile
- (or gnus-signature-file (expand-file-name "~/.signature"))))
- (progn
- (insert "-- \n") ; that is what I get inserted...
- (insert-file sigfile))
- (setq sigfile nil))
-
- (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))))))
-