Changed certificates to be specific not only to host but also to port.
Rewrote settings dialog to verify settings in a more sane way.
This commit is contained in:
@ -152,6 +152,14 @@ public class Settings extends RegisteredFrame{
|
|||||||
populateSettings();
|
populateSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVisible(boolean isVisible){
|
||||||
|
if (isVisible){
|
||||||
|
populateSettings();
|
||||||
|
}
|
||||||
|
super.setVisible(isVisible);
|
||||||
|
}
|
||||||
|
|
||||||
private void populateSettings(){
|
private void populateSettings(){
|
||||||
textFieldRouterIP.setText(_conf.getConf("server.hostname", "127.0.0.1"));
|
textFieldRouterIP.setText(_conf.getConf("server.hostname", "127.0.0.1"));
|
||||||
textFieldRouterPort.setText(_conf.getConf("server.port", 7560)+"");
|
textFieldRouterPort.setText(_conf.getConf("server.port", 7560)+"");
|
||||||
@ -160,15 +168,14 @@ public class Settings extends RegisteredFrame{
|
|||||||
|
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
private int saveSettings(){
|
private int saveSettings(){
|
||||||
boolean newSettings = false;
|
String oldIP = _conf.getConf("server.hostname", "127.0.0.1");
|
||||||
|
int oldPort = _conf.getConf("server.port", 7560);
|
||||||
|
String oldPW = _conf.getConf("server.password", "itoopie");
|
||||||
|
|
||||||
|
|
||||||
String ipText = textFieldRouterIP.getText();
|
String ipText = textFieldRouterIP.getText();
|
||||||
if (!ipText.equals(_conf.getConf("server.hostname", "127.0.0.1"))){
|
|
||||||
System.out.println("Password changed: \""+_conf.getConf("server.hostname","127.0.0.1")+"\"->\"" + ipText + "\"");
|
|
||||||
try {
|
try {
|
||||||
InetAddress.getByName(ipText);
|
InetAddress.getByName(ipText);
|
||||||
newSettings = true;
|
|
||||||
_conf.setConf("server.hostname", ipText);
|
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
JOptionPane.showConfirmDialog(
|
JOptionPane.showConfirmDialog(
|
||||||
this,
|
this,
|
||||||
@ -179,17 +186,13 @@ public class Settings extends RegisteredFrame{
|
|||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return SAVE_ERROR;
|
return SAVE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String portText = textFieldRouterPort.getText();
|
String portText = textFieldRouterPort.getText();
|
||||||
if (!portText.equals(_conf.getConf("server.port",7560)+"")){
|
int port = 0;
|
||||||
System.out.println("Password changed: \""+_conf.getConf("server.port",7560)+"\"->\"" + portText + "\"");
|
|
||||||
try {
|
try {
|
||||||
int nbr = Integer.parseInt(portText);
|
port = Integer.parseInt(portText);
|
||||||
if (nbr > 65535 || nbr <= 0)
|
if (port > 65535 || port <= 0)
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
newSettings = true;
|
|
||||||
_conf.setConf("server.port", nbr);
|
|
||||||
} catch (NumberFormatException e){
|
} catch (NumberFormatException e){
|
||||||
JOptionPane.showConfirmDialog(
|
JOptionPane.showConfirmDialog(
|
||||||
this,
|
this,
|
||||||
@ -200,28 +203,27 @@ public class Settings extends RegisteredFrame{
|
|||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return SAVE_ERROR;
|
return SAVE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String pwText = new String(passwordField.getPassword());
|
String pwText = new String(passwordField.getPassword());
|
||||||
String oldPW = _conf.getConf("server.password", "itoopie");
|
|
||||||
if (!pwText.equals(oldPW)){
|
|
||||||
try {
|
try {
|
||||||
System.out.println("Password changed: \""+oldPW+"\"->\"" + pwText + "\"");
|
_conf.setConf("server.hostname", ipText);
|
||||||
|
_conf.setConf("server.port", port);
|
||||||
_conf.setConf("server.password", pwText);
|
_conf.setConf("server.password", pwText);
|
||||||
JSONRPC2Interface.testSettings();
|
JSONRPC2Interface.testSettings();
|
||||||
newSettings = true;
|
|
||||||
} catch (InvalidPasswordException e) {
|
} catch (InvalidPasswordException e) {
|
||||||
_conf.setConf("server.password", oldPW);
|
_conf.setConf("server.password", oldPW);
|
||||||
JOptionPane.showConfirmDialog(
|
JOptionPane.showConfirmDialog(
|
||||||
this,
|
this,
|
||||||
Transl._("The password was not accepted as valid by the specified host.\r\n" +
|
Transl._("The password was not accepted as valid by the specified host.\r\n" +
|
||||||
"\r\nPassword was reset to the default password, \"itoopie\"."),
|
"\r\n(by default the password is, \"itoopie\")"),
|
||||||
Transl._("Rejected password."),
|
Transl._("Rejected password."),
|
||||||
JOptionPane.DEFAULT_OPTION,
|
JOptionPane.DEFAULT_OPTION,
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return SAVE_ERROR;
|
return SAVE_ERROR;
|
||||||
} catch (JSONRPC2SessionException e) {
|
} catch (JSONRPC2SessionException e) {
|
||||||
e.printStackTrace();
|
_conf.setConf("server.hostname", oldIP);
|
||||||
|
_conf.setConf("server.port", oldPort);
|
||||||
|
_conf.setConf("server.password", oldPW);
|
||||||
JOptionPane.showConfirmDialog(
|
JOptionPane.showConfirmDialog(
|
||||||
this,
|
this,
|
||||||
Transl._("The remote host at the ip and port did not respond.\r\n" +
|
Transl._("The remote host at the ip and port did not respond.\r\n" +
|
||||||
@ -232,17 +234,30 @@ public class Settings extends RegisteredFrame{
|
|||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return SAVE_ERROR;
|
return SAVE_ERROR;
|
||||||
}
|
}
|
||||||
}
|
_conf.setConf("server.hostname", ipText);
|
||||||
if (newSettings){
|
_conf.setConf("server.port", port);
|
||||||
|
_conf.setConf("server.password", pwText);
|
||||||
|
|
||||||
|
System.out.println("Ip old->new: \""+_conf.getConf("server.hostname","127.0.0.1")+"\"->\"" + ipText + "\"");
|
||||||
|
System.out.println("Port old->new: \""+_conf.getConf("server.port",7560)+"\"->\"" + portText + "\"");
|
||||||
|
System.out.println("Password old->new: \""+oldPW+"\"->\"" + pwText + "\"");
|
||||||
|
|
||||||
StatusHandler.setStatus("Settings saved");
|
StatusHandler.setStatus("Settings saved");
|
||||||
|
|
||||||
(new Thread() {
|
(new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
_conf.writeConfFile();
|
_conf.writeConfFile();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
|
||||||
return SAVE_OK;
|
return SAVE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to signify that a setting was not accepted.
|
||||||
|
* @author hottuna
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private class BadSettingsException extends Exception{ }
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public class CertificateHelper {
|
|||||||
return new HostnameVerifier(){
|
return new HostnameVerifier(){
|
||||||
|
|
||||||
public boolean verify(String urlHostName, SSLSession session) {
|
public boolean verify(String urlHostName, SSLSession session) {
|
||||||
String serverHost = session.getPeerHost();
|
String serverHost = session.getPeerHost() + ":" + session.getPeerPort();
|
||||||
try {
|
try {
|
||||||
javax.security.cert.X509Certificate[] certs = session.getPeerCertificateChain();
|
javax.security.cert.X509Certificate[] certs = session.getPeerCertificateChain();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user