fix
This commit is contained in:
@ -110,7 +110,7 @@ void deinitConfig(t_configHandle *configHandle) {
|
||||
|
||||
t_device *findDevice(t_configHandle *configHandle, char *deviceId) {
|
||||
for (uint16_t i = 0; i < configHandle->numOfDevices; i++) {
|
||||
if (! strcmp(configHandle->devices[i].deviceId, deviceId)) {
|
||||
if (! strncmp(configHandle->devices[i].deviceId, deviceId, strlen(configHandle->devices[i].deviceId))) {
|
||||
return &(configHandle->devices[i]);
|
||||
}
|
||||
}
|
||||
@ -165,11 +165,15 @@ int receiveAndVerifyMinuteBuffer(t_receiverHandle *handle, t_minuteBuffer *buf)
|
||||
((cliaddr.sin_addr.s_addr >> 24) & 0x0ff));
|
||||
|
||||
if (n != sizeof(buf->b)) {
|
||||
logmsg(LOG_INFO, "Illegal packet size: %d", n);
|
||||
logmsg(LOG_ERR, "Illegal packet size: %d", n);
|
||||
return -1;
|
||||
}
|
||||
|
||||
t_device *device = findDevice(handle->configHandle, buf->s.deviceId);
|
||||
if (device == NULL) {
|
||||
logmsg(LOG_ERR, "unknown device");
|
||||
return -7;
|
||||
}
|
||||
const char *sharedSecret = device->sharedSecret;
|
||||
|
||||
uint8_t receivedHash[SHA256_BLOCK_SIZE];
|
||||
@ -183,7 +187,7 @@ int receiveAndVerifyMinuteBuffer(t_receiverHandle *handle, t_minuteBuffer *buf)
|
||||
sha256_final(&ctx, calculatedHash);
|
||||
|
||||
if (memcmp(receivedHash, calculatedHash, SHA256_BLOCK_SIZE) != 0) {
|
||||
logmsg(LOG_INFO, "Invalid hash in msg for device %s", buf->s.deviceId);
|
||||
logmsg(LOG_ERR, "Invalid hash in msg for device %s", buf->s.deviceId);
|
||||
return -5;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user