I am experimenting on enabling FIPS 180-3 on my java application. FIPS 180-3 allows only usage of 5 secure [hashes] (http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf) , MD5 is not one among them. Hence i am trying to programatically remove MD5 algorithms from the Sun provider. This is the sample code.
public static void main(String[] args) throws Exception {
Security.removeProvider("SUN");
Sun sun = new Sun();
sun.remove("MessageDigest.MD5"); //Comment and it will work !!!
Security.addProvider(sun);
Cipher ciph = Cipher.getInstance("AES");
}
But this is throwing the following exception. If you comment "sun.remove(.." the program works fine. If i remove MD2, instead of MD5 then also it works fine.
To me it looks like the jre libs are using MD5 for their signing, but i checked jre/lib/ext/sunjce_provider.jar signer and its using sha1.
Any idea why my code is failing with this error?
Exception in thread "main" java.lang.ExceptionInInitializerError at javax.crypto.Cipher.getInstance(DashoA13*..) at TestRemoveMD5.main(TestRemoveMD5.java:20)
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs at javax.crypto.SunJCE_b.(DashoA13*..) ... 3 more
Caused by: java.lang.SecurityException: Signature classes have been tampered with at javax.crypto.SunJCE_b.d(DashoA13*..) at javax.crypto.SunJCE_b.c(DashoA13*..) at javax.crypto.SunJCE_b$1.run(DashoA13*..) at java.security.AccessController.doPrivileged(Native Method) ... 4 more