Skip to content

Commit dd3f0b4

Browse files
authored
Merge pull request #140 from onelogin/inflexiontecnologia-master
Support the ability to parse IdP XML metadata (remote url or file) + extend MultiCert support
2 parents fa1df60 + 6bc0899 commit dd3f0b4

16 files changed

+1386
-18
lines changed

core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,30 @@ public boolean isValid(String requestId) {
281281

282282
validateSubjectConfirmation(responseInResponseTo);
283283

284-
if (settings.getWantAssertionsSigned() && !hasSignedAssertion) {
285-
throw new ValidationError("The Assertion of the Response is not signed and the SP requires it", ValidationError.NO_SIGNED_ASSERTION);
286-
}
284+
if (settings.getWantAssertionsSigned() && !hasSignedAssertion) {
285+
throw new ValidationError("The Assertion of the Response is not signed and the SP requires it", ValidationError.NO_SIGNED_ASSERTION);
286+
}
287287

288-
if (settings.getWantMessagesSigned() && !hasSignedResponse) {
289-
throw new ValidationError("The Message of the Response is not signed and the SP requires it", ValidationError.NO_SIGNED_MESSAGE);
290-
}
288+
if (settings.getWantMessagesSigned() && !hasSignedResponse) {
289+
throw new ValidationError("The Message of the Response is not signed and the SP requires it", ValidationError.NO_SIGNED_MESSAGE);
290+
}
291291
}
292292

293293
if (signedElements.isEmpty() || (!hasSignedAssertion && !hasSignedResponse)) {
294294
throw new ValidationError("No Signature found. SAML Response rejected", ValidationError.NO_SIGNATURE_FOUND);
295295
} else {
296-
List<X509Certificate> certList = settings.getIdpx509certMulti();
296+
X509Certificate cert = settings.getIdpx509cert();
297+
List<X509Certificate> certList = new ArrayList<X509Certificate>();
298+
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();
299+
300+
if (multipleCertList != null && multipleCertList.size() != 0) {
301+
certList.addAll(multipleCertList);
302+
}
303+
304+
if (cert != null && !certList.contains(cert)) {
305+
certList.add(0, cert);
306+
}
307+
297308
String fingerprint = settings.getIdpCertFingerprint();
298309
String alg = settings.getIdpCertFingerprintAlgorithm();
299310

core/src/main/java/com/onelogin/saml2/logout/LogoutRequest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ public Boolean isValid() throws Exception {
363363
throw new SettingsException("In order to validate the sign on the Logout Request, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
364364
}
365365

366+
List<X509Certificate> certList = new ArrayList<X509Certificate>();
367+
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();
368+
369+
if (multipleCertList != null && multipleCertList.size() != 0) {
370+
certList.addAll(multipleCertList);
371+
}
372+
373+
if (certList.isEmpty() || !certList.contains(cert)) {
374+
certList.add(0, cert);
375+
}
376+
366377
String signAlg = request.getParameter("SigAlg");
367378
if (signAlg == null || signAlg.isEmpty()) {
368379
signAlg = Constants.RSA_SHA1;
@@ -377,7 +388,7 @@ public Boolean isValid() throws Exception {
377388

378389
signedQuery += "&SigAlg=" + request.getEncodedParameter("SigAlg", signAlg);
379390

380-
if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), cert, signAlg)) {
391+
if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), certList, signAlg)) {
381392
throw new ValidationError("Signature validation failed. Logout Request rejected", ValidationError.INVALID_SIGNATURE);
382393
}
383394
}

core/src/main/java/com/onelogin/saml2/logout/LogoutResponse.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import java.io.IOException;
44
import java.net.URL;
55
import java.security.cert.X509Certificate;
6+
import java.util.ArrayList;
67
import java.util.Calendar;
78
import java.util.HashMap;
9+
import java.util.List;
810
import java.util.Map;
911
import java.util.Objects;
1012

@@ -231,6 +233,17 @@ public Boolean isValid(String requestId) {
231233
throw new SettingsException("In order to validate the sign on the Logout Response, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
232234
}
233235

236+
List<X509Certificate> certList = new ArrayList<X509Certificate>();
237+
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();
238+
239+
if (multipleCertList != null && multipleCertList.size() != 0) {
240+
certList.addAll(multipleCertList);
241+
}
242+
243+
if (certList.isEmpty() || !certList.contains(cert)) {
244+
certList.add(0, cert);
245+
}
246+
234247
String signAlg = request.getParameter("SigAlg");
235248
if (signAlg == null || signAlg.isEmpty()) {
236249
signAlg = Constants.RSA_SHA1;
@@ -245,7 +258,7 @@ public Boolean isValid(String requestId) {
245258

246259
signedQuery += "&SigAlg=" + request.getEncodedParameter("SigAlg", signAlg);
247260

248-
if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), cert, signAlg)) {
261+
if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), certList, signAlg)) {
249262
throw new ValidationError("Signature validation failed. Logout Response rejected", ValidationError.INVALID_SIGNATURE);
250263
}
251264
}

0 commit comments

Comments
 (0)