summaryrefslogtreecommitdiff
path: root/Utility/Gpg.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-08-04 12:10:00 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-08-04 13:03:34 -0400
commit944730682471f4e808f4f1faa9797a965ebadb8f (patch)
treefea08098ca33d2f3eadcb35efe3fe5b4407fa735 /Utility/Gpg.hs
parente63d8ef269fa8c89af5785fe4201fc43a82bcb7b (diff)
Windows: Added support for encrypted special remotes.
Diffstat (limited to 'Utility/Gpg.hs')
-rw-r--r--Utility/Gpg.hs29
1 files changed, 19 insertions, 10 deletions
diff --git a/Utility/Gpg.hs b/Utility/Gpg.hs
index d9969ed2f..b06ea2fd1 100644
--- a/Utility/Gpg.hs
+++ b/Utility/Gpg.hs
@@ -18,6 +18,9 @@ import System.Path
import Common
import Utility.Env
import qualified Build.SysConfig as SysConfig
+#ifdef mingw32_HOST_OS
+import Utility.Tmp
+#endif
newtype KeyIds = KeyIds [String]
deriving (Ord, Eq)
@@ -77,8 +80,8 @@ pipeStrict params input = do
- Note that to avoid deadlock with the cleanup stage,
- the reader must fully consume gpg's input before returning. -}
feedRead :: [CommandParam] -> String -> (Handle -> IO ()) -> (Handle -> IO a) -> IO a
-#ifndef mingw32_HOST_OS
feedRead params passphrase feeder reader = do
+#ifndef mingw32_HOST_OS
-- pipe the passphrase into gpg on a fd
(frompipe, topipe) <- createPipe
void $ forkIO $ do
@@ -89,17 +92,23 @@ feedRead params passphrase feeder reader = do
let passphrasefd = [Param "--passphrase-fd", Param $ show pfd]
params' <- stdParams $ [Param "--batch"] ++ passphrasefd ++ params
- closeFd frompipe `after`
- withBothHandles createProcessSuccess (proc gpgcmd params') go
- where
- go (to, from) = do
- void $ forkIO $ do
- feeder to
- hClose to
- reader from
+ closeFd frompipe `after` go params'
#else
-feedRead = error "gpg feedRead not implemented on Windows" -- TODO
+ -- store the passphrase in a temp file for gpg
+ withTmpFile "gpg" $ \tmpfile h -> do
+ hPutStr h passphrase
+ hClose h
+ let passphrasefile = [Param "--passphrase-file", File tmpfile]
+ params' <- stdParams $ [Param "--batch"] ++ passphrasefile ++ params
+ go params'
#endif
+ where
+ go params' = withBothHandles createProcessSuccess (proc gpgcmd params')
+ $ \(to, from) -> do
+ void $ forkIO $ do
+ feeder to
+ hClose to
+ reader from
{- Finds gpg public keys matching some string. (Could be an email address,
- a key id, or a name; See the section 'HOW TO SPECIFY A USER ID' of