Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vincenthz/hs-tls
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthz committed Dec 4, 2016
2 parents 0770c13 + 9650cf7 commit 0f0cb19
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/Network/TLS/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Control.Monad.State
bye :: MonadIO m => Context -> m ()
bye ctx = sendPacket ctx $ Alert [(AlertLevel_Warning, CloseNotify)]

-- | If the Next Protocol Negotiation extension has been used, this will
-- | If the Next Protocol Negotiation or ALPN extensions have been used, this will
-- return get the protocol agreed upon.
getNegotiatedProtocol :: MonadIO m => Context -> m (Maybe B.ByteString)
getNegotiatedProtocol ctx = liftIO $ usingState_ ctx S.getNegotiatedProtocol
Expand Down
5 changes: 2 additions & 3 deletions core/Network/TLS/Crypto.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import qualified Crypto.PubKey.ECC.Types as ECC
import qualified Crypto.PubKey.RSA as RSA
import qualified Crypto.PubKey.RSA.PKCS15 as RSA
import Crypto.Number.Serialize (os2ip)
import Crypto.Number.Basic (numBits)

import Data.X509 (PrivKey(..), PubKey(..), PubKeyEC(..), SerializedPoint(..))
import Network.TLS.Crypto.DH
Expand Down Expand Up @@ -215,7 +214,7 @@ kxVerify (PubKeyEC key) alg msg sigBS = maybe False id $ do
Nothing -> Nothing
Just (ptFormat, input) ->
case ptFormat of
4 -> if B.length bs == 2 * bytes
4 -> if B.length input /= 2 * bytes
then Nothing
else
let (x, y) = B.splitAt bytes input
Expand All @@ -225,7 +224,7 @@ kxVerify (PubKeyEC key) alg msg sigBS = maybe False id $ do
else Nothing
-- 2 and 3 for compressed format.
_ -> Nothing
where bits = numBits . ECC.ecc_n . ECC.common_curve $ curve
where bits = ECC.curveSizeBits curve
bytes = (bits + 7) `div` 8
kxVerify _ _ _ _ = False

Expand Down
6 changes: 3 additions & 3 deletions core/Network/TLS/Crypto/ECDH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Network.TLS.Crypto.ECDH
, ecdhUnwrapPublic
) where

import Network.TLS.Util.Serialization (lengthBytes)
import Network.TLS.Extension.EC
import qualified Crypto.PubKey.ECC.DH as ECDH
import qualified Crypto.PubKey.ECC.Types as ECDH
Expand Down Expand Up @@ -72,5 +71,6 @@ ecdhUnwrapPublic (ECDHPublic (ECDH.Point x y) siz) = (x,y,siz)
ecdhUnwrapPublic _ = error "ecdhUnwrapPublic"

pointSize :: ECDH.Curve -> Int
pointSize (ECDH.CurveFP curve) = lengthBytes $ ECDH.ecc_p curve
pointSize _ = error "pointSize" -- FIXME
pointSize = toBytes . ECDH.curveSizeBits
where
toBytes bits = (bits + 7) `div` 8

0 comments on commit 0f0cb19

Please sign in to comment.