2727import java .security .cert .CertificateFactory ;
2828import java .security .cert .X509Certificate ;
2929import java .security .spec .PKCS8EncodedKeySpec ;
30+ import java .util .Arrays ;
3031import java .util .Calendar ;
3132import java .util .HashMap ;
3233import java .util .HashSet ;
@@ -116,6 +117,8 @@ public final class Util {
116117 /** Indicates if JAXP 1.5 support has been detected. */
117118 private static boolean JAXP_15_SUPPORTED = isJaxp15Supported ();
118119
120+ private static final Set <String > DEPRECATED_ALGOS = new HashSet <>(Arrays .asList (Constants .RSA_SHA1 , Constants .DSA_SHA1 ));
121+
119122 static {
120123 System .setProperty ("org.apache.xml.security.ignoreLineBreaks" , "true" );
121124 org .apache .xml .security .Init .init ();
@@ -1093,13 +1096,8 @@ private static Map<String,Object> getSignatureData(Node signNode, String alg, Bo
10931096 throw new Exception (sigMethodAlg + " is not a valid supported algorithm" );
10941097 }
10951098
1096- if (sigMethodAlg .equals (Constants .RSA_SHA1 )) {
1097- if (rejectDeprecatedAlg ) {
1098- LOGGER .error ("A deprecated algorithm (RSA_SHA1) found in the Signature element, rejecting it" );
1099- return signatureData ;
1100- } else {
1101- LOGGER .info ("RSA_SHA1 alg found in a Signature element, consider request a more robust alg" );
1102- }
1099+ if (Util .mustRejectDeprecatedSignatureAlgo (sigMethodAlg , rejectDeprecatedAlg )) {
1100+ return signatureData ;
11031101 }
11041102
11051103 signatureData .put ("signature" , signature );
@@ -1122,6 +1120,19 @@ private static Map<String,Object> getSignatureData(Node signNode, String alg, Bo
11221120 return signatureData ;
11231121 }
11241122
1123+ public static Boolean mustRejectDeprecatedSignatureAlgo (String signAlg , Boolean rejectDeprecatedAlg ) {
1124+ if (DEPRECATED_ALGOS .contains (signAlg )) {
1125+ String errorMsg = "Found a deprecated algorithm " + signAlg +" related to the Signature element," ;
1126+ if (rejectDeprecatedAlg ) {
1127+ LOGGER .error (errorMsg + " rejecting it" );
1128+ return true ;
1129+ } else {
1130+ LOGGER .info (errorMsg + " consider requesting a more robust algorithm" );
1131+ }
1132+ }
1133+ return false ;
1134+ }
1135+
11251136 /**
11261137 * Validate signature of the Node.
11271138 *
0 commit comments