S3, Glacier, WebDAV: Fix bug that prevented accessing the creds when the repository was configured with encryption=shared embedcreds=yes.

Since encryption=shared, the encryption key is stored in the git repo, so
there is no point at all in encrypting the creds, also stored in the git
repo with that key. So `initremote` doesn't. The creds are simply stored
base-64 encoded.

However, it then tried to always decrypt creds when encryption was used..
This commit is contained in:
Joey Hess 2014-08-12 15:35:29 -04:00
parent 631bf3cbc2
commit fbdeeeed5f
3 changed files with 18 additions and 9 deletions

View file

@ -23,7 +23,7 @@ import Annex.Perms
import Utility.FileMode import Utility.FileMode
import Crypto import Crypto
import Types.Remote (RemoteConfig, RemoteConfigKey) import Types.Remote (RemoteConfig, RemoteConfigKey)
import Remote.Helper.Encryptable (remoteCipher, embedCreds) import Remote.Helper.Encryptable (remoteCipher, remoteCipher', embedCreds)
import Utility.Env (getEnv) import Utility.Env (getEnv)
import qualified Data.ByteString.Lazy.Char8 as L import qualified Data.ByteString.Lazy.Char8 as L
@ -85,15 +85,19 @@ getRemoteCredPair c storage = maybe fromcache (return . Just) =<< fromenv
fromcache = maybe fromconfig (return . Just) =<< readCacheCredPair storage fromcache = maybe fromconfig (return . Just) =<< readCacheCredPair storage
fromconfig = case credPairRemoteKey storage of fromconfig = case credPairRemoteKey storage of
Just key -> do Just key -> do
mcipher <- remoteCipher c mcipher <- remoteCipher' c
case (M.lookup key c, mcipher) of case (mcipher, M.lookup key c) of
(Nothing, _) -> return Nothing (_, Nothing) -> return Nothing
(Just enccreds, Just cipher) -> do (Just (_cipher, SharedCipher {}), Just bcreds) ->
-- When using a shared cipher, the
-- creds are not stored encrypted.
fromcreds $ fromB64 bcreds
(Just (cipher, _), Just enccreds) -> do
creds <- liftIO $ decrypt cipher creds <- liftIO $ decrypt cipher
(feedBytes $ L.pack $ fromB64 enccreds) (feedBytes $ L.pack $ fromB64 enccreds)
(readBytes $ return . L.unpack) (readBytes $ return . L.unpack)
fromcreds creds fromcreds creds
(Just bcreds, Nothing) -> (Nothing, Just bcreds) ->
fromcreds $ fromB64 bcreds fromcreds $ fromB64 bcreds
Nothing -> return Nothing Nothing -> return Nothing
fromcreds creds = case decodeCredPair creds of fromcreds creds = case decodeCredPair creds of

View file

@ -71,18 +71,21 @@ encryptionSetup c = maybe genCipher updateCipher $ extractCipher c
{- Gets encryption Cipher. The decrypted Ciphers are cached in the Annex {- Gets encryption Cipher. The decrypted Ciphers are cached in the Annex
- state. -} - state. -}
remoteCipher :: RemoteConfig -> Annex (Maybe Cipher) remoteCipher :: RemoteConfig -> Annex (Maybe Cipher)
remoteCipher c = go $ extractCipher c remoteCipher = fmap fst <$$> remoteCipher'
remoteCipher' :: RemoteConfig -> Annex (Maybe (Cipher, StorableCipher))
remoteCipher' c = go $ extractCipher c
where where
go Nothing = return Nothing go Nothing = return Nothing
go (Just encipher) = do go (Just encipher) = do
cache <- Annex.getState Annex.ciphers cache <- Annex.getState Annex.ciphers
case M.lookup encipher cache of case M.lookup encipher cache of
Just cipher -> return $ Just cipher Just cipher -> return $ Just (cipher, encipher)
Nothing -> do Nothing -> do
showNote "gpg" showNote "gpg"
cipher <- liftIO $ decryptCipher encipher cipher <- liftIO $ decryptCipher encipher
Annex.changeState (\s -> s { Annex.ciphers = M.insert encipher cipher cache }) Annex.changeState (\s -> s { Annex.ciphers = M.insert encipher cipher cache })
return $ Just cipher return $ Just (cipher, encipher)
{- Checks if the remote's config allows storing creds in the remote's config. {- Checks if the remote's config allows storing creds in the remote's config.
- -

2
debian/changelog vendored
View file

@ -33,6 +33,8 @@ git-annex (5.20140718) UNRELEASED; urgency=medium
* direct: Fix ugly warning messages. * direct: Fix ugly warning messages.
* WORM backend: When adding a file in a subdirectory, avoid including the * WORM backend: When adding a file in a subdirectory, avoid including the
subdirectory in the key name. subdirectory in the key name.
* S3, Glacier, WebDAV: Fix bug that prevented accessing the creds
when the repository was configured with encryption=shared embedcreds=yes.
-- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2014 14:41:26 -0400 -- Joey Hess <joeyh@debian.org> Mon, 21 Jul 2014 14:41:26 -0400