ReadRequest request = new ReadRequest(contentFormat, target); ReadResponse cResponse = server.send(registration, request, TIMEOUT); processDeviceResponse(req, resp, cResponse);
@Override public String getIdentity(InetSocketAddress inetAddress) { if (inetAddress == null) return null; LwM2mObject securities = (LwM2mObject) securityEnabler.read(SYSTEM, new ReadRequest(SECURITY)).getContent(); for (LwM2mObjectInstance security : securities.getInstances().values()) { long securityMode = (long) security.getResource(SEC_SECURITY_MODE).getValue(); if (securityMode == SecurityMode.PSK.code) { try { URI uri = new URI((String) security.getResource(SEC_SERVER_URI).getValue()); if (inetAddress.equals(ServerInfo.getAddress(uri))) { byte[] pskIdentity = (byte[]) security.getResource(SEC_PUBKEY_IDENTITY).getValue(); return new String(pskIdentity); } } catch (URISyntaxException e) { LOG.error(String.format("Invalid URI %s", (String) security.getResource(SEC_SERVER_URI).getValue()), e); } } } return null; }
@Override public byte[] getKey(String identity) { if (identity == null) return null; byte[] res = null; LwM2mObject securities = (LwM2mObject) securityEnabler.read(SYSTEM, new ReadRequest(SECURITY)).getContent(); for (LwM2mObjectInstance security : securities.getInstances().values()) { long securityMode = (long) security.getResource(SEC_SECURITY_MODE).getValue(); if (securityMode == SecurityMode.PSK.code) // psk { byte[] pskIdentity = (byte[]) security.getResource(SEC_PUBKEY_IDENTITY).getValue(); if (Arrays.equals(identity.getBytes(), pskIdentity)) { if (res == null) { // we continue to check if the is duplication res = (byte[]) security.getResource(SEC_SECRET_KEY).getValue(); } else { LOG.warn("There is several security object instance with the same psk identity : '{}'", identity); // we find 1 duplication and warn for it no need to continue. return res; } } } } return res; }
protected ObserveResponse doObserve(ServerIdentity identity, ObserveRequest request) { ReadResponse readResponse = this.read(identity, new ReadRequest(request.getPath().toString())); return new ObserveResponse(readResponse.getCode(), readResponse.getContent(), null, null, readResponse.getErrorMessage()); }
LwM2mObject securities = (LwM2mObject) securityEnabler.read(SYSTEM, new ReadRequest(SECURITY)).getContent(); LwM2mObject servers = (LwM2mObject) serverEnabler.read(SYSTEM, new ReadRequest(SERVER)).getContent();
return new ReadRequest(ContentFormat.fromCode(format), path);
return new ReadRequest(ContentFormat.fromCode(format), path);
ReadRequest readRequest = new ReadRequest(URI); ReadResponse response = nodeEnabler.read(identity, readRequest); if (response.getCode() == org.eclipse.leshan.ResponseCode.CONTENT) {