summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaneshSittampalam <>2015-10-06 20:38:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2015-10-06 20:38:00 (GMT)
commit9df18b5c159c4122d94152749fec9729cd54ecf8 (patch)
treecadb30d06ec8b72b77fd7faba085b7925b6efb16
parentf8074eff703f736f3de27927950967f8fac74e70 (diff)
version 0.3.2HEAD0.3.2master
-rw-r--r--src/SSH.hs32
-rw-r--r--src/SSH/Channel.hs18
-rw-r--r--src/SSH/Crypto.hs29
-rw-r--r--src/SSH/Debug.hs2
-rw-r--r--src/SSH/NetReader.hs8
-rw-r--r--src/SSH/Sender.hs16
-rw-r--r--src/SSH/Session.hs24
-rw-r--r--src/SSH/Util.hs5
-rw-r--r--ssh.cabal9
-rw-r--r--test/keys/client/id_dsa212
-rw-r--r--test/keys/client/id_dsa2.pub1
-rw-r--r--test/keys/host.pub1
12 files changed, 77 insertions, 80 deletions
diff --git a/src/SSH.hs b/src/SSH.hs
index 1614632..322b7eb 100644
--- a/src/SSH.hs
+++ b/src/SSH.hs
@@ -1,31 +1,37 @@
module SSH where
import Control.Concurrent (forkIO)
-import Control.Concurrent.Chan
+import Control.Concurrent.Chan (newChan, writeChan)
import Control.Exception (bracket)
import Control.Monad (replicateM)
-import Control.Monad.Trans.State
+import Control.Monad.Trans.State (evalStateT, get, gets, modify)
import Data.Digest.Pure.SHA (bytestringDigest, sha1)
-import Crypto.HMAC
-import Crypto.Hash.CryptoAPI
+import Crypto.HMAC (hmac, MacKey(MacKey))
+import Crypto.Hash.CryptoAPI (SHA1, MD5)
import Data.List (intercalate)
import Data.List.Split (splitOn)
-import Network
+import Network (PortID(..), PortNumber, withSocketsDo, listenOn, sClose, Socket, accept)
import OpenSSL.BN (randIntegerOneToNMinusOne, modexp)
-import System.IO
-import System.Random
+import System.IO (hPutStr, hSetBinaryMode, hPutStr, hFlush, hIsEOF, hGetLine)
+import System.Random (randomRIO)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Map as M
import qualified Data.Serialize as S
-import SSH.Channel
+import SSH.Channel (ChannelConfig(..), ChannelRequest(..), ChannelMessage(..), newChannel)
import SSH.Crypto
-import SSH.Debug
-import SSH.NetReader
-import SSH.Packet
-import SSH.Sender
+ ( Cipher(..), CipherType(..), CipherMode(..), HMAC(..), KeyPair(..)
+ , sign, blob, blobToKey, verify, safePrime, generator
+ )
+import SSH.Debug (dump)
+import SSH.NetReader (readByte, readBytes, readLBS, readULong, readInteger, readBool, readString)
+import SSH.Packet (Packet, io, byte, raw, string, long, integer, byteString, doPacket, makeKey)
+import SSH.Sender (SenderState(..), Sender(..), SenderMessage(..), sender)
import SSH.Session
-import SSH.Util
+ ( SessionConfig(..), SessionState(..), Session, Authorize(..)
+ , getPacket, net, getChannel, newChannelID
+ )
+import SSH.Util (strictLBS, fromLBS)
version :: String
diff --git a/src/SSH/Channel.hs b/src/SSH/Channel.hs
index bf14f5d..9e425e9 100644
--- a/src/SSH/Channel.hs
+++ b/src/SSH/Channel.hs
@@ -1,20 +1,20 @@
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
module SSH.Channel where
-import Control.Concurrent
-import Control.Exception
+import Control.Concurrent (ThreadId, Chan, newChan, readChan, writeChan, forkIO, killThread)
+import Control.Exception (catch, IOException)
import Control.Monad (when)
-import Control.Monad.Trans.State
-import Data.Word
-import System.Exit
-import System.IO
+import Control.Monad.Trans.State (StateT, evalStateT, get, gets, modify)
+import Data.Word (Word32)
+import System.Exit (ExitCode(..))
+import System.IO (Handle, hFlush, hClose, hIsEOF, hGetChar, hReady, hSetBinaryMode)
import System.Process (ProcessHandle, runInteractiveCommand,
terminateProcess, waitForProcess,)
import qualified Data.ByteString.Lazy as LBS
-import SSH.Debug
-import SSH.Packet
-import SSH.Sender
+import SSH.Debug (dump)
+import SSH.Packet (io, long, byte, string, Packet, packetLength)
+import SSH.Sender (Sender(..), SenderMessage)
type Channel = StateT ChannelState IO
diff --git a/src/SSH/Crypto.hs b/src/SSH/Crypto.hs
index 9ef3c4e..69b8391 100644
--- a/src/SSH/Crypto.hs
+++ b/src/SSH/Crypto.hs
@@ -1,23 +1,23 @@
module SSH.Crypto where
import Control.Monad (replicateM)
-import Control.Monad.Trans.State
+import Control.Monad.Trans.State (evalState)
import Data.ASN1.BinaryEncoding (BER(..), DER(..))
import Data.ASN1.Encoding (decodeASN1, encodeASN1)
-import Data.ASN1.Stream
-import Data.ASN1.Types
+import Data.ASN1.Stream (getConstructedEnd)
+import Data.ASN1.Types (ASN1(..), ASN1ConstructionType(..))
import Data.Digest.Pure.SHA (bytestringDigest, sha1)
import Data.List (isPrefixOf)
import qualified Codec.Binary.Base64.String as B64
-import qualified Codec.Crypto.RSA as RSA
+import qualified Codec.Crypto.RSA.Pure as RSA
import qualified Data.ByteString.Lazy as LBS
import qualified OpenSSL.DSA as DSA
import qualified Crypto.Types.PubKey.RSA as RSAKey
-import SSH.Packet
-import SSH.NetReader
-import SSH.Util
+import SSH.Packet (doPacket, string, integer, netString, netLBS)
+import SSH.NetReader (readString, readInteger)
+import SSH.Util (toLBS, fromLBS, strictLBS, fromOctets, i2osp, integerLog2)
data Cipher =
Cipher
@@ -207,10 +207,12 @@ blobToKey s = flip evalState s $ do
sign :: KeyPair -> LBS.ByteString -> IO LBS.ByteString
sign (RSAKeyPair p@(RSAPublicKey e n) d _ _ _ _ _) m = do
let keyLen = rsaKeyLen p
- return $ LBS.concat
- [ netString "ssh-rsa"
- , netLBS (RSA.rsassa_pkcs1_v1_5_sign RSA.ha_SHA1 (RSAKey.PrivateKey (RSAKey.PublicKey keyLen n e) d 0 0 0 0 0) m)
- ]
+ sig = RSA.rsassa_pkcs1_v1_5_sign RSA.hashSHA1 (RSAKey.PrivateKey (RSAKey.PublicKey keyLen n e) d 0 0 0 0 0) m
+ case sig of
+ Right sigBs -> return $ LBS.concat [ netString "ssh-rsa"
+ , netLBS sigBs
+ ]
+ Left rsaErr -> error $ "Error while performing RSA signature: " ++ show rsaErr
sign (DSAKeyPair (DSAPublicKey p q g y) x) m = do
(r, s) <- DSA.signDigestedDataWithDSA (DSA.tupleToDSAKeyPair (p, q, g, y, x)) digest
return $ LBS.concat
@@ -235,7 +237,10 @@ verify :: PublicKey -> LBS.ByteString -> LBS.ByteString -> IO Bool
verify p@(RSAPublicKey e n) message signature = do
let keyLen = rsaKeyLen p
realSignature = LBS.drop (LBS.length signature - fromIntegral keyLen) signature
- return $ RSA.rsassa_pkcs1_v1_5_verify RSA.ha_SHA1 (RSAKey.PublicKey keyLen n e) message realSignature
+ sigRes = RSA.rsassa_pkcs1_v1_5_verify RSA.hashSHA1 (RSAKey.PublicKey keyLen n e) message realSignature
+ return $ case sigRes of
+ Right r -> r
+ Left _ -> False
verify (DSAPublicKey p q g y) message signature = do
let realSignature = LBS.drop (LBS.length signature - 40) signature
diff --git a/src/SSH/Debug.hs b/src/SSH/Debug.hs
index 9517658..3296535 100644
--- a/src/SSH/Debug.hs
+++ b/src/SSH/Debug.hs
@@ -1,4 +1,4 @@
-module SSH.Debug where
+module SSH.Debug (debug, debugging, dump) where
import Debug.Trace
diff --git a/src/SSH/NetReader.hs b/src/SSH/NetReader.hs
index 099880c..f536860 100644
--- a/src/SSH/NetReader.hs
+++ b/src/SSH/NetReader.hs
@@ -1,12 +1,12 @@
module SSH.NetReader where
-import Control.Monad.Trans.State
+import Control.Monad.Trans.State (State, gets, modify)
import Data.Binary (decode)
-import Data.Int
-import Data.Word
+import Data.Int (Int32)
+import Data.Word (Word8, Word32)
import qualified Data.ByteString.Lazy as LBS
-import SSH.Packet
+import SSH.Packet (unmpint)
import SSH.Util (fromLBS)
diff --git a/src/SSH/Sender.hs b/src/SSH/Sender.hs
index c806789..c437e4e 100644
--- a/src/SSH/Sender.hs
+++ b/src/SSH/Sender.hs
@@ -1,18 +1,18 @@
module SSH.Sender where
-import Control.Concurrent.Chan
+import Control.Concurrent.Chan (Chan, readChan)
import Control.Monad (replicateM)
-import Data.Word
-import System.IO
-import System.Random
+import Data.Word (Word8, Word32)
+import System.IO (Handle, hFlush)
+import System.Random (randomRIO)
import qualified Codec.Crypto.SimpleAES as A
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
-import SSH.Debug
-import SSH.Crypto
-import SSH.Packet
-import SSH.Util
+import SSH.Debug (dump)
+import SSH.Crypto (Cipher(..), HMAC(..), CipherType(..), CipherMode(..), fromBlocks, toBlocks)
+import SSH.Packet (Packet, doPacket, raw, byte, long)
+import SSH.Util (strictLBS)
data SenderState
diff --git a/src/SSH/Session.hs b/src/SSH/Session.hs
index f5aa044..61ab336 100644
--- a/src/SSH/Session.hs
+++ b/src/SSH/Session.hs
@@ -1,24 +1,24 @@
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
module SSH.Session where
-import Control.Concurrent.Chan
-import Control.Monad.IO.Class
-import Control.Monad.Trans.State
+import Control.Concurrent.Chan (Chan)
+import Control.Monad.IO.Class (liftIO)
+import Control.Monad.Trans.State (StateT, get, gets, modify, runState)
import Data.Binary (decode, encode)
-import Data.Word
-import System.IO
+import Data.Word (Word8, Word32)
+import System.IO (Handle)
import qualified Codec.Crypto.SimpleAES as A
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Map as M
-import SSH.Channel
-import SSH.Crypto hiding (verify)
-import SSH.Debug
-import SSH.NetReader
-import SSH.Packet
-import SSH.Sender
-import SSH.Util
+import SSH.Channel (ChannelConfig, ChannelMessage)
+import SSH.Crypto (Cipher(..), HMAC(..), KeyPair(..), PublicKey(..), CipherType(..), CipherMode(..), toBlocks)
+import SSH.Debug (dump)
+import SSH.NetReader (NetReader)
+import SSH.Packet (io)
+import SSH.Sender (Sender(..), SenderMessage)
+import SSH.Util (strictLBS)
type Session = StateT SessionState IO
diff --git a/src/SSH/Util.hs b/src/SSH/Util.hs
index 24364de..6682863 100644
--- a/src/SSH/Util.hs
+++ b/src/SSH/Util.hs
@@ -1,5 +1,8 @@
{-# LANGUAGE MagicHash #-}
-module SSH.Util where
+module SSH.Util
+ ( toLBS, fromLBS, strictLBS
+ , integerLog2, toOctets, fromOctets, i2osp
+ ) where
import Data.Word (Word8)
import qualified Data.ByteString as BS
diff --git a/ssh.cabal b/ssh.cabal
index 77e62b3..d2aaca6 100644
--- a/ssh.cabal
+++ b/ssh.cabal
@@ -1,5 +1,5 @@
name: ssh
-version: 0.3.1
+version: 0.3.2
synopsis: A pure-Haskell SSH server library.
description:
This a library for implementing your own servers that handle SSH
@@ -20,7 +20,6 @@ tested-with: GHC==7.8.2
extra-source-files: CHANGES,
README,
test/keys/host,
- test/keys/host.pub,
test/keys/client/id_rsa_test,
test/keys/client/id_rsa_test.pub,
test/keys/client/id_rsa_test2,
@@ -32,9 +31,7 @@ extra-source-files: CHANGES,
test/keys/client/id_rsa_4096,
test/keys/client/id_rsa_4096.pub,
test/keys/client/id_dsa,
- test/keys/client/id_dsa.pub,
- test/keys/client/id_dsa2,
- test/keys/client/id_dsa2.pub
+ test/keys/client/id_dsa.pub
source-repository head
@@ -71,7 +68,7 @@ library
integer-gmp >= 0.5 && < 1.1,
network,
process,
- RSA >= 1.2 && < 1.3,
+ RSA >= 2.1.0 && < 2.1.1,
random,
SHA,
SimpleAES,
diff --git a/test/keys/client/id_dsa2 b/test/keys/client/id_dsa2
deleted file mode 100644
index 937a218..0000000
--- a/test/keys/client/id_dsa2
+++ /dev/null
@@ -1,12 +0,0 @@
------BEGIN DSA PRIVATE KEY-----
-MIIBuwIBAAKBgQD3ncQcimGZGV5mMZxfYRpfMcwUhMXbW7jUuWLDvfMXm9dpfw4H
-nKeXP7LtDSjzUQreXA6lf20wh3/dxsKNFAbqPwgDuOxZD5JXPahMaoNqOg+/V5DD
-qhTjJrxGzsMCWstYV1nsCQMN4aVlZLqJ4dhiVwwRIkCbPXFmhuJYxhL8aQIVAO9L
-HPk1IGpMSi2gcGqKS754Kr+JAoGAfWTPY44qm5T+z6Tn7EwVaak5wj4XwrzvfGKY
-ay/LKyPGn9m8Y+YfJ2zv1QQyTXmNC1wjpKI8ZL6ff8d0ft1RO6+HsFvoCSHDWPKR
-x5ZopfUg/pDeiVwwU83IhSmPUECz/+8jGZ+rKrQdLc3bc1GhyfvcsAWL5PBwzqDs
-z4X4WTUCgYAPrLJresqVe+jDHRIzvW5WhyYgyjN2PMHYxV/J7i54pM4Qj/zHPiK3
-TpeuaCLgih2DQbtJrn+4KfIbv+/v2AsHGcj/kZEGvS1+t+pX98zo10gdsSAVoOig
-nAp4Rt18vFbSc+0xQgj0NFrWvSrU6bszSVD1fYGkpdzbg+WSwscMsQIVALC8wPU1
-fTf6hMJojbMUTbOZWMRM
------END DSA PRIVATE KEY-----
diff --git a/test/keys/client/id_dsa2.pub b/test/keys/client/id_dsa2.pub
deleted file mode 100644
index 052c00c..0000000
--- a/test/keys/client/id_dsa2.pub
+++ /dev/null
@@ -1 +0,0 @@
-ssh-dss AAAAB3NzaC1kc3MAAACBAPedxByKYZkZXmYxnF9hGl8xzBSExdtbuNS5YsO98xeb12l/Dgecp5c/su0NKPNRCt5cDqV/bTCHf93Gwo0UBuo/CAO47FkPklc9qExqg2o6D79XkMOqFOMmvEbOwwJay1hXWewJAw3hpWVkuonh2GJXDBEiQJs9cWaG4ljGEvxpAAAAFQDvSxz5NSBqTEotoHBqiku+eCq/iQAAAIB9ZM9jjiqblP7PpOfsTBVpqTnCPhfCvO98YphrL8srI8af2bxj5h8nbO/VBDJNeY0LXCOkojxkvp9/x3R+3VE7r4ewW+gJIcNY8pHHlmil9SD+kN6JXDBTzciFKY9QQLP/7yMZn6sqtB0tzdtzUaHJ+9ywBYvk8HDOoOzPhfhZNQAAAIAPrLJresqVe+jDHRIzvW5WhyYgyjN2PMHYxV/J7i54pM4Qj/zHPiK3TpeuaCLgih2DQbtJrn+4KfIbv+/v2AsHGcj/kZEGvS1+t+pX98zo10gdsSAVoOignAp4Rt18vFbSc+0xQgj0NFrWvSrU6bszSVD1fYGkpdzbg+WSwscMsQ== ganesh@paxton
diff --git a/test/keys/host.pub b/test/keys/host.pub
deleted file mode 100644
index 9283b31..0000000
--- a/test/keys/host.pub
+++ /dev/null
@@ -1 +0,0 @@
-ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzNP/nr/FCVvTwv5Z0m/ThcDFXcsWo2TvccYJ3Yw66XpDlKIMtP6zZ+KwrY8Vih3BEPXIh3nmi7LfEJU2SPUV1itfgVred10+3yrOHCsouGahZUSjh7n2SPPyrmqEIU4ey1iwe0oc0rW98mJlpiUi4b39eYFkdMtWbO/CSGfSdcq2EwVKrmHwwu+M/TT8RjjfyW5jGSXqtqjk7sko4Wcz8DX+jOfGFilt3/NCd3I7vPkByE704MY0L6FsQKQgLxzZXpdskKF+iUdNR7pbPzT0R2/LPBcIjldT9aTevo/qlVrUD+q4nqWDfduJz8VtlTEyFUmDG1ZQeL+Cg43lSI9zP ganesh@paxton