From e454eea330d68636a34c31990b64a5c166f52c31 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Mon, 1 Jul 2019 13:47:08 -0400 Subject: Generated signatures for kiki.hs. --- kiki.hs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/kiki.hs b/kiki.hs index fa22451..63c9f02 100644 --- a/kiki.hs +++ b/kiki.hs @@ -24,6 +24,7 @@ import Data.List import Data.Maybe import Data.OpenPGP import Data.Ord +import Data.String import Data.Text.Encoding import System.Posix.User import System.Posix.Files @@ -105,7 +106,7 @@ import FunctorToMaybe isCertificationSig :: SignatureOver -> Bool isSubkeySignature :: SignatureOver -> Bool kiki :: forall a. - (Eq a, Data.String.IsString a) => + (Eq a, IsString a) => a -> [[Char]] -> IO () kiki_sync_help :: IO () listKeys :: [Packet] -> [Char] @@ -137,15 +138,18 @@ import FunctorToMaybe -} +isCertificationSig :: SignatureOver -> Bool isCertificationSig (CertificationSignature {}) = True isCertificationSig _ = True +fpmatch :: Maybe [Char] -> Packet -> Bool fpmatch grip key = (==) Nothing (fmap (backend (fingerprint key)) grip >>= guard . not) where backend xs ys = and $ zipWith (==) (reverse xs) (reverse ys) +listKeys :: [Packet] -> [Char] listKeys pkts = listKeysFiltered [] pkts -- | listKeysFiltered @@ -154,6 +158,7 @@ listKeys pkts = listKeysFiltered [] pkts -- Build the display output -- Operates in List Monad... -- returns all output as a single string +listKeysFiltered :: Foldable t => t [Char] -> [Packet] -> [Char] listKeysFiltered grips pkts = do let masterkeys = filter (\k -> isKey k && not (is_subkey k)) pkts (certs,bs) = getBindings pkts @@ -273,6 +278,8 @@ toLast f [x] = [f x] toLast f (x:xs) = x : toLast f xs -- partitionStaticArguments :: Ord a => [(a, Int)] -> [a] -> ([[a]], [a]) +partitionStaticArguments :: [([Char], Int)] + -> [[Char]] -> ([[[Char]]], [[Char]]) partitionStaticArguments specs args = psa args where smap = Map.fromList specs @@ -285,6 +292,8 @@ partitionStaticArguments specs args = psa args Nothing -> second (a:) $ psa as Just n -> first ((a:take n as):) $ psa (drop n as) +show_wk :: FilePath + -> Maybe [Char] -> Map.Map KeyKey KeyData -> IO () show_wk secring_file grip db = do -- printf "show_wk(%s,%s,%s)\n" (show secring_file) (show grip) (show db) let sec_db = Map.filter gripmatch db @@ -294,6 +303,7 @@ show_wk secring_file grip db = do Message sec = flattenKeys False sec_db putStrLn $ listKeysFiltered (maybeToList grip) sec +debug_dump :: FilePath -> p -> Map.Map KeyKey KeyData -> IO () debug_dump secring_file grip db = do let sec_db = Map.filter gripmatch db gripmatch (KeyData p _ _ _) = @@ -302,14 +312,18 @@ debug_dump secring_file grip db = do Message sec = flattenKeys False sec_db mapM_ print sec +show_all :: KeyDB -> IO () show_all db = do let Message packets = flattenKeys True db putStrLn $ listKeys packets +show_packets :: (Eq a, IsString a) => + [a] -> KeyDB -> IO () show_packets puborsec db = do let Message packets = flattenKeys (case puborsec of { "sec":_ -> False; _ -> True }) db forM_ packets $ putStrLn . showPacket +show_whose_key :: Maybe RSAPublicKey -> KeyDB -> IO () show_whose_key input_key db = flip (maybe $ return ()) input_key $ \input_key -> do let ks = whoseKey input_key db @@ -320,8 +334,10 @@ show_whose_key input_key db = (_:_) -> error "ambiguous" [] -> return () +show_dns :: [Char] -> String -> KeyDB -> IO () show_dns keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db dnsPresentationFromPacket +dnsPresentationFromPacket :: Monad m => Packet -> m String dnsPresentationFromPacket k = do let RSAKey (MPI n) (MPI e) = fromJust $ rsaKeyFromPacket k dnskey = DNS.RSA n e @@ -345,6 +361,7 @@ dnsPresentationFromPacket k = do ,qq ] +show_id :: String -> p -> Map.Map KeyKey KeyData -> IO () show_id keyspec wkgrip db = do let s = parseSpec "" keyspec let ps = do @@ -354,6 +371,7 @@ show_id keyspec wkgrip db = do -- putStrLn $ "show key " ++ show s putStrLn $ listKeys ps +show_wip :: [Char] -> String -> KeyDB -> IO () show_wip keyspec wkgrip db = do let s = parseSpec wkgrip keyspec flip (maybe $ void (warn (keyspec ++ ": not found"))) @@ -362,6 +380,7 @@ show_wip keyspec wkgrip db = do let nwb = maybe 0x80 CryptoCoins.secretByteFromName $ snd s putStrLn $ walletImportFormat nwb k +show_torhash :: FilePath -> p -> IO () show_torhash pubkey _ = do bs <- Char8.readFile pubkey let parsekey f dta = do @@ -386,6 +405,7 @@ show_torhash pubkey _ = do keys = catMaybes $ scanAndParse (pkcs1 <> pkcs8 <> cert) $ Char8.lines bs mapM_ (putStrLn . addy . torhash) keys +show_cert :: [Char] -> String -> KeyDB -> IO () show_cert keyspec wkgrip db = do let s = parseSpec wkgrip keyspec case selectPublicKeyAndSigs s db of @@ -452,6 +472,8 @@ show_cert certfile _ = do return () -} +cannonical_eckey :: (Integral b1, Integral b2) => + b1 -> b2 -> [Word8] cannonical_eckey x y = 0x4:pad32(numToBytes x) ++ pad32(numToBytes y) :: [Word8] where numToBytes n = reverse $ unfoldr getbyte n @@ -465,6 +487,7 @@ cannonical_eckey x y = 0x4:pad32(numToBytes x) ++ pad32(numToBytes y) :: [Word8] zlen = 32 - length xs +bitcoinAddress :: Word8 -> Packet -> String bitcoinAddress network_id k = address where Just (MPI x) = lookup 'x' (key k) @@ -780,6 +803,8 @@ documentHomeDir = ," exactly the same functionality." ] +documentPassphraseFDFlag :: IsString a => + p1 -> p2 -> Bool -> [a] documentPassphraseFDFlag bExport bImport bSecret = if bSecret then [" --passphrase-fd FD" @@ -790,6 +815,8 @@ documentPassphraseFDFlag bExport bImport bSecret = ,""] else [] +documentImportFlag :: IsString a => + p1 -> Bool -> p2 -> [a] documentImportFlag bExport bImport bSecret = if bImport then [" --import Add master keys to pubring.gpg. Without this option, only UID" @@ -797,6 +824,8 @@ documentImportFlag bExport bImport bSecret = ,""] else [] +documentImportIfAuthenticFlag :: IsString a => + p1 -> Bool -> p2 -> [a] documentImportIfAuthenticFlag bExport bImport bSecret = if bImport then [" --import-if-authentic" @@ -806,6 +835,8 @@ documentImportIfAuthenticFlag bExport bImport bSecret = ,""] else [] +documentAutoSignFlag :: IsString a => + p1 -> p2 -> p3 -> [a] documentAutoSignFlag bExport bImport bSecret = [" --autosign Sign all cross-certified tor-style UIDs." ," A tor-style UID is of the form:" @@ -1029,6 +1060,8 @@ processArgs sargspec polyVariadicArgs defaultPoly args_raw = (sargs,margs) else error . unlines $ [ "unrecognized option "++k , "Use --help for usage." ] +parseCommonArgs :: (Ord k, IsString k) => + Map.Map k [[Char]] -> CommonArgsParsed parseCommonArgs margs = CommonArgsParsed { cap_homespec = homespec, cap_passfd = passfd } where passphrase_fd = concat <$> Map.lookup "--passphrase-fd" margs @@ -1776,6 +1809,7 @@ commands = , ( "tar", "import or export system key files in tar format" ) ] +main :: IO () main = do dotlock_init args_raw <- getArgs -- cgit v1.2.3