diff options
author | joe <joe@jerkface.net> | 2014-04-30 23:01:07 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-04-30 23:01:07 -0400 |
commit | aa5bf4e7ba36a07898a8ffaf9c6b25d973fb05d6 (patch) | |
tree | 07168074c0ee93ea72350ebad63559c112333ade | |
parent | 69acbc5156a69393ab97e444f51945706365da4b (diff) |
Support default passphrase specification
-rw-r--r-- | KeyRing.hs | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -171,13 +171,11 @@ data InputFile = HomeSec | |||
171 | 171 | ||
172 | -- type UsageTag = String | 172 | -- type UsageTag = String |
173 | type Initializer = String | 173 | type Initializer = String |
174 | type PassWordFile = InputFile | 174 | type PasswordFile = InputFile |
175 | 175 | ||
176 | -- TODO: This should become a simple enum. | 176 | data FileType = KeyRingFile (Maybe PasswordFile) |
177 | -- The parameter to PEMFile will be subsumed by | 177 | -- ^ PasswordFile parameter is deprecated in favor |
178 | -- the KF_Match fill/spill KeyFilter styles. The parameter | 178 | -- of kPassphrases. TODO: remove it. |
179 | -- to KeyRingFile will be subsumbed by kPassphrases | ||
180 | data FileType = KeyRingFile (Maybe PassWordFile) | ||
181 | | PEMFile | 179 | | PEMFile |
182 | | WalletFile -- (Maybe UsageTag) | 180 | | WalletFile -- (Maybe UsageTag) |
183 | | Hosts | 181 | | Hosts |
@@ -225,7 +223,7 @@ ispem :: FileType -> Bool | |||
225 | ispem (PEMFile {}) = True | 223 | ispem (PEMFile {}) = True |
226 | ispem _ = False | 224 | ispem _ = False |
227 | 225 | ||
228 | pwfile :: FileType -> Maybe PassWordFile | 226 | pwfile :: FileType -> Maybe PasswordFile |
229 | pwfile (KeyRingFile f) = f | 227 | pwfile (KeyRingFile f) = f |
230 | pwfile _ = Nothing | 228 | pwfile _ = Nothing |
231 | 229 | ||
@@ -1661,14 +1659,20 @@ makeMemoizingDecrypter operation ctx = do | |||
1661 | guard $ isNothing $ passSpecKeySpec spec | 1659 | guard $ isNothing $ passSpecKeySpec spec |
1662 | passSpecRingFile spec) | 1660 | passSpecRingFile spec) |
1663 | (kPassphrases operation) | 1661 | (kPassphrases operation) |
1662 | defpw <- do | ||
1663 | Traversable.mapM (cachedContents ctx . passSpecPassFile) | ||
1664 | $ listToMaybe $ filter (\sp -> isNothing (passSpecRingFile sp) | ||
1665 | && isNothing (passSpecKeySpec sp)) | ||
1666 | $ kPassphrases operation | ||
1664 | unkeysRef <- newIORef Map.empty | 1667 | unkeysRef <- newIORef Map.empty |
1665 | return $ doDecrypt unkeysRef (pws `Map.union` pws2) | 1668 | return $ doDecrypt unkeysRef (pws `Map.union` pws2) defpw |
1666 | where | 1669 | where |
1667 | doDecrypt :: IORef (Map.Map KeyKey Packet) | 1670 | doDecrypt :: IORef (Map.Map KeyKey Packet) |
1668 | -> Map.Map FilePath (IO S.ByteString) | 1671 | -> Map.Map FilePath (IO S.ByteString) |
1672 | -> Maybe (IO S.ByteString) | ||
1669 | -> MappedPacket | 1673 | -> MappedPacket |
1670 | -> IO (KikiCondition Packet) | 1674 | -> IO (KikiCondition Packet) |
1671 | doDecrypt unkeysRef pws mp = do | 1675 | doDecrypt unkeysRef pws defpw mp = do |
1672 | unkeys <- readIORef unkeysRef | 1676 | unkeys <- readIORef unkeysRef |
1673 | let wk = packet mp | 1677 | let wk = packet mp |
1674 | kk = keykey wk | 1678 | kk = keykey wk |