-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
See #294 Support Alg Deprecated rejection. #295
Conversation
pitbulk
commented
Nov 20, 2020
- Set SHA-256 as default alg in settings
- Support Alg Deprecated rejection by the use of a new setting.
- Notify with Logger.info if sha-1 alg used on Signature
…ion. Notify with Logger.info if sha-1 alg used on Signature
@@ -323,12 +323,14 @@ public boolean isValid(String requestId) { | |||
String fingerprint = settings.getIdpCertFingerprint(); | |||
String alg = settings.getIdpCertFingerprintAlgorithm(); | |||
|
|||
if (hasSignedResponse && !Util.validateSign(samlResponseDocument, certList, fingerprint, alg, Util.RESPONSE_SIGNATURE_XPATH)) { | |||
Boolean rejectDeprecatedAlg = settings.getRejectDeprecatedAlg(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect an unboxed, non-nullable (primitive) bool here
@@ -456,6 +456,17 @@ public Boolean isValid() throws Exception { | |||
if (signAlg == null || signAlg.isEmpty()) { | |||
signAlg = Constants.RSA_SHA1; | |||
} | |||
|
|||
if (signAlg.equals(Constants.RSA_SHA1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should DSA_SHA1
be rejected too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
} else { | ||
LOGGER.info("RSA_SHA1 alg found in a Signature element, consider request a more robust alg"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe hide/share the common logic inside an utility method:
if (Util.mustRejectDeprecatedSignatureAlgo(signAlg, settings.getRejectDeprecatedAlg())
return false;
private static final Set<String> DEPRECATED_ALGOS = new HashSet<>(Arrays.asList(
Constants.RSA_SHA1, Constants.DSA_SHA1));
public boolean mustRejectDeprecatedSignatureAlgo(String signAlg, boolean rejectDeprecatedAlg) {
if (DEPRECATED_ALGOS.contains(signAlg) {
boolean rejectDeprecatedAlg = settings.getRejectDeprecatedAlg();
if (rejectDeprecatedAlg) {
LOGGER.error("A deprecated algorithm (xxx_SHA1) found in the Signature element, rejecting it");
return true; // must reject
} else {
LOGGER.info("xxx_SHA1 alg found in a Signature element, consider request a more robust alg");
return false; // can continue
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
@@ -1073,7 +1139,29 @@ public static Boolean validateMetadataSign(Document doc, X509Certificate cert, S | |||
* @throws Exception | |||
*/ | |||
public static Boolean validateSignNode(Node signNode, X509Certificate cert, String fingerprint, String alg) { | |||
Map<String,Object> signatureData = getSignatureData(signNode, alg); | |||
return validateSignNode(signNode, cert, fingerprint, alg, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other comment about forced flag
@@ -1026,6 +1063,26 @@ public static Boolean validateMetadataSign(Document doc, X509Certificate cert, S | |||
* @return True if the sign is valid, false otherwise. | |||
*/ | |||
private static Map<String,Object> getSignatureData(Node signNode, String alg) { | |||
return getSignatureData(signNode, alg, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bit risky to have an implicit rejectDeprecatedAlg=false no? (the safer flag true
could be accidentally ignored)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't set it true, I need to maintain backward compatibility. But notice that in the settings file I added the rejection of deprecated alg as default.
if (signAlg.equals(Constants.RSA_SHA1)) { | ||
Boolean rejectDeprecatedAlg = settings.getRejectDeprecatedAlg(); | ||
if (rejectDeprecatedAlg) { | ||
LOGGER.error("A deprecated algorithm (RSA_SHA1) found in the Signature element, rejecting it"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it can be confusing that there are 2 kinds of rejections, the other being:
if (!isAlgorithmWhitelisted(sigMethodAlg)){
throw new Exception(sigMethodAlg + " is not a valid supported algorithm");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supported by the toolkit vs Acceptable