Skip to content
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

Merged
merged 2 commits into from
Nov 23, 2020
Merged

See #294 Support Alg Deprecated rejection. #295

merged 2 commits into from
Nov 23, 2020

Conversation

pitbulk
Copy link
Contributor

@pitbulk 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();

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)) {

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?

Copy link
Contributor Author

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");
}
}

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       
					}
				}
}

Copy link
Contributor Author

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);

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);

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)

Copy link
Contributor Author

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");

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");
			}

Copy link
Contributor Author

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

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 93.37% when pulling 1d79874 on deprecated-alg into e756d62 on master.

@pitbulk pitbulk merged commit e69b53b into master Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants