Update handling of https info on restart if failure

This commit is contained in:
BWS Systems
2019-07-25 13:20:43 -05:00
parent 5c2d30e24b
commit d014240fba
4 changed files with 31 additions and 11 deletions

View File

@@ -376,6 +376,13 @@ public class BridgeSecurity {
return newUser;
}
public void removeHttpsSettings() {
securityDescriptor.setUseHttps(false);
securityDescriptor.setKeyfilePassword(null);
securityDescriptor.setKeyfilePath(null);
setSettingsChanged(true);
}
public void removeTestUsers() {
if (securityDescriptor.getWhitelist() != null) {

View File

@@ -16,7 +16,6 @@ import com.bwssystems.HABridge.util.UDPDatagramSender;
public class HABridge {
private static SystemControl theSystem;
private static boolean secureFailed;
/*
* This program is based on the work of armzilla from this github repository:
@@ -47,7 +46,6 @@ public class HABridge {
HttpClientPool thePool;
ShutdownHook shutdownHook = null;
secureFailed = false;
log.info("HA Bridge startup sequence...");
theVersion = new Version();
// Singleton initialization
@@ -58,7 +56,7 @@ public class HABridge {
while(!bridgeSettings.getBridgeControl().isStop()) {
log.info("HA Bridge (v{}) initializing....", theVersion.getVersion() );
bridgeSettings.buildSettings();
if(bridgeSettings.getBridgeSecurity().isUseHttps() && !secureFailed) {
if(bridgeSettings.getBridgeSecurity().isUseHttps()) {
secure(bridgeSettings.getBridgeSecurity().getKeyfilePath(), bridgeSettings.getBridgeSecurity().getKeyfilePassword(), null, null);
log.info("Using https for web and api calls");
}
@@ -156,13 +154,13 @@ public class HABridge {
private static void theExceptionHandler(Exception e, Integer thePort) {
Logger log = LoggerFactory.getLogger(HABridge.class);
if(e.getMessage().equals("no valid keystore")) {
log.error("Could not start ha-bridge using https webservice on port [{}] due to: {}", thePort, e.getMessage());
secureFailed = true;
theSystem.reinit();
return;
if(e.getMessage().equals("no valid keystore") || e.getMessage().equals("keystore password was incorrect")) {
log.error("Https settings have been removed as {}. Restart system manually after this process exits....", e.getMessage());
log.warn(theSystem.removeHttpsSettings());
}
else {
log.error("Could not start ha-bridge webservice on port [{}] due to: {}", thePort, e.getMessage());
log.warn(theSystem.stop());
}
log.error("Could not start ha-bridge webservice on port [{}] due to: {}", thePort, e.getMessage());
System.exit(0);
}
}

View File

@@ -598,7 +598,12 @@ public class SystemControl {
log.warn("Error pinging listener. " + e.getMessage());
}
}
public String removeHttpsSettings() {
bridgeSettings.getBridgeSecurity().removeHttpsSettings();
return stop();
}
public String reinit() {
bridgeSettings.getBridgeControl().setReinit(true);
pingListener();

View File

@@ -133,6 +133,11 @@ public class UpnpListener {
}
public boolean startListening() {
if (bridgeControl.isReinit() || bridgeControl.isStop()) {
log.warn("UPNP Listener exiting as reinit or stop requested....");
return false;
}
log.info("UPNP Discovery Listener starting....");
Enumeration<NetworkInterface> ifs = null;
@@ -206,6 +211,11 @@ public class UpnpListener {
}
}
if (bridgeControl.isReinit() || bridgeControl.isStop()) {
log.warn("UPNP Listener exiting as reinit or stop requested....");
return false;
}
log.info("UPNP Discovery Listener running and ready....");
boolean loopControl = true;
boolean error = false;