snmp 0.1.0.2 → 0.1.0.3
raw patch · 5 files changed
+25/−24 lines, 5 filesdep ~base
Dependency ranges changed: base
Files
- snmp.cabal +2/−2
- src/Network/Protocol/Snmp.hs +13/−15
- src/Network/Snmp/Client.hs +1/−1
- src/Network/Snmp/Client/Version2.hs +2/−1
- src/Network/Snmp/Client/Version3.hs +7/−5
snmp.cabal view
@@ -1,5 +1,5 @@ name: snmp-version: 0.1.0.2+version: 0.1.0.3 synopsis: API for write snmp client. description: API for write snmp client. license: BSD3@@ -20,7 +20,7 @@ exposed-modules: Network.Protocol.Snmp, Network.Snmp.Client, Network.Snmp.Example other-modules: Network.Snmp.Client.Internal, Network.Snmp.Client.Types, Network.Snmp.Client.Version2, Network.Snmp.Client.Version3 -- other-extensions: - build-depends: base >=4.6 && <4.8, + build-depends: base >=4.6 && <4.9, asn1-encoding, asn1-types, asn1-parse,
src/Network/Protocol/Snmp.hs view
@@ -44,8 +44,6 @@ -- *** PDU snmpV3 , ContextEngineID(..) , ContextName(..)--- * pack, unpack Packet-, Pack(..) -- * some classes and helpers -- *** universal, for work with both versions , HasItem(..)@@ -113,7 +111,6 @@ import Data.ByteString (ByteString) import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL-import Data.Word (Word8, Word32, Word64) #if MIN_VERSION_base(4,7,0) import Data.Bits (testBit, complement, shiftL, (.|.), (.&.), setBit, shiftR, zeroBits, xor, clearBit) #else@@ -134,6 +131,9 @@ import qualified Crypto.Cipher.DES as Priv import qualified Crypto.Cipher.AES as Priv import Data.Int+import Data.Binary+import Data.Binary.Get+import Data.Binary.Put -- $example --@@ -310,11 +310,6 @@ | ServerException Integer deriving (Typeable, Eq) --- | class for make binary packet from [ASN1] -class Pack a where- encode :: a -> ByteString- decode :: ByteString -> a- -- | some universal getters, setters class HasItem a where getHeader :: Packet -> Header a@@ -805,9 +800,11 @@ End Sequence <- getNext return $ SecurityParameter msgAuthoritiveEngineId (fromIntegral msgAuthoritiveEngineBoots) (fromIntegral msgAuthoritiveEngineTime) msgUserName msgAuthenticationParameters msgPrivacyParameters -instance Pack (PDU V3) where- encode s = encodeASN1' DER $ toASN1 s []- decode = toP+instance Binary (PDU V3) where+ put = putByteString . encodeASN1' DER . flip toASN1 [] + get = toP . BL.toStrict <$> getRemainingLazyByteString+-- encode s = encodeASN1' DER $ toASN1 s []+-- decode = toP toP :: ByteString -> PDU V3 toP bs = let a = fromASN1 <$> decodeASN1' DER bs@@ -815,9 +812,10 @@ Right (Right (r, _)) -> r _ -> throw $ ServerException 9 -instance Pack Packet where- encode s = encodeASN1' DER $ toASN1 s []- decode = toB +instance Binary Packet where+ put = putByteString . encodeASN1' DER . flip toASN1 []+-- encode s = encodeASN1' DER $ toASN1 s []+ get = toB . BL.toStrict <$> getRemainingLazyByteString toB :: ByteString -> Packet toB bs = let a = fromASN1 <$> decodeASN1' DER bs@@ -949,7 +947,7 @@ -- | (only V3) sign Packet signPacket :: AuthType -> Key -> Packet -> Packet signPacket at key packet = - let packetAsBin = encode packet+ let packetAsBin = BL.toStrict $ encode packet sign = B.take 12 $ HMAC.hmac (hash at) 64 key packetAsBin in setAuthenticationParametersP sign packet
src/Network/Snmp/Client.hs view
@@ -26,7 +26,7 @@ , bulkwalk , set , close--- * usefull functions+-- * useful functions , oidFromBS ) where
src/Network/Snmp/Client/Version2.hs view
@@ -5,7 +5,7 @@ import Network.Socket hiding (recv, socket, close) import qualified Network.Socket as NS-import Network.Socket.ByteString (recv, sendAll)+import Network.Socket.ByteString.Lazy (recv, sendAll) import Control.Applicative ((<$>)) import Control.Concurrent.Async import Data.IORef (newIORef)@@ -13,6 +13,7 @@ import Control.Exception import Control.Monad (when) import Data.Monoid ((<>), mconcat, mempty)+import Data.Binary hiding (get) import Network.Protocol.Snmp hiding (rid) import Network.Snmp.Client.Internal
src/Network/Snmp/Client/Version3.hs view
@@ -9,9 +9,10 @@ where import Data.ByteString (ByteString)+import Data.ByteString.Lazy (toStrict, fromStrict) import Network.Socket hiding (recv, socket, close) import qualified Network.Socket as NS-import Network.Socket.ByteString (recv, sendAll)+import Network.Socket.ByteString.Lazy (recv, sendAll) import Control.Applicative ((<$>)) import Control.Concurrent.Async import Data.IORef (newIORef, IORef, readIORef, atomicWriteIORef)@@ -22,6 +23,7 @@ import Data.Int import Control.Exception import System.Random (randomIO)+import Data.Binary import Network.Protocol.Snmp import Network.Snmp.Client.Types@@ -232,13 +234,13 @@ | privType' st == DES = do s <- succCounter (salt32 st) let eib = getEngineBootsP packet'- (encrypted, salt) = desEncrypt key eib s (encode $ (getPDU packet' :: PDU V3))+ (encrypted, salt) = desEncrypt key eib s (toStrict $ encode $ (getPDU packet' :: PDU V3)) return $ setPrivParametersP salt . setPDU (CryptedPDU encrypted) $ packet' | privType' st == AES = do s <- succCounter (salt64 st) let eib = getEngineBootsP packet' t = getEngineTimeP packet'- (encrypted, salt) = aesEncrypt key eib t s (encode $ (getPDU packet' :: PDU V3))+ (encrypted, salt) = aesEncrypt key eib t s (toStrict $ encode $ (getPDU packet' :: PDU V3)) return $ setPrivParametersP salt . setPDU (CryptedPDU encrypted) $ packet' | otherwise = throwIO $ ServerException 5 @@ -248,7 +250,7 @@ let pdu = getPDU packet' :: PDU V3 salt = getPrivParametersP packet' in case pdu of- CryptedPDU x -> setPDU (decode (desDecrypt key salt x) :: PDU V3) packet'+ CryptedPDU x -> setPDU (decode (fromStrict $ desDecrypt key salt x) :: PDU V3) packet' _ -> packet' | privType' st == AES = let pdu = getPDU packet' :: PDU V3@@ -256,7 +258,7 @@ eib = getEngineBootsP packet' t = getEngineTimeP packet' in case pdu of- CryptedPDU x -> setPDU (decode (aesDecrypt key salt eib t x) :: PDU V3) packet'+ CryptedPDU x -> setPDU (decode (fromStrict $ aesDecrypt key salt eib t x) :: PDU V3) packet' _ -> packet' | otherwise = throw $ ServerException 5