pgg.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. ;;; pgg.el --- glue for the various PGP implementations.
  2. ;; Copyright (C) 1999-2000, 2002-2012 Free Software Foundation, Inc.
  3. ;; Author: Daiki Ueno <ueno@unixuser.org>
  4. ;; Symmetric encryption added by: Sascha Wilde <wilde@sha-bang.de>
  5. ;; Created: 1999/10/28
  6. ;; Keywords: PGP
  7. ;; Obsolete-since: 24.1
  8. ;; This file is part of GNU Emacs.
  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 by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Code:
  20. (require 'pgg-def)
  21. (require 'pgg-parse)
  22. (autoload 'run-at-time "timer")
  23. ;; Don't merge these two `eval-when-compile's.
  24. (eval-when-compile
  25. ;; For Emacs <22.2 and XEmacs.
  26. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))
  27. (require 'cl))
  28. ;;; @ utility functions
  29. ;;;
  30. (eval-when-compile
  31. (when (featurep 'xemacs)
  32. (defmacro pgg-run-at-time-1 (time repeat function args)
  33. (if (condition-case nil
  34. (let ((delete-itimer 'delete-itimer)
  35. (itimer-driver-start 'itimer-driver-start)
  36. (itimer-value 'itimer-value)
  37. (start-itimer 'start-itimer))
  38. (unless (or (symbol-value 'itimer-process)
  39. (symbol-value 'itimer-timer))
  40. (funcall itimer-driver-start))
  41. ;; Check whether there is a bug to which the difference of
  42. ;; the present time and the time when the itimer driver was
  43. ;; woken up is subtracted from the initial itimer value.
  44. (let* ((inhibit-quit t)
  45. (ctime (current-time))
  46. (itimer-timer-last-wakeup
  47. (prog1
  48. ctime
  49. (setcar ctime (1- (car ctime)))))
  50. (itimer-list nil)
  51. (itimer (funcall start-itimer "pgg-run-at-time"
  52. 'ignore 5)))
  53. (sleep-for 0.1) ;; Accept the timeout interrupt.
  54. (prog1
  55. (> (funcall itimer-value itimer) 0)
  56. (funcall delete-itimer itimer))))
  57. (error nil))
  58. `(let ((time ,time))
  59. (apply #'start-itimer "pgg-run-at-time"
  60. ,function (if time (max time 1e-9) 1e-9)
  61. ,repeat nil t ,args))
  62. `(let ((time ,time)
  63. (itimers (list nil)))
  64. (setcar
  65. itimers
  66. (apply #'start-itimer "pgg-run-at-time"
  67. (lambda (itimers repeat function &rest args)
  68. (let ((itimer (car itimers)))
  69. (if repeat
  70. (progn
  71. (set-itimer-function
  72. itimer
  73. (lambda (itimer repeat function &rest args)
  74. (set-itimer-restart itimer repeat)
  75. (set-itimer-function itimer function)
  76. (set-itimer-function-arguments itimer args)
  77. (apply function args)))
  78. (set-itimer-function-arguments
  79. itimer
  80. (append (list itimer repeat function) args)))
  81. (set-itimer-function
  82. itimer
  83. (lambda (itimer function &rest args)
  84. (delete-itimer itimer)
  85. (apply function args)))
  86. (set-itimer-function-arguments
  87. itimer
  88. (append (list itimer function) args)))))
  89. 1e-9 (if time (max time 1e-9) 1e-9)
  90. nil t itimers ,repeat ,function ,args)))))))
  91. (eval-and-compile
  92. (if (featurep 'xemacs)
  93. (progn
  94. (defun pgg-run-at-time (time repeat function &rest args)
  95. "Emulating function run as `run-at-time'.
  96. TIME should be nil meaning now, or a number of seconds from now.
  97. Return an itimer object which can be used in either `delete-itimer'
  98. or `cancel-timer'."
  99. (pgg-run-at-time-1 time repeat function args))
  100. (defun pgg-cancel-timer (timer)
  101. "Emulate cancel-timer for xemacs."
  102. (let ((delete-itimer 'delete-itimer))
  103. (funcall delete-itimer timer))))
  104. (defalias 'pgg-run-at-time 'run-at-time)
  105. (defalias 'pgg-cancel-timer 'cancel-timer)))
  106. (defun pgg-invoke (func scheme &rest args)
  107. (progn
  108. (require (intern (format "pgg-%s" scheme)))
  109. (apply 'funcall (intern (format "pgg-%s-%s" scheme func)) args)))
  110. (put 'pgg-save-coding-system 'lisp-indent-function 2)
  111. (defmacro pgg-save-coding-system (start end &rest body)
  112. `(if (called-interactively-p 'interactive)
  113. (let ((buffer (current-buffer)))
  114. (with-temp-buffer
  115. (let (buffer-undo-list)
  116. (insert-buffer-substring buffer ,start ,end)
  117. (encode-coding-region (point-min)(point-max)
  118. buffer-file-coding-system)
  119. (prog1 (save-excursion ,@body)
  120. (push nil buffer-undo-list)
  121. (ignore-errors (undo))))))
  122. (save-restriction
  123. (narrow-to-region ,start ,end)
  124. ,@body)))
  125. (defun pgg-temp-buffer-show-function (buffer)
  126. (let ((window (or (get-buffer-window buffer 'visible)
  127. (split-window-vertically))))
  128. (set-window-buffer window buffer)
  129. (shrink-window-if-larger-than-buffer window)))
  130. ;; XXX `pgg-display-output-buffer' is a horrible name for this function.
  131. ;; It should be something like `pgg-situate-output-or-display-error'.
  132. (defun pgg-display-output-buffer (start end status)
  133. "Situate en/decryption results or pop up an error buffer.
  134. Text from START to END is replaced by contents of output buffer if STATUS
  135. is true, or else the output buffer is displayed."
  136. (if status
  137. (pgg-situate-output start end)
  138. (pgg-display-error-buffer)))
  139. (defun pgg-situate-output (start end)
  140. "Place en/decryption result in place of current text from START to END."
  141. (delete-region start end)
  142. (insert-buffer-substring pgg-output-buffer)
  143. (decode-coding-region start (point) buffer-file-coding-system))
  144. (defun pgg-display-error-buffer ()
  145. "Pop up an error buffer indicating the reason for an en/decryption failure."
  146. (let ((temp-buffer-show-function
  147. (function pgg-temp-buffer-show-function)))
  148. (with-output-to-temp-buffer pgg-echo-buffer
  149. (set-buffer standard-output)
  150. (insert-buffer-substring pgg-errors-buffer))))
  151. (defvar pgg-passphrase-cache (make-vector 7 0))
  152. (defvar pgg-pending-timers (make-vector 7 0)
  153. "Hash table for managing scheduled pgg cache management timers.
  154. We associate key and timer, so the timer can be canceled if a new
  155. timeout for the key is set while an old one is still pending.")
  156. (defun pgg-read-passphrase (prompt &optional key notruncate)
  157. "Using PROMPT, obtain passphrase for KEY from cache or user.
  158. Truncate the key to 8 trailing characters unless NOTRUNCATE is true
  159. \(default false).
  160. Custom variables `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry'
  161. regulate cache behavior."
  162. (or (pgg-read-passphrase-from-cache key notruncate)
  163. (read-passwd prompt)))
  164. (defun pgg-read-passphrase-from-cache (key &optional notruncate)
  165. "Obtain passphrase for KEY from time-limited passphrase cache.
  166. Truncate the key to 8 trailing characters unless NOTRUNCATE is true
  167. \(default false).
  168. Custom variables `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry'
  169. regulate cache behavior."
  170. (and pgg-cache-passphrase
  171. key (or notruncate
  172. (setq key (pgg-truncate-key-identifier key)))
  173. (symbol-value (intern-soft key pgg-passphrase-cache))))
  174. (defun pgg-add-passphrase-to-cache (key passphrase &optional notruncate)
  175. "Associate KEY with PASSPHRASE in time-limited passphrase cache.
  176. Truncate the key to 8 trailing characters unless NOTRUNCATE is true
  177. \(default false).
  178. Custom variables `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry'
  179. regulate cache behavior."
  180. (let* ((key (if notruncate key (pgg-truncate-key-identifier key)))
  181. (interned-timer-key (intern-soft key pgg-pending-timers))
  182. (old-timer (symbol-value interned-timer-key))
  183. new-timer)
  184. (when old-timer
  185. (cancel-timer old-timer)
  186. (unintern interned-timer-key pgg-pending-timers))
  187. (set (intern key pgg-passphrase-cache)
  188. passphrase)
  189. (set (intern key pgg-pending-timers)
  190. (pgg-run-at-time pgg-passphrase-cache-expiry nil
  191. #'pgg-remove-passphrase-from-cache
  192. key notruncate))))
  193. (if (fboundp 'clear-string)
  194. (defalias 'pgg-clear-string 'clear-string)
  195. (defun pgg-clear-string (string)
  196. (fillarray string ?_)))
  197. (declare-function pgg-clear-string "pgg" (string))
  198. (defun pgg-remove-passphrase-from-cache (key &optional notruncate)
  199. "Omit passphrase associated with KEY in time-limited passphrase cache.
  200. Truncate the key to 8 trailing characters unless NOTRUNCATE is true
  201. \(default false).
  202. This is a no-op if there is not entry for KEY (eg, it's already expired.
  203. The memory for the passphrase is filled with underscores to clear any
  204. references to it.
  205. Custom variables `pgg-cache-passphrase' and `pgg-passphrase-cache-expiry'
  206. regulate cache behavior."
  207. (let* ((passphrase (pgg-read-passphrase-from-cache key notruncate))
  208. (key (if notruncate key (pgg-truncate-key-identifier key)))
  209. (interned-timer-key (intern-soft key pgg-pending-timers))
  210. (old-timer (symbol-value interned-timer-key)))
  211. (when passphrase
  212. (pgg-clear-string passphrase)
  213. (unintern key pgg-passphrase-cache))
  214. (when old-timer
  215. (pgg-cancel-timer old-timer)
  216. (unintern interned-timer-key pgg-pending-timers))))
  217. (defmacro pgg-convert-lbt-region (start end lbt)
  218. `(let ((pgg-conversion-end (set-marker (make-marker) ,end)))
  219. (goto-char ,start)
  220. (case ,lbt
  221. (CRLF
  222. (while (progn
  223. (end-of-line)
  224. (> (marker-position pgg-conversion-end) (point)))
  225. (insert "\r")
  226. (forward-line 1)))
  227. (LF
  228. (while (re-search-forward "\r$" pgg-conversion-end t)
  229. (replace-match ""))))))
  230. (put 'pgg-as-lbt 'lisp-indent-function 3)
  231. (defmacro pgg-as-lbt (start end lbt &rest body)
  232. `(let ((inhibit-read-only t)
  233. buffer-read-only
  234. buffer-undo-list)
  235. (pgg-convert-lbt-region ,start ,end ,lbt)
  236. (let ((,end (point)))
  237. ,@body)
  238. (push nil buffer-undo-list)
  239. (ignore-errors (undo))))
  240. (put 'pgg-process-when-success 'lisp-indent-function 0)
  241. (defmacro pgg-process-when-success (&rest body)
  242. `(with-current-buffer pgg-output-buffer
  243. (if (zerop (buffer-size)) nil ,@body t)))
  244. (defalias 'pgg-make-temp-file
  245. (if (fboundp 'make-temp-file)
  246. 'make-temp-file
  247. (lambda (prefix &optional dir-flag)
  248. (let ((file (expand-file-name
  249. (make-temp-name prefix)
  250. (if (fboundp 'temp-directory)
  251. (temp-directory)
  252. temporary-file-directory))))
  253. (if dir-flag
  254. (make-directory file))
  255. file))))
  256. ;;; @ interface functions
  257. ;;;
  258. ;;;###autoload
  259. (defun pgg-encrypt-region (start end rcpts &optional sign passphrase)
  260. "Encrypt the current region between START and END for RCPTS.
  261. If optional argument SIGN is non-nil, do a combined sign and encrypt.
  262. If optional PASSPHRASE is not specified, it will be obtained from the
  263. passphrase cache or user."
  264. (interactive
  265. (list (region-beginning)(region-end)
  266. (split-string (read-string "Recipients: ") "[ \t,]+")))
  267. (let ((status
  268. (pgg-save-coding-system start end
  269. (pgg-invoke "encrypt-region" (or pgg-scheme pgg-default-scheme)
  270. (point-min) (point-max) rcpts sign passphrase))))
  271. (when (called-interactively-p 'interactive)
  272. (pgg-display-output-buffer start end status))
  273. status))
  274. ;;;###autoload
  275. (defun pgg-encrypt-symmetric-region (start end &optional passphrase)
  276. "Encrypt the current region between START and END symmetric with passphrase.
  277. If optional PASSPHRASE is not specified, it will be obtained from the
  278. cache or user."
  279. (interactive "r")
  280. (let ((status
  281. (pgg-save-coding-system start end
  282. (pgg-invoke "encrypt-symmetric-region"
  283. (or pgg-scheme pgg-default-scheme)
  284. (point-min) (point-max) passphrase))))
  285. (when (called-interactively-p 'interactive)
  286. (pgg-display-output-buffer start end status))
  287. status))
  288. ;;;###autoload
  289. (defun pgg-encrypt-symmetric (&optional start end passphrase)
  290. "Encrypt the current buffer using a symmetric, rather than key-pair, cipher.
  291. If optional arguments START and END are specified, only encrypt within
  292. the region.
  293. If optional PASSPHRASE is not specified, it will be obtained from the
  294. passphrase cache or user."
  295. (interactive)
  296. (let* ((start (or start (point-min)))
  297. (end (or end (point-max)))
  298. (status (pgg-encrypt-symmetric-region start end passphrase)))
  299. (when (called-interactively-p 'interactive)
  300. (pgg-display-output-buffer start end status))
  301. status))
  302. ;;;###autoload
  303. (defun pgg-encrypt (rcpts &optional sign start end passphrase)
  304. "Encrypt the current buffer for RCPTS.
  305. If optional argument SIGN is non-nil, do a combined sign and encrypt.
  306. If optional arguments START and END are specified, only encrypt within
  307. the region.
  308. If optional PASSPHRASE is not specified, it will be obtained from the
  309. passphrase cache or user."
  310. (interactive (list (split-string (read-string "Recipients: ") "[ \t,]+")))
  311. (let* ((start (or start (point-min)))
  312. (end (or end (point-max)))
  313. (status (pgg-encrypt-region start end rcpts sign passphrase)))
  314. (when (called-interactively-p 'interactive)
  315. (pgg-display-output-buffer start end status))
  316. status))
  317. ;;;###autoload
  318. (defun pgg-decrypt-region (start end &optional passphrase)
  319. "Decrypt the current region between START and END.
  320. If optional PASSPHRASE is not specified, it will be obtained from the
  321. passphrase cache or user."
  322. (interactive "r")
  323. (let* ((buf (current-buffer))
  324. (status
  325. (pgg-save-coding-system start end
  326. (pgg-invoke "decrypt-region" (or pgg-scheme pgg-default-scheme)
  327. (point-min) (point-max) passphrase))))
  328. (when (called-interactively-p 'interactive)
  329. (pgg-display-output-buffer start end status))
  330. status))
  331. ;;;###autoload
  332. (defun pgg-decrypt (&optional start end passphrase)
  333. "Decrypt the current buffer.
  334. If optional arguments START and END are specified, only decrypt within
  335. the region.
  336. If optional PASSPHRASE is not specified, it will be obtained from the
  337. passphrase cache or user."
  338. (interactive "")
  339. (let* ((start (or start (point-min)))
  340. (end (or end (point-max)))
  341. (status (pgg-decrypt-region start end passphrase)))
  342. (when (called-interactively-p 'interactive)
  343. (pgg-display-output-buffer start end status))
  344. status))
  345. ;;;###autoload
  346. (defun pgg-sign-region (start end &optional cleartext passphrase)
  347. "Make the signature from text between START and END.
  348. If the optional 3rd argument CLEARTEXT is non-nil, it does not create
  349. a detached signature.
  350. If this function is called interactively, CLEARTEXT is enabled
  351. and the output is displayed.
  352. If optional PASSPHRASE is not specified, it will be obtained from the
  353. passphrase cache or user."
  354. (interactive "r")
  355. (let ((status (pgg-save-coding-system start end
  356. (pgg-invoke "sign-region" (or pgg-scheme pgg-default-scheme)
  357. (point-min) (point-max)
  358. (or (called-interactively-p 'interactive)
  359. cleartext)
  360. passphrase))))
  361. (when (called-interactively-p 'interactive)
  362. (pgg-display-output-buffer start end status))
  363. status))
  364. ;;;###autoload
  365. (defun pgg-sign (&optional cleartext start end passphrase)
  366. "Sign the current buffer.
  367. If the optional argument CLEARTEXT is non-nil, it does not create a
  368. detached signature.
  369. If optional arguments START and END are specified, only sign data
  370. within the region.
  371. If this function is called interactively, CLEARTEXT is enabled
  372. and the output is displayed.
  373. If optional PASSPHRASE is not specified, it will be obtained from the
  374. passphrase cache or user."
  375. (interactive "")
  376. (let* ((start (or start (point-min)))
  377. (end (or end (point-max)))
  378. (status (pgg-sign-region start end
  379. (or (called-interactively-p 'interactive)
  380. cleartext)
  381. passphrase)))
  382. (when (called-interactively-p 'interactive)
  383. (pgg-display-output-buffer start end status))
  384. status))
  385. ;;;###autoload
  386. (defun pgg-verify-region (start end &optional signature fetch)
  387. "Verify the current region between START and END.
  388. If the optional 3rd argument SIGNATURE is non-nil, it is treated as
  389. the detached signature of the current region.
  390. If the optional 4th argument FETCH is non-nil, we attempt to fetch the
  391. signer's public key from `pgg-default-keyserver-address'."
  392. (interactive "r")
  393. (let* ((packet
  394. (if (null signature) nil
  395. (with-temp-buffer
  396. (buffer-disable-undo)
  397. (unless (featurep 'xemacs)
  398. (set-buffer-multibyte nil))
  399. (insert-file-contents signature)
  400. (cdr (assq 2 (pgg-decode-armor-region
  401. (point-min)(point-max)))))))
  402. (key (cdr (assq 'key-identifier packet)))
  403. status keyserver)
  404. (and (stringp key)
  405. pgg-query-keyserver
  406. (setq key (concat "0x" (pgg-truncate-key-identifier key)))
  407. (null (pgg-lookup-key key))
  408. (or fetch (called-interactively-p 'interactive))
  409. (y-or-n-p (format "Key %s not found; attempt to fetch? " key))
  410. (setq keyserver
  411. (or (cdr (assq 'preferred-key-server packet))
  412. pgg-default-keyserver-address))
  413. (pgg-fetch-key keyserver key))
  414. (setq status
  415. (pgg-save-coding-system start end
  416. (pgg-invoke "verify-region" (or pgg-scheme pgg-default-scheme)
  417. (point-min) (point-max) signature)))
  418. (when (called-interactively-p 'interactive)
  419. (let ((temp-buffer-show-function
  420. (function pgg-temp-buffer-show-function)))
  421. (with-output-to-temp-buffer pgg-echo-buffer
  422. (set-buffer standard-output)
  423. (insert-buffer-substring (if status pgg-output-buffer
  424. pgg-errors-buffer)))))
  425. status))
  426. ;;;###autoload
  427. (defun pgg-verify (&optional signature fetch start end)
  428. "Verify the current buffer.
  429. If the optional argument SIGNATURE is non-nil, it is treated as
  430. the detached signature of the current region.
  431. If the optional argument FETCH is non-nil, we attempt to fetch the
  432. signer's public key from `pgg-default-keyserver-address'.
  433. If optional arguments START and END are specified, only verify data
  434. within the region."
  435. (interactive "")
  436. (let* ((start (or start (point-min)))
  437. (end (or end (point-max)))
  438. (status (pgg-verify-region start end signature fetch)))
  439. (when (called-interactively-p 'interactive)
  440. (let ((temp-buffer-show-function
  441. (function pgg-temp-buffer-show-function)))
  442. (with-output-to-temp-buffer pgg-echo-buffer
  443. (set-buffer standard-output)
  444. (insert-buffer-substring (if status pgg-output-buffer
  445. pgg-errors-buffer)))))
  446. status))
  447. ;;;###autoload
  448. (defun pgg-insert-key ()
  449. "Insert the ASCII armored public key."
  450. (interactive)
  451. (pgg-invoke "insert-key" (or pgg-scheme pgg-default-scheme)))
  452. ;;;###autoload
  453. (defun pgg-snarf-keys-region (start end)
  454. "Import public keys in the current region between START and END."
  455. (interactive "r")
  456. (pgg-save-coding-system start end
  457. (pgg-invoke "snarf-keys-region" (or pgg-scheme pgg-default-scheme)
  458. start end)))
  459. ;;;###autoload
  460. (defun pgg-snarf-keys ()
  461. "Import public keys in the current buffer."
  462. (interactive "")
  463. (pgg-snarf-keys-region (point-min) (point-max)))
  464. (defun pgg-lookup-key (string &optional type)
  465. (pgg-invoke "lookup-key" (or pgg-scheme pgg-default-scheme) string type))
  466. (defvar pgg-insert-url-function (function pgg-insert-url-with-w3))
  467. (defun pgg-insert-url-with-w3 (url)
  468. (ignore-errors
  469. (require 'url)
  470. (let (buffer-file-name)
  471. (url-insert-file-contents url))))
  472. (defvar pgg-insert-url-extra-arguments nil)
  473. (defvar pgg-insert-url-program nil)
  474. (defun pgg-insert-url-with-program (url)
  475. (let ((args (copy-sequence pgg-insert-url-extra-arguments))
  476. process)
  477. (insert
  478. (with-temp-buffer
  479. (setq process
  480. (apply #'start-process " *PGG url*" (current-buffer)
  481. pgg-insert-url-program (nconc args (list url))))
  482. (set-process-sentinel process #'ignore)
  483. (while (eq 'run (process-status process))
  484. (accept-process-output process 5))
  485. (delete-process process)
  486. (if (and process (eq 'run (process-status process)))
  487. (interrupt-process process))
  488. (buffer-string)))))
  489. (defun pgg-fetch-key (keyserver key)
  490. "Attempt to fetch a KEY from KEYSERVER for addition to PGP or GnuPG keyring."
  491. (with-current-buffer (get-buffer-create pgg-output-buffer)
  492. (buffer-disable-undo)
  493. (erase-buffer)
  494. (let ((proto (if (string-match "^[a-zA-Z\\+\\.\\\\-]+:" keyserver)
  495. (substring keyserver 0 (1- (match-end 0))))))
  496. (save-excursion
  497. (funcall pgg-insert-url-function
  498. (if proto keyserver
  499. (format "http://%s:11371/pks/lookup?op=get&search=%s"
  500. keyserver key))))
  501. (when (re-search-forward "^-+BEGIN" nil 'last)
  502. (delete-region (point-min) (match-beginning 0))
  503. (when (re-search-forward "^-+END" nil t)
  504. (delete-region (progn (end-of-line) (point))
  505. (point-max)))
  506. (insert "\n")
  507. (with-temp-buffer
  508. (insert-buffer-substring pgg-output-buffer)
  509. (pgg-snarf-keys-region (point-min)(point-max)))))))
  510. (provide 'pgg)
  511. ;;; pgg.el ends here