diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-10-06 15:37:12 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-10-06 16:10:18 -0400 |
commit | f17abaa8ec3654ab4973641e2f551fe5b7088671 (patch) | |
tree | 5e0a692a0c21187b2cdfca5a35fea5575faa5f22 /SecretKey.hs | |
parent | eeda326eb9aa34ff325bc9d2d97f5cb42f3958b5 (diff) | |
download | keysafe-f17abaa8ec3654ab4973641e2f551fe5b7088671.tar.gz |
Gpg keyid bugs
Fix bugs with entry of gpg keyid in the keysafe.log. Gpg.anyKey was being
used in writing the log, which made the log contain gpg keys with an empty
keyid.
Fix bug in --autostart that caused the full gpg keyid to be
used in the name, so restores would only work when --gpgkeyid was
specifid.
Added a Distinguisher data type rather than the Gpg.anyKey hack.
This commit was sponsored by Thom May on Patreon.
Diffstat (limited to 'SecretKey.hs')
-rw-r--r-- | SecretKey.hs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/SecretKey.hs b/SecretKey.hs index 45d9680..8dc2ada 100644 --- a/SecretKey.hs +++ b/SecretKey.hs @@ -6,19 +6,24 @@ module SecretKey where import Types +import Share import qualified Gpg import qualified Data.ByteString as B import System.IO import System.Posix.IO -getSecretKey :: SecretKeySource -> IO SecretKey -getSecretKey (GpgKey kid) = Gpg.getSecretKey kid -getSecretKey (KeyFile f) = SecretKey <$> B.readFile f +getSecretKey :: SecretKeySource -> IO (SecretKeySource, SecretKey) +getSecretKey sks = do + sk <- case sks of + GpgKey kid -> Gpg.getSecretKey kid + KeyFile f -> SecretKey <$> B.readFile f + return (sks, sk) -- | Can throw exception if the secret key already exists. -writeSecretKey :: SecretKeySource -> SecretKey -> IO () -writeSecretKey (GpgKey _) secretkey = Gpg.writeSecretKey secretkey -writeSecretKey (KeyFile f) (SecretKey b) = do +writeSecretKey :: Distinguisher -> SecretKey -> IO () +writeSecretKey (Distinguisher (GpgKey _)) secretkey = Gpg.writeSecretKey secretkey +writeSecretKey AnyGpgKey secretkey = Gpg.writeSecretKey secretkey +writeSecretKey (Distinguisher (KeyFile f)) (SecretKey b) = do fd <- openFd f WriteOnly (Just 0o666) (defaultFileFlags { exclusive = True } ) h <- fdToHandle fd |