|
|
|
@ -59,15 +59,27 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { |
|
|
|
TbLwM2MSecurityInfo tbLwM2MSecurityInfo = JavaSerDesUtil.decode(data); |
|
|
|
if (tbLwM2MSecurityInfo != null) { |
|
|
|
if (SecurityMode.NO_SEC.equals(tbLwM2MSecurityInfo.getSecurityMode())){ |
|
|
|
|
|
|
|
// for tests: redis connect NoSec (securityInfo == null)
|
|
|
|
log.info("lwm2m redis securityStore (decode -ok). Endpoint: [{}], secMode: [NoSec] key: [{}], data [{}]", endpoint, SEC_EP, data); |
|
|
|
|
|
|
|
return SecurityInfo.newPreSharedKeyInfo(SecurityMode.NO_SEC.toString(), SecurityMode.NO_SEC.toString(), |
|
|
|
SecurityMode.NO_SEC.toString().getBytes()); |
|
|
|
} else { |
|
|
|
return tbLwM2MSecurityInfo.getSecurityInfo(); |
|
|
|
} |
|
|
|
} else if (SecurityMode.NO_SEC.equals(getSecurityModeByRegistration (connection, endpoint))){ |
|
|
|
|
|
|
|
// for tests: redis connect NoSec (securityInfo == null)
|
|
|
|
log.info("lwm2m redis securityStore (decode - bad, registration - unsecure). Endpoint: [{}], secMode: [NoSec] key: [{}], data [{}]", endpoint, SEC_EP, data); |
|
|
|
|
|
|
|
return SecurityInfo.newPreSharedKeyInfo(SecurityMode.NO_SEC.toString(), SecurityMode.NO_SEC.toString(), |
|
|
|
SecurityMode.NO_SEC.toString().getBytes()); |
|
|
|
} else { |
|
|
|
|
|
|
|
// for tests: redis connect NoSec (securityInfo == null)
|
|
|
|
log.info("lwm2m redis securityStore (decode - bad, registration is not unsecure) - return null. Endpoint: [{}], key: [{}], data [{}]", endpoint, SEC_EP, data); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -127,6 +139,11 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { |
|
|
|
} |
|
|
|
|
|
|
|
byte[] previousData = connection.getSet((SEC_EP + tbSecurityInfo.getEndpoint()).getBytes(), tbSecurityInfoSerialized); |
|
|
|
|
|
|
|
// for tests: redis connect NoSec (securityInfo == null)
|
|
|
|
log.info("lwm2m redis connect. Endpoint: [{}], secMode: [{}] key: [{}], tbSecurityInfoSerialized [{}]", |
|
|
|
tbSecurityInfo.getEndpoint(), tbSecurityInfo.getSecurityMode().name(), SEC_EP, tbSecurityInfoSerialized); |
|
|
|
|
|
|
|
if (previousData != null && info != null) { |
|
|
|
String previousIdentity = ((TbLwM2MSecurityInfo) JavaSerDesUtil.decode(previousData)).getSecurityInfo().getPskIdentity(); |
|
|
|
if (previousIdentity != null && !previousIdentity.equals(info.getPskIdentity())) { |
|
|
|
@ -191,7 +208,7 @@ public class TbLwM2mRedisSecurityStore implements TbEditableSecurityStore { |
|
|
|
String typeModeStr = registrationNode.get("transportdata").get("identity").get("type").asText(); |
|
|
|
return "unsecure".equals(typeModeStr) ? SecurityMode.NO_SEC : null; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("Redis: Failed get SecurityMode by Registration, endpoint: [{}]", endpoint); |
|
|
|
log.error("Redis: Failed get SecurityMode by Registration, endpoint: [{}]", endpoint, e); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|