]> code.delx.au - gnu-emacs/blob - lisp/gnus/smime.el
(mm-uu-copy-to-buffer): Use with-current-buffer.
[gnu-emacs] / lisp / gnus / smime.el
1 ;;; smime.el --- S/MIME support library
2 ;; Copyright (c) 2000, 2001, 2003 Free Software Foundation, Inc.
3
4 ;; Author: Simon Josefsson <simon@josefsson.org>
5 ;; Keywords: SMIME X.509 PEM OpenSSL
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Commentary:
25
26 ;; This library perform S/MIME operations from within Emacs.
27 ;;
28 ;; Functions for fetching certificates from public repositories are
29 ;; provided, currently only from DNS. LDAP support (via EUDC) is planned.
30 ;;
31 ;; It uses OpenSSL (tested with version 0.9.5a and 0.9.6) for signing,
32 ;; encryption and decryption.
33 ;;
34 ;; Some general knowledge of S/MIME, X.509, PKCS#12, PEM etc is
35 ;; probably required to use this library in any useful way.
36 ;; Especially, don't expect this library to buy security for you. If
37 ;; you don't understand what you are doing, you're as likely to lose
38 ;; security than gain any by using this library.
39 ;;
40 ;; This library is not intended to provide a "raw" API for S/MIME,
41 ;; PKCSx or similar, it's intended to perform common operations
42 ;; done on messages encoded in these formats. The terminology chosen
43 ;; reflect this.
44 ;;
45 ;; The home of this file is in Gnus CVS, but also available from
46 ;; http://josefsson.org/smime.html.
47
48 ;;; Quick introduction:
49
50 ;; Get your S/MIME certificate from VeriSign or someplace. I used
51 ;; Netscape to generate the key and certificate request and stuff, and
52 ;; Netscape can export the key into PKCS#12 format.
53 ;;
54 ;; Enter OpenSSL. To be able to use this library, it need to have the
55 ;; SMIME key readable in PEM format. OpenSSL is used to convert the
56 ;; key:
57 ;;
58 ;; $ openssl pkcs12 -in mykey.p12 -clcerts -nodes > mykey.pem
59 ;; ...
60 ;;
61 ;; Now, use M-x customize-variable smime-keys and add mykey.pem as
62 ;; a key.
63 ;;
64 ;; Now you should be able to sign messages! Create a buffer and write
65 ;; something and run M-x smime-sign-buffer RET RET and you should see
66 ;; your message MIME armoured and a signature. Encryption, M-x
67 ;; smime-encrypt-buffer, should also work.
68 ;;
69 ;; To be able to verify messages you need to build up trust with
70 ;; someone. Perhaps you trust the CA that issued your certificate, at
71 ;; least I did, so I export it's certificates from my PKCS#12
72 ;; certificate with:
73 ;;
74 ;; $ openssl pkcs12 -in mykey.p12 -cacerts -nodes > cacert.pem
75 ;; ...
76 ;;
77 ;; Now, use M-x customize-variable smime-CAs and add cacert.pem as a
78 ;; CA certificate.
79 ;;
80 ;; You should now be able to sign messages, and even verify messages
81 ;; sent by others that use the same CA as you.
82
83 ;; Bugs:
84 ;;
85 ;; Don't complain that this package doesn't do encrypted PEM files,
86 ;; submit a patch instead. I store my keys in a safe place, so I
87 ;; didn't need the encryption. Also, programming was made easier by
88 ;; that decision. One might think that this even influenced were I
89 ;; store my keys, and one would probably be right. :-)
90 ;;
91 ;; Update: Mathias Herberts sent the patch. However, it uses
92 ;; environment variables to pass the password to OpenSSL, which is
93 ;; slightly insecure. Hence a new todo: use a better -passin method.
94 ;;
95 ;; Cache password for e.g. 1h
96 ;;
97 ;; Suggestions and comments are appreciated, mail me at simon@josefsson.org.
98
99 ;; begin rant
100 ;;
101 ;; I would include pointers to introductory text on concepts used in
102 ;; this library here, but the material I've read are so horrible I
103 ;; don't want to recomend them.
104 ;;
105 ;; Why can't someone write a simple introduction to all this stuff?
106 ;; Until then, much of this resemble security by obscurity.
107 ;;
108 ;; Also, I'm not going to mention anything about the wonders of
109 ;; cryptopolitics. Oops, I just did.
110 ;;
111 ;; end rant
112
113 ;;; Revision history:
114
115 ;; 2000-06-05 initial version, committed to Gnus CVS contrib/
116 ;; 2000-10-28 retrieve certificates via DNS CERT RRs
117 ;; 2001-10-14 posted to gnu.emacs.sources
118
119 ;;; Code:
120
121 (require 'dig)
122 (eval-when-compile (require 'cl))
123
124 (defgroup smime nil
125 "S/MIME configuration."
126 :group 'mime)
127
128 (defcustom smime-keys nil
129 "*Map mail addresses to a file containing Certificate (and private key).
130 The file is assumed to be in PEM format. You can also associate additional
131 certificates to be sent with every message to each address."
132 :type '(repeat (list (string :tag "Mail address")
133 (file :tag "File name")
134 (repeat :tag "Additional certificate files"
135 (file :tag "File name"))))
136 :group 'smime)
137
138 (defcustom smime-CA-directory nil
139 "*Directory containing certificates for CAs you trust.
140 Directory should contain files (in PEM format) named to the X.509
141 hash of the certificate. This can be done using OpenSSL such as:
142
143 $ ln -s ca.pem `openssl x509 -noout -hash -in ca.pem`.0
144
145 where `ca.pem' is the file containing a PEM encoded X.509 CA
146 certificate."
147 :type '(choice (const :tag "none" nil)
148 directory)
149 :group 'smime)
150
151 (defcustom smime-CA-file nil
152 "*Files containing certificates for CAs you trust.
153 File should contain certificates in PEM format."
154 :version "22.1"
155 :type '(choice (const :tag "none" nil)
156 file)
157 :group 'smime)
158
159 (defcustom smime-certificate-directory "~/Mail/certs/"
160 "*Directory containing other people's certificates.
161 It should contain files named to the X.509 hash of the certificate,
162 and the files themself should be in PEM format."
163 ;The S/MIME library provide simple functionality for fetching
164 ;certificates into this directory, so there is no need to populate it
165 ;manually.
166 :type 'directory
167 :group 'smime)
168
169 (defcustom smime-openssl-program
170 (and (condition-case ()
171 (eq 0 (call-process "openssl" nil nil nil "version"))
172 (error nil))
173 "openssl")
174 "*Name of OpenSSL binary."
175 :type 'string
176 :group 'smime)
177
178 ;; OpenSSL option to select the encryption cipher
179
180 (defcustom smime-encrypt-cipher "-des3"
181 "*Cipher algorithm used for encryption."
182 :version "22.1"
183 :type '(choice (const :tag "Triple DES" "-des3")
184 (const :tag "DES" "-des")
185 (const :tag "RC2 40 bits" "-rc2-40")
186 (const :tag "RC2 64 bits" "-rc2-64")
187 (const :tag "RC2 128 bits" "-rc2-128"))
188 :group 'smime)
189
190 (defcustom smime-crl-check nil
191 "*Check revocation status of signers certificate using CRLs.
192 Enabling this will have OpenSSL check the signers certificate
193 against a certificate revocation list (CRL).
194
195 For this to work the CRL must be up-to-date and since they are
196 normally updated quite often (ie. several times a day) you
197 probably need some tool to keep them up-to-date. Unfortunately
198 Gnus cannot do this for you.
199
200 The CRL should either be appended (in PEM format) to your
201 `smime-CA-file' or be located in a file (also in PEM format) in
202 your `smime-certificate-directory' named to the X.509 hash of the
203 certificate with .r0 as file name extension.
204
205 At least OpenSSL version 0.9.7 is required for this to work."
206 :type '(choice (const :tag "No check" nil)
207 (const :tag "Check certificate" "-crl_check")
208 (const :tag "Check certificate chain" "-crl_check_all"))
209 :group 'smime)
210
211 (defcustom smime-dns-server nil
212 "*DNS server to query certificates from.
213 If nil, use system defaults."
214 :version "22.1"
215 :type '(choice (const :tag "System defaults")
216 string)
217 :group 'smime)
218
219 (defvar smime-details-buffer "*OpenSSL output*")
220
221 ;; Use mm-util?
222 (eval-and-compile
223 (defalias 'smime-make-temp-file
224 (if (fboundp 'make-temp-file)
225 'make-temp-file
226 (lambda (prefix &optional dir-flag) ;; Simple implementation
227 (expand-file-name
228 (make-temp-name prefix)
229 (if (fboundp 'temp-directory)
230 (temp-directory)
231 temporary-file-directory))))))
232
233 ;; Password dialog function
234
235 (defun smime-ask-passphrase ()
236 "Asks the passphrase to unlock the secret key."
237 (let ((passphrase
238 (read-passwd
239 "Passphrase for secret key (RET for no passphrase): ")))
240 (if (string= passphrase "")
241 nil
242 passphrase)))
243
244 ;; OpenSSL wrappers.
245
246 (defun smime-call-openssl-region (b e buf &rest args)
247 (case (apply 'call-process-region b e smime-openssl-program nil buf nil args)
248 (0 t)
249 (1 (message "OpenSSL: An error occurred parsing the command options.") nil)
250 (2 (message "OpenSSL: One of the input files could not be read.") nil)
251 (3 (message "OpenSSL: An error occurred creating the PKCS#7 file or when reading the MIME message.") nil)
252 (4 (message "OpenSSL: An error occurred decrypting or verifying the message.") nil)
253 (t (error "Unknown OpenSSL exitcode") nil)))
254
255 (defun smime-make-certfiles (certfiles)
256 (if certfiles
257 (append (list "-certfile" (expand-file-name (car certfiles)))
258 (smime-make-certfiles (cdr certfiles)))))
259
260 ;; Sign+encrypt region
261
262 (defun smime-sign-region (b e keyfile)
263 "Sign region with certified key in KEYFILE.
264 If signing fails, the buffer is not modified. Region is assumed to
265 have proper MIME tags. KEYFILE is expected to contain a PEM encoded
266 private key and certificate as its car, and a list of additional
267 certificates to include in its caar. If no additional certificates is
268 included, KEYFILE may be the file containing the PEM encoded private
269 key and certificate itself."
270 (smime-new-details-buffer)
271 (let ((keyfile (or (car-safe keyfile) keyfile))
272 (certfiles (and (cdr-safe keyfile) (cadr keyfile)))
273 (buffer (generate-new-buffer (generate-new-buffer-name " *smime*")))
274 (passphrase (smime-ask-passphrase))
275 (tmpfile (smime-make-temp-file "smime")))
276 (if passphrase
277 (setenv "GNUS_SMIME_PASSPHRASE" passphrase))
278 (prog1
279 (when (prog1
280 (apply 'smime-call-openssl-region b e (list buffer tmpfile)
281 "smime" "-sign" "-signer" (expand-file-name keyfile)
282 (append
283 (smime-make-certfiles certfiles)
284 (if passphrase
285 (list "-passin" "env:GNUS_SMIME_PASSPHRASE"))))
286 (if passphrase
287 (setenv "GNUS_SMIME_PASSPHRASE" "" t))
288 (with-current-buffer smime-details-buffer
289 (insert-file-contents tmpfile)
290 (delete-file tmpfile)))
291 (delete-region b e)
292 (insert-buffer-substring buffer)
293 (goto-char b)
294 (when (looking-at "^MIME-Version: 1.0$")
295 (delete-region (point) (progn (forward-line 1) (point))))
296 t)
297 (with-current-buffer smime-details-buffer
298 (goto-char (point-max))
299 (insert-buffer-substring buffer))
300 (kill-buffer buffer))))
301
302 (defun smime-encrypt-region (b e certfiles)
303 "Encrypt region for recipients specified in CERTFILES.
304 If encryption fails, the buffer is not modified. Region is assumed to
305 have proper MIME tags. CERTFILES is a list of filenames, each file
306 is expected to contain of a PEM encoded certificate."
307 (smime-new-details-buffer)
308 (let ((buffer (generate-new-buffer (generate-new-buffer-name " *smime*")))
309 (tmpfile (smime-make-temp-file "smime")))
310 (prog1
311 (when (prog1
312 (apply 'smime-call-openssl-region b e (list buffer tmpfile)
313 "smime" "-encrypt" smime-encrypt-cipher
314 (mapcar 'expand-file-name certfiles))
315 (with-current-buffer smime-details-buffer
316 (insert-file-contents tmpfile)
317 (delete-file tmpfile)))
318 (delete-region b e)
319 (insert-buffer-substring buffer)
320 (goto-char b)
321 (when (looking-at "^MIME-Version: 1.0$")
322 (delete-region (point) (progn (forward-line 1) (point))))
323 t)
324 (with-current-buffer smime-details-buffer
325 (goto-char (point-max))
326 (insert-buffer-substring buffer))
327 (kill-buffer buffer))))
328
329 ;; Sign+encrypt buffer
330
331 (defun smime-sign-buffer (&optional keyfile buffer)
332 "S/MIME sign BUFFER with key in KEYFILE.
333 KEYFILE should contain a PEM encoded key and certificate."
334 (interactive)
335 (with-current-buffer (or buffer (current-buffer))
336 (unless (smime-sign-region
337 (point-min) (point-max)
338 (if keyfile
339 keyfile
340 (smime-get-key-with-certs-by-email
341 (completing-read
342 (concat "Sign using which key? "
343 (if smime-keys (concat "(default " (caar smime-keys) ") ")
344 ""))
345 smime-keys nil nil (car-safe (car-safe smime-keys))))))
346 (error "Signing failed"))))
347
348 (defun smime-encrypt-buffer (&optional certfiles buffer)
349 "S/MIME encrypt BUFFER for recipients specified in CERTFILES.
350 CERTFILES is a list of filenames, each file is expected to consist of
351 a PEM encoded key and certificate. Uses current buffer if BUFFER is
352 nil."
353 (interactive)
354 (with-current-buffer (or buffer (current-buffer))
355 (unless (smime-encrypt-region
356 (point-min) (point-max)
357 (or certfiles
358 (list (read-file-name "Recipient's S/MIME certificate: "
359 smime-certificate-directory nil))))
360 (error "Encryption failed"))))
361
362 ;; Verify+decrypt region
363
364 (defun smime-verify-region (b e)
365 "Verify S/MIME message in region between B and E.
366 Returns non-nil on success.
367 Any details (stdout and stderr) are left in the buffer specified by
368 `smime-details-buffer'."
369 (smime-new-details-buffer)
370 (let ((CAs (append (if smime-CA-file
371 (list "-CAfile"
372 (expand-file-name smime-CA-file)))
373 (if smime-CA-directory
374 (list "-CApath"
375 (expand-file-name smime-CA-directory))))))
376 (unless CAs
377 (error "No CA configured"))
378 (if smime-crl-check
379 (add-to-list 'CAs smime-crl-check))
380 (if (apply 'smime-call-openssl-region b e (list smime-details-buffer t)
381 "smime" "-verify" "-out" "/dev/null" CAs)
382 t
383 (insert-buffer-substring smime-details-buffer)
384 nil)))
385
386 (defun smime-noverify-region (b e)
387 "Verify integrity of S/MIME message in region between B and E.
388 Returns non-nil on success.
389 Any details (stdout and stderr) are left in the buffer specified by
390 `smime-details-buffer'."
391 (smime-new-details-buffer)
392 (if (apply 'smime-call-openssl-region b e (list smime-details-buffer t)
393 "smime" "-verify" "-noverify" "-out" '("/dev/null"))
394 t
395 (insert-buffer-substring smime-details-buffer)
396 nil))
397
398 (eval-when-compile
399 (defvar from))
400
401 (defun smime-decrypt-region (b e keyfile)
402 "Decrypt S/MIME message in region between B and E with key in KEYFILE.
403 On success, replaces region with decrypted data and return non-nil.
404 Any details (stderr on success, stdout and stderr on error) are left
405 in the buffer specified by `smime-details-buffer'."
406 (smime-new-details-buffer)
407 (let ((buffer (generate-new-buffer (generate-new-buffer-name " *smime*")))
408 CAs (passphrase (smime-ask-passphrase))
409 (tmpfile (smime-make-temp-file "smime")))
410 (if passphrase
411 (setenv "GNUS_SMIME_PASSPHRASE" passphrase))
412 (if (prog1
413 (apply 'smime-call-openssl-region b e
414 (list buffer tmpfile)
415 "smime" "-decrypt" "-recip" (expand-file-name keyfile)
416 (if passphrase
417 (list "-passin" "env:GNUS_SMIME_PASSPHRASE")))
418 (if passphrase
419 (setenv "GNUS_SMIME_PASSPHRASE" "" t))
420 (with-current-buffer smime-details-buffer
421 (insert-file-contents tmpfile)
422 (delete-file tmpfile)))
423 (progn
424 (delete-region b e)
425 (when (boundp 'from)
426 ;; `from' is dynamically bound in mm-dissect.
427 (insert "From: " from "\n"))
428 (insert-buffer-substring buffer)
429 (kill-buffer buffer)
430 t)
431 (with-current-buffer smime-details-buffer
432 (insert-buffer-substring buffer))
433 (kill-buffer buffer)
434 (delete-region b e)
435 (insert-buffer-substring smime-details-buffer)
436 nil)))
437
438 ;; Verify+Decrypt buffer
439
440 (defun smime-verify-buffer (&optional buffer)
441 "Verify integrity of S/MIME message in BUFFER.
442 Uses current buffer if BUFFER is nil. Returns non-nil on success.
443 Any details (stdout and stderr) are left in the buffer specified by
444 `smime-details-buffer'."
445 (interactive)
446 (with-current-buffer (or buffer (current-buffer))
447 (smime-verify-region (point-min) (point-max))))
448
449 (defun smime-noverify-buffer (&optional buffer)
450 "Verify integrity of S/MIME message in BUFFER.
451 Does NOT verify validity of certificate (only message integrity).
452 Uses current buffer if BUFFER is nil. Returns non-nil on success.
453 Any details (stdout and stderr) are left in the buffer specified by
454 `smime-details-buffer'."
455 (interactive)
456 (with-current-buffer (or buffer (current-buffer))
457 (smime-noverify-region (point-min) (point-max))))
458
459 (defun smime-decrypt-buffer (&optional buffer keyfile)
460 "Decrypt S/MIME message in BUFFER using KEYFILE.
461 Uses current buffer if BUFFER is nil, and query user of KEYFILE if it's nil.
462 On success, replaces data in buffer and return non-nil.
463 Any details (stderr on success, stdout and stderr on error) are left
464 in the buffer specified by `smime-details-buffer'."
465 (interactive)
466 (with-current-buffer (or buffer (current-buffer))
467 (smime-decrypt-region
468 (point-min) (point-max)
469 (expand-file-name
470 (or keyfile
471 (smime-get-key-by-email
472 (completing-read
473 (concat "Decipher using which key? "
474 (if smime-keys (concat "(default " (caar smime-keys) ") ")
475 ""))
476 smime-keys nil nil (car-safe (car-safe smime-keys)))))))))
477
478 ;; Various operations
479
480 (defun smime-new-details-buffer ()
481 (with-current-buffer (get-buffer-create smime-details-buffer)
482 (erase-buffer)))
483
484 (defun smime-pkcs7-region (b e)
485 "Convert S/MIME message between points B and E into a PKCS7 message."
486 (smime-new-details-buffer)
487 (when (smime-call-openssl-region b e smime-details-buffer "smime" "-pk7out")
488 (delete-region b e)
489 (insert-buffer-substring smime-details-buffer)
490 t))
491
492 (defun smime-pkcs7-certificates-region (b e)
493 "Extract any certificates enclosed in PKCS7 message between points B and E."
494 (smime-new-details-buffer)
495 (when (smime-call-openssl-region
496 b e smime-details-buffer "pkcs7" "-print_certs" "-text")
497 (delete-region b e)
498 (insert-buffer-substring smime-details-buffer)
499 t))
500
501 (defun smime-pkcs7-email-region (b e)
502 "Get email addresses contained in certificate between points B and E.
503 A string or a list of strings is returned."
504 (smime-new-details-buffer)
505 (when (smime-call-openssl-region
506 b e smime-details-buffer "x509" "-email" "-noout")
507 (delete-region b e)
508 (insert-buffer-substring smime-details-buffer)
509 t))
510
511 ;; Utility functions
512
513 (defun smime-get-certfiles (keyfile keys)
514 (if keys
515 (let ((curkey (car keys))
516 (otherkeys (cdr keys)))
517 (if (string= keyfile (cadr curkey))
518 (caddr curkey)
519 (smime-get-certfiles keyfile otherkeys)))))
520
521 ;; Use mm-util?
522 (eval-and-compile
523 (defalias 'smime-point-at-eol
524 (if (fboundp 'point-at-eol)
525 'point-at-eol
526 'line-end-position)))
527
528 (defun smime-buffer-as-string-region (b e)
529 "Return each line in region between B and E as a list of strings."
530 (save-excursion
531 (goto-char b)
532 (let (res)
533 (while (< (point) e)
534 (let ((str (buffer-substring (point) (smime-point-at-eol))))
535 (unless (string= "" str)
536 (push str res)))
537 (forward-line))
538 res)))
539
540 ;; Find certificates
541
542 (defun smime-mail-to-domain (mailaddr)
543 (if (string-match "@" mailaddr)
544 (replace-match "." 'fixedcase 'literal mailaddr)
545 mailaddr))
546
547 (defun smime-cert-by-dns (mail)
548 (let* ((dig-dns-server smime-dns-server)
549 (digbuf (dig-invoke (smime-mail-to-domain mail) "cert" nil nil "+vc"))
550 (retbuf (generate-new-buffer (format "*certificate for %s*" mail)))
551 (certrr (with-current-buffer digbuf
552 (dig-extract-rr (smime-mail-to-domain mail) "cert")))
553 (cert (and certrr (dig-rr-get-pkix-cert certrr))))
554 (if cert
555 (with-current-buffer retbuf
556 (insert "-----BEGIN CERTIFICATE-----\n")
557 (let ((i 0) (len (length cert)))
558 (while (> (- len 64) i)
559 (insert (substring cert i (+ i 64)) "\n")
560 (setq i (+ i 64)))
561 (insert (substring cert i len) "\n"))
562 (insert "-----END CERTIFICATE-----\n"))
563 (kill-buffer retbuf)
564 (setq retbuf nil))
565 (kill-buffer digbuf)
566 retbuf))
567
568 ;; User interface.
569
570 (defvar smime-buffer "*SMIME*")
571
572 (defvar smime-mode-map nil)
573 (put 'smime-mode 'mode-class 'special)
574
575 (unless smime-mode-map
576 (setq smime-mode-map (make-sparse-keymap))
577 (suppress-keymap smime-mode-map)
578
579 (define-key smime-mode-map "q" 'smime-exit)
580 (define-key smime-mode-map "f" 'smime-certificate-info))
581
582 (defun smime-mode ()
583 "Major mode for browsing, viewing and fetching certificates.
584
585 All normal editing commands are switched off.
586 \\<smime-mode-map>
587
588 The following commands are available:
589
590 \\{smime-mode-map}"
591 (interactive)
592 (kill-all-local-variables)
593 (setq major-mode 'smime-mode)
594 (setq mode-name "SMIME")
595 (setq mode-line-process nil)
596 (use-local-map smime-mode-map)
597 (buffer-disable-undo)
598 (setq truncate-lines t)
599 (setq buffer-read-only t)
600 (gnus-run-mode-hooks 'smime-mode-hook))
601
602 (defun smime-certificate-info (certfile)
603 (interactive "fCertificate file: ")
604 (let ((buffer (get-buffer-create (format "*certificate %s*" certfile))))
605 (switch-to-buffer buffer)
606 (erase-buffer)
607 (call-process smime-openssl-program nil buffer 'display
608 "x509" "-in" (expand-file-name certfile) "-text")
609 (fundamental-mode)
610 (set-buffer-modified-p nil)
611 (toggle-read-only t)
612 (goto-char (point-min))))
613
614 (defun smime-draw-buffer ()
615 (with-current-buffer smime-buffer
616 (let (buffer-read-only)
617 (erase-buffer)
618 (insert "\nYour keys:\n")
619 (dolist (key smime-keys)
620 (insert
621 (format "\t\t%s: %s\n" (car key) (cadr key))))
622 (insert "\nTrusted Certificate Authoritys:\n")
623 (insert "\nKnown Certificates:\n"))))
624
625 (defun smime ()
626 "Go to the SMIME buffer."
627 (interactive)
628 (unless (get-buffer smime-buffer)
629 (save-excursion
630 (set-buffer (get-buffer-create smime-buffer))
631 (smime-mode)))
632 (smime-draw-buffer)
633 (switch-to-buffer smime-buffer))
634
635 (defun smime-exit ()
636 "Quit the S/MIME buffer."
637 (interactive)
638 (kill-buffer (current-buffer)))
639
640 ;; Other functions
641
642 (defun smime-get-key-by-email (email)
643 (cadr (assoc email smime-keys)))
644
645 (defun smime-get-key-with-certs-by-email (email)
646 (cdr (assoc email smime-keys)))
647
648 (provide 'smime)
649
650 ;;; arch-tag: e3f9b938-5085-4510-8a11-6625269c9a9e
651 ;;; smime.el ends here