2021-06-25 23:42:29 -04:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | rofi-pinentry - a simply pinentry proxy for bitwarden
|
|
|
|
--
|
|
|
|
-- Rather than prompt the user like all the other pinentry programs, call the
|
|
|
|
-- bitwarden deamon and prompt for a password there
|
|
|
|
|
|
|
|
module Main where
|
|
|
|
|
2021-06-25 23:57:37 -04:00
|
|
|
import Data.List
|
|
|
|
|
|
|
|
import Bitwarden.Internal
|
2021-06-26 00:07:37 -04:00
|
|
|
import System.Environment
|
2021-06-25 23:42:29 -04:00
|
|
|
import System.Exit
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2021-06-26 00:07:37 -04:00
|
|
|
n <- parseArgs =<< getArgs
|
2021-06-25 23:42:29 -04:00
|
|
|
putStrLn "Hello loser"
|
2021-06-26 00:07:37 -04:00
|
|
|
pinentryLoop n
|
2021-06-25 23:42:29 -04:00
|
|
|
|
2021-06-26 00:07:37 -04:00
|
|
|
parseArgs :: [String] -> IO String
|
|
|
|
parseArgs [n] = return n
|
|
|
|
parseArgs _ = do
|
|
|
|
putStrLn "Usage: pinentry-rofi [BWNAME]"
|
|
|
|
exitWith $ ExitFailure 1
|
|
|
|
|
|
|
|
pinentryLoop :: String -> IO ()
|
|
|
|
pinentryLoop n = do
|
2021-06-25 23:42:29 -04:00
|
|
|
c <- getLine
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine n $ words c
|
|
|
|
pinentryLoop n
|
2021-06-25 23:42:29 -04:00
|
|
|
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine :: String -> [String] -> IO ()
|
|
|
|
processLine _ [] = noop
|
|
|
|
processLine _ ["BYE"] = exitSuccess
|
|
|
|
processLine n ["GETPIN"] = getPin n
|
2021-06-25 23:42:29 -04:00
|
|
|
|
|
|
|
-- TODO this might be important
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine _ ["OPTION", o] = processOption o
|
2021-06-25 23:42:29 -04:00
|
|
|
|
|
|
|
-- TODO this might be important
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine _ ["GETINFO", _] = noop
|
2021-06-25 23:42:29 -04:00
|
|
|
|
|
|
|
-- these all take one arg and should do nothing here
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine _ ["SETDESC", _] = noop
|
|
|
|
processLine _ ["SETOK", _] = noop
|
|
|
|
processLine _ ["SETNOTOK", _] = noop
|
|
|
|
processLine _ ["SETCANCEL", _] = noop
|
|
|
|
processLine _ ["SETPROMPT", _] = noop
|
|
|
|
processLine _ ["SETERROR", _] = noop
|
2021-06-25 23:42:29 -04:00
|
|
|
|
|
|
|
-- CONFIRM can take a flag
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine _ ["CONFIRM"] = noop
|
|
|
|
processLine _ ["CONFIRM", "--one-button", _] = noop
|
2021-06-25 23:42:29 -04:00
|
|
|
|
2021-06-26 00:07:37 -04:00
|
|
|
processLine _ ss = unknownCommand $ unwords ss
|
2021-06-25 23:42:29 -04:00
|
|
|
|
|
|
|
unknownCommand :: String -> IO ()
|
|
|
|
unknownCommand c = putStrLn $ "ERR 275 Unknown command " ++ c
|
|
|
|
|
2021-06-26 00:07:37 -04:00
|
|
|
getPin :: String -> IO ()
|
|
|
|
getPin n = do
|
2021-06-25 23:57:37 -04:00
|
|
|
its <- getItems
|
2021-06-26 00:07:37 -04:00
|
|
|
let p = (password . login) =<< find (\i -> n == name i) its
|
2021-06-25 23:57:37 -04:00
|
|
|
maybe err printPin p
|
|
|
|
where
|
|
|
|
err = putStrLn "ERR 83886179 Operation canceled <rofi>"
|
|
|
|
printPin p = putStrLn ("D " ++ p) >> ok
|
2021-06-25 23:42:29 -04:00
|
|
|
|
|
|
|
processOption :: String -> IO ()
|
|
|
|
processOption = undefined
|
|
|
|
|
|
|
|
noop :: IO ()
|
|
|
|
noop = ok
|
|
|
|
|
|
|
|
ok :: IO ()
|
|
|
|
ok = putStrLn "OK"
|