summaryrefslogtreecommitdiff
path: root/src/Propellor/Gpg.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Propellor/Gpg.hs')
-rw-r--r--src/Propellor/Gpg.hs34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs
index fd2fca79..c48bc060 100644
--- a/src/Propellor/Gpg.hs
+++ b/src/Propellor/Gpg.hs
@@ -1,8 +1,9 @@
module Propellor.Gpg where
import System.IO
+import System.Posix.IO
+import System.Posix.Terminal
import Data.Maybe
-import Data.List.Utils
import Control.Monad
import Control.Applicative
import Prelude
@@ -16,9 +17,32 @@ import Utility.Process.NonConcurrent
import Utility.Monad
import Utility.Misc
import Utility.Tmp
-import Utility.FileSystemEncoding
import Utility.Env
import Utility.Directory
+import Utility.Split
+import Utility.Exception
+
+-- | When at a tty, set GPG_TTY to point to the tty device. This is needed
+-- so that when gpg is run with stio connected to a pipe, it is still able
+-- to display password prompts at the console.
+--
+-- This should not prevent gpg from using the GUI for prompting when one is
+-- available.
+setupGpgEnv :: IO ()
+setupGpgEnv = checkhandles [stdInput, stdOutput, stdError]
+ where
+ checkhandles [] = return ()
+ checkhandles (h:hs) = do
+ isterm <- queryTerminal h
+ if isterm
+ then do
+ v <- tryNonAsync $ getTerminalName h
+ case v of
+ Right ttyname ->
+ -- do not overwrite
+ setEnv "GPG_TTY" ttyname False
+ Left _ -> checkhandles hs
+ else checkhandles hs
type KeyId = String
@@ -183,7 +207,7 @@ gpgDecrypt :: FilePath -> IO String
gpgDecrypt f = do
gpgbin <- getGpgBin
ifM (doesFileExist f)
- ( writeReadProcessEnv gpgbin ["--decrypt", f] Nothing Nothing (Just fileEncoding)
+ ( writeReadProcessEnv gpgbin ["--decrypt", f] Nothing Nothing Nothing
, return ""
)
@@ -201,6 +225,4 @@ gpgEncrypt f s = do
encrypted <- writeReadProcessEnv gpgbin opts Nothing (Just writer) Nothing
viaTmp writeFile f encrypted
where
- writer h = do
- fileEncoding h
- hPutStr h s
+ writer h = hPutStr h s