Skip to content

Commit

Permalink
BootstrapServer: add validation about path to delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 30, 2021
1 parent 227f129 commit 0c03682
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.util.SecurityUtil;
import org.eclipse.leshan.core.util.StringUtils;
import org.eclipse.leshan.server.bootstrap.BootstrapConfig.ServerSecurity;
Expand All @@ -43,6 +45,9 @@ public class ConfigurationChecker {
* @throws InvalidConfigurationException if bootstrap configuration is not invalid.
*/
public void verify(BootstrapConfig config) throws InvalidConfigurationException {
// validate path
validatePath(config.toDelete);

// check security configurations
for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> e : config.security.entrySet()) {
BootstrapConfig.ServerSecurity sec = e.getValue();
Expand Down Expand Up @@ -111,6 +116,17 @@ protected void checkX509(ServerSecurity sec) throws InvalidConfigurationExceptio
"x509 mode, server public key must be DER encoded X.509 certificate");
}

protected void validatePath(List<String> pathtoDelete) throws InvalidConfigurationException {
for (String path : pathtoDelete) {
try {
new LwM2mPath(path);
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException(String.format(" %s is not a valid path", path), e);
}
}

}

protected void validateMandatoryField(ServerSecurity sec) throws InvalidConfigurationException {
// checks mandatory fields
if (StringUtils.isEmpty(sec.uri))
Expand Down

0 comments on commit 0c03682

Please sign in to comment.