From 1b5db5396eda6ae8651e802857c83b8bdc17d2aa Mon Sep 17 00:00:00 2001 From: Michael Clausen Date: Mon, 11 Jan 2021 10:25:29 +0100 Subject: [PATCH 1/2] Using effective UUID to load client certificate and key --- src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java b/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java index 3de8d23..75fe741 100755 --- a/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java +++ b/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java @@ -602,7 +602,7 @@ public InternalEndpoint(String uuidOrAppName, CloudioEndpointConfiguration confi // Create a SSL based MQTT option object. options = new MqttConnectOptions(); try { - options.setSocketFactory(createSocketFactory(uuidOrAppName, configuration)); + options.setSocketFactory(createSocketFactory(uuid, configuration)); } catch (Exception exception) { throw new CloudioEndpointInitializationException(exception); } From 684f464e8c5d8e09d0b1b449c5e637fb6861084d Mon Sep 17 00:00:00 2001 From: Michael Clausen Date: Mon, 11 Jan 2021 11:56:23 +0100 Subject: [PATCH 2/2] Check that endpoint uuid is corrext formatted UUID --- .../hevs/cloudio/endpoint/CloudioEndpoint.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java b/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java index 75fe741..9801db5 100755 --- a/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java +++ b/src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.security.KeyStore; import java.util.*; +import java.util.regex.Pattern; /** * An Endpoint is the root object of any connection of a device or a gateway to cloud.io. The parameters of the @@ -466,14 +467,6 @@ class InternalEndpoint implements CloudioNodeContainer, MqttCallback, Runnable, private static final String PERSISTENCE_MQTT_LOG = "cloudioPersistenceLog"; private static final String PERSISTENCE_MQTT_LIFECYCLE = "cloudioPersistenceLifecycle"; - /** - * Characters prohibited in the UUID. - * - * This list of characters will prevent using separator or wildcard characters for most uses - * (messaging, databases, filesystems, ...). - */ - private static final String UUID_INVALID_CHARS = "./#*+\\\r\n?\"\0',:;<>"; - /*** Attributes ***********************************************************************************************/ private final String uuid; private final String version = "v0.2"; @@ -526,11 +519,9 @@ public InternalEndpoint(String uuidOrAppName, CloudioEndpointConfiguration confi // Set the UUID. uuid = configuration.getProperty(UUID_PROPERTY, uuidOrAppName); - // Verify the UUID will be valid - for (char c : UUID_INVALID_CHARS.toCharArray()) { - if (uuid.contains(""+c)) { - throw new InvalidUuidException(String.format("uuid(value:'%s') contains the invalid char 'UTF+%04X'", uuid, (int)c)); - } + // Verify the UUID is valid + if (!Pattern.matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", uuid)) { + throw new InvalidUuidException(String.format("uuid(value:'%s') is not a valid UUID", uuid)); } persistenceFile = uuid+"-persistence.db";