missed use https in the response of the upnp listener

This commit is contained in:
BWS Systems
2019-07-15 08:38:07 -05:00
parent ff2973e473
commit 53208ddabc
3 changed files with 30 additions and 23 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.bwssystems.HABridge</groupId> <groupId>com.bwssystems.HABridge</groupId>
<artifactId>ha-bridge</artifactId> <artifactId>ha-bridge</artifactId>
<version>5.3.0RC10</version> <version>5.3.0RC11</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HA Bridge</name> <name>HA Bridge</name>

View File

@@ -112,7 +112,7 @@ public class HABridge {
// start the upnp ssdp discovery listener // start the upnp ssdp discovery listener
theUpnpListener = null; theUpnpListener = null;
try { try {
theUpnpListener = new UpnpListener(bridgeSettings.getBridgeSettingsDescriptor(), bridgeSettings.getBridgeControl(), udpSender); theUpnpListener = new UpnpListener(bridgeSettings, bridgeSettings.getBridgeControl(), udpSender);
} catch (IOException e) { } catch (IOException e) {
log.error("Could not initialize UpnpListener, exiting....", e); log.error("Could not initialize UpnpListener, exiting....", e);
theUpnpListener = null; theUpnpListener = null;

View File

@@ -4,7 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.bwssystems.HABridge.BridgeControlDescriptor; import com.bwssystems.HABridge.BridgeControlDescriptor;
import com.bwssystems.HABridge.BridgeSettingsDescriptor; import com.bwssystems.HABridge.BridgeSettings;
import com.bwssystems.HABridge.Configuration; import com.bwssystems.HABridge.Configuration;
import com.bwssystems.HABridge.api.hue.HueConstants; import com.bwssystems.HABridge.api.hue.HueConstants;
import com.bwssystems.HABridge.api.hue.HuePublicConfig; import com.bwssystems.HABridge.api.hue.HuePublicConfig;
@@ -34,13 +34,14 @@ public class UpnpListener {
private BridgeControlDescriptor bridgeControl; private BridgeControlDescriptor bridgeControl;
private String bridgeId; private String bridgeId;
private String bridgeSNUUID; private String bridgeSNUUID;
private String httpType;
private HuePublicConfig aHueConfig; private HuePublicConfig aHueConfig;
private Integer theUpnpSendDelay; private Integer theUpnpSendDelay;
private String responseTemplate1 = "HTTP/1.1 200 OK\r\n" + private String responseTemplate1 = "HTTP/1.1 200 OK\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"HUE-BRIDGEID: %s\r\n" + "HUE-BRIDGEID: %s\r\n" +
"ST: upnp:rootdevice\r\n" + "ST: upnp:rootdevice\r\n" +
@@ -49,7 +50,7 @@ public class UpnpListener {
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"HUE-BRIDGEID: %s\r\n" + "HUE-BRIDGEID: %s\r\n" +
"ST: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n" + "ST: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n" +
@@ -58,7 +59,7 @@ public class UpnpListener {
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"EXT:\r\n" + "EXT:\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"HUE-BRIDGEID: %s\r\n" + "HUE-BRIDGEID: %s\r\n" +
"ST: urn:schemas-upnp-org:device:basic:1\r\n" + "ST: urn:schemas-upnp-org:device:basic:1\r\n" +
@@ -67,7 +68,7 @@ public class UpnpListener {
private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" + private String notifyTemplate1 = "NOTIFY * HTTP/1.1\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"NTS: ssdp:alive\r\n" + "NTS: ssdp:alive\r\n" +
"HUE-BRIDGEID: %s\r\n" + "HUE-BRIDGEID: %s\r\n" +
@@ -77,7 +78,7 @@ public class UpnpListener {
private String notifyTemplate2 = "NOTIFY * HTTP/1.1\r\n" + private String notifyTemplate2 = "NOTIFY * HTTP/1.1\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"NTS: ssdp:alive\r\n" + "HUE-BRIDGEID: %s\r\n" + "NTS: ssdp:alive\r\n" + "HUE-BRIDGEID: %s\r\n" +
"NT: upnp:rootdevice\r\n" + "NT: upnp:rootdevice\r\n" +
@@ -86,30 +87,36 @@ public class UpnpListener {
private String notifyTemplate3 = "NOTIFY * HTTP/1.1\r\n" + private String notifyTemplate3 = "NOTIFY * HTTP/1.1\r\n" +
"HOST: %s:%s\r\n" + "HOST: %s:%s\r\n" +
"CACHE-CONTROL: max-age=100\r\n" + "CACHE-CONTROL: max-age=100\r\n" +
"LOCATION: http://%s:%s/description.xml\r\n" + "LOCATION: %s://%s:%s/description.xml\r\n" +
"SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" + "SERVER: Linux/3.14.0 UPnP/1.0 IpBridge/" + HueConstants.API_VERSION + "\r\n" +
"NTS: ssdp:alive\r\n" + "NTS: ssdp:alive\r\n" +
"HUE-BRIDGEID: %s\r\n" + "HUE-BRIDGEID: %s\r\n" +
"NT: urn:schemas-upnp-org:device:basic:1\r\n" + "NT: urn:schemas-upnp-org:device:basic:1\r\n" +
"USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n"; "USN: uuid:" + HueConstants.UUID_PREFIX + "%s\r\n\r\n";
public UpnpListener(BridgeSettingsDescriptor theSettings, BridgeControlDescriptor theControl, public UpnpListener(BridgeSettings theSettings, BridgeControlDescriptor theControl,
UDPDatagramSender aUdpDatagramSender) throws IOException { UDPDatagramSender aUdpDatagramSender) throws IOException {
super(); super();
theUDPDatagramSender = aUdpDatagramSender; theUDPDatagramSender = aUdpDatagramSender;
upnpMulticastSocket = null; upnpMulticastSocket = null;
httpServerPort = Integer.valueOf(theSettings.getServerPort()); httpServerPort = Integer.valueOf(theSettings.getBridgeSettingsDescriptor().getServerPort());
upnpConfigIP = theSettings.getUpnpConfigAddress(); upnpConfigIP = theSettings.getBridgeSettingsDescriptor().getUpnpConfigAddress();
// strict = theSettings.isUpnpStrict(); // strict = theSettings.isUpnpStrict();
upnpOriginal = theSettings.isUpnporiginal(); upnpOriginal = theSettings.getBridgeSettingsDescriptor().isUpnporiginal();
traceupnp = theSettings.isTraceupnp(); traceupnp = theSettings.getBridgeSettingsDescriptor().isTraceupnp();
useUpnpIface = theSettings.isUseupnpiface(); useUpnpIface = theSettings.getBridgeSettingsDescriptor().isUseupnpiface();
theUpnpSendDelay = theSettings.getUpnpsenddelay(); theUpnpSendDelay = theSettings.getBridgeSettingsDescriptor().getUpnpsenddelay();
bridgeControl = theControl; bridgeControl = theControl;
aHueConfig = HuePublicConfig.createConfig("temp", upnpConfigIP, HueConstants.HUB_VERSION, aHueConfig = HuePublicConfig.createConfig("temp", upnpConfigIP, HueConstants.HUB_VERSION,
theSettings.getHubmac()); theSettings.getBridgeSettingsDescriptor().getHubmac());
bridgeId = aHueConfig.getBridgeid(); bridgeId = aHueConfig.getBridgeid();
bridgeSNUUID = aHueConfig.getSNUUIDFromMac(); bridgeSNUUID = aHueConfig.getSNUUIDFromMac();
if(theSettings.getBridgeSecurity().isUseHttps()) {
httpType = "https";
} else {
httpType = "http";
}
try { try {
if (useUpnpIface) if (useUpnpIface)
upnpMulticastSocket = new MulticastSocket( upnpMulticastSocket = new MulticastSocket(
@@ -321,7 +328,7 @@ public class UpnpListener {
// noop // noop
} }
discoveryResponse = String.format(responseTemplate1, Configuration.UPNP_MULTICAST_ADDRESS, discoveryResponse = String.format(responseTemplate1, httpType, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: send upnp discovery template 1 with response address: " + httpLocationAddress + ":" log.info("Traceupnp: send upnp discovery template 1 with response address: " + httpLocationAddress + ":"
@@ -336,7 +343,7 @@ public class UpnpListener {
} catch (InterruptedException e) { } catch (InterruptedException e) {
// noop // noop
} }
discoveryResponse = String.format(responseTemplate2, Configuration.UPNP_MULTICAST_ADDRESS, discoveryResponse = String.format(responseTemplate2, httpType, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID, Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID,
bridgeSNUUID); bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
@@ -352,7 +359,7 @@ public class UpnpListener {
} catch (InterruptedException e) { } catch (InterruptedException e) {
// noop // noop
} }
discoveryResponse = String.format(responseTemplate3, Configuration.UPNP_MULTICAST_ADDRESS, discoveryResponse = String.format(responseTemplate3, httpType, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, httpLocationAddress, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: send upnp discovery template 3 with response address: " + httpLocationAddress + ":" log.info("Traceupnp: send upnp discovery template 3 with response address: " + httpLocationAddress + ":"
@@ -383,7 +390,7 @@ public class UpnpListener {
// noop // noop
} }
notifyData = String.format(notifyTemplate1, Configuration.UPNP_MULTICAST_ADDRESS, notifyData = String.format(notifyTemplate1, httpType, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: sendUpnpNotify notifyTemplate1"); log.info("Traceupnp: sendUpnpNotify notifyTemplate1");
@@ -397,7 +404,7 @@ public class UpnpListener {
// noop // noop
} }
notifyData = String.format(notifyTemplate2, Configuration.UPNP_MULTICAST_ADDRESS, notifyData = String.format(notifyTemplate2, httpType, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: sendUpnpNotify notifyTemplate2"); log.info("Traceupnp: sendUpnpNotify notifyTemplate2");
@@ -411,7 +418,7 @@ public class UpnpListener {
// noop // noop
} }
notifyData = String.format(notifyTemplate3, Configuration.UPNP_MULTICAST_ADDRESS, notifyData = String.format(notifyTemplate3, httpType, Configuration.UPNP_MULTICAST_ADDRESS,
Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID); Configuration.UPNP_DISCOVERY_PORT, upnpConfigIP, httpServerPort, bridgeId, bridgeSNUUID);
if (traceupnp) { if (traceupnp) {
log.info("Traceupnp: sendUpnpNotify notifyTemplate3"); log.info("Traceupnp: sendUpnpNotify notifyTemplate3");