Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Save passwords scrambled [JENKINS-13706]
  • Loading branch information
kutzi committed Jun 3, 2012
1 parent 967f956 commit cbe23a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -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>

Expand Down
28 changes: 24 additions & 4 deletions src/main/java/hudson/plugins/ircbot/IrcPublisher.java
Expand Up @@ -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;
Expand Down Expand Up @@ -169,6 +170,13 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>
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
Expand Down Expand Up @@ -213,13 +221,17 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>
*/
@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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -466,6 +478,7 @@ public String getCharset() {
/**
* Deserialize old descriptors.
*/
@SuppressWarnings("deprecation")
private Object readResolve() {
if (this.defaultTargets == null) {
if (this.channels != null) {
Expand All @@ -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;
}

Expand Down

0 comments on commit cbe23a1

Please sign in to comment.