Feature: do not store the passwrd as plain text but instead use a public key generated on server side

This commit is contained in:
Laurent Clouet
2019-08-22 21:35:26 +02:00
parent e044c35ad7
commit 72462b88c7
7 changed files with 46 additions and 2 deletions

View File

@@ -38,6 +38,8 @@ public interface Gui {
public void AddFrameRendered(); public void AddFrameRendered();
public void successfulAuthenticationEvent(String publickey);
public void setClient(Client cli); public void setClient(Client cli);
public void setComputeMethod(String computeMethod_); public void setComputeMethod(String computeMethod_);

View File

@@ -185,6 +185,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
public Error.Type getConfiguration() { public Error.Type getConfiguration() {
OS os = OS.getOS(); OS os = OS.getOS();
HttpURLConnection connection = null; HttpURLConnection connection = null;
String publickey = null;
try { try {
String url_remote = this.base_url + "/server/config.php"; String url_remote = this.base_url + "/server/config.php";
String parameters = String.format("login=%s&password=%s&cpu_family=%s&cpu_model=%s&cpu_model_name=%s&cpu_cores=%s&os=%s&ram=%s&bits=%s&version=%s&hostname=%s&ui=%s&extras=%s", String parameters = String.format("login=%s&password=%s&cpu_family=%s&cpu_model=%s&cpu_model_name=%s&cpu_cores=%s&os=%s&ram=%s&bits=%s&version=%s&hostname=%s&ui=%s&extras=%s",
@@ -241,6 +242,16 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
} }
config_node = (Element) ns.item(0); config_node = (Element) ns.item(0);
if (config_node.hasAttribute("publickey")) {
publickey = config_node.getAttribute("publickey");
if (publickey.isEmpty()) {
publickey = null;
}
else {
this.user_config.setPassword(publickey);
}
}
ns = config_node.getElementsByTagName("request"); ns = config_node.getElementsByTagName("request");
if (ns.getLength() == 0) { if (ns.getLength() == 0) {
this.log.error("getConfiguration error: failed to parse XML, node 'config' has no child node 'request'"); this.log.error("getConfiguration error: failed to parse XML, node 'config' has no child node 'request'");
@@ -285,6 +296,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
connection.disconnect(); connection.disconnect();
} }
} }
this.client.getGui().successfulAuthenticationEvent(publickey);
return Error.Type.OK; return Error.Type.OK;
} }

View File

@@ -36,12 +36,16 @@ import com.sheepit.client.Configuration;
import com.sheepit.client.Configuration.ComputeType; import com.sheepit.client.Configuration.ComputeType;
import com.sheepit.client.hardware.gpu.GPU; import com.sheepit.client.hardware.gpu.GPU;
import com.sheepit.client.hardware.gpu.GPUDevice; import com.sheepit.client.hardware.gpu.GPUDevice;
import lombok.Setter;
public class SettingsLoader { public class SettingsLoader {
private String path; private String path;
private String login; private String login;
@Setter
private String password; private String password;
private String proxy; private String proxy;
private String hostname; private String hostname;
private String computeMethod; private String computeMethod;

View File

@@ -45,9 +45,11 @@ import javax.swing.border.EmptyBorder;
import com.sheepit.client.Client; import com.sheepit.client.Client;
import com.sheepit.client.Configuration; import com.sheepit.client.Configuration;
import com.sheepit.client.Gui; import com.sheepit.client.Gui;
import com.sheepit.client.SettingsLoader;
import com.sheepit.client.Stats; import com.sheepit.client.Stats;
import com.sheepit.client.standalone.swing.activity.Settings; import com.sheepit.client.standalone.swing.activity.Settings;
import com.sheepit.client.standalone.swing.activity.Working; import com.sheepit.client.standalone.swing.activity.Working;
import lombok.Setter;
public class GuiSwing extends JFrame implements Gui { public class GuiSwing extends JFrame implements Gui {
public static final String type = "swing"; public static final String type = "swing";
@@ -69,6 +71,9 @@ public class GuiSwing extends JFrame implements Gui {
private boolean waitingForAuthentication; private boolean waitingForAuthentication;
private Client client; private Client client;
@Setter
private SettingsLoader settingsLoader;
private ThreadClient threadClient; private ThreadClient threadClient;
public GuiSwing(boolean useSysTray_, String title_) { public GuiSwing(boolean useSysTray_, String title_) {
@@ -223,6 +228,16 @@ public class GuiSwing extends JFrame implements Gui {
return client.getConfiguration(); return client.getConfiguration();
} }
@Override
public void successfulAuthenticationEvent(String publickey) {
if (settingsLoader != null) {
if (publickey != null) {
settingsLoader.setPassword(publickey);
}
settingsLoader.saveFile();
}
}
public void setCredentials(String contentLogin, String contentPassword) { public void setCredentials(String contentLogin, String contentPassword) {
client.getConfiguration().setLogin(contentLogin); client.getConfiguration().setLogin(contentLogin);
client.getConfiguration().setPassword(contentPassword); client.getConfiguration().setPassword(contentPassword);

View File

@@ -145,4 +145,8 @@ public class GuiText implements Gui {
return client; return client;
} }
@Override
public void successfulAuthenticationEvent(String publickey) {
}
} }

View File

@@ -158,6 +158,11 @@ public class GuiTextOneLine implements Gui {
return client; return client;
} }
@Override
public void successfulAuthenticationEvent(String publickey) {
}
private void updateLine() { private void updateLine() {
int charToRemove = line.length(); int charToRemove = line.length();

View File

@@ -619,7 +619,7 @@ public class Settings implements Activity {
} }
if (saveFile.isSelected()) { if (saveFile.isSelected()) {
new SettingsLoader(config.getConfigFilePath(), login.getText(), new String(password.getPassword()), proxyText, hostnameText, method, selected_gpu, cpu_cores, max_ram, max_rendertime, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()).saveFile(); parent.setSettingsLoader(new SettingsLoader(config.getConfigFilePath(), login.getText(), new String(password.getPassword()), proxyText, hostnameText, method, selected_gpu, cpu_cores, max_ram, max_rendertime, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()));
} }
} }
} }