ENH make rofi pinentry actually work

This commit is contained in:
Nathan Dwarshuis 2021-06-26 16:09:49 -04:00
parent 5a063fe237
commit a606056b26
1 changed files with 28 additions and 22 deletions

View File

@ -9,21 +9,18 @@ module Main where
import Data.List import Data.List
import Bitwarden.Internal import Bitwarden.Internal
import System.Environment
import System.Exit import System.Exit
import System.IO
import System.Posix.Process
main :: IO () main :: IO ()
main = do main = do
n <- parseArgs =<< getArgs hSetBuffering stdout LineBuffering
putStrLn "Hello loser" -- TODO don't hardcode this
let n = "gnupg"
putStrLn "OK Pleased to meet you"
pinentryLoop n pinentryLoop n
parseArgs :: [String] -> IO String
parseArgs [n] = return n
parseArgs _ = do
putStrLn "Usage: pinentry-rofi [BWNAME]"
exitWith $ ExitFailure 1
pinentryLoop :: String -> IO () pinentryLoop :: String -> IO ()
pinentryLoop n = do pinentryLoop n = do
c <- getLine c <- getLine
@ -35,19 +32,18 @@ processLine _ [] = noop
processLine _ ["BYE"] = exitSuccess processLine _ ["BYE"] = exitSuccess
processLine n ["GETPIN"] = getPin n processLine n ["GETPIN"] = getPin n
processLine _ ["GETINFO", o] = processGetInfo o
-- TODO this might be important -- TODO this might be important
processLine _ ["OPTION", o] = processOption o processLine _ ["OPTION", o] = processOption o
-- TODO this might be important -- these should all do nothing
processLine _ ["GETINFO", _] = noop processLine _ ("SETDESC":_) = noop
processLine _ ("SETOK":_) = noop
-- these all take one arg and should do nothing here processLine _ ("SETNOTOK":_) = noop
processLine _ ["SETDESC", _] = noop processLine _ ("SETCANCEL":_) = noop
processLine _ ["SETOK", _] = noop processLine _ ("SETPROMPT":_) = noop
processLine _ ["SETNOTOK", _] = noop processLine _ ("SETERROR":_) = noop
processLine _ ["SETCANCEL", _] = noop
processLine _ ["SETPROMPT", _] = noop
processLine _ ["SETERROR", _] = noop
-- CONFIRM can take a flag -- CONFIRM can take a flag
processLine _ ["CONFIRM"] = noop processLine _ ["CONFIRM"] = noop
@ -62,13 +58,23 @@ getPin :: String -> IO ()
getPin n = do getPin n = do
its <- getItems its <- getItems
let p = (password . login) =<< find (\i -> n == name i) its let p = (password . login) =<< find (\i -> n == name i) its
maybe err printPin p maybe err send p
where where
err = putStrLn "ERR 83886179 Operation canceled <rofi>" err = putStrLn "ERR 83886179 Operation canceled <rofi>"
printPin p = putStrLn ("D " ++ p) >> ok
-- these are the only supported options for GETINFO; anything else is an error
processGetInfo :: String -> IO ()
processGetInfo "pid" = send . show =<< getProcessID
processGetInfo "version" = noop
processGetInfo "flavor" = noop
processGetInfo "ttyinfo" = noop
processGetInfo _ = putStrLn "ERR 83886360 IPC parameter error <rofi>"
processOption :: String -> IO () processOption :: String -> IO ()
processOption = undefined processOption _ = noop
send :: String -> IO ()
send s = putStrLn ("D " ++ s) >> ok
noop :: IO () noop :: IO ()
noop = ok noop = ok