@@ -256,7 +256,7 @@ void SensorMesh::sendAlert(const ClientInfo* c, Trigger* t) {
256256 mesh::Utils::sha256 ((uint8_t *)&t->expected_acks [t->attempt ], 4 , data, 5 + text_len, self_id.pub_key , PUB_KEY_SIZE );
257257 t->attempt ++;
258258
259- auto pkt = createDatagram (PAYLOAD_TYPE_TXT_MSG , c->id , c->shared_secret , data, 5 + text_len);
259+ auto pkt = createDatagram (PAYLOAD_TYPE_TXT_MSG , c->id , c->shared_secret , data, 5 + text_len, c-> nextAeadNonce () );
260260 if (pkt) {
261261 if (c->out_path_len != OUT_PATH_UNKNOWN ) { // we have an out_path, so send DIRECT
262262 sendDirect (pkt, c->out_path , c->out_path_len );
@@ -497,6 +497,31 @@ void SensorMesh::getPeerSharedSecret(uint8_t* dest_secret, int peer_idx) {
497497 }
498498}
499499
500+ uint8_t SensorMesh::getPeerFlags (int peer_idx) {
501+ int i = matching_peer_indexes[peer_idx];
502+ if (i >= 0 && i < acl.getNumClients ())
503+ return acl.getClientByIdx (i)->flags ;
504+ return 0 ;
505+ }
506+
507+ uint16_t SensorMesh::getPeerNextAeadNonce (int peer_idx) {
508+ int i = matching_peer_indexes[peer_idx];
509+ if (i >= 0 && i < acl.getNumClients ())
510+ return acl.getClientByIdx (i)->nextAeadNonce ();
511+ return 0 ;
512+ }
513+
514+ void SensorMesh::onPeerAeadDetected (int peer_idx) {
515+ int i = matching_peer_indexes[peer_idx];
516+ if (i >= 0 && i < acl.getNumClients ()) {
517+ auto c = acl.getClientByIdx (i);
518+ if (!(c->flags & CONTACT_FLAG_AEAD )) {
519+ c->flags |= CONTACT_FLAG_AEAD ;
520+ getRNG ()->random ((uint8_t *)&c->aead_nonce , sizeof (c->aead_nonce ));
521+ }
522+ }
523+ }
524+
500525void SensorMesh::sendAckTo (const ClientInfo& dest, uint32_t ack_hash, uint8_t path_hash_size) {
501526 if (dest.out_path_len == OUT_PATH_UNKNOWN ) {
502527 mesh::Packet* ack = createAck (ack_hash);
@@ -537,10 +562,10 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
537562 if (packet->isRouteFlood ()) {
538563 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
539564 mesh::Packet* path = createPathReturn (from->id , secret, packet->path , packet->path_len ,
540- PAYLOAD_TYPE_RESPONSE , reply_data, reply_len);
565+ PAYLOAD_TYPE_RESPONSE , reply_data, reply_len, from-> nextAeadNonce () );
541566 if (path) sendFlood (path, SERVER_RESPONSE_DELAY , packet->getPathHashSize ());
542567 } else {
543- mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE , from->id , secret, reply_data, reply_len);
568+ mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE , from->id , secret, reply_data, reply_len, from-> nextAeadNonce () );
544569 if (reply) {
545570 if (from->out_path_len != OUT_PATH_UNKNOWN ) { // we have an out_path, so send DIRECT
546571 sendDirect (reply, from->out_path , from->out_path_len , SERVER_RESPONSE_DELAY );
@@ -567,7 +592,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
567592 if (packet->isRouteFlood ()) {
568593 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the ACK
569594 mesh::Packet* path = createPathReturn (from->id , secret, packet->path , packet->path_len ,
570- PAYLOAD_TYPE_ACK , (uint8_t *) &ack_hash, 4 );
595+ PAYLOAD_TYPE_ACK , (uint8_t *) &ack_hash, 4 , from-> nextAeadNonce () );
571596 if (path) sendFlood (path, TXT_ACK_DELAY , packet->getPathHashSize ());
572597 } else {
573598 sendAckTo (*from, ack_hash, packet->getPathHashSize ());
@@ -595,7 +620,7 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
595620 memcpy (temp, ×tamp, 4 ); // mostly an extra blob to help make packet_hash unique
596621 temp[4 ] = (TXT_TYPE_CLI_DATA << 2 );
597622
598- auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , from->id , secret, temp, 5 + text_len);
623+ auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG , from->id , secret, temp, 5 + text_len, from-> nextAeadNonce () );
599624 if (reply) {
600625 if (from->out_path_len == OUT_PATH_UNKNOWN ) {
601626 sendFlood (reply, CLI_REPLY_DELAY_MILLIS , packet->getPathHashSize ());
0 commit comments