Skip to content
Permalink
Browse files

Save passwords scrambled [JENKINS-13706]

  • Loading branch information
kutzi committed Jun 3, 2012
1 parent 967f956 commit cbe23a16db65a2e857ff5f5404a37b61192ffbc2
Showing with 25 additions and 5 deletions.
  1. +1 −1 pom.xml
  2. +24 −4 src/main/java/hudson/plugins/ircbot/IrcPublisher.java
@@ -5,7 +5,7 @@
<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>instant-messaging-parent</artifactId>
<version>1.19</version>
<version>1.20-SNAPSHOT</version>
<relativePath>../instant-messaging-parent-plugin/pom.xml</relativePath>
</parent>

@@ -23,6 +23,7 @@
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.util.Scrambler;

import java.nio.charset.Charset;
import java.util.ArrayList;
@@ -169,6 +170,13 @@ protected Object readResolve() {
String nick = "jenkins-bot";

String nickServPassword = null;

/**
* Marks if passwords are already scrambled.
* Needed to migrate old, unscrambled passwords.
* @since 2.19
*/
private boolean scrambledPasswords = false;

/**
* channels to join
@@ -213,13 +221,17 @@ protected Object readResolve() {
*/
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
this.scrambledPasswords = true;

this.enabled = "on".equals(req.getParameter("irc_publisher.enabled"))
|| "true".equals(req.getParameter("irc_publisher.enabled"));
if (this.enabled) {
this.hostname = req.getParameter("irc_publisher.hostname");
this.password = req.getParameter("irc_publisher.password");
this.password = Scrambler.scramble(
req.getParameter("irc_publisher.password"));
this.nick = req.getParameter("irc_publisher.nick");
this.nickServPassword = req.getParameter(PARAMETERNAME_NICKSERV_PASSWORD);
this.nickServPassword = Scrambler.scramble(
req.getParameter(PARAMETERNAME_NICKSERV_PASSWORD));
try {
this.port = Integer.valueOf(req.getParameter("irc_publisher.port"));
} catch (NumberFormatException e) {
@@ -385,12 +397,12 @@ public String getNick() {
* with NickServ.
*/
public String getNickServPassword() {
return nickServPassword;
return Scrambler.descramble(nickServPassword);
}

//@Override
public String getPassword() {
return password;
return Scrambler.descramble(password);
}

//@Override
@@ -466,6 +478,7 @@ public String getCharset() {
/**
* Deserialize old descriptors.
*/
@SuppressWarnings("deprecation")
private Object readResolve() {
if (this.defaultTargets == null) {
if (this.channels != null) {
@@ -483,6 +496,13 @@ private Object readResolve() {
this.charset = "UTF-8";
}

if (!this.scrambledPasswords) {
this.password = Scrambler.scramble(this.password);
this.nickServPassword = Scrambler.scramble(this.nickServPassword);
this.scrambledPasswords = true;
save();
}

return this;
}

0 comments on commit cbe23a1

Please sign in to comment.