How to verify SAML signature statements?
for (Assertion assertion : samlResponse.getAssertions()) { try { if (assertion.getSignature() != null) { Optional<X509Certificate> x509Certificate = assertion.getSignature().getKeyInfo().getX509Datas() .stream() .findFirst() .map(x509Data -> x509Data.getX509Certificates() .stream() .findFirst() .orElse(null) ); if (x509Certificate.isPresent()) { BasicX509Credential credential = new BasicX509Credential(); credential.setEntityCertificate(KeyInfoHelper.getCertificate(x509Certificate.get())); // what pub key credential to use here? SignatureValidator validator = new SignatureValidator(credential); validator.validate(assertion.getSignature()); } } } catch (ValidationException | CertificateException e) { throw new SAMLException(e.getMessage(), e); } }
Basically, what to put in new SignatureValidator(credential)
As I understand it, a SAML statement with KeyInfo provided and an X809 certificate should at least verify ( SAML: why is the certificate in Signature? )
I also have an x509 certificate from idps metadata, which I believe should be used at all if in a statement or in a trust chain (?)
no x509 certificate,
Basically, neither the x509 certificate in the approval, nor the certificate from the idp metadata seems to work. What am I missing here?
source share