This commit is contained in:
Wolfgang Hottgenroth
2021-03-08 15:19:01 +01:00
parent 03ae897425
commit 0759475be8

View File

@ -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;
}