Skip to content

Commit

Permalink
Merge pull request #91 from wireapp/validation-error-stack
Browse files Browse the repository at this point in the history
Clear error stack after validation failure
  • Loading branch information
vshabanov authored Jun 11, 2024
2 parents 05118c0 + 2d7afef commit 66089b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion HsOpenSSL.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Description:
systems and stable. You may also be interested in the @tls@ package,
<http://hackage.haskell.org/package/tls>, which is a pure Haskell
implementation of SSL.
Version: 0.11.7.6
Version: 0.11.7.7
License: PublicDomain
License-File: COPYING
Author: Adam Langley, Mikhail Vorozhtsov, PHO, Taru Karttunen
Expand Down
8 changes: 8 additions & 0 deletions OpenSSL/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ module OpenSSL.Utils
, failIf
, failIf_
, raiseOpenSSLError
, clearErrorStack
, toHex
, fromHex
, peekCStringCLen
)
where
import Control.Monad
import Foreign.C.String
import Foreign.C.Types
import Foreign.Ptr
Expand Down Expand Up @@ -41,6 +43,12 @@ failIf_ f a
raiseOpenSSLError :: IO a
raiseOpenSSLError = getError >>= errorString >>= fail


clearErrorStack :: IO ()
clearErrorStack = do
e <- getError
when (e /= 0) clearErrorStack

-- | Convert an integer to a hex string
toHex :: (Num i, Bits i) => i -> String
toHex = reverse . map hexByte . unfoldr step where
Expand Down
4 changes: 3 additions & 1 deletion OpenSSL/X509.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ verifyX509 x509 key
where
interpret :: CInt -> IO VerifyStatus
interpret 1 = return VerifySuccess
interpret 0 = return VerifyFailure
interpret 0 = do
clearErrorStack
return VerifyFailure
interpret _ = raiseOpenSSLError

-- |@'printX509' cert@ translates a certificate into human-readable
Expand Down

0 comments on commit 66089b9

Please sign in to comment.