packages feed

tls-session-manager 0.0.1.0 → 0.0.2.0

raw patch · 3 files changed

+68/−15 lines, 3 filesdep +basementdep +bytestringdep +memoryPVP ok

version bump matches the API change (PVP)

Dependencies added: basement, bytestring, memory

API changes (from Hackage documentation)

+ Network.TLS.SessionManager: instance GHC.Classes.Eq Network.TLS.SessionManager.SessionDataCopy
+ Network.TLS.SessionManager: instance GHC.Show.Show Network.TLS.SessionManager.SessionDataCopy

Files

ChangeLog.md view
@@ -1,2 +1,11 @@+# 0.1.0.0++- Using ShortByteString internally to avoid ByteString's fragmentation.+- The default value of dbMaxSize is now 1,000.++# 0.0.1.0++- Supporting sessionResumeOnlyOnce.+ # 0.0.0.0 - A first release.
Network/TLS/SessionManager.hs view
@@ -14,12 +14,15 @@   , newSessionManager   ) where +import Basement.Block (Block)+import Data.ByteArray (convert) import Control.Exception (assert) import Control.Reaper+import Data.ByteString (ByteString) import Data.IORef import Data.OrdPSQ (OrdPSQ) import qualified Data.OrdPSQ as Q-import Network.TLS (SessionID, SessionData, SessionManager(..))+import Network.TLS import qualified System.Clock as C  import Network.TLS.Imports@@ -36,20 +39,52 @@     , dbMaxSize      :: !Int     } --- | Lifetime: 1 day , delay: 10 minutes, limit: 10,000 entries.+-- | Lifetime: 1 day , delay: 10 minutes, max size: 1000 entries. defaultConfig :: Config defaultConfig = Config {       ticketLifetime = 86400     , pruningDelay   = 6000-    , dbMaxSize      = 10000+    , dbMaxSize      = 1000     }  ---------------------------------------------------------------- +toKey :: ByteString -> Block Word8+toKey = convert++toValue :: SessionData -> SessionDataCopy+toValue (SessionData v cid comp msni sec mg mti malpn siz) =+    SessionDataCopy v cid comp msni sec' mg mti malpn' siz+  where+    !sec' = convert sec+    !malpn' = convert <$> malpn++fromValue :: SessionDataCopy -> SessionData+fromValue (SessionDataCopy v cid comp msni sec' mg mti malpn' siz) =+    (SessionData v cid comp msni sec mg mti malpn siz)+  where+    !sec = convert sec'+    !malpn = convert <$> malpn'++----------------------------------------------------------------++type SessionIDCopy = Block Word8+data SessionDataCopy = SessionDataCopy {+      ssVersion     :: !Version+    , ssCipher      :: !CipherID+    , ssCompression :: !CompressionID+    , ssClientSNI   :: !(Maybe HostName)+    , ssSecret      :: Block Word8+    , ssGroup       :: !(Maybe Group)+    , ssTicketInfo  :: !(Maybe TLS13TicketInfo)+    , ssALPN        :: !(Maybe (Block Word8))+    , ssMaxEarlyDataSize :: Int+    } deriving (Show,Eq)+ type Sec = Int64-type Value = (SessionData, IORef Availability)-type DB = OrdPSQ SessionID Sec Value-type Item = (SessionID, Sec, Value, Operation)+type Value = (SessionDataCopy, IORef Availability)+type DB = OrdPSQ SessionIDCopy Sec Value+type Item = (SessionIDCopy, Sec, Value, Operation)  data Operation = Add | Del data Use = SingleUse | MultipleUse@@ -108,30 +143,36 @@ establish reaper lifetime k sd = do     ref <- newIORef Fresh     !p <- ((+ lifetime) . C.sec) <$> C.getTime C.Monotonic-    let !v = (sd,ref)-    reaperAdd reaper (k,p,v,Add)+    let !v = (sd',ref)+    reaperAdd reaper (k',p,v,Add)+  where+    !k' = toKey k+    !sd' = toValue sd  resume :: Reaper DB Item -> Use        -> SessionID -> IO (Maybe SessionData) resume reaper use k = do     db <- reaperRead reaper-    case Q.lookup k db of+    case Q.lookup k' db of       Nothing             -> return Nothing       Just (p,v@(sd,ref)) -> do            case use of                SingleUse -> do                    available <- atomicModifyIORef' ref check-                   reaperAdd reaper (k,p,v,Del)-                   return $ if available then Just sd else Nothing-               MultipleUse -> return $ Just sd+                   reaperAdd reaper (k',p,v,Del)+                   return $ if available then Just (fromValue sd) else Nothing+               MultipleUse -> return $ Just (fromValue sd)   where     check Fresh = (Used,True)     check Used  = (Used,False)+    !k' = toKey k  invalidate :: Reaper DB Item            -> SessionID -> IO () invalidate reaper k = do     db <- reaperRead reaper-    case Q.lookup k db of+    case Q.lookup k' db of       Nothing    -> return ()-      Just (p,v) -> reaperAdd reaper (k,p,v,Del)+      Just (p,v) -> reaperAdd reaper (k',p,v,Del)+  where+    !k' = toKey k
tls-session-manager.cabal view
@@ -1,5 +1,5 @@ name:                tls-session-manager-version:             0.0.1.0+version:             0.0.2.0 synopsis:            In-memory TLS session manager description:         TLS session manager with limitation, automatic pruning, energy saving and replay resistance license:             BSD3@@ -18,7 +18,10 @@   -- other-extensions:   build-depends:       base >= 4.7 && < 5                      , auto-update+                     , basement+                     , bytestring                      , clock+                     , memory                      , psqueues >= 0.2.3                      , tls   -- hs-source-dirs: