jamessan / vim-gnupg

This script implements transparent editing of gpg encrypted files.
http://www.vim.org/scripts/script.php?script_id=3645
729 stars 73 forks source link

Doesn't seem to work #31

Closed pbrisbin closed 9 years ago

pbrisbin commented 9 years ago

Steps:

% echo Hello > test
% gpg --encrypt -r pbrisbin@gmail.com test
% vim test.gpg

Contents in buffer (unreadable gibberish).

��^Ȝ3����A
�"��f����l��V$�w6�B�D�5B��Nݶ_��s�l��(��!h�
z��WJ��j��,[=t�\-3��N��*sR�%��������3�S�g�(!���|須�!q��'�┟���d|��a���}#�!��5�{f�:����������r��u�6�)����0//�U�Y�C
$^���t��#�z��>���~r��ۚY�����JbʐJ�$�bI�{�,�y��J��%�Q���ElP��9���<:z�����   s=�T��n�WG�aNJז6h�v��$��.����1��k��.�tk�3�ЍK

Debug log:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.5
GnuPG: shellredirsave: >%s 2>&1
GnuPG: shellsave: /bin/zsh
GnuPG: shelltempsave: 1
GnuPG: shell: /bin/sh
GnuPG: shellcmdflag: -c
GnuPG: shellxquote:
GnuPG: shellredir: >%s 2>&1
GnuPG: stderrredirnull: 2>/dev/null
GnuPG: shell implementation: /usr/bin/bash
GnuPG: command: LANG=C LC_ALL=C gpg --trust-model always --use-agent --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.1.2^@libgcrypt 1.6.3^@Copyright (C) 2015 Free Software Foundation, Inc.^@License GPLv3+: GNU
GPL version 3 or later <http://gnu.org/licenses/gpl.html>^@This is free software: you are free to change and redistribute
it.^@There is NO WARRANTY, to the extent permitted by law.^@^@Home: /home/patrick/.config/gnupg^@Supported algorithms:^@Pu
bkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^@        CAMEL
LIA128, CAMELLIA192, CAMELLIA256^@Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^@Compression: Uncompressed, ZIP, Z
LIB, BZIP2
GnuPG: public key algorithms: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
GnuPG: hashing algorithms: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: LANG=C LC_ALL=C gpg --trust-model always --use-agent --verbose --decrypt --list-only --dry-run --batch --n
o-use-agent --logger-fd 1 '/home/patrick/test.gpg' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg: public key is 33868FEC
GnuPG: this file is asymmetric encrypted
GnuPG: recipient is 33868FEC
GnuPG: >>>>>>>> Entering s:GPGNameToID()
GnuPG: command: LANG=C LC_ALL=C gpg --trust-model always --use-agent --quiet --with-colons --fixed-list-mode --list-keys '
33868FEC' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: tru:t:1:1427982702:1439805005:3:1:5^@pub:u:2048:1:75481C55CEC8925D:1376662444:1439805005::u:::scESC::::::^@
uid:u::::1409513761::FAAD99E657D009E66EE2B81F47D718CCBC2DE359::Patrick Brisbin <pbrisbin@gmail.com>:^@uid:u::::1408269005:
:974B5C77A4F08DDF04E3FB513DCB1DA75F30F1E8::Patrick Brisbin <pat@thoughtbot.com>:^@sub:u:2048:1:C35EC89C33868FEC:1376662444
:1439805092:::::e::::::^@sub:u:4096:1:DB04E2CE780A17DE:1409514434:1441050434:::::s::::::
GnuPG: <<<<<<<< Leaving s:GPGNameToID()
GnuPG: name of recipient is 75481C55CEC8925D
GnuPG: called BufReadPre autocommand for test
GnuPG: decrypting file
GnuPG: command: silent r !LANG=C LC_ALL=C gpg --trust-model always --use-agent --quiet --decrypt '/home/patrick/test.gpg'
2>/dev/null
GnuPG: rc: 0
GnuPG: called BufReadPost autocommand for test
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()

The file is valid, and the command works:

% LANG=C LC_ALL=C gpg --trust-model always --use-agent --quiet --decrypt '/home/patrick/test.gpg'
Hello

What am I doing wrong?

jamessan commented 9 years ago

I can't reproduce this. I updated my gpg to the same version you're using (which I actually expected to cause some issues) and everything is working fine.

Is gpg an alias in your shell? Are you using the latest plugin from Git or a different version?

pbrisbin commented 9 years ago

Yeah, I also suspected the new gpg. Here is the answer to your questions:

% command -v gpg
/usr/bin/gpg
% /bin/sh -c 'command -v gpg'
/usr/bin/gpg
% (cd ~/.vim/bundle/vim-gnupg && g show)
commit dd8e4adb4d1c6c9fda7a1d60cbc863e260687de9
Author: James McCoy <vega.james@gmail.com>
Date:   Sat Mar 21 21:46:00 2015 -0400

    Silence "No matching autocommands" for TermChanged event

    Signed-off-by: James McCoy <vega.james@gmail.com>

diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim
...
pbrisbin commented 9 years ago

I found the issue. If I have file-line enabled, I get this behavior. Without that, it all works fine. I should've known, this plugin seems to do some buffer re-loading in a way that can beak other plugins (it breaks Fugitive in certain ways too).

Sorry for the noise.

jamessan commented 9 years ago

Yeah, file-line seems to break a lot of plugins: bogado/file-line#38 (tar.vim), bogado/file-line#39 (vim-gnupg), bogado/file-line#42 (NERDTree), bogado/file-line#44 (fugitive), bogado/file-line#47 (MRU), and bogado/file-line#48 (NetRW).

bogado/file-line#37 is supposed to fix it, but there's apparently a Vim issue too.

atoponce commented 8 years ago

I hate to reopen this, but I cannot seem to get this to work. I do not have any other Vim plugins installed. I've tried completely removing my ~/.vimrc as well as the system /etc/vim/vimrc configs, and still no dice. Not sure what I'm missing. Here's my environment:

$ command -v gpg
/usr/bin/gpg
$ command -v vim
/usr/bin/vim
$ gpg --version
gpg (GnuPG) 1.4.20
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 18 2015 06:18:22)
Included patches: 1-963
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       -python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux -lacl -lattr -lgpm -ldl           
$ ls -l ~/.vim/plugins/     
total 0
lrwxrwxrwx. 1 aaron aaron 42 Dec 30 07:21 gnupg.vim -> /home/aaron/src/vim-gnupg/plugin/gnupg.vim
$ cat ~/.vimrc
colorscheme hybrid
let g:GPGPreferArmor=1
let g:GPGPreferSign=1
set autoindent
set colorcolumn=80
set expandtab
set guifont=Liberation\ Mono\ 8
set guioptions='aegit'
set laststatus=2
set nobackup
set nocompatible
set nojoinspaces
set nowrap
set number
set relativenumber
set ruler
set shell=/bin/zsh
set shiftwidth=4
set smarttab
set softtabstop=4
set t_Co=256
set tabstop=8
set textwidth=79
syntax enable

The results:

$ vim /tmp/file.pgp
(add 'foo bar baz')
$ cat /tmp/file.pgp # happens with *.asc and *.gpg extensions also
foo bar baz
$ cat /etc/issue
Debian GNU/Linux stretch/sid \n \l
jamessan commented 8 years ago

@atoponce Your issue is completely different than the one originally reported here. You don't seem to have the plugin loaded. If you've verified, with :scriptnames, that it is loaded after vim /tmp/file.pgp, please open a separate issue.

atoponce commented 8 years ago

I got it working after analyzing "vim -V", and verifying that it was looking for "/home/aaron/.vim/plugin/*/.vim", where I had "/home/aaron/.vim/plugins/gnupg.vim", which didn't match. Sorry for the false alarm.