Skip to content

Commit

Permalink
Fix unwanted warning when creating server without secure CoAP endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jul 2, 2019
1 parent 91d30d1 commit d0de9db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,19 @@ public BootstrapHandler create(BootstrapConfigStore store, LwM2mBootstrapRequest

// handle dtlsConfig
DtlsConnectorConfig dtlsConfig = null;
if (!noSecuredEndpoint) {
if (!noSecuredEndpoint && shouldTryToCreateSecureEndpoint()) {
if (dtlsConfigBuilder == null) {
dtlsConfigBuilder = new DtlsConnectorConfig.Builder();
}
// Set default DTLS setting for Leshan unless user change it.
DtlsConnectorConfig incompleteConfig = dtlsConfigBuilder.getIncompleteConfig();

// Handle PSK Store
if (incompleteConfig.getPskStore() == null && securityStore != null) {
dtlsConfigBuilder.setPskStore(new LwM2mBootstrapPskStore(securityStore));
} else {
if (incompleteConfig.getPskStore() != null) {
LOG.warn(
"PskStore should be automatically set by Leshan. Using a custom implementation is not advised.");
} else if (securityStore != null) {
dtlsConfigBuilder.setPskStore(new LwM2mBootstrapPskStore(securityStore));
}

// Handle secure address
Expand Down Expand Up @@ -538,6 +539,14 @@ public BootstrapHandler create(BootstrapConfigStore store, LwM2mBootstrapRequest
bootstrapHandlerFactory, model, coapConfig);
}

/**
* @return true if we should try to create a secure endpoint on {@link #build()}
*/
protected boolean shouldTryToCreateSecureEndpoint() {
return dtlsConfigBuilder != null || certificateChain != null || privateKey != null || publicKey != null
|| securityStore != null || trustedCertificates != null;
}

/**
* Create the <code>LeshanBootstrapServer</code>.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,19 @@ public LeshanServer build() {

// handle dtlsConfig
DtlsConnectorConfig dtlsConfig = null;
if (!noSecuredEndpoint) {
if (!noSecuredEndpoint && shouldTryToCreateSecureEndpoint()) {
if (dtlsConfigBuilder == null) {
dtlsConfigBuilder = new DtlsConnectorConfig.Builder();
}
// set default DTLS setting for Leshan unless user change it.
// Set default DTLS setting for Leshan unless user change it.
DtlsConnectorConfig incompleteConfig = dtlsConfigBuilder.getIncompleteConfig();

// Handle PSK Store
if (incompleteConfig.getPskStore() == null && securityStore != null) {
dtlsConfigBuilder.setPskStore(new LwM2mPskStore(this.securityStore, registrationStore));
} else {
if (incompleteConfig.getPskStore() != null) {
LOG.warn(
"PskStore should be automatically set by Leshan. Using a custom implementation is not advised.");
} else if (securityStore != null) {
dtlsConfigBuilder.setPskStore(new LwM2mPskStore(this.securityStore, registrationStore));
}

// Handle secure address
Expand Down Expand Up @@ -516,4 +517,12 @@ public LeshanServer build() {
return new LeshanServer(unsecuredEndpoint, securedEndpoint, registrationStore, securityStore, authorizer,
modelProvider, encoder, decoder, coapConfig, noQueueMode, awakeTimeProvider, registrationIdProvider);
}

/**
* @return true if we should try to create a secure endpoint on {@link #build()}
*/
protected boolean shouldTryToCreateSecureEndpoint() {
return dtlsConfigBuilder != null || certificateChain != null || privateKey != null || publicKey != null
|| securityStore != null || trustedCertificates != null;
}
}

0 comments on commit d0de9db

Please sign in to comment.