Skip to content
Permalink
Browse files
[FIXED JENKINS-4000] , [FIXED JENKINS-4002] encrypt proxy password
Proxy password is encrypted in xml config file, and in the UI
  • Loading branch information
bap2000 committed May 21, 2011
1 parent 78c709e commit c4d9fe8e0707330d1d59d6f30a3a2e32b36a88c0
@@ -27,6 +27,7 @@
import hudson.model.Saveable;
import hudson.model.listeners.SaveableListener;
import hudson.util.Scrambler;
import hudson.util.Secret;
import hudson.util.XStream2;

import java.io.File;
@@ -59,10 +60,17 @@
public final int port;

/**
* Possibly null proxy user name and password.
* Password is base64 scrambled since this is persisted to disk.
* Possibly null proxy user name.
*/
private final String userName,password;
private final String userName;
/**
* null
*/
private String password;
/**
* encrypted password
*/
private Secret secretPassword;

public ProxyConfiguration(String name, int port) {
this(name,port,null,null);
@@ -72,15 +80,24 @@ public ProxyConfiguration(String name, int port, String userName, String passwor
this.name = name;
this.port = port;
this.userName = userName;
this.password = Scrambler.scramble(password);
this.secretPassword = Secret.fromString(password);
}

public String getUserName() {
return userName;
}

// This method is public, if it was public only for jelly, then should make it private (or inline contents)
// Have left public, as can't tell if anyone else is using from plugins
/**
* @return the password in plain text
*/
public String getPassword() {
return Scrambler.descramble(password);
return Secret.toString(secretPassword);
}

public String getEncryptedPassword() {
return (secretPassword == null) ? null : secretPassword.getEncryptedValue();
}

public Proxy createProxy() {
@@ -94,6 +111,13 @@ public void save() throws IOException {
SaveableListener.fireOnChange(this, config);
}

public Object readResolve() {
if (secretPassword == null)
secretPassword = Secret.fromString(Scrambler.descramble(password));
password = null;
return this;
}

public static XmlFile getXmlFile() {
return new XmlFile(XSTREAM, new File(Hudson.getInstance().getRootDir(), "proxy.xml"));
}
@@ -48,7 +48,7 @@ THE SOFTWARE.
<f:textbox name="proxy.userName" value="${app.proxy.userName}" />
</f:entry>
<f:entry title="${%Password}">
<f:password name="proxy.password" value="${app.proxy.password}" />
<f:password name="proxy.password" value="${app.proxy.encryptedPassword}" />
</f:entry>
<f:block>
<f:submit value="${%Submit}" />

0 comments on commit c4d9fe8

Please sign in to comment.