Skip to content

Commit bedffad

Browse files
committed
Add extra protection to whitelist algorithm used on Signature
1 parent 06fff7a commit bedffad

File tree

1 file changed

+37
-0
lines changed
  • core/src/main/java/com/onelogin/saml2/util

1 file changed

+37
-0
lines changed

core/src/main/java/com/onelogin/saml2/util/Util.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828
import java.security.cert.X509Certificate;
2929
import java.security.spec.PKCS8EncodedKeySpec;
3030
import java.util.Calendar;
31+
import java.util.HashSet;
3132
import java.util.Iterator;
3233
import java.util.List;
3334
import java.util.Locale;
35+
import java.util.Set;
3436
import java.util.TimeZone;
3537
import java.util.UUID;
3638
import java.util.zip.Deflater;
@@ -967,6 +969,11 @@ public static Boolean validateSignNode(Node signNode, X509Certificate cert, Stri
967969
Element sigElement = (Element) signNode;
968970
XMLSignature signature = new XMLSignature(sigElement, "", true);
969971

972+
String sigMethodAlg = signature.getSignedInfo().getSignatureMethodURI();
973+
if (!isAlgorithmWhitelisted(sigMethodAlg)){
974+
throw new Exception(sigMethodAlg + " is not a valid supported algorithm");
975+
}
976+
970977
if (cert != null) {
971978
res = signature.checkSignatureValue(cert);
972979
} else {
@@ -987,6 +994,36 @@ public static Boolean validateSignNode(Node signNode, X509Certificate cert, Stri
987994
return res;
988995
}
989996

997+
/**
998+
* Whitelist the XMLSignature algorithm
999+
*
1000+
* @param signNode
1001+
* The document we should validate
1002+
* @param cert
1003+
* The public certificate
1004+
* @param fingerprint
1005+
* The fingerprint of the public certificate
1006+
* @param alg
1007+
* The signature algorithm method
1008+
*
1009+
* @return True if the sign is valid, false otherwise.
1010+
*/
1011+
public static boolean isAlgorithmWhitelisted(String alg) {
1012+
Set<String> whiteListedAlgorithm = new HashSet<String>();
1013+
whiteListedAlgorithm.add(Constants.DSA_SHA1);
1014+
whiteListedAlgorithm.add(Constants.RSA_SHA1);
1015+
whiteListedAlgorithm.add(Constants.RSA_SHA256);
1016+
whiteListedAlgorithm.add(Constants.RSA_SHA384);
1017+
whiteListedAlgorithm.add(Constants.RSA_SHA512);
1018+
1019+
Boolean whitelisted = false;
1020+
if (whiteListedAlgorithm.contains(alg)) {
1021+
whitelisted = true;
1022+
}
1023+
1024+
return whitelisted;
1025+
}
1026+
9901027
/**
9911028
* Decrypt an encrypted element.
9921029
*

0 commit comments

Comments
 (0)