2013-11-11 04:03:24 +00:00
|
|
|
From e1a2f80f6bec25921ab645a0aaf1c6422a8917ab Mon Sep 17 00:00:00 2001
|
|
|
|
From: dummy <dummy@example.com>
|
|
|
|
Date: Mon, 11 Nov 2013 01:06:58 +0000
|
|
|
|
Subject: [PATCH] fix
|
2013-03-01 03:43:26 +00:00
|
|
|
|
|
|
|
---
|
2013-09-22 05:27:15 +00:00
|
|
|
Network/Socks5/Command.hs | 8 +-------
|
|
|
|
Network/Socks5/Conf.hs | 1 -
|
|
|
|
Network/Socks5/Lowlevel.hs | 1 -
|
|
|
|
Network/Socks5/Types.hs | 18 +-----------------
|
|
|
|
Network/Socks5/Wire.hs | 2 --
|
|
|
|
5 files changed, 2 insertions(+), 28 deletions(-)
|
2013-03-01 03:43:26 +00:00
|
|
|
|
|
|
|
diff --git a/Network/Socks5/Command.hs b/Network/Socks5/Command.hs
|
2013-11-11 04:03:24 +00:00
|
|
|
index db95fbd..fdba5ec 100644
|
2013-03-01 03:43:26 +00:00
|
|
|
--- a/Network/Socks5/Command.hs
|
|
|
|
+++ b/Network/Socks5/Command.hs
|
2013-11-11 04:03:24 +00:00
|
|
|
@@ -13,7 +13,6 @@ module Network.Socks5.Command
|
2013-09-22 05:27:15 +00:00
|
|
|
, Connect(..)
|
|
|
|
, Command(..)
|
|
|
|
, connectIPV4
|
|
|
|
- , connectIPV6
|
|
|
|
, connectDomainName
|
|
|
|
-- * lowlevel interface
|
|
|
|
, rpc
|
2013-11-11 04:03:24 +00:00
|
|
|
@@ -29,7 +28,7 @@ import qualified Data.ByteString as B
|
2013-03-01 03:43:26 +00:00
|
|
|
import qualified Data.ByteString.Char8 as BC
|
|
|
|
import Data.Serialize
|
|
|
|
|
|
|
|
-import Network.Socket (Socket, PortNumber, HostAddress, HostAddress6)
|
|
|
|
+import Network.Socket (Socket, PortNumber, HostAddress)
|
|
|
|
import Network.Socket.ByteString
|
|
|
|
|
|
|
|
import Network.Socks5.Types
|
2013-11-11 04:03:24 +00:00
|
|
|
@@ -65,11 +64,6 @@ connectIPV4 socket hostaddr port = onReply <$> rpc_ socket (Connect $ SocksAddre
|
2013-09-22 05:27:15 +00:00
|
|
|
where onReply (SocksAddrIPV4 h, p) = (h, p)
|
|
|
|
onReply _ = error "ipv4 requested, got something different"
|
2013-03-01 03:43:26 +00:00
|
|
|
|
2013-09-22 05:27:15 +00:00
|
|
|
-connectIPV6 :: Socket -> HostAddress6 -> PortNumber -> IO (HostAddress6, PortNumber)
|
|
|
|
-connectIPV6 socket hostaddr6 port = onReply <$> rpc_ socket (Connect $ SocksAddress (SocksAddrIPV6 hostaddr6) port)
|
|
|
|
- where onReply (SocksAddrIPV6 h, p) = (h, p)
|
|
|
|
- onReply _ = error "ipv6 requested, got something different"
|
2013-03-01 03:43:26 +00:00
|
|
|
-
|
|
|
|
-- TODO: FQDN should only be ascii, maybe putting a "fqdn" data type
|
|
|
|
-- in front to make sure and make the BC.pack safe.
|
2013-09-22 05:27:15 +00:00
|
|
|
connectDomainName :: Socket -> String -> PortNumber -> IO (SocksHostAddress, PortNumber)
|
|
|
|
diff --git a/Network/Socks5/Conf.hs b/Network/Socks5/Conf.hs
|
|
|
|
index c29ff7b..007d382 100644
|
|
|
|
--- a/Network/Socks5/Conf.hs
|
|
|
|
+++ b/Network/Socks5/Conf.hs
|
|
|
|
@@ -47,5 +47,4 @@ defaultSocksConfFromSockAddr sockaddr = SocksConf server SocksVer5
|
|
|
|
where server = SocksAddress haddr port
|
|
|
|
(haddr,port) = case sockaddr of
|
|
|
|
SockAddrInet p h -> (SocksAddrIPV4 h, p)
|
|
|
|
- SockAddrInet6 p _ h _ -> (SocksAddrIPV6 h, p)
|
|
|
|
_ -> error "unsupported unix sockaddr type"
|
|
|
|
diff --git a/Network/Socks5/Lowlevel.hs b/Network/Socks5/Lowlevel.hs
|
|
|
|
index c10d9b9..2c3d59c 100644
|
|
|
|
--- a/Network/Socks5/Lowlevel.hs
|
|
|
|
+++ b/Network/Socks5/Lowlevel.hs
|
|
|
|
@@ -17,7 +17,6 @@ resolveToSockAddr :: SocksAddress -> IO SockAddr
|
|
|
|
resolveToSockAddr (SocksAddress sockHostAddr port) =
|
|
|
|
case sockHostAddr of
|
|
|
|
SocksAddrIPV4 ha -> return $ SockAddrInet port ha
|
|
|
|
- SocksAddrIPV6 ha6 -> return $ SockAddrInet6 port 0 ha6 0
|
|
|
|
SocksAddrDomainName bs -> do he <- getHostByName (BC.unpack bs)
|
|
|
|
return $ SockAddrInet port (hostAddress he)
|
|
|
|
|
2013-03-01 03:43:26 +00:00
|
|
|
diff --git a/Network/Socks5/Types.hs b/Network/Socks5/Types.hs
|
2013-09-22 05:27:15 +00:00
|
|
|
index 7fbec25..17c7c83 100644
|
2013-03-01 03:43:26 +00:00
|
|
|
--- a/Network/Socks5/Types.hs
|
|
|
|
+++ b/Network/Socks5/Types.hs
|
2013-09-22 05:27:15 +00:00
|
|
|
@@ -19,7 +19,7 @@ module Network.Socks5.Types
|
2013-03-01 03:43:26 +00:00
|
|
|
import Data.ByteString (ByteString)
|
|
|
|
import Data.Word
|
|
|
|
import Data.Data
|
2013-09-22 05:27:15 +00:00
|
|
|
-import Network.Socket (HostAddress, HostAddress6, PortNumber)
|
|
|
|
+import Network.Socket (HostAddress, PortNumber)
|
2013-03-01 03:43:26 +00:00
|
|
|
import Control.Exception
|
2013-09-22 05:27:15 +00:00
|
|
|
import qualified Data.ByteString.Char8 as BC
|
|
|
|
import Numeric (showHex)
|
|
|
|
@@ -53,12 +53,10 @@ data SocksMethod =
|
|
|
|
data SocksHostAddress =
|
|
|
|
SocksAddrIPV4 !HostAddress
|
|
|
|
| SocksAddrDomainName !ByteString
|
|
|
|
- | SocksAddrIPV6 !HostAddress6
|
|
|
|
deriving (Eq,Ord)
|
2013-03-01 03:43:26 +00:00
|
|
|
|
2013-09-22 05:27:15 +00:00
|
|
|
instance Show SocksHostAddress where
|
|
|
|
show (SocksAddrIPV4 ha) = "SocksAddrIPV4(" ++ showHostAddress ha ++ ")"
|
|
|
|
- show (SocksAddrIPV6 ha6) = "SocksAddrIPV6(" ++ showHostAddress6 ha6 ++ ")"
|
|
|
|
show (SocksAddrDomainName dn) = "SocksAddrDomainName(" ++ BC.unpack dn ++ ")"
|
2013-03-01 03:43:26 +00:00
|
|
|
|
2013-09-22 05:27:15 +00:00
|
|
|
-- | Converts a HostAddress to a String in dot-decimal notation
|
|
|
|
@@ -69,20 +67,6 @@ showHostAddress num = concat [show q1, ".", show q2, ".", show q3, ".", show q4]
|
|
|
|
(num''',q3) = num'' `quotRem` 256
|
|
|
|
(_,q4) = num''' `quotRem` 256
|
|
|
|
|
|
|
|
--- | Converts a IPv6 HostAddress6 to standard hex notation
|
|
|
|
-showHostAddress6 :: HostAddress6 -> String
|
|
|
|
-showHostAddress6 (a,b,c,d) =
|
|
|
|
- (concat . intersperse ":" . map (flip showHex ""))
|
|
|
|
- [p1,p2,p3,p4,p5,p6,p7,p8]
|
|
|
|
- where (a',p2) = a `quotRem` 65536
|
|
|
|
- (_,p1) = a' `quotRem` 65536
|
|
|
|
- (b',p4) = b `quotRem` 65536
|
|
|
|
- (_,p3) = b' `quotRem` 65536
|
|
|
|
- (c',p6) = c `quotRem` 65536
|
|
|
|
- (_,p5) = c' `quotRem` 65536
|
|
|
|
- (d',p8) = d `quotRem` 65536
|
|
|
|
- (_,p7) = d' `quotRem` 65536
|
|
|
|
-
|
|
|
|
-- | Describe a Socket address on the SOCKS protocol
|
|
|
|
data SocksAddress = SocksAddress !SocksHostAddress !PortNumber
|
|
|
|
deriving (Show,Eq,Ord)
|
2013-03-01 03:43:26 +00:00
|
|
|
diff --git a/Network/Socks5/Wire.hs b/Network/Socks5/Wire.hs
|
2013-11-11 04:03:24 +00:00
|
|
|
index 10bd262..a30f32e 100644
|
2013-03-01 03:43:26 +00:00
|
|
|
--- a/Network/Socks5/Wire.hs
|
|
|
|
+++ b/Network/Socks5/Wire.hs
|
2013-09-22 05:27:15 +00:00
|
|
|
@@ -46,12 +46,10 @@ data SocksResponse = SocksResponse
|
2013-03-01 03:43:26 +00:00
|
|
|
|
2013-11-11 04:03:24 +00:00
|
|
|
getAddr 1 = SocksAddrIPV4 <$> getWord32host
|
2013-03-01 03:43:26 +00:00
|
|
|
getAddr 3 = SocksAddrDomainName <$> (getWord8 >>= getByteString . fromIntegral)
|
2013-11-11 04:03:24 +00:00
|
|
|
-getAddr 4 = SocksAddrIPV6 <$> (liftM4 (,,,) getWord32host getWord32host getWord32host getWord32host)
|
2013-03-01 03:43:26 +00:00
|
|
|
getAddr n = error ("cannot get unknown socket address type: " ++ show n)
|
|
|
|
|
|
|
|
putAddr (SocksAddrIPV4 h) = putWord8 1 >> putWord32host h
|
|
|
|
putAddr (SocksAddrDomainName b) = putWord8 3 >> putWord8 (fromIntegral $ B.length b) >> putByteString b
|
|
|
|
-putAddr (SocksAddrIPV6 (a,b,c,d)) = putWord8 4 >> mapM_ putWord32host [a,b,c,d]
|
|
|
|
|
|
|
|
getSocksRequest 5 = do
|
2013-09-22 05:27:15 +00:00
|
|
|
cmd <- toEnum . fromIntegral <$> getWord8
|
2013-03-01 03:43:26 +00:00
|
|
|
--
|
|
|
|
1.7.10.4
|
|
|
|
|