Permalink
Browse files

[FIXED JENKINS-25937] Treat BadPaddingException as an unloadable key …

…and continue.

(cherry picked from commit 6318b8d)
  • Loading branch information...
jglick committed Dec 5, 2014
1 parent 877f4b3 commit 16afb73b254504d0f0f1246e34cce1fb5bd65c35
Showing with 10 additions and 1 deletion.
  1. +3 −1 changelog.html
  2. +7 −0 core/src/main/java/jenkins/security/DefaultConfidentialStore.java
@@ -55,7 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=>
<li class=bug>
After recent Java security updates, Jenkins would not gracefully recover from a deleted <code>secrets/master.key</code>.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-25937">issue 25937</a>)
</ul>
</div><!--=TRUNK-END=-->
@@ -16,6 +16,7 @@
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import javax.crypto.BadPaddingException;
import org.apache.commons.io.IOUtils;
/**
@@ -107,6 +108,12 @@ protected void store(ConfidentialKey key, byte[] payload) throws IOException {
return verifyMagic(bytes);
} catch (GeneralSecurityException e) {
throw new IOException("Failed to load the key: "+key.getId(),e);
} catch (IOException x) {
if (x.getCause() instanceof BadPaddingException) {
return null; // broken somehow
} else {
throw x;
}
} finally {
IOUtils.closeQuietly(cis);
IOUtils.closeQuietly(fis);

0 comments on commit 16afb73

Please sign in to comment.