diff options
author | joe <joe@jerkface.net> | 2014-04-18 00:35:30 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-04-18 00:35:30 -0400 |
commit | 60f9591a217e07da45b6f16769a9b65a18301754 (patch) | |
tree | 55a296600c770f5daa558de7f5579f33303da655 | |
parent | 67e5ad3df24cea8f16e7cb1f95e557c13b75d4ee (diff) |
export secret keys as pem files
-rw-r--r-- | KeyRing.hs | 9 | ||||
-rw-r--r-- | kiki.hs | 20 |
2 files changed, 19 insertions, 10 deletions
@@ -88,7 +88,7 @@ type UsageTag = String | |||
88 | type Initializer = String | 88 | type Initializer = String |
89 | type PassWordFile = InputFile | 89 | type PassWordFile = InputFile |
90 | 90 | ||
91 | data FileType = KeyRingFile PassWordFile | 91 | data FileType = KeyRingFile (Maybe PassWordFile) |
92 | | PEMFile UsageTag | 92 | | PEMFile UsageTag |
93 | | WalletFile -- (Maybe UsageTag) | 93 | | WalletFile -- (Maybe UsageTag) |
94 | 94 | ||
@@ -101,7 +101,7 @@ isring (KeyRingFile {}) = True | |||
101 | isring _ = False | 101 | isring _ = False |
102 | 102 | ||
103 | pwfile (KeyRingFile f) = f | 103 | pwfile (KeyRingFile f) = f |
104 | pwfile _ = HomeSec | 104 | pwfile _ = Nothing |
105 | 105 | ||
106 | iswallet (WalletFile {}) = True | 106 | iswallet (WalletFile {}) = True |
107 | iswallet _ = False | 107 | iswallet _ = False |
@@ -279,6 +279,7 @@ data KikiReportAction = | |||
279 | | ExternallyGeneratedFile | 279 | | ExternallyGeneratedFile |
280 | | UnableToExport KeyAlgorithm String | 280 | | UnableToExport KeyAlgorithm String |
281 | | FailedFileWrite | 281 | | FailedFileWrite |
282 | deriving Show | ||
282 | 283 | ||
283 | data KikiResult a = KikiResult | 284 | data KikiResult a = KikiResult |
284 | { kikiCondition :: KikiCondition a | 285 | { kikiCondition :: KikiCondition a |
@@ -1173,9 +1174,9 @@ runKeyRing keyring = do | |||
1173 | -- TODO: head will throw an exception if a File Descriptor keyring | 1174 | -- TODO: head will throw an exception if a File Descriptor keyring |
1174 | -- file is present. We probably should change OriginMap to use InputFile | 1175 | -- file is present. We probably should change OriginMap to use InputFile |
1175 | -- instead of FilePath. | 1176 | -- instead of FilePath. |
1176 | Traversable.mapM (cachedContents secring pubring . pwfile . snd) | 1177 | Traversable.mapM (cachedContents secring pubring . fromJust . pwfile . snd) |
1177 | (Map.mapKeys (head . resolveInputFile secring pubring) | 1178 | (Map.mapKeys (head . resolveInputFile secring pubring) |
1178 | $ Map.filter (isring . snd) $ kFiles keyring) | 1179 | $ Map.filter (isJust . pwfile . snd) $ kFiles keyring) |
1179 | 1180 | ||
1180 | unkeysRef <- newIORef Map.empty | 1181 | unkeysRef <- newIORef Map.empty |
1181 | 1182 | ||
@@ -1232,8 +1232,8 @@ main = do | |||
1232 | let keypairs = catMaybes keypairs0 | 1232 | let keypairs = catMaybes keypairs0 |
1233 | btcpairs = catMaybes btcpairs0 | 1233 | btcpairs = catMaybes btcpairs0 |
1234 | 1234 | ||
1235 | {- | ||
1236 | putStrLn $ "keypairs = "++show keypairs | 1235 | putStrLn $ "keypairs = "++show keypairs |
1236 | {- | ||
1237 | putStrLn $ "publics = "++show publics | 1237 | putStrLn $ "publics = "++show publics |
1238 | putStrLn $ "keyrings = "++show keyrings | 1238 | putStrLn $ "keyrings = "++show keyrings |
1239 | -} | 1239 | -} |
@@ -1324,19 +1324,25 @@ main = do | |||
1324 | return db' | 1324 | return db' |
1325 | 1325 | ||
1326 | let homespec = join . take 1 <$> Map.lookup "--homedir" margs | 1326 | let homespec = join . take 1 <$> Map.lookup "--homedir" margs |
1327 | passfd = fmap (FileDesc . read) passphrase_fd | ||
1328 | pems = flip map keypairs | ||
1329 | $ \(usage,path,cmd) -> | ||
1330 | let cmd' = guard (not $ null cmd) >> return cmd | ||
1331 | in (ArgFile path, (MutableRef cmd', PEMFile usage)) | ||
1327 | kikiOp = KeyRingData | 1332 | kikiOp = KeyRingData |
1328 | { kFiles = Map.fromList | 1333 | { kFiles = Map.fromList $ |
1329 | [ ( HomeSec, (ConstRef, KeyRingFile (FileDesc 8)) ) | 1334 | [ ( HomeSec, (MutableRef Nothing, KeyRingFile passfd) ) |
1330 | , ( HomePub, (ConstRef, KeyRingFile (FileDesc 8)) ) | 1335 | , ( HomePub, (MutableRef Nothing, KeyRingFile Nothing) ) |
1331 | ] | 1336 | ] |
1337 | ++ pems | ||
1332 | , kImports = Map.empty | 1338 | , kImports = Map.empty |
1333 | , homeSpec = homespec | 1339 | , homeSpec = homespec |
1334 | } | 1340 | } |
1335 | 1341 | ||
1336 | rt <- runKeyRing kikiOp | 1342 | KikiResult rt report <- runKeyRing kikiOp |
1337 | 1343 | ||
1338 | case rt of | 1344 | case rt of |
1339 | KikiResult (KikiSuccess rt) _ -> do -- interpret --show-* commands. | 1345 | KikiSuccess rt -> do -- interpret --show-* commands. |
1340 | let grip = rtGrip rt | 1346 | let grip = rtGrip rt |
1341 | let shspec = Map.fromList [("--show-wk", const $ show_wk (rtSecring rt) grip) | 1347 | let shspec = Map.fromList [("--show-wk", const $ show_wk (rtSecring rt) grip) |
1342 | ,("--show-all",const $ show_all) | 1348 | ,("--show-all",const $ show_all) |
@@ -1349,7 +1355,9 @@ main = do | |||
1349 | shargs = mapMaybe (\(x:xs) -> (,xs) <$> Map.lookup x shspec) sargs | 1355 | shargs = mapMaybe (\(x:xs) -> (,xs) <$> Map.lookup x shspec) sargs |
1350 | 1356 | ||
1351 | forM_ shargs $ \(cmd,args) -> cmd args (rtKeyDB rt) | 1357 | forM_ shargs $ \(cmd,args) -> cmd args (rtKeyDB rt) |
1358 | e -> putStrLn $ show (fmap (const ()) e) | ||
1352 | 1359 | ||
1360 | putStrLn $ show report | ||
1353 | return() | 1361 | return() |
1354 | where | 1362 | where |
1355 | 1363 | ||