@@ -72,6 +72,7 @@ import Data.UUID as UUID
72
72
import Data.X509 qualified as X509
73
73
import GHC.Stack
74
74
import Network.URI (URI (.. ), parseRelativeReference )
75
+ import Network.Wai.Utilities.Exception
75
76
import SAML2.XML qualified as HS hiding (Node , URI )
76
77
import SAML2.XML.Canonical qualified as HS
77
78
import SAML2.XML.Signature qualified as HS
@@ -145,7 +146,7 @@ parseKeyInfo doVerify (cs @LT @LBS -> lbs) = case HS.xmlToSAML @HS.KeyInfo =<< s
145
146
146
147
-- | Call 'stripWhitespaceDoc' on a rendered bytestring.
147
148
stripWhitespaceLBS :: (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)
149
150
150
151
renderKeyInfo :: (HasCallStack ) => X509. SignedCertificate -> LT
151
152
renderKeyInfo cert = cs . ourSamlToXML . HS. KeyInfo Nothing $ HS. X509Data (HS. X509Certificate cert :| [] ) :| []
@@ -224,16 +225,16 @@ mkSignCredsWithCert mValidSince size = do
224
225
verify :: forall m . (MonadError String m ) => NonEmpty SignCreds -> LBS -> String -> m HXTC. XmlTree
225
226
verify creds el sid = case unsafePerformIO (try @ SomeException $ verifyIO creds el sid) of
226
227
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
229
230
230
231
-- | Convenient wrapper that picks the ID of the root element node and passes it to `verify`.
231
232
verifyRoot :: forall m . (MonadError String m ) => NonEmpty SignCreds -> LBS -> m HXTC. XmlTree
232
233
verifyRoot creds el = do
233
234
signedID <- do
234
235
XML. Document _ (XML. Element _ attrs _) _ <-
235
236
either
236
- (throwError . (" Could not parse signed document: " <> ) . cs . show )
237
+ (throwError . (" Could not parse signed document: " <> ) . cs . displayExceptionNoBacktrace )
237
238
pure
238
239
(XML. parseLBS XML. def el)
239
240
maybe
@@ -272,7 +273,7 @@ verifySignatureUnenvelopedSigs :: HS.PublicKeys -> String -> HXTC.XmlTree -> IO
272
273
verifySignatureUnenvelopedSigs pks xid doc = catchAll $ warpResult <$> verifySignature pks xid doc
273
274
where
274
275
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 )
276
277
277
278
warpResult :: Maybe HXTC. XmlTree -> Either HS. SignatureError HXTC. XmlTree
278
279
warpResult (Just xml) = Right xml
@@ -413,7 +414,7 @@ signRootAt sigPos (SignPrivCreds hashAlg (SignPrivKeyRSA keypair)) doc =
413
414
}
414
415
]
415
416
docCanonic :: SBS <-
416
- either (throwError . show ) (pure . cs) . unsafePerformIO . try @ SomeException $
417
+ either (throwError . displayExceptionNoBacktrace ) (pure . cs) . unsafePerformIO . try @ SomeException $
417
418
HS. applyTransforms transforms (HXT. mkRoot [] [docInHXT])
418
419
let digest :: SBS
419
420
digest = case hashAlg of
@@ -437,7 +438,7 @@ signRootAt sigPos (SignPrivCreds hashAlg (SignPrivKeyRSA keypair)) doc =
437
438
-- (note that there are two rounds of SHA256 application, hence two mentions of the has alg here)
438
439
439
440
signedInfoSBS :: SBS <-
440
- either (throwError . show ) (pure . cs) . unsafePerformIO . try @ SomeException $
441
+ either (throwError . displayExceptionNoBacktrace ) (pure . cs) . unsafePerformIO . try @ SomeException $
441
442
HS. applyCanonicalization (HS. signedInfoCanonicalizationMethod signedInfo) Nothing $
442
443
HS. samlToDoc signedInfo
443
444
sigval :: SBS <-
0 commit comments