Skip to content

Commit

Permalink
fix NPE in BootstrapSecurityStore of bsserver-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jul 26, 2016
1 parent defadcf commit 6081674
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public SecurityInfo getByIdentity(String identity) {
byte[] identityBytes = identity.getBytes(Charsets.UTF_8);
for (Map.Entry<String, BootstrapConfig> e : bsStore.getBootstrapConfigs().entrySet()) {
BootstrapConfig bsConfig = e.getValue();
for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> ec : bsConfig.security.entrySet()) {
ServerSecurity serverSecurity = ec.getValue();
if (serverSecurity.bootstrapServer && serverSecurity.securityMode == SecurityMode.PSK
&& Arrays.equals(serverSecurity.publicKeyOrId, identityBytes)) {
return SecurityInfo.newPreSharedKeyInfo(e.getKey(), identity, serverSecurity.secretKey);
if (bsConfig.security != null) {
for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> ec : bsConfig.security.entrySet()) {
ServerSecurity serverSecurity = ec.getValue();
if (serverSecurity.bootstrapServer && serverSecurity.securityMode == SecurityMode.PSK
&& Arrays.equals(serverSecurity.publicKeyOrId, identityBytes)) {
return SecurityInfo.newPreSharedKeyInfo(e.getKey(), identity, serverSecurity.secretKey);
}
}
}
}
Expand All @@ -58,12 +60,15 @@ public List<SecurityInfo> getAllByEndpoint(String endpoint) {

BootstrapConfig bsConfig = bsStore.getBootstrap(endpoint);

if (bsConfig.security == null)
return null;

for (Map.Entry<Integer, BootstrapConfig.ServerSecurity> e : bsConfig.security.entrySet()) {
ServerSecurity value = e.getValue();
if (value.bootstrapServer && value.securityMode == SecurityMode.PSK) {
// got it!
SecurityInfo securityInfo = SecurityInfo.newPreSharedKeyInfo(endpoint, new String(value.publicKeyOrId,
Charsets.UTF_8), value.secretKey);
SecurityInfo securityInfo = SecurityInfo.newPreSharedKeyInfo(endpoint,
new String(value.publicKeyOrId, Charsets.UTF_8), value.secretKey);
return Arrays.asList(securityInfo);
}
}
Expand Down

0 comments on commit 6081674

Please sign in to comment.