From cb65e33c6bc464f94ba9219c1d201675e38f344d Mon Sep 17 00:00:00 2001 From: mindless Date: Fri, 28 May 2010 05:01:37 +0000 Subject: [PATCH] [FIXED HUDSON-6459] Fix in 1.358 did not work because exception thrown when Cipher is used, not when it is created. Refactor to use a system property to force a particular provider, so Glassfish Enterprise users can workaround this glassfish bug until it is fixed. In 1.360. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@31455 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/util/Secret.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/hudson/util/Secret.java b/core/src/main/java/hudson/util/Secret.java index 2b1e65f23f..276cdbfca0 100644 --- a/core/src/main/java/hudson/util/Secret.java +++ b/core/src/main/java/hudson/util/Secret.java @@ -144,14 +144,13 @@ public final class Secret { /** * Workaround for HUDSON-6459 / https://glassfish.dev.java.net/issues/show_bug.cgi?id=11862 . - * Falls back to "SunJCE" provider if unable to get the Cipher from the default provider. + * This method uses specific provider selected via hudson.util.Secret.provider system property + * to provide a workaround for the above bug where default provide gives an unusable instance. + * (Glassfish Enterprise users should set value of this property to "SunJCE") */ public static Cipher getCipher(String algorithm) throws GeneralSecurityException { - try { - return Cipher.getInstance(algorithm); - } catch (Exception e) { - return Cipher.getInstance(algorithm, "SunJCE"); - } + return PROVIDER != null ? Cipher.getInstance(algorithm, PROVIDER) + : Cipher.getInstance(algorithm); } /** @@ -199,6 +198,12 @@ public final class Secret { private static final String MAGIC = "::::MAGIC::::"; + /** + * Workaround for HUDSON-6459 / https://glassfish.dev.java.net/issues/show_bug.cgi?id=11862 . + * @see #getCipher(String) + */ + private static final String PROVIDER = System.getProperty(Secret.class.getName()+".provider"); + /** * For testing only. Override the secret key so that we can test this class without {@link Hudson}. */