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 successfulAuthenticationEvent(String publickey);
public void setClient(Client cli);
public void setComputeMethod(String computeMethod_);

View File

@@ -185,6 +185,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
public Error.Type getConfiguration() {
OS os = OS.getOS();
HttpURLConnection connection = null;
String publickey = null;
try {
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",
@@ -241,6 +242,16 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
}
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");
if (ns.getLength() == 0) {
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();
}
}
this.client.getGui().successfulAuthenticationEvent(publickey);
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.hardware.gpu.GPU;
import com.sheepit.client.hardware.gpu.GPUDevice;
import lombok.Setter;
public class SettingsLoader {
private String path;
private String login;
@Setter
private String password;
private String proxy;
private String hostname;
private String computeMethod;

View File

@@ -45,13 +45,15 @@ import javax.swing.border.EmptyBorder;
import com.sheepit.client.Client;
import com.sheepit.client.Configuration;
import com.sheepit.client.Gui;
import com.sheepit.client.SettingsLoader;
import com.sheepit.client.Stats;
import com.sheepit.client.standalone.swing.activity.Settings;
import com.sheepit.client.standalone.swing.activity.Working;
import lombok.Setter;
public class GuiSwing extends JFrame implements Gui {
public static final String type = "swing";
public enum ActivityType {
WORKING, SETTINGS
}
@@ -68,6 +70,9 @@ public class GuiSwing extends JFrame implements Gui {
private boolean waitingForAuthentication;
private Client client;
@Setter
private SettingsLoader settingsLoader;
private ThreadClient threadClient;
@@ -222,6 +227,16 @@ public class GuiSwing extends JFrame implements Gui {
public Configuration 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) {
client.getConfiguration().setLogin(contentLogin);

View File

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

View File

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

View File

@@ -619,7 +619,7 @@ public class Settings implements Activity {
}
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()));
}
}
}