use P2P auth for git-remote-tor-annex
This changes the environment variable name to the more generic GIT_ANNEX_P2P_AUTHTOKEN. This commit was sponsored by andrea rota.
This commit is contained in:
parent
3ab12ba923
commit
b88e44ea9a
4 changed files with 18 additions and 23 deletions
|
@ -16,6 +16,8 @@ import Remote.Helper.Tor
|
||||||
import Utility.Tor
|
import Utility.Tor
|
||||||
import Utility.AuthToken
|
import Utility.AuthToken
|
||||||
import Annex.UUID
|
import Annex.UUID
|
||||||
|
import P2P.Address
|
||||||
|
import P2P.Auth
|
||||||
|
|
||||||
run :: [String] -> IO ()
|
run :: [String] -> IO ()
|
||||||
run (_remotename:address:[]) = forever $ do
|
run (_remotename:address:[]) = forever $ do
|
||||||
|
@ -54,7 +56,7 @@ connectService address port service = do
|
||||||
state <- Annex.new =<< Git.CurrentRepo.get
|
state <- Annex.new =<< Git.CurrentRepo.get
|
||||||
Annex.eval state $ do
|
Annex.eval state $ do
|
||||||
authtoken <- fromMaybe nullAuthToken
|
authtoken <- fromMaybe nullAuthToken
|
||||||
<$> getTorAuthTokenFor address
|
<$> loadP2PRemoteAuthToken (TorAnnex address port)
|
||||||
myuuid <- getUUID
|
myuuid <- getUUID
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
h <- liftIO $ torHandle =<< connectHiddenService address port
|
h <- liftIO $ torHandle =<< connectHiddenService address port
|
||||||
|
@ -62,4 +64,4 @@ connectService address port service = do
|
||||||
v <- auth myuuid authtoken
|
v <- auth myuuid authtoken
|
||||||
case v of
|
case v of
|
||||||
Just _theiruuid -> connect service stdin stdout
|
Just _theiruuid -> connect service stdin stdout
|
||||||
Nothing -> giveup $ "authentication failed, perhaps you need to set " ++ torAuthTokenEnv
|
Nothing -> giveup $ "authentication failed, perhaps you need to set " ++ p2pAuthTokenEnv
|
||||||
|
|
15
P2P/Auth.hs
15
P2P/Auth.hs
|
@ -12,6 +12,7 @@ import Creds
|
||||||
import P2P.Address
|
import P2P.Address
|
||||||
import Utility.AuthToken
|
import Utility.AuthToken
|
||||||
import Utility.Tor
|
import Utility.Tor
|
||||||
|
import Utility.Env
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
@ -38,9 +39,19 @@ p2pAuthCredsFile :: FilePath
|
||||||
p2pAuthCredsFile = "p2pauth"
|
p2pAuthCredsFile = "p2pauth"
|
||||||
|
|
||||||
-- | Loads the AuthToken to use when connecting with a given P2P address.
|
-- | Loads the AuthToken to use when connecting with a given P2P address.
|
||||||
|
--
|
||||||
|
-- It's loaded from the first line of the creds file, but
|
||||||
|
-- GIT_ANNEX_P2P_AUTHTOKEN overrides.
|
||||||
loadP2PRemoteAuthToken :: P2PAddress -> Annex (Maybe AuthToken)
|
loadP2PRemoteAuthToken :: P2PAddress -> Annex (Maybe AuthToken)
|
||||||
loadP2PRemoteAuthToken addr = maybe Nothing (toAuthToken . T.pack)
|
loadP2PRemoteAuthToken addr = maybe Nothing mk <$> getM id
|
||||||
<$> readCacheCreds (addressCredsFile addr)
|
[ liftIO $ getEnv "GIT_ANNEX_P2P_AUTHTOKEN"
|
||||||
|
, readCacheCreds (addressCredsFile addr)
|
||||||
|
]
|
||||||
|
where
|
||||||
|
mk = toAuthToken . T.pack . takeWhile (/= '\n')
|
||||||
|
|
||||||
|
p2pAuthTokenEnv :: String
|
||||||
|
p2pAuthTokenEnv = "GIT_ANNEX_P2P_AUTHTOKEN"
|
||||||
|
|
||||||
-- | Stores the AuthToken o use when connecting with a given P2P address.
|
-- | Stores the AuthToken o use when connecting with a given P2P address.
|
||||||
storeP2PRemoteAuthToken :: P2PAddress -> AuthToken -> Annex ()
|
storeP2PRemoteAuthToken :: P2PAddress -> AuthToken -> Annex ()
|
||||||
|
|
|
@ -8,26 +8,8 @@
|
||||||
module Remote.Helper.Tor where
|
module Remote.Helper.Tor where
|
||||||
|
|
||||||
import Annex.Common
|
import Annex.Common
|
||||||
import Utility.AuthToken
|
|
||||||
import Creds
|
|
||||||
import Utility.Tor
|
|
||||||
import Utility.Env
|
|
||||||
|
|
||||||
import Network.Socket
|
import Network.Socket
|
||||||
import qualified Data.Text as T
|
|
||||||
|
|
||||||
-- Read the first line of the creds file. Environment variable overrides.
|
|
||||||
getTorAuthTokenFor :: OnionAddress -> Annex (Maybe AuthToken)
|
|
||||||
getTorAuthTokenFor (OnionAddress onionaddress) =
|
|
||||||
maybe Nothing mk <$> getM id
|
|
||||||
[ liftIO $ getEnv torAuthTokenEnv
|
|
||||||
, readCacheCreds onionaddress
|
|
||||||
]
|
|
||||||
where
|
|
||||||
mk = toAuthToken . T.pack . takeWhile (/= '\n')
|
|
||||||
|
|
||||||
torAuthTokenEnv :: String
|
|
||||||
torAuthTokenEnv = "GIT_ANNEX_TOR_AUTHTOKEN"
|
|
||||||
|
|
||||||
torHandle :: Socket -> IO Handle
|
torHandle :: Socket -> IO Handle
|
||||||
torHandle s = do
|
torHandle s = do
|
||||||
|
|
|
@ -15,7 +15,7 @@ over tor(1), communicating with a tor hidden service.
|
||||||
|
|
||||||
The tor hidden service probably requires an authtoken to use it.
|
The tor hidden service probably requires an authtoken to use it.
|
||||||
The authtoken can be provided in the environment variable
|
The authtoken can be provided in the environment variable
|
||||||
`GIT_ANNEX_TOR_AUTHTOKEN`. Or, if there is a file in
|
`GIT_ANNEX_P2P_AUTHTOKEN`. Or, if there is a file in
|
||||||
`.git/annex/creds/` matching the onion address of the hidden
|
`.git/annex/creds/` matching the onion address of the hidden
|
||||||
service, its first line is used as the authtoken.
|
service, its first line is used as the authtoken.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue