releasing gnupg.vim 2276

- added support for default recipients via the variable g:GPGDefaultRecipients.
- fixed an wrong error message with symmetric encryption and set recipients (thanks to Sebastian Luettich).
- create a empty new buffer on leaving vim to wipe out sensitive data on console.
- make sure senisitive data is never written unencrypted to disk.
This commit is contained in:
Markus Braun 2008-08-15 12:50:33 -04:00 committed by James Vega
parent 4b5db78267
commit 7fd5c92bce

View File

@ -1,5 +1,5 @@
" Name: gnupg.vim
" Version: $Id: gnupg.vim 2249 2008-07-31 11:43:14Z mbr $
" Version: $Id: gnupg.vim 2276 2008-08-15 12:50:33Z mbr $
" Author: Markus Braun <markus.braun@krawel.de>
" Summary: Vim plugin for transparent editing of gpg encrypted files.
" Licence: This program is free software; you can redistribute it and/or
@ -68,6 +68,10 @@
" g:GPGPreferArmor
" If set to 1 armored data is preferred for new files. Defaults to 0.
"
" g:GPGDefaultRecipients
" If set, these recipients are used as defaults when no other recipient is
" defined. This variable is a Vim list. Default is unset.
"
" Credits:
" - Mathieu Clabaut for inspirations through his vimspell.vim script.
" - Richard Bronosky for patch to enable ".pgp" suffix.
@ -78,9 +82,11 @@
" - Karl-Heinz Ruskowski for patch to fix unknown recipients and trust model
" and patient beta testing.
" - Giel van Schijndel for patch to get GPG_TTY dynamically.
" - Sebastian Luettich for patch to fix issue with symmetric encryption an set
" recipients.
"
" Section: Plugin header {{{1
if v:version < 700
if (v:version < 700)
echohl ErrorMsg | echo 'plugin gnupg.vim requires Vim version >= 7.0' | echohl None
finish
endif
@ -89,7 +95,7 @@ if (exists("g:loaded_gnupg") || &cp || exists("#BufReadPre#*.\(gpg\|asc\|pgp\)")
finish
endif
let g:loaded_gnupg = "$Revision: 2249 $"
let g:loaded_gnupg = "$Revision: 2276 $"
" Section: Autocmd setup {{{1
augroup GnuPG
@ -108,6 +114,9 @@ augroup GnuPG
" undo the encryption so we are back in the normal text, directly
" after the file has been written.
autocmd BufWritePost,FileWritePost *.\(gpg\|asc\|pgp\) call s:GPGEncryptPost()
" cleanup on leaving vim
autocmd VimLeave *.\(gpg\|asc\|pgp\) call s:GPGCleanup()
augroup END
" Section: Highlight setup {{{1
@ -148,6 +157,11 @@ function s:GPGInit()
let g:GPGPreferArmor = 0
endif
" check if debugging is turned on
if (!exists("g:GPGDefaultRecipients"))
let g:GPGDefaultRecipients = []
endif
" check if debugging is turned on
if (!exists("g:GPGDebugLevel"))
let g:GPGDebugLevel = 0
@ -176,7 +190,7 @@ function s:GPGInit()
" don't use tty in gvim
" FIXME find a better way to avoid an error.
" with this solution only --use-agent will work
if has("gui_running")
if (has("gui_running"))
let s:GPGCommand = s:GPGCommand . " --no-tty"
endif
@ -209,6 +223,16 @@ function s:GPGInit()
let s:GPGCompress = substitute(output, ".*Compress: \\(.\\{-}\\)\n.*", "\\1", "")
endfunction
" Function: s:GPGCleanup() {{{2
"
" cleanup on leaving vim
"
function s:GPGCleanup()
" wipe out screen
new +only
redraw!
endfunction
" Function: s:GPGDecrypt() {{{2
"
" decrypt the buffer and find all recipients of the encrypted file
@ -334,7 +358,7 @@ function s:GPGEncrypt()
call s:GPGDebug(2, "saved window view " . string(s:GPGWindowView))
" store encoding and switch to a safe one
if &fileencoding != &encoding
if (&fileencoding != &encoding)
let s:GPGEncoding = &encoding
let &encoding = &fileencoding
call s:GPGDebug(2, "encoding was \"" . s:GPGEncoding . "\", switched to \"" . &encoding . "\"")
@ -359,6 +383,7 @@ function s:GPGEncrypt()
let b:GPGOptions = []
if (exists("g:GPGPreferSymmetric") && g:GPGPreferSymmetric == 1)
let b:GPGOptions += ["symmetric"]
let b:GPGRecipients = []
else
let b:GPGOptions += ["encrypt"]
endif
@ -411,11 +436,13 @@ function s:GPGEncrypt()
let &shell = s:shellsave
call s:GPGDebug(1, "called gpg command is: " . "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . " " . s:stderrredirnull)
if (v:shell_error) " message could not be encrypted
silent u
" delete content of the buffer to be sure no data is written unencrypted
" content will be recovered in GPGEncryptPost()
silent normal! 1GdG
echohl GPGError
let blackhole = input("Message could not be encrypted! File might be empty! (Press ENTER)")
echohl None
bwipeout
return
endif
@ -438,7 +465,7 @@ function s:GPGEncryptPost()
set nobin
" restore encoding
if s:GPGEncoding != ""
if (s:GPGEncoding != "")
let &encoding = s:GPGEncoding
call s:GPGDebug(2, "restored encoding \"" . &encoding . "\"")
endif
@ -554,6 +581,17 @@ function s:GPGEditRecipients()
" get the recipients
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(getbufvar(b:GPGCorrespondingTo, "GPGRecipients"))
" if there are no known or unknown recipients, use the default ones
if (len(recipients) == 0 && len(unknownrecipients) == 0)
if (type(g:GPGDefaultRecipients) == type([]))
let [ recipients, unknownrecipients ] = s:GPGCheckRecipients(g:GPGDefaultRecipients)
else
echohl GPGWarning
echom "g:GPGDefaultRecipients is not a Vim list, please correct this in your vimrc!"
echohl None
endif
endif
" put the recipients in the scratch buffer
for name in recipients
let name = s:GPGIDToName(name)
@ -635,7 +673,7 @@ function s:GPGFinishRecipientsBuffer()
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
echohl None
endif
end
endif
endif
endfor
@ -859,7 +897,7 @@ function s:GPGNameToID(name)
" when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8,
" so convert it, if necessary
if &encoding != "utf-8"
if (&encoding != "utf-8")
let output = iconv(output, "utf-8", &encoding)
endif
let lines = split(output, "\n")
@ -927,7 +965,7 @@ function s:GPGIDToName(identity)
" when called with "--with-colons" gpg encodes its output _ALWAYS_ as UTF-8,
" so convert it, if necessary
if &encoding != "utf-8"
if (&encoding != "utf-8")
let output = iconv(output, "utf-8", &encoding)
endif
let lines = split(output, "\n")
@ -968,7 +1006,7 @@ command! GPGEditRecipients call s:GPGEditRecipients()
command! GPGViewOptions call s:GPGViewOptions()
command! GPGEditOptions call s:GPGEditOptions()
" Section: Menu {{{1
if has("menu")
if (has("menu"))
amenu <silent> Plugin.GnuPG.View\ Recipients :GPGViewRecipients<CR>
amenu <silent> Plugin.GnuPG.Edit\ Recipients :GPGEditRecipients<CR>
amenu <silent> Plugin.GnuPG.View\ Options :GPGViewOptions<CR>