Skip to content

Commit

Permalink
Fix client side : create right server identity type in EndpointsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 17, 2019
1 parent f315c66 commit b365633
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.leshan.client.servers.EndpointsManager;
import org.eclipse.leshan.client.servers.Server;
import org.eclipse.leshan.client.servers.ServerInfo;
import org.eclipse.leshan.core.californium.EndpointContextUtil;
import org.eclipse.leshan.core.californium.EndpointFactory;
import org.eclipse.leshan.core.request.Identity;
import org.slf4j.Logger;
Expand Down Expand Up @@ -88,6 +89,7 @@ public synchronized Server createEndpoint(ServerInfo serverInfo) {
if (serverInfo.secureMode == SecurityMode.PSK) {
StaticPskStore staticPskStore = new StaticPskStore(serverInfo.pskId, serverInfo.pskKey);
newBuilder.setPskStore(staticPskStore);
serverIdentity = Identity.psk(serverInfo.getAddress(), serverInfo.pskId);
} else if (serverInfo.secureMode == SecurityMode.RPK) {
// set identity
newBuilder.setIdentity(serverInfo.privateKey, serverInfo.publicKey);
Expand All @@ -110,6 +112,7 @@ public boolean isTrusted(RawPublicKeyIdentity id) {
return true;
}
});
serverIdentity = Identity.rpk(serverInfo.getAddress(), expectedKey);
} else if (serverInfo.secureMode == SecurityMode.X509) {
// set identity
newBuilder.setIdentity(serverInfo.privateKey, new Certificate[] { serverInfo.clientCertificate },
Expand Down Expand Up @@ -155,7 +158,10 @@ public boolean isTrusted(RawPublicKeyIdentity id) {
return false;
}
});

serverIdentity = Identity.x509(serverInfo.getAddress(), EndpointContextUtil
.extractCN(((X509Certificate) expectedServerCertificate).getSubjectX500Principal().getName()));
} else {
throw new RuntimeException("Unable to create connector : unsupported security mode");
}
if (endpointFactory != null) {
currentEndpoint = endpointFactory.createSecuredEndpoint(newBuilder.build(), coapConfig, null);
Expand All @@ -165,7 +171,6 @@ public boolean isTrusted(RawPublicKeyIdentity id) {
builder.setNetworkConfig(coapConfig);
currentEndpoint = builder.build();
}
serverIdentity = Identity.psk(serverInfo.getAddress(), serverInfo.pskId);
} else {
if (endpointFactory != null) {
currentEndpoint = endpointFactory.createUnsecuredEndpoint(localAddress, coapConfig, null);
Expand Down

0 comments on commit b365633

Please sign in to comment.