Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
13 Network/TLS/Context.hs
View
@@ -56,7 +56,7 @@ import qualified Data.ByteString as B
import Control.Concurrent.MVar
import Control.Monad.State
-import Control.Exception (throwIO, Exception(), onException)
+import Control.Exception (throwIO, Exception())
import Data.IORef
import System.IO (Handle, hSetBuffering, BufferMode(..), hFlush)
import Prelude hiding (catch)
@@ -211,13 +211,10 @@ throwCore = liftIO . throwIO
usingState :: MonadIO m => TLSCtx c -> TLSSt a -> m (Either TLSError a)
-usingState ctx f = liftIO (takeMVar mvar) >>= \st -> liftIO $ onException (execAndStore st) (putMVar mvar st)
- where
- mvar = ctxState ctx
- execAndStore st = do
- let (a, newst) = runTLSState f st
- putMVar mvar newst
- return a
+usingState ctx f =
+ liftIO $ modifyMVar (ctxState ctx) $ \st ->
+ let (a, newst) = runTLSState f st
+ in newst `seq` return (newst, a)
usingState_ :: MonadIO m => TLSCtx c -> TLSSt a -> m a
usingState_ ctx f = do
12 Network/TLS/Core.hs
View
@@ -186,7 +186,7 @@ clientWith params rng connection flushF sendF recvF =
where st = (newTLSState rng) { stClientContext = True }
-- | Create a new Client context with a configuration, a RNG, and a Handle.
--- It reconfigures the handle buffermode to noBuffering
+-- It reconfigures the handle's 'System.IO.BufferMode' to @NoBuffering@.
client :: (MonadIO m, CryptoRandomGen g)
=> TLSParams -- ^ parameters to use for this context
-> g -- ^ random number generator associated with the context
@@ -202,7 +202,7 @@ serverWith params rng connection flushF sendF recvF =
where st = (newTLSState rng) { stClientContext = False }
-- | Create a new Server context with a configuration, a RNG, and a Handle.
--- It reconfigures the handle buffermode to noBuffering
+-- It reconfigures the handle's 'System.IO.BufferMode' to @NoBuffering@.
server :: (MonadIO m, CryptoRandomGen g) => TLSParams -> g -> Handle -> m (TLSCtx Handle)
server params rng handle = liftIO $ newCtx handle params st
where st = (newTLSState rng) { stClientContext = False }
@@ -477,7 +477,7 @@ handshakeServer ctx = do
_ -> fail ("unexpected handshake received, excepting client hello and received " ++ show hss)
-- | Handshake for a new TLS connection
--- This is to be called at the beginning of a connection, and during renegociation
+-- This is to be called at the beginning of a connection, and during renegotiation
handshake :: MonadIO m => TLSCtx c -> m ()
handshake ctx = do
cc <- usingState_ ctx (stClientContext <$> get)
@@ -500,17 +500,17 @@ sendData ctx dataToSend = checkValid ctx >> mapM_ sendDataChunk (L.toChunks data
sendDataChunk remain
| otherwise = sendPacket ctx $ AppData d
--- | recvData get data out of Data packet, and automatically renegociate if
+-- | recvData get data out of Data packet, and automatically renegotiate if
-- a Handshake ClientHello is received
recvData :: MonadIO m => TLSCtx c -> m B.ByteString
recvData ctx = do
checkValid ctx
pkt <- recvPacket ctx
case pkt of
- -- on server context receiving a client hello == renegociation
+ -- on server context receiving a client hello == renegotiation
Right (Handshake [ch@(ClientHello _ _ _ _ _ _)]) ->
handshakeServerWith ctx ch >> recvData ctx
- -- on client context, receiving a hello request == renegociation
+ -- on client context, receiving a hello request == renegotiation
Right (Handshake [HelloRequest]) ->
handshakeClient ctx >> recvData ctx
Right (Alert [(AlertLevel_Fatal, _)]) -> do
2  Network/TLS/Receiving.hs
View
@@ -104,7 +104,7 @@ processServerHello (ServerHello sver ran _ _ _ ex) = do
processServerHello _ = error "processServerHello called on wrong type"
-- process the client key exchange message. the protocol expects the initial
--- client version received in ClientHello, not the negociated version.
+-- client version received in ClientHello, not the negotiated version.
-- in case the version mismatch, generate a random master secret
processClientKeyXchg :: ByteString -> TLSSt ()
processClientKeyXchg encryptedPremaster = do

No commit comments for this range

Something went wrong with that request. Please try again.