Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/enforce UUID validity #47

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/main/java/ch/hevs/cloudio/endpoint/CloudioEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -602,7 +593,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);
}
Expand Down