Open ChuckMash opened 2 months ago
Receiving encrypted ESP-NOW messages is now supported, but sending is not yet.
Possibly related to needing AAD/MIC calculation.
AAD/MIC may also benefit validating received encrypted messages.
If the issue is the 8 byte MIC validation, it is made worse by the failing the validation check of received messages.
def callback(from_mac, to_mac, msg):
packet = espnow.packet
nonce = b'\x00'+bytes.fromhex(from_mac.replace(':',''))+struct.pack("BBBBBB",packet.PN5,packet.PN4,packet.PN3,packet.PN2,packet.PN1,packet.PN0)
cipher = AES.new(espnow.key, AES.MODE_CCM, nonce, mac_len=8)
try:
data = cipher.decrypt_and_verify(packet.data[:-8], packet.data[-8:]) # does not validate
print("success")
except Exception as e:
print("Error decrypting:",e)
If a solution is found to calculate MIC and validate correctly for receiving encrypted messages, it will be a big help for generating the MIC for sending encrypted messages.
CCMP documentation suggests the MIC is calculated/validated with AES CBC apart from the message itself encrypted with CCM
Compiled ESP-IDF from source with modified debug and ccmp.c to track through AAD and MIC. Unable to see output of DEBUG statements in ccmp.c.
List of potentially helpful links found so far. This comment will be updated
~ESPythoNOW does not currently support the encryption method optionally used with ESP-NOW.~
According to the documentation