I'm migrating my application from Spring Boot 3.3.6 to 3.4.1.
I have a certification file used for SAML authentication. It's like
And I set it as
spring.security.saml2:
relyingparty:
registration:
azuread: # registration id
entity-id: ArchitecturePoC # entity id of project, need to be registered to Azure AD in advance
assertingparty:
verification:
credentials:
- certificate-location: "classpath:ArchitecturePoC.cer"
It worked fine on spring boot 3.3.6, but when I upgraded to 3.4.1, the certification file cannot be recognized.
Caused by: java.lang.IllegalStateException: Missing certificates or unrecognized format
at org.springframework.util.Assert.state(Assert.java:79)
at org.springframework.boot.ssl.pem.PemCertificateParser.parse(PemCertificateParser.java:64)
at org.springframework.boot.ssl.pem.PemContent.getCertificates(PemContent.java:64)
at org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyRegistrationConfiguration.readCertificate(Saml2RelyingPartyRegistrationConfiguration.java:192)
... 97 common frames omitted
It seems to be the changes in Saml2RelyingPartyRegistrationConfiguration#readCertificate
, in 3.3.x, it's like
private X509Certificate readCertificate(Resource location) {
Assert.state(location != null, "No certificate location specified");
Assert.state(location.exists(), () -> "Certificate location '" + location + "' does not exist");
try (InputStream inputStream = location.getInputStream()) {
return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(inputStream);
}
catch (Exception ex) {
throw new IllegalArgumentException(ex);
}
}
in 3.4.x, it's
private X509Certificate readCertificate(Resource location) {
Assert.state(location != null, "No certificate location specified");
Assert.state(location.exists(), () -> "Certificate location '" + location + "' does not exist");
try (InputStream inputStream = location.getInputStream()) {
PemContent pemContent = PemContent.load(inputStream);
List<X509Certificate> certificates = pemContent.getCertificates();
return certificates.get(0);
}
catch (Exception ex) {
throw new IllegalArgumentException(ex);
}
}
I cannot see the necessity of forcing apps to use pem files starts with BEGIN CERTIFICATE
, and it makes no sense to stop supporting certifications which are not pem format.