fix some things

This commit is contained in:
Cyberes 2024-07-03 19:01:19 -06:00
parent 09602b2745
commit 8fae0cd5db
4 changed files with 16 additions and 14 deletions

View File

@ -271,7 +271,7 @@ bool TeleClientUDP::notify(byte event, const char* payload)
#if SERVER_ENCRYPTION_ENABLE == 1
unsigned int encrypted_len;
unsigned char* encrypted_buf = encrypt_buffer(netbuf.buffer(), netbuf.length(), &encrypted_len);
bool cell_send = cell.send((const char *)encrypted_buf, sizeof(encrypted_buf));
bool cell_send = cell.send((const char *)encrypted_buf, encrypted_len);
free(encrypted_buf);
if (!cell_send) break;
#else

View File

@ -87,8 +87,6 @@ void decrypt_string(const unsigned char *input, size_t length, unsigned char *ou
return;
}
///// END TAG VERIFY
output[decryptedLength] = '\0';
chachaPoly.clear();
}

View File

@ -62,6 +62,12 @@ PID_POLLING_INFO obdData[]= {
{PID_TIMING_ADVANCE, 2},
{PID_COOLANT_TEMP, 3},
{PID_INTAKE_TEMP, 3},
{PID_ODOMETER, 3},
{PID_DISTANCE, 3},
{PID_AMBIENT_TEMP, 2},
{PID_ENGINE_OIL_TEMP, 2},
{PID_FUEL_LEVEL, 1}
};
CBufferManager bufman;
@ -1009,7 +1015,7 @@ void telemetry(void* inst)
#if SERVER_ENCRYPTION_ENABLE == 1
unsigned int encrypted_len;
unsigned char* encrypted_buf = encrypt_buffer(store.buffer(), store.length(), &encrypted_len);
bool transmit_success = teleClient.transmit((const char *)encrypted_buf, sizeof(encrypted_buf));
bool transmit_success = teleClient.transmit((const char *)encrypted_buf, encrypted_len);
free(encrypted_buf);
if (transmit_success) {
#else

View File

@ -86,23 +86,21 @@ func main() {
go func(addr *net.UDPAddr, buf []byte, n int) {
var plaintext []byte
shouldEncrypt := true
if len(buf[:n]) > 0 {
plaintext, err = encryption.Decrypt(key, buf[:n]) // Use only the part of the buffer that has data.
recievedContent := buf[:n]
if len(recievedContent) > 0 {
plaintext, err = encryption.Decrypt(key, recievedContent) // Use only the part of the buffer that has data.
if err != nil {
rawHex := hex.EncodeToString(buf[:n])
logger.Warningf(formatLogMsg(addr.IP.String(), dest.Address, dest.Port, fmt.Sprintf(`Error decrypting message: %s. Length: %d, Raw: "%s"`, err, len(rawHex), rawHex)))
plaintext = buf[:n] // Don't bother with decryption.
logger.Warningf(formatLogMsg(addr.IP.String(), dest.Address, dest.Port, fmt.Sprintf(`Error decrypting message: %s. Length: %d, Raw: "%s"`, err, len(recievedContent), recievedContent)))
plaintext = recievedContent // Don't bother with decryption.
shouldEncrypt = false
if len(buf[:n]) > 0 {
logger.Warningln("Encryption failed, possibly recieved unencrypted message")
}
} else {
logger.Infof(formatLogMsg(addr.IP.String(), dest.Address, dest.Port, string(plaintext)))
}
} else {
// If empty message.
plaintext = buf[:n]
plaintext = recievedContent
shouldEncrypt = false
}
logger.Infof(formatLogMsg(addr.IP.String(), dest.Address, dest.Port, string(plaintext)))
forwardAddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", dest.Address, dest.Port))
if err != nil {