maj sock5
This commit is contained in:
parent
ae4198fd56
commit
e6950ea526
1 changed files with 36 additions and 1 deletions
|
@ -9,7 +9,8 @@ module Socks5 where
|
||||||
|
|
||||||
|
|
||||||
import ClassyPrelude
|
import ClassyPrelude
|
||||||
import qualified Data.Binary.Get as Bin
|
import Data.Binary
|
||||||
|
import Data.Binary.Get
|
||||||
import Network.Socket (HostName, PortNumber)
|
import Network.Socket (HostName, PortNumber)
|
||||||
|
|
||||||
data AuthMethod = NoAuth
|
data AuthMethod = NoAuth
|
||||||
|
@ -24,6 +25,40 @@ data RequestAuth = RequestAuth
|
||||||
, methods :: Vector AuthMethod
|
, methods :: Vector AuthMethod
|
||||||
} deriving (Show, Read)
|
} deriving (Show, Read)
|
||||||
|
|
||||||
|
instance Binary AuthMethod where
|
||||||
|
put val = case val of
|
||||||
|
NoAuth -> putWord8 0x00
|
||||||
|
GSSAPI -> putWord8 0x01
|
||||||
|
Login -> putWord8 0x02
|
||||||
|
NotAllowed -> putWord8 0xFF
|
||||||
|
_ {- Reserverd -} -> putWord8 0x03
|
||||||
|
|
||||||
|
get = do
|
||||||
|
method <- getWord8
|
||||||
|
return $ case method of
|
||||||
|
0x00 -> NoAuth
|
||||||
|
0x01 -> GSSAPI
|
||||||
|
0x02 -> Login
|
||||||
|
0xFF -> NotAllowed
|
||||||
|
_ -> Reserved
|
||||||
|
|
||||||
|
|
||||||
|
instance Binary RequestAuth where
|
||||||
|
put RequestAuth{..} = do
|
||||||
|
putWord8 (fromIntegral version)
|
||||||
|
putWord8 (fromIntegral $ length methods)
|
||||||
|
sequence_ ( put <$> methods)
|
||||||
|
|
||||||
|
get = do
|
||||||
|
version <- fromIntegral <$> getWord8
|
||||||
|
guard (version == 0x05)
|
||||||
|
nbMethods <- fromIntegral <$> getWord8
|
||||||
|
guard (version <= 0xFF)
|
||||||
|
methods <- replicateM nbMethods get
|
||||||
|
return $ RequestAuth version methods
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data Request = Request
|
data Request = Request
|
||||||
{ version :: Int
|
{ version :: Int
|
||||||
|
|
Loading…
Reference in a new issue