moesocks 0.1.0.20 → 0.1.0.21
raw patch · 9 files changed
+48/−40 lines, 9 files
Files
- CHANGELOG.md +4/−0
- README.md +18/−12
- moesocks.cabal +1/−1
- src/Network/MoeSocks/App.hs +6/−5
- src/Network/MoeSocks/Common.hs +0/−3
- src/Network/MoeSocks/Encrypt.hs +13/−16
- src/Network/MoeSocks/Options.hs +1/−1
- src/Network/MoeSocks/TCP.hs +3/−2
- src/Network/MoeSocks/Type.hs +2/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+0.1.0.21+--------+* Add in README that `GHC 7.10.2` is a must!+ 0.1.0.20 -------- * Rewrite Encrypt module, cache password hash
README.md view
@@ -10,6 +10,24 @@ type `moesocks --help` for help. +Installation+------------++* Need `GHC 7.10.2` and `cabal-install`.+ + Installing [haskell-platform](https://www.haskell.org/platform/) should be+ sufficient. (Linux users should pick the *Generic* distribution, since+ it's the most up to date)++* Repeat, you need `GHC 7.10.2` exactly, not `7.10.1` or anything else, since+ remote only runs well in `7.10.2`.+* Update packages++ cabal update+* Install++ cabal install moesocks+ Usage ----- * Edit `config.json` to fit your setup (at least the `remote` and `password`@@ -35,8 +53,6 @@ Not working ------------* Remote is flaky, particularly when trying to send data through the Great- Firewall of China (GFW). * UDP over Socks5 is not implemented * More then 2 times slower then the original Python implementation (measured at 20M/s vs 43M/s on an Intel P8800, using the AES-256-CFB method)@@ -47,16 +63,6 @@ Notes --------There's a bug that prevents remote from working correctly with GFW.-Thanks, Prof Fang!--You should use the original Python implementation of [shadowsocks] on the remote-server if your primary goal is to bypass internet censorship in China.--From the author's limited testing, [shadowsocks-go] also works reasonably-well, though it might not run as fast as the Python's version.- There is an earlier implementation of [shadowsocks-haskell] by rnons that makes MoeSocks possible.
moesocks.cabal view
@@ -1,6 +1,6 @@ name: moesocks category: Network-version: 0.1.0.20+version: 0.1.0.21 license: Apache-2.0 synopsis: A functional firewall killer description: A socks5 proxy using the client / server architecture.
src/Network/MoeSocks/App.hs view
@@ -183,9 +183,11 @@ <> _method ^. _Text Just (a, b, c, d) -> pure - CipherBox a b c d - let localAppBuilder :: AppType -> String -> - (ByteString -> (Socket, SockAddr) -> IO ()) -> - (Socket, SockAddr) -> IO ()+ let localAppBuilder :: AppType + -> String + -> (ByteString -> (Socket, SockAddr) -> IO ()) + -> (Socket, SockAddr) + -> IO () localAppBuilder aAppType aID aHandler s = logSA "L loop" (pure s) - \(_localSocket, _localAddr) -> do _say - "L " <> aID <> ": nyaa!"@@ -238,8 +240,7 @@ <> show _remotePort <> "]" - forward_TCP_App :: Forward -> (Socket, SockAddr) - -> IO ()+ forward_TCP_App :: Forward -> (Socket, SockAddr) -> IO () forward_TCP_App _f _s = do let _m = showForwarding _f localAppBuilder TCP_App ("TCP forwarding " <> _m)
src/Network/MoeSocks/Common.hs view
@@ -11,10 +11,7 @@ import Network.Socket hiding (send, recv, recvFrom, sendTo) import Prelude hiding ((-), take) import qualified Data.List as L-import qualified Network.MoeSocks.Encrypt as E -plainCipher :: Cipher-plainCipher = E.plainCipher showAddressType :: AddressType -> Text showAddressType (IPv4_address xs) = view (from _Text) -
src/Network/MoeSocks/Encrypt.hs view
@@ -39,7 +39,7 @@ type CipherBuilder = ByteString -> IO Cipher type CipherBox = (Int, IO ByteString, CipherBuilder, CipherBuilder) -type MaybeExceptT = ExceptT () IO+type MaybeT_IO = ExceptT () IO methods :: Map Text (KeyLength, IV_Length) methods = fromList@@ -80,44 +80,41 @@ eitherToMaybe (Left _) = Nothing eitherToMaybe (Right x) = Just x -getMaybe :: Maybe a -> MaybeExceptT a+getMaybe :: Maybe a -> MaybeT_IO a getMaybe Nothing = throwError () getMaybe (Just x) = pure x -mio :: IO (Maybe a) -> MaybeExceptT a-mio = (>>= getMaybe) . io--io :: (MonadIO m) => IO a -> m a-io = liftIO+mio :: IO (Maybe a) -> MaybeT_IO a+mio = (>>= getMaybe) . liftIO -plainCipher :: Cipher-plainCipher = pure . S.fromMaybe mempty+identityCipher :: Cipher+identityCipher = pure . S.fromMaybe mempty initBuilder :: Text -> Text -> IO (Maybe CipherBox) initBuilder aMethod aPassword - | aMethod == "none" = let constCipher = const - pure plainCipher+ | aMethod == "none" = let constCipher = const - pure identityCipher in pure - Just (0, pure mempty, constCipher, constCipher) | otherwise = fmap eitherToMaybe - runExceptT - initBuilder' aMethod aPassword -initBuilder' :: Text -> Text -> MaybeExceptT CipherBox+initBuilder' :: Text -> Text -> MaybeT_IO CipherBox initBuilder' aMethod aPassword = do _method <- mio - ssl - getCipherByName - aMethod ^. _Text (_keyLength, _IV_Length) <- getMaybe - methods ^? ix aMethod let _hashed = hashKey (review utf8 aPassword) _keyLength _IV_Length- _IV_Maker = io - ssl - randBytes _IV_Length+ _IV_Maker = ssl - randBytes _IV_Length _encryptBuilder :: ByteString -> IO Cipher _encryptBuilder _iv = do- _ctx <- io - ssl - E.cipherInitBS _method _hashed _iv Encrypt+ _ctx <- ssl - E.cipherInitBS _method _hashed _iv Encrypt let _encrypt :: Cipher _encrypt = \case- S.Nothing -> E.cipherFinalBS _ctx+ S.Nothing -> ssl - E.cipherFinalBS _ctx S.Just _bytes -> do ssl - E.cipherUpdateBS _ctx _bytes @@ -125,11 +122,11 @@ _decryptBuilder :: ByteString -> IO Cipher _decryptBuilder _iv = do- _ctx <- io - ssl - E.cipherInitBS _method _hashed _iv Decrypt+ _ctx <- ssl - E.cipherInitBS _method _hashed _iv Decrypt let _decrypt :: Cipher _decrypt = \case- S.Nothing -> E.cipherFinalBS _ctx+ S.Nothing -> ssl - E.cipherFinalBS _ctx S.Just _bytes -> do ssl - E.cipherUpdateBS _ctx _bytes
src/Network/MoeSocks/Options.hs view
@@ -61,7 +61,7 @@ & view (from _Text)) ("The number of packets used as a " <> "buffer. A packet can hold "- <> "at most 4K of data.")+ <> "at most 4K of data") _config = optional - textOption - short 'c'
src/Network/MoeSocks/TCP.hs view
@@ -11,6 +11,7 @@ import Network.MoeSocks.BuilderAndParser import Network.MoeSocks.Common import Network.MoeSocks.Constant+import Network.MoeSocks.Encrypt (identityCipher) import Network.MoeSocks.Helper import Network.MoeSocks.Type import Network.Socket hiding (send, recv, recvFrom, sendTo)@@ -25,7 +26,7 @@ -> IO () local_Socks5_RequestHandler aCipherBox aConfig _ (aSocket,_) = do (_partialBytesAfterGreeting, _r) <- - parseSocket "clientGreeting" mempty plainCipher+ parseSocket "clientGreeting" mempty identityCipher greetingParser aSocket when (not - _No_authentication `elem` (_r ^. authenticationMethods)) - @@ -37,7 +38,7 @@ _parsedRequest <- parseSocket "clientRequest" _partialBytesAfterGreeting- plainCipher+ identityCipher connectionParser aSocket
src/Network/MoeSocks/Type.hs view
@@ -112,6 +112,7 @@ makeLenses '' CipherBox +{- data Env = Env { _options :: MoeOptions@@ -120,6 +121,7 @@ } makeLenses ''Env+-}