jamessan / vim-gnupg

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

Support using vim-gnupg from cygwin with Gpg4win #73

Closed jamessan closed 7 years ago

jamessan commented 7 years ago

Gpg4win expects native Windows paths even when it's being run from a cygwin environment. In order to satisfy that, update s:shellescape to know whether it should convert the paths to native Windows paths using cygpath -am.

In order to detect whether cygpath should be invoked, look for the combination of has('win32unix') being true and gpg --version reporting a Windows style path for gpg's home directory.

Closes jamessan/vim-gnupg#62

Signed-off-by: James McCoy jamessan@jamessan.com

jamessan commented 7 years ago

@kenny-evitt Can you see if this works for you? I don't have a cygwin environment to test with.

byronsanchez commented 7 years ago

Is there any vimrc-type config I should do to make this work or should it theoretically just work if I load it as a plugin while using vim in cygwin?

jamessan commented 7 years ago

@byronsanchez If I understood the original report correctly, this should just work for the case where you're running cygwin's Vim with Gpg4win's gpg.

byronsanchez commented 7 years ago

Here are my results.

Environment

Windows 10 Cygwin 64bit Vim 8.0 (packaged in Cygwin) GPG4Win

Steps I Took

I use vundle to manage vim plugins.

So I executed the following commands to load up the patched version with the cygwin-gpg fix:

cd ~/.vim/bundle/vim-gnupg/plugin
rm gnupg.vim
wget https://github.com/jamessan/vim-gnupg/blob/b0a042a6d9cee87e7c5ee259cc5584f7ffa9d06e/plugin/gnupg.vim
cd ~
vim test.gpg
  1. In the recipient buffer I add in the email associated with my gpg key.
  2. In the file buffer, I type in some text and save.
  3. Pinentry from GPG4Win prompts me for my key's password, as expected and the file is saved and I close vim.
  4. I cat out the file, I get the "BEGIN PGP MESSAGE" and all the stuff that tells me the file has been successfully encrypted.
  5. I open the encrypted file with vim.
  6. I see "File is not encrypted, all GPG functions disabled!"

Let me know if I should provide more information or if there's anything I can do to help out.

jamessan commented 7 years ago

What does :echo has('win32unix') show?

Can you run vim, :let g:GPGDebugLevel=3, :let g:GPGDebugLog="debug.log", :e test.gpg and then post the contents of debug.log?

byronsanchez commented 7 years ago

:echo has('win32unix') results in a 1

debug.log:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 '/cygdrive/c/Users/bfs50/.vim/bundle/vim-gnupg/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: gpg: can't open `/cygdrive/c/Users/bfs50/.vim/bundle/vim-gnupg/test.gpg': System error w/o errno^M^@gpg: decrypt_message failed: System error w/o errno^M^@
GnuPG: this file is not encrypted
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()
GnuPG: >>>>>>>> Entering s:GPGCleanup()
GnuPG: <<<<<<<< Leaving s:GPGCleanup()
jamessan commented 7 years ago

Hmm, you're getting a different error than the original report. Is /cygdrive/c/Users/bfs50/.vim/bundle/vim-gnupg/test.gpg the correct path for the file?

byronsanchez commented 7 years ago

Yea, I was in that directory when I wrote the test.gpg file.

Here's the same one after moving test.gpg to my home directory:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 '/cygdrive/c/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: gpg: can't open `/cygdrive/c/Users/bfs50/test.gpg': System error w/o errno^M^@gpg: decrypt_message failed: System error w/o errno^M^@
GnuPG: this file is not encrypted
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()
GnuPG: >>>>>>>> Entering s:GPGCleanup()
GnuPG: <<<<<<<< Leaving s:GPGCleanup()

I suspect the issue I'm running into has more to do with GPG4Win.

I'll play around with GPG4win in Cygwin and the native windows command prompt and see if I find anything over the next few days. I'll post a message here if I find something relevant.

Let me know if anything else comes to mind, and I'll try it out.

jamessan commented 7 years ago

I just updated the plugin to log when it's detected that cygpath needs to be used. Can you get the new file and post the debug log from using that? I get the feeling it isn't detecting that properly.

byronsanchez commented 7 years ago

I downloaded the new file and repeated the process:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 '/cygdrive/c/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: gpg: can't open `/cygdrive/c/Users/bfs50/test.gpg': System error w/o errno^M^@gpg: decrypt_message failed: System error w/o errno^M^@
GnuPG: this file is not encrypted
GnuPG: called BufReadPre autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: called BufReadPost autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()

Just a heads up. I think it may have to do with how GPG4win is handling paths.

When I run gpg --batch -q -d ~/test.gpg in Cygwin, I get the following output:

gpg: can't open `/cygdrive/c/Users/bfs50/test.gpg': System error w/o errno
gpg: decrypt_message failed: System error w/o errno

But when I run gpg --batch -q -d test.gpg in Cygwin, I get the pinentry GUI from GPG4win, which is the expected behavior.

And just for completeness, my gpg path in cygwin for the command which gpg is:

/cygdrive/c/Program Files (x86)/GNU/GnuPG/pub/gpg
jamessan commented 7 years ago

Yeah, the change in this PR is supposed to be detecting that GPG4win is being used from Cygwin and use cygpath -am to get the filename into a format that GPG4win understands.

Pushed another update. Does that help?

byronsanchez commented 7 years ago

Ohhh I see now.

Unfortunately, the results appear to be the same:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 '/cygdrive/c/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: gpg: can't open `/cygdrive/c/Users/bfs50/test.gpg': System error w/o errno^M^@gpg: decrypt_message failed: System error w/o errno^M^@
GnuPG: this file is not encrypted
GnuPG: called BufReadPre autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: called BufReadPost autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()
jamessan commented 7 years ago

Ok, I think I finally got it working.

byronsanchez commented 7 years ago

All right, just to be sure, this is the file I downloaded:

wget https://raw.githubusercontent.com/jamessan/vim-gnupg/fef722c1c29112486eb54cdce23b62116d8a12da/plugin/gnupg.vim

And the results:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
GnuPG: shellredirsave: >%s 2>&1
GnuPG: shellsave: 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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: Enabling use of cygpath
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 '/cygdrive/c/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: gpg: can't open `/cygdrive/c/Users/bfs50/test.gpg': System error w/o errno^M^@gpg: decrypt_message failed: System error w/o errno^M^@
GnuPG: this file is not encrypted
GnuPG: called BufReadPre autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: called BufReadPost autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()
jamessan commented 7 years ago

:cry: I should just setup cygwin and GPG4win...

jamessan commented 7 years ago

Oh man, I must've been really tired when I wrote this initially... Can you give it one last try? :)

byronsanchez commented 7 years ago

Something new happened. When opening test.gpg, I get a new error message that says:

The recipient "0x7BB443991D4BCF27" is not in your public keyring!

Then after a second or so:

Message could not be decrypted! (Press ENTER)

Here's debug.log:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
GnuPG: shellredirsave: >%s 2>&1
GnuPG: shellsave: 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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: Enabling use of cygpath
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 'C:/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg: public key is 0x7BB443991D4BCF27^M^@
GnuPG: this file is asymmetric encrypted
GnuPG: recipient is 0x7BB443991D4BCF27
GnuPG: >>>>>>>> Entering s:GPGNameToID()
GnuPG: command: gpg --trust-model always --no-use-agent --quiet --with-colons --fixed-list-mode --list-keys 'C:/Users/bfs50/0x7BB443991D4BCF27' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: tru:t:1:1496190649:0:3:1:5^M^@
GnuPG: <<<<<<<< Leaving s:GPGNameToID()
GnuPG: called BufReadPre autocommand for test
GnuPG: decrypting file
GnuPG: command: silent read ++edit !gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()
jamessan commented 7 years ago

Ok, that's better. I undid a bit too much. I'll have another version up shortly.

jamessan commented 7 years ago

Ok, this time should really work. :crossed_fingers:

byronsanchez commented 7 years ago
wget https://raw.githubusercontent.com/jamessan/vim-gnupg/01533d0cd5bfadf1b45924d829b8b461e8bc6c18/plugin/gnupg.vim

And back to the same old error messages haha:

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
GnuPG: shellredirsave: >%s 2>&1
GnuPG: shellsave: 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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: Enabling use of cygpath
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 '/cygdrive/c/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: output: gpg: can't open `/cygdrive/c/Users/bfs50/test.gpg': System error w/o errno^M^@gpg: decrypt_message failed: System error w/o errno^M^@
GnuPG: this file is not encrypted
GnuPG: called BufReadPre autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: called BufReadPost autocommand for /cygdrive/c/Users/bfs50/test.gpg
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()
jamessan commented 7 years ago

Ugh, thanks for putting up with all these tests. I swear the last push will work. I've banged out all of the stupid.

byronsanchez commented 7 years ago
Message could not be decrypted! (Press ENTER)

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
GnuPG: shellredirsave: >%s 2>&1
GnuPG: shellsave: 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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: Enabling use of cygpath
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: command: gpg --trust-model always --no-use-agent --verbose --decrypt --list-only --dry-run --no-use-agent --logger-fd 1 'C:/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg: public key is 0x7BB443991D4BCF27^M^@
GnuPG: this file is asymmetric encrypted
GnuPG: recipient is 0x7BB443991D4BCF27
GnuPG: >>>>>>>> Entering s:GPGNameToID()
GnuPG: command: gpg --trust-model always --no-use-agent --quiet --with-colons --fixed-list-mode --list-keys '0x7BB443991D4BCF27' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: tru:t:1:1496190649:0:3:1:5^M^@pub:-:4096:1:AD5672614FEE6CBA:1496186337:::-:::scESC:^M^@fpr:::::::::AB389AE502B5DE9ABFB85DB4AD5672614FEE6CBA:^M^@uid:-::::1496186337::48F725227E3599C87AE1F06661D5810E6209D497::Byron Sanchez <byron@byronsanchez.io>:^M^@sub:-:4096:1:7BB443991D4BCF27:1496186337::::::e:^M^@sub:-:4096:1:F828BEAF8F7F9BCD:1496186650::::::s:^M^@
GnuPG: <<<<<<<< Leaving s:GPGNameToID()
GnuPG: name of recipient is AD5672614FEE6CBA
GnuPG: called BufReadPre autocommand for test
GnuPG: decrypting file
GnuPG: command: silent read ++edit !gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg' 2>/dev/null
GnuPG: rc: 2
GnuPG: <<<<<<<< Leaving s:GPGDecrypt()

I feel like it's getting closer. The paths look right.

Let me know if you have more updates. Having vim-gnupg working on Cygwin would be very convenient, so it's no problem, I'll test where I can.

jamessan commented 7 years ago

Can you run this sequence of commands?

$ gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg' 2>/dev/null
$ echo $?

Do you see the decrypted contents of the file? What is the value of $? that's reported?

byronsanchez commented 7 years ago

Here's what I get straight from cygwin:

bfs50 at navi in ~
$ gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg' 2>/dev/null

bfs50 at navi in ~
$ echo $?
2

The gpg command prints nothing out and echo of the exit status is a 2.

...

I tried to encrypt a new file, :e new.gpg and for the most recent revision of this patched gnupg.vim it failed.

I was able to see the recipients buffer and the file buffer. It looked like it was even able to save the recipients buffer. But the moment I tried to save the file buffer so that the file would actually write to disk in encrypted format, I received the following message:

Message could not be encrypted! (Press ENTER)

Here's the debug.log of the attempt to create a new encrypted file (this operation worked in the first revision from this thread):

GnuPG: >>>>>>>> Entering s:GPGInit(1)
GnuPG: gnupg.vim 2.6.1-dev
GnuPG: shellredirsave: >%s 2>&1
GnuPG: shellsave: 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: /bin/sh
GnuPG: command: gpg --trust-model always --version 2>/dev/null
GnuPG: rc: 0
GnuPG: output: gpg (GnuPG) 2.0.30 (Gpg4win 2.3.3)^M^@libgcrypt 1.6.6^M^@Copyright (C) 2015 Free Software Foundation, Inc.^M^@License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>^M^@This is free software: you are free to change and redistribute it.^M^@There is NO WARRANTY, to the extent permitted by law.^M^@^M^@Home: C:/Users/bfs50/AppData/Roaming/gnupg^M^@Supported algorithms:^M^@Pubkey: RSA, RSA, RSA, ELG, DSA^M^@Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M^@        CAMELLIA128, CAMELLIA192, CAMELLIA256^M^@Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M^@Compression: Uncompressed, ZIP, ZLIB, BZIP2^M^@
GnuPG: Enabling use of cygpath
GnuPG: public key algorithms: RSA, RSA, RSA, ELG, DSA^M
GnuPG: cipher algorithms: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,^M
GnuPG: hashing algorithms: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224^M
GnuPG: compression algorithms: Uncompressed, ZIP, ZLIB, BZIP2^M
GnuPG: <<<<<<<< Leaving s:GPGInit()
GnuPG: >>>>>>>> Entering s:GPGDecrypt(1)
GnuPG: called BufNewFile autocommand for new
GnuPG: >>>>>>>> Entering s:GPGEditRecipients()
GnuPG: >>>>>>>> Entering s:GPGCheckRecipients()
GnuPG: recipients are: []
GnuPG: unknown recipients are: []
GnuPG: <<<<<<<< Leaving s:GPGCheckRecipients()
GnuPG: >>>>>>>> Entering s:GPGCheckRecipients()
GnuPG: recipients are: []
GnuPG: unknown recipients are: []
GnuPG: <<<<<<<< Leaving s:GPGCheckRecipients()
GnuPG: <<<<<<<< Leaving s:GPGEditRecipients()
GnuPG: >>>>>>>> Entering s:GPGFinishRecipientsBuffer()
GnuPG: >>>>>>>> Entering s:GPGNameToID()
GnuPG: command: gpg --trust-model always --no-use-agent --quiet --with-colons --fixed-list-mode --list-keys 'byron@byronsanchez.io' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: tru:t:1:1496190649:0:3:1:5^M^@pub:-:4096:1:AD5672614FEE6CBA:1496186337:::-:::scESC:^M^@fpr:::::::::AB389AE502B5DE9ABFB85DB4AD5672614FEE6CBA:^M^@uid:-::::1496186337::48F725227E3599C87AE1F06661D5810E6209D497::Byron Sanchez <byron@byronsanchez.io>:^M^@sub:-:4096:1:7BB443991D4BCF27:1496186337::::::e:^M^@sub:-:4096:1:F828BEAF8F7F9BCD:1496186650::::::s:^M^@
GnuPG: <<<<<<<< Leaving s:GPGNameToID()
GnuPG: <<<<<<<< Leaving s:GPGFinishRecipientsBuffer()
GnuPG: >>>>>>>> Entering s:GPGInit(0)
GnuPG: >>>>>>>> Entering s:GPGEncrypt()
GnuPG: called BufWritePre autocommand for new
GnuPG: no options set, so using default options: ['encrypt', 'armor', 'sign']
GnuPG: >>>>>>>> Entering s:GPGCheckRecipients()
GnuPG: >>>>>>>> Entering s:GPGNameToID()
GnuPG: command: gpg --trust-model always --no-use-agent --quiet --with-colons --fixed-list-mode --list-keys 'AD5672614FEE6CBA' 2>/dev/null
GnuPG: rc: 0
GnuPG: output: tru:t:1:1496190649:0:3:1:5^M^@pub:-:4096:1:AD5672614FEE6CBA:1496186337:::-:::scESC:^M^@fpr:::::::::AB389AE502B5DE9ABFB85DB4AD5672614FEE6CBA:^M^@uid:-::::1496186337::48F725227E3599C87AE1F06661D5810E6209D497::Byron Sanchez <byron@byronsanchez.io>:^M^@sub:-:4096:1:7BB443991D4BCF27:1496186337::::::e:^M^@sub:-:4096:1:F828BEAF8F7F9BCD:1496186650::::::s:^M^@
GnuPG: <<<<<<<< Leaving s:GPGNameToID()
GnuPG: recipients are: ['AD5672614FEE6CBA']
GnuPG: unknown recipients are: []
GnuPG: <<<<<<<< Leaving s:GPGCheckRecipients()
GnuPG: command: '[,']write !gpg --trust-model always --no-use-agent --quiet --no-encrypt-to  --encrypt  --armor  --sign  -r AD5672614FEE6CBA >'C:/tools/cygwin/tmp/bfs50/vWA0Bgh/4' 2>/dev/null
GnuPG: rc: 2
GnuPG: <<<<<<<< Leaving s:GPGEncrypt()
byronsanchez commented 7 years ago

Also, in case it matters, my gpg keys are structured as described in:

https://alexcabal.com/creating-the-perfect-gpg-keypair/

In short, I have a signing and encryption subkey (having removed the original signing key and adding a new signing subkey such that the original key can be used as the "master" signing key and not keep it on a machine that moves around).

jamessan commented 7 years ago

Is there any useful error output if you run gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg' (no stderr redirection)?

byronsanchez commented 7 years ago

Here's the output after running the command:

bfs50 at navi in ~
$ gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg'
gpg: WARNING: "--no-use-agent" is an obsolete option - it has no effect
gpg: error running `C:\Program Files (x86)\GNU\GnuPG\gpg-agent.exe': exit status 2
gpg-agent[9124]: C:\Users\bfs50\AppData\Roaming\gnupg\gpg-agent.conf:1: invalid option
gpg: can't connect to the agent: End of file
gpg: problem with the agent: No agent running
gpg: decryption failed: No secret key

Oh wow.

So I removed the gpg.conf and gpg-agent.conf files I had in ~/AppData/Roaming/gnupg which is the config directory for GPG4Win.

I ran the command again and here's the output:

gpg --trust-model always --no-use-agent --quiet --decrypt 'C:/Users/bfs50/test.gpg'
gpg: WARNING: "--no-use-agent" is an obsolete option - it has no effect
test
gpg: Signature made 05/31/17 02:21:40 ric using RSA key ID 8F7F9BCD
gpg: Good signature from "Byron Sanchez <byron@byronsanchez.io>" [unknown]

I tried creating a new file new.gpg. Edited the recipients and was able to successfully save after GPG4win pinentry prompted me for the password.

Then I cat the file out and got the -----BEGIN PGP MESSAGE----- output showing the file was encrypted.

Lastly, I ran:

vim
:e new.gpg

And vim opened the encrypted file successfully.

Looks like you got it working! The last piece must have been my malformed configs (I copied it directly from my linux machine, and it looks like some settings are invalid for GPG4Win).

I'll keep messing around with it but it looks like everything is functional! 👍

jamessan commented 7 years ago

Awesome! Thanks for all the help getting this working, @byronsanchez.