@@ -506,7 +506,7 @@ bool MyMesh::filterRecvFloodPacket(mesh::Packet* pkt) {
506506}
507507
508508void MyMesh::onAnonDataRecv (mesh::Packet *packet, const uint8_t *secret, const mesh::Identity &sender,
509- uint8_t *data, size_t len) {
509+ uint8_t *data, size_t len, bool was_ascon ) {
510510 if (packet->getPayloadType () == PAYLOAD_TYPE_ANON_REQ) { // received an initial request by a possible admin
511511 // client (unknown at this stage)
512512 uint32_t timestamp;
@@ -530,16 +530,17 @@ void MyMesh::onAnonDataRecv(mesh::Packet *packet, const uint8_t *secret, const m
530530
531531 if (reply_len == 0 ) return ; // invalid request
532532
533+ // Reply with same encryption the sender used
533534 if (packet->isRouteFlood ()) {
534535 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
535536 mesh::Packet* path = createPathReturn (sender, secret, packet->path , packet->path_len ,
536- PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
537+ PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, was_ascon );
537538 if (path) sendFlood (path, SERVER_RESPONSE_DELAY);
538539 } else if (reply_path_len < 0 ) {
539- mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
540+ mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, was_ascon );
540541 if (reply) sendFlood (reply, SERVER_RESPONSE_DELAY);
541542 } else {
542- mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len);
543+ mesh::Packet* reply = createDatagram (PAYLOAD_TYPE_RESPONSE, sender, secret, reply_data, reply_len, was_ascon );
543544 if (reply) sendDirect (reply, reply_path, reply_path_len, SERVER_RESPONSE_DELAY);
544545 }
545546 }
@@ -565,6 +566,17 @@ void MyMesh::getPeerSharedSecret(uint8_t *dest_secret, int peer_idx) {
565566 }
566567}
567568
569+ void MyMesh::onPeerAsconCapabilityDetected (int peer_idx, bool supports_ascon) {
570+ int i = matching_peer_indexes[peer_idx];
571+ if (i >= 0 && i < acl.getNumClients ()) {
572+ auto client = acl.getClientByIdx (i);
573+ if (supports_ascon && !client->supports_ascon ) {
574+ client->supports_ascon = true ;
575+ MESH_DEBUG_PRINTLN (" Auto-detected Ascon capability for client %d" , i);
576+ }
577+ }
578+ }
579+
568580static bool isShare (const mesh::Packet *packet) {
569581 if (packet->hasTransportCodes ()) {
570582 return packet->transport_codes [0 ] == 0 && packet->transport_codes [1 ] == 0 ; // codes { 0, 0 } means 'send to nowhere'
@@ -576,11 +588,19 @@ void MyMesh::onAdvertRecv(mesh::Packet *packet, const mesh::Identity &id, uint32
576588 const uint8_t *app_data, size_t app_data_len) {
577589 mesh::Mesh::onAdvertRecv (packet, id, timestamp, app_data, app_data_len); // chain to super impl
578590
579- // if this a zero hop advert (and not via 'Share'), add it to neighbours
580- if (packet->path_len == 0 && !isShare (packet)) {
581- AdvertDataParser parser (app_data, app_data_len);
582- if (parser.isValid () && parser.getType () == ADV_TYPE_REPEATER) { // just keep neigbouring Repeaters
583- putNeighbour (id, timestamp, packet->getSNR ());
591+ AdvertDataParser parser (app_data, app_data_len);
592+ if (parser.isValid ()) {
593+ // Update Ascon encryption capability for known clients (chat nodes that are in our ACL)
594+ ClientInfo* client = acl.getClient (id.pub_key , PUB_KEY_SIZE);
595+ if (client) {
596+ client->supports_ascon = (parser.getFeat1 () & ADV_FEAT1_ASCON_CAPABLE) != 0 ;
597+ }
598+
599+ // if this a zero hop advert (and not via 'Share'), add it to neighbours
600+ if (packet->path_len == 0 && !isShare (packet)) {
601+ if (parser.getType () == ADV_TYPE_REPEATER) { // just keep neigbouring Repeaters
602+ putNeighbour (id, timestamp, packet->getSNR ());
603+ }
584604 }
585605 }
586606}
@@ -608,11 +628,11 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
608628 if (packet->isRouteFlood ()) {
609629 // let this sender know path TO here, so they can use sendDirect(), and ALSO encode the response
610630 mesh::Packet *path = createPathReturn (client->id , secret, packet->path , packet->path_len ,
611- PAYLOAD_TYPE_RESPONSE, reply_data, reply_len);
631+ PAYLOAD_TYPE_RESPONSE, reply_data, reply_len, client-> supports_ascon );
612632 if (path) sendFlood (path, SERVER_RESPONSE_DELAY);
613633 } else {
614634 mesh::Packet *reply =
615- createDatagram (PAYLOAD_TYPE_RESPONSE, client->id , secret, reply_data, reply_len);
635+ createDatagram (PAYLOAD_TYPE_RESPONSE, client->id , secret, reply_data, reply_len, client-> supports_ascon );
616636 if (reply) {
617637 if (client->out_path_len >= 0 ) { // we have an out_path, so send DIRECT
618638 sendDirect (reply, client->out_path , client->out_path_len , SERVER_RESPONSE_DELAY);
@@ -673,7 +693,7 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
673693 memcpy (temp, ×tamp, 4 ); // mostly an extra blob to help make packet_hash unique
674694 temp[4 ] = (TXT_TYPE_CLI_DATA << 2 ); // NOTE: legacy was: TXT_TYPE_PLAIN
675695
676- auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG, client->id , secret, temp, 5 + text_len);
696+ auto reply = createDatagram (PAYLOAD_TYPE_TXT_MSG, client->id , secret, temp, 5 + text_len, client-> supports_ascon );
677697 if (reply) {
678698 if (client->out_path_len < 0 ) {
679699 sendFlood (reply, CLI_REPLY_DELAY_MILLIS);
0 commit comments