Skip to content

Commit

Permalink
Merge pull request #140 from onelogin/inflexiontecnologia-master
Browse files Browse the repository at this point in the history
Support the ability to parse IdP XML metadata (remote url or file) + extend MultiCert support
  • Loading branch information
pitbulk authored Jan 23, 2018
2 parents fa1df60 + 6bc0899 commit dd3f0b4
Show file tree
Hide file tree
Showing 16 changed files with 1,386 additions and 18 deletions.
25 changes: 18 additions & 7 deletions core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,30 @@ public boolean isValid(String requestId) {

validateSubjectConfirmation(responseInResponseTo);

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

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

if (signedElements.isEmpty() || (!hasSignedAssertion && !hasSignedResponse)) {
throw new ValidationError("No Signature found. SAML Response rejected", ValidationError.NO_SIGNATURE_FOUND);
} else {
List<X509Certificate> certList = settings.getIdpx509certMulti();
X509Certificate cert = settings.getIdpx509cert();
List<X509Certificate> certList = new ArrayList<X509Certificate>();
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();

if (multipleCertList != null && multipleCertList.size() != 0) {
certList.addAll(multipleCertList);
}

if (cert != null && !certList.contains(cert)) {
certList.add(0, cert);
}

String fingerprint = settings.getIdpCertFingerprint();
String alg = settings.getIdpCertFingerprintAlgorithm();

Expand Down
13 changes: 12 additions & 1 deletion core/src/main/java/com/onelogin/saml2/logout/LogoutRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,17 @@ public Boolean isValid() throws Exception {
throw new SettingsException("In order to validate the sign on the Logout Request, the x509cert of the IdP is required", SettingsException.CERT_NOT_FOUND);
}

List<X509Certificate> certList = new ArrayList<X509Certificate>();
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();

if (multipleCertList != null && multipleCertList.size() != 0) {
certList.addAll(multipleCertList);
}

if (certList.isEmpty() || !certList.contains(cert)) {
certList.add(0, cert);
}

String signAlg = request.getParameter("SigAlg");
if (signAlg == null || signAlg.isEmpty()) {
signAlg = Constants.RSA_SHA1;
Expand All @@ -377,7 +388,7 @@ public Boolean isValid() throws Exception {

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

if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), cert, signAlg)) {
if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), certList, signAlg)) {
throw new ValidationError("Signature validation failed. Logout Request rejected", ValidationError.INVALID_SIGNATURE);
}
}
Expand Down
15 changes: 14 additions & 1 deletion core/src/main/java/com/onelogin/saml2/logout/LogoutResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.io.IOException;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

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

List<X509Certificate> certList = new ArrayList<X509Certificate>();
List<X509Certificate> multipleCertList = settings.getIdpx509certMulti();

if (multipleCertList != null && multipleCertList.size() != 0) {
certList.addAll(multipleCertList);
}

if (certList.isEmpty() || !certList.contains(cert)) {
certList.add(0, cert);
}

String signAlg = request.getParameter("SigAlg");
if (signAlg == null || signAlg.isEmpty()) {
signAlg = Constants.RSA_SHA1;
Expand All @@ -245,7 +258,7 @@ public Boolean isValid(String requestId) {

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

if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), cert, signAlg)) {
if (!Util.validateBinarySignature(signedQuery, Util.base64decoder(signature), certList, signAlg)) {
throw new ValidationError("Signature validation failed. Logout Response rejected", ValidationError.INVALID_SIGNATURE);
}
}
Expand Down
Loading

0 comments on commit dd3f0b4

Please sign in to comment.