UART encryption

ferrero
Posts: 12
Joined: Tue Nov 05, 2024 3:11 am

UART encryption

Postby ferrero » Tue Nov 26, 2024 7:45 am

Is it possible to encrypt data coming through UART, such as AT commands and data using ESD-IDF or some Espressif lib?

ferrero
Posts: 12
Joined: Tue Nov 05, 2024 3:11 am

Re: UART encryption

Postby ferrero » Wed Dec 04, 2024 5:47 am

I tried using encryption in the at_port_read_data and at_port_write_data functions. The recording function works properly, it correctly encrypts data from the *buffer and sends it further. However, the reading function works strangely. Even with decryption disabled, when you try to read a buffer with data, the previous request is always there. At the same time, the requests themselves are executed successfully, as can be seen in the logs. Maybe the logging function works in a special way, which is why it does not read data from the buffer correctly.
Anyway, when I try to enable decryption of incoming data, for some reason it breaks, apparently due to the addition of the decryption process...
Maybe someone knows the features of working with the at_port_read_data function, how to correctly interpret and modify data from it

  1. FIRST REQUEST AFTER BOOT-------------------------------------
  2. V (24926)[RX]: MESSAGE NUM:3, LENGHT:13
  3. I (24926) [RX]: DECRYPTED DATA AT at_port_read_data:           <------- AT REQUEST SHOULD BE HERE
  4.  
  5. V (24926)[TX]: MESSAGE NUM:3, LENGHT:13
  6. I (24929) [TX]: DECRYPTED DATA AT at_port_write_data: AT+CWSTATE?
  7. I (24936) [TX]: START ENCRYPT PROCCES
  8. I (24941) [TX]: ENCRYPTED DATA AT LEN: 0d 00
  9. I (24945) [TX]: ENCRYPTED DATA AT CRC16ENCRYPT: 18 e5
  10. I (24951) [TX]: ENCRYPTED DATA AT CRC16DECRYPT: b3 a9
  11. I (24957) [TX]: ENCRYPTED DATA AT NONCE: 8b c2 d2 28 49 5d 8f 6e bf 16 5e b8
  12. I (24965) [TX]: ENCRYPT PROCCES RES:0
  13. I (24969) [TX]: ENCRYPTED DATA AT at_port_write_data: aa 0d 00 18 e5 b3 a9 8b c2 d2 28 49 5d 8f 6e bf
  14. I (24979) [TX]: ENCRYPTED DATA AT at_port_write_data: 16 5e b8 63 04 28 e7 14 f1 57 13 0f 67 55 1e c0
  15.  
  16. V (24990)[TX]: MESSAGE NUM:4, LENGHT:15
  17. I (24994) [TX]: DECRYPTED DATA AT at_port_write_data: +CWSTATE:0,""
  18. I (25001) [TX]: START ENCRYPT PROCCES
  19. I (25005) [TX]: ENCRYPTED DATA AT LEN: 0f 00
  20. I (25010) [TX]: ENCRYPTED DATA AT CRC16ENCRYPT: 95 6c
  21. I (25016) [TX]: ENCRYPTED DATA AT CRC16DECRYPT: 58 48
  22. I (25022) [TX]: ENCRYPTED DATA AT NONCE: e7 19 27 98 e7 1e ea b2 cd cc 1c ef
  23. I (25029) [TX]: ENCRYPT PROCCES RES:0
  24. I (25034) [TX]: ENCRYPTED DATA AT at_port_write_data: aa 0f 00 95 6c 58 48 e7 19 27 98 e7 1e ea b2 cd
  25. I (25044) [TX]: ENCRYPTED DATA AT at_port_write_data: cc 1c ef 1c 4f a1 99 46 f9 5b 3a 05 89 90 fd 38
  26. I (25054) [TX]: ENCRYPTED DATA AT at_port_write_data: 93 44
  27.  
  28. V (25061)[TX]: MESSAGE NUM:5, LENGHT:6
  29. I (25065) [TX]: DECRYPTED DATA AT at_port_write_data: OK
  30. I (25071) [TX]: START ENCRYPT PROCCES
  31. I (25076) [TX]: ENCRYPTED DATA AT LEN: 06 00
  32. I (25080) [TX]: ENCRYPTED DATA AT CRC16ENCRYPT: 5f c9
  33. I (25086) [TX]: ENCRYPTED DATA AT CRC16DECRYPT: c5 86
  34. I (25092) [TX]: ENCRYPTED DATA AT NONCE: 3d 38 da fd 52 8c a0 4c cd 1b fc c9
  35. I (25100) [TX]: ENCRYPT PROCCES RES:0
  36. I (25105) [TX]: ENCRYPTED DATA AT at_port_write_data: aa 06 00 5f c9 c5 86 3d 38 da fd 52 8c a0 4c cd
  37. I (25116) [TX]: ENCRYPTED DATA AT at_port_write_data: 1b fc c9 70 aa 62 b4 d6 b6
  38. SECOND REQUEST------------------------------------
  39. V (44052)[RX]: MESSAGE NUM:4, LENGHT:6
  40. I (44052) [RX]: DECRYPTED DATA AT at_port_read_data: AT+CWS  <----- WIERD PREV REQUEST DATA
  41.  
  42. [b]V (44053)[TX]: MESSAGE NUM:6, LENGHT:6[/b]
  43. I (44056) [TX]: DECRYPTED DATA AT at_port_write_data: ATE1
  44. I (44062) [TX]: START ENCRYPT PROCCES
  45. I (44067) [TX]: ENCRYPTED DATA AT LEN: 06 00
  46. I (44071) [TX]: ENCRYPTED DATA AT CRC16ENCRYPT: 63 21
  47. I (44077) [TX]: ENCRYPTED DATA AT CRC16DECRYPT: ce 4a
  48. I (44083) [TX]: ENCRYPTED DATA AT NONCE: 93 d7 9d 0a d6 1f 66 a5 9a 33 37 6d
  49. I (44091) [TX]: ENCRYPT PROCCES RES:0
  50. I (44095) [TX]: ENCRYPTED DATA AT at_port_write_data: aa 06 00 63 21 ce 4a 93 d7 9d 0a d6 1f 66 a5 9a
  51. I (44105) [TX]: ENCRYPTED DATA AT at_port_write_data: 33 37 6d 26 2e 38 f3 68 85
  52.  
  53. V (44114)[TX]: MESSAGE NUM:7, LENGHT:6
  54. I (44118) [TX]: DECRYPTED DATA AT at_port_write_data: OK
  55. I (44124) [TX]: START ENCRYPT PROCCES
  56. I (44129) [TX]: ENCRYPTED DATA AT LEN: 06 00
  57. I (44133) [TX]: ENCRYPTED DATA AT CRC16ENCRYPT: 6a 66
  58. I (44139) [TX]: ENCRYPTED DATA AT CRC16DECRYPT: c5 86
  59. I (44145) [TX]: ENCRYPTED DATA AT NONCE: a5 f8 95 94 3d e3 a2 58 1a 9e cc 95
  60. I (44153) [TX]: ENCRYPT PROCCES RES:0
  61. I (44157) [TX]: ENCRYPTED DATA AT at_port_write_data: aa 06 00 6a 66 c5 86 a5 f8 95 94 3d e3 a2 58 1a
  62. I (44167) [TX]: ENCRYPTED DATA AT at_port_write_data: 9e cc 95 b4 fa ee 08 80 ca

ferrero
Posts: 12
Joined: Tue Nov 05, 2024 3:11 am

Re: UART encryption

Postby ferrero » Wed Dec 04, 2024 7:33 am

The problem was solved.
I placed the encryption and data processing processes in the at_port_read_data function before executing read_fn, but it was necessary after.
Encryption now works properly

Who is online

Users browsing this forum: No registered users and 22 guests