@@ -72,6 +72,7 @@ import Data.UUID as UUID
7272import Data.X509 qualified as X509
7373import GHC.Stack
7474import Network.URI (URI (.. ), parseRelativeReference )
75+ import Network.Wai.Utilities.Exception
7576import SAML2.XML qualified as HS hiding (Node , URI )
7677import SAML2.XML.Canonical qualified as HS
7778import SAML2.XML.Signature qualified as HS
@@ -145,7 +146,7 @@ parseKeyInfo doVerify (cs @LT @LBS -> lbs) = case HS.xmlToSAML @HS.KeyInfo =<< s
145146
146147-- | Call 'stripWhitespaceDoc' on a rendered bytestring.
147148stripWhitespaceLBS :: (m ~ Either String ) => LBS -> m LBS
148- stripWhitespaceLBS lbs = renderLBS def . stripWhitespace <$> fmapL show (parseLBS def lbs)
149+ stripWhitespaceLBS lbs = renderLBS def . stripWhitespace <$> fmapL displayExceptionNoBacktrace (parseLBS def lbs)
149150
150151renderKeyInfo :: (HasCallStack ) => X509. SignedCertificate -> LT
151152renderKeyInfo cert = cs . ourSamlToXML . HS. KeyInfo Nothing $ HS. X509Data (HS. X509Certificate cert :| [] ) :| []
@@ -224,16 +225,16 @@ mkSignCredsWithCert mValidSince size = do
224225verify :: forall m . (MonadError String m ) => NonEmpty SignCreds -> LBS -> String -> m HXTC. XmlTree
225226verify creds el sid = case unsafePerformIO (try @ SomeException $ verifyIO creds el sid) of
226227 Right (_, Right xml) -> pure xml
227- Right (_, Left exc ) -> throwError $ show exc
228- Left exc -> throwError $ show exc
228+ Right (_, Left signErr ) -> throwError $ show signErr
229+ Left exc -> throwError $ displayExceptionNoBacktrace exc
229230
230231-- | Convenient wrapper that picks the ID of the root element node and passes it to `verify`.
231232verifyRoot :: forall m . (MonadError String m ) => NonEmpty SignCreds -> LBS -> m HXTC. XmlTree
232233verifyRoot creds el = do
233234 signedID <- do
234235 XML. Document _ (XML. Element _ attrs _) _ <-
235236 either
236- (throwError . (" Could not parse signed document: " <> ) . cs . show )
237+ (throwError . (" Could not parse signed document: " <> ) . cs . displayExceptionNoBacktrace )
237238 pure
238239 (XML. parseLBS XML. def el)
239240 maybe
@@ -272,7 +273,7 @@ verifySignatureUnenvelopedSigs :: HS.PublicKeys -> String -> HXTC.XmlTree -> IO
272273verifySignatureUnenvelopedSigs pks xid doc = catchAll $ warpResult <$> verifySignature pks xid doc
273274 where
274275 catchAll :: IO (Either HS. SignatureError a ) -> IO (Either HS. SignatureError a )
275- catchAll = handle $ pure . Left . HS. SignatureVerificationLegacyFailure . Left . (show @ SomeException )
276+ catchAll = handle $ pure . Left . HS. SignatureVerificationLegacyFailure . Left . (displayExceptionNoBacktrace @ SomeException )
276277
277278 warpResult :: Maybe HXTC. XmlTree -> Either HS. SignatureError HXTC. XmlTree
278279 warpResult (Just xml) = Right xml
@@ -413,7 +414,7 @@ signRootAt sigPos (SignPrivCreds hashAlg (SignPrivKeyRSA keypair)) doc =
413414 }
414415 ]
415416 docCanonic :: SBS <-
416- either (throwError . show ) (pure . cs) . unsafePerformIO . try @ SomeException $
417+ either (throwError . displayExceptionNoBacktrace ) (pure . cs) . unsafePerformIO . try @ SomeException $
417418 HS. applyTransforms transforms (HXT. mkRoot [] [docInHXT])
418419 let digest :: SBS
419420 digest = case hashAlg of
@@ -437,7 +438,7 @@ signRootAt sigPos (SignPrivCreds hashAlg (SignPrivKeyRSA keypair)) doc =
437438 -- (note that there are two rounds of SHA256 application, hence two mentions of the has alg here)
438439
439440 signedInfoSBS :: SBS <-
440- either (throwError . show ) (pure . cs) . unsafePerformIO . try @ SomeException $
441+ either (throwError . displayExceptionNoBacktrace ) (pure . cs) . unsafePerformIO . try @ SomeException $
441442 HS. applyCanonicalization (HS. signedInfoCanonicalizationMethod signedInfo) Nothing $
442443 HS. samlToDoc signedInfo
443444 sigval :: SBS <-
0 commit comments