Skip to content

Commit

Permalink
#522: ensure Security/Server object will be used even after a bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jun 14, 2018
1 parent fdc0897 commit 53d854d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Expand Up @@ -15,13 +15,7 @@
*******************************************************************************/
package org.eclipse.leshan.client.object;

import static org.eclipse.leshan.LwM2mId.SEC_BOOTSTRAP;
import static org.eclipse.leshan.LwM2mId.SEC_PUBKEY_IDENTITY;
import static org.eclipse.leshan.LwM2mId.SEC_SECRET_KEY;
import static org.eclipse.leshan.LwM2mId.SEC_SECURITY_MODE;
import static org.eclipse.leshan.LwM2mId.SEC_SERVER_ID;
import static org.eclipse.leshan.LwM2mId.SEC_SERVER_PUBKEY;
import static org.eclipse.leshan.LwM2mId.SEC_SERVER_URI;
import static org.eclipse.leshan.LwM2mId.*;

import org.eclipse.leshan.SecurityMode;
import org.eclipse.leshan.client.resource.BaseInstanceEnabler;
Expand Down Expand Up @@ -51,6 +45,10 @@ public class Security extends BaseInstanceEnabler {

private Integer shortServerId;

public Security() {
// should only be used at bootstrap time
}

public Security(String serverUri, boolean bootstrapServer, int securityMode, byte[] publicKeyOrIdentity,
byte[] serverPublicKey, byte[] secretKey, Integer shortServerId) {
this.serverUri = serverUri;
Expand Down
Expand Up @@ -38,6 +38,10 @@ public class Server extends BaseInstanceEnabler {
private BindingMode binding;
private boolean notifyWhenDisable;

public Server() {
// should only be used at bootstrap time
}

public Server(int shortServerId, long lifetime, BindingMode binding, boolean notifyWhenDisable) {
this.shortServerId = shortServerId;
this.lifetime = lifetime;
Expand Down
Expand Up @@ -218,10 +218,13 @@ public static void createAndStartClient(String endpoint, String localAddress, in
// Initialize object list
ObjectsInitializer initializer = new ObjectsInitializer(new LwM2mModel(models));
if (needBootstrap) {
if (pskIdentity == null)
if (pskIdentity == null) {
initializer.setInstancesForObject(SECURITY, noSecBootstap(serverURI));
else
initializer.setClassForObject(SERVER, Server.class);
} else {
initializer.setInstancesForObject(SECURITY, pskBootstrap(serverURI, pskIdentity, pskKey));
initializer.setClassForObject(SERVER, Server.class);
}
} else {
if (pskIdentity == null) {
initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
Expand Down

0 comments on commit 53d854d

Please sign in to comment.