quic 0.1.13 → 0.1.14
raw patch · 3 files changed
+44/−32 lines, 3 filesdep ~crypto-tokenPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: crypto-token
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- Network/QUIC/Packet/Token.hs +38/−30
- quic.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.1.14++- Using crypto-token v0.1+ ## 0.1.13 - Garding the path_request attack.
Network/QUIC/Packet/Token.hs view
@@ -7,11 +7,10 @@ decryptToken, ) where +import qualified UnliftIO.Exception as E import qualified Crypto.Token as CT import Data.UnixTime import Foreign.C.Types-import Foreign.Ptr-import Foreign.Storable import Network.ByteOrder import Network.QUIC.Imports@@ -43,42 +42,23 @@ ---------------------------------------------------------------- encryptToken :: CT.TokenManager -> CryptoToken -> IO Token-encryptToken = CT.encryptToken+encryptToken mgr ct = encodeCryptoToken ct >>= CT.encryptToken mgr decryptToken :: CT.TokenManager -> Token -> IO (Maybe CryptoToken)-decryptToken = CT.decryptToken+decryptToken mgr token = do+ mx <- CT.decryptToken mgr token+ case mx of+ Nothing -> return Nothing+ Just x -> decodeCryptoToken x ---------------------------------------------------------------- cryptoTokenSize :: Int cryptoTokenSize = 76 -- 4 + 8 + 1 + (1 + 20) * 3 --- length includes its field-instance Storable CryptoToken where- sizeOf ~_ = cryptoTokenSize- alignment ~_ = 4- peek ptr = do- rbuf <- newReadBuffer (castPtr ptr) cryptoTokenSize- ver <- Version <$> read32 rbuf- s <- CTime . fromIntegral <$> read64 rbuf- let tim = UnixTime s 0- typ <- read8 rbuf- case typ of- 0 -> return $ CryptoToken ver tim Nothing- _ -> do- l <- pick rbuf- r <- pick rbuf- o <- pick rbuf- return $ CryptoToken ver tim $ Just (l, r, o)- where- pick rbuf = do- xlen0 <- fromIntegral <$> read8 rbuf- let xlen = min xlen0 20- x <- makeCID <$> extractShortByteString rbuf xlen- ff rbuf (20 - xlen)- return x- poke ptr (CryptoToken (Version ver) tim mcids) = do- wbuf <- newWriteBuffer (castPtr ptr) cryptoTokenSize+encodeCryptoToken :: CryptoToken -> IO Token+encodeCryptoToken (CryptoToken (Version ver) tim mcids) =+ withWriteBuffer cryptoTokenSize $ \wbuf -> do write32 wbuf ver let CTime s = utSeconds tim write64 wbuf $ fromIntegral s@@ -95,3 +75,31 @@ write8 wbuf xlen copyShortByteString wbuf xcid ff wbuf (20 - fromIntegral xlen)++decodeCryptoToken :: Token -> IO (Maybe CryptoToken)+decodeCryptoToken token = do+ ex <- E.try $ decodeCryptoToken' token+ case ex of+ Left (E.SomeException _) -> return Nothing+ Right x -> return $ Just x++decodeCryptoToken' :: ByteString -> IO CryptoToken+decodeCryptoToken' token = withReadBuffer token $ \rbuf -> do+ ver <- Version <$> read32 rbuf+ s <- CTime . fromIntegral <$> read64 rbuf+ let tim = UnixTime s 0+ typ <- read8 rbuf+ case typ of+ 0 -> return $ CryptoToken ver tim Nothing+ _ -> do+ l <- pick rbuf+ r <- pick rbuf+ o <- pick rbuf+ return $ CryptoToken ver tim $ Just (l, r, o)+ where+ pick rbuf = do+ xlen0 <- fromIntegral <$> read8 rbuf+ let xlen = min xlen0 20+ x <- makeCID <$> extractShortByteString rbuf xlen+ ff rbuf (20 - xlen)+ return x
quic.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: quic-version: 0.1.13+version: 0.1.14 license: BSD3 license-file: LICENSE maintainer: kazu@iij.ad.jp@@ -130,7 +130,7 @@ base16-bytestring >= 1.0 && < 1.1, bytestring >= 0.10 && < 0.12, containers >= 0.6 && < 0.7,- crypto-token >= 0.0.2 && < 0.1,+ crypto-token >= 0.1 && < 0.2, crypton >= 0.34 && < 0.35, memory >= 0.18.0 && < 0.19, crypton-x509 >= 1.7.6 && < 1.8,