From 267b7057748d2c1e3a9de6984c0600e3a2ea123c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Sep 2016 10:30:50 -0400 Subject: Tor.hiddenService: Converted port parameter from Int to Port. (API change) --- src/Propellor/Property/Tor.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Tor.hs b/src/Propellor/Property/Tor.hs index 92dbd507..fb756f56 100644 --- a/src/Propellor/Property/Tor.hs +++ b/src/Propellor/Property/Tor.hs @@ -119,7 +119,7 @@ bandwidthRate' s divby = case readSize dataUnits s of `describe` ("tor BandwidthRate " ++ v) Nothing -> property ("unable to parse " ++ s) noChange -hiddenServiceAvailable :: HiddenServiceName -> Int -> Property DebianLike +hiddenServiceAvailable :: HiddenServiceName -> Port -> Property DebianLike hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port where hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do @@ -128,8 +128,8 @@ hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port warningMessage $ unwords ["hidden service hostname:", h] return r -hiddenService :: HiddenServiceName -> Int -> Property DebianLike -hiddenService hn port = ConfFile.adjustSection +hiddenService :: HiddenServiceName -> Port -> Property DebianLike +hiddenService hn (Port port) = ConfFile.adjustSection (unwords ["hidden service", hn, "available on port", show port]) (== oniondir) (not . isPrefixOf "HiddenServicePort") -- cgit v1.2.3 From e350175be425e966bd81153580644c741a09eafb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Sep 2016 10:36:22 -0400 Subject: propellor spin --- joeyconfig.hs | 2 +- src/Propellor/Property/Tor.hs | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/joeyconfig.hs b/joeyconfig.hs index 67398048..9c2985ae 100644 --- a/joeyconfig.hs +++ b/joeyconfig.hs @@ -484,7 +484,7 @@ keysafe = host "keysafe.joeyh.name" $ props & Tor.installed & Tor.hiddenServiceAvailable "keysafe" (Port 4242) - `requires` Tor.hiddenServiceData "keysafe" hostContext + -- `requires` Tor.hiddenServiceData "keysafe" hostContext -- keysafe installed manually until package is available iabak :: Host diff --git a/src/Propellor/Property/Tor.hs b/src/Propellor/Property/Tor.hs index fb756f56..951084b4 100644 --- a/src/Propellor/Property/Tor.hs +++ b/src/Propellor/Property/Tor.hs @@ -119,15 +119,7 @@ bandwidthRate' s divby = case readSize dataUnits s of `describe` ("tor BandwidthRate " ++ v) Nothing -> property ("unable to parse " ++ s) noChange -hiddenServiceAvailable :: HiddenServiceName -> Port -> Property DebianLike -hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port - where - hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do - r <- satisfy - h <- liftIO $ readFile (varLib hn "hostname") - warningMessage $ unwords ["hidden service hostname:", h] - return r - +-- | Enables a hidden service for a given port. hiddenService :: HiddenServiceName -> Port -> Property DebianLike hiddenService hn (Port port) = ConfFile.adjustSection (unwords ["hidden service", hn, "available on port", show port]) @@ -141,6 +133,18 @@ hiddenService hn (Port port) = ConfFile.adjustSection oniondir = unwords ["HiddenServiceDir", varLib hn] onionport = unwords ["HiddenServicePort", show port, "127.0.0.1:" ++ show port] +-- | Same as `hiddenService` but also causes propellor to display +-- the onion address of the hidden service. +hiddenServiceAvailable :: HiddenServiceName -> Port -> Property DebianLike +hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port + where + hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do + r <- satisfy + h <- liftIO $ readFile (varLib hn "hostname") + warningMessage $ unwords ["hidden service hostname:", h] + return r + +-- | hiddenServiceData :: IsContext c => HiddenServiceName -> c -> Property (HasInfo + DebianLike) hiddenServiceData hn context = combineProperties desc $ props & installonion "hostname" -- cgit v1.2.3 From bc75f84f58aafaf7b69f20f1507df80dccc8023b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Sep 2016 11:19:35 -0400 Subject: Tor.hiddenServiceAvailable: The hidden service hostname file may not be available immedaitely after configuring tor; avoid ugly error in this case. --- debian/changelog | 3 +++ src/Propellor/Property/Tor.hs | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/debian/changelog b/debian/changelog index e01f4a20..ab8d6907 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,9 @@ propellor (3.2.0) UNRELEASED; urgency=medium * Tor.hiddenService: Converted port parameter from Int to Port. (API change) + * Tor.hiddenServiceAvailable: The hidden service hostname file may not + be available immedaitely after configuring tor; avoid ugly error in + this case. -- Joey Hess Thu, 01 Sep 2016 10:30:17 -0400 diff --git a/src/Propellor/Property/Tor.hs b/src/Propellor/Property/Tor.hs index 951084b4..2fe97e4e 100644 --- a/src/Propellor/Property/Tor.hs +++ b/src/Propellor/Property/Tor.hs @@ -120,6 +120,9 @@ bandwidthRate' s divby = case readSize dataUnits s of Nothing -> property ("unable to parse " ++ s) noChange -- | Enables a hidden service for a given port. +-- +-- If used without `hiddenServiceData`, tor will generate a new +-- private key. hiddenService :: HiddenServiceName -> Port -> Property DebianLike hiddenService hn (Port port) = ConfFile.adjustSection (unwords ["hidden service", hn, "available on port", show port]) @@ -140,11 +143,13 @@ hiddenServiceAvailable hn port = hiddenServiceHostName $ hiddenService hn port where hiddenServiceHostName p = adjustPropertySatisfy p $ \satisfy -> do r <- satisfy - h <- liftIO $ readFile (varLib hn "hostname") - warningMessage $ unwords ["hidden service hostname:", h] + mh <- liftIO $ tryIO $ readFile (varLib hn "hostname") + case mh of + Right h -> warningMessage $ unwords ["hidden service hostname:", h] + Left _e -> warningMessage "hidden service hostname not available yet" return r --- | +-- | Load the private key for a hidden service from the privdata. hiddenServiceData :: IsContext c => HiddenServiceName -> c -> Property (HasInfo + DebianLike) hiddenServiceData hn context = combineProperties desc $ props & installonion "hostname" -- cgit v1.2.3