luci: luci-proto-wireguard: incorrect peer name detection when more than one peer with the same public key exist

If an OpenWrt device is used as a Wireguard client (i.e. no “listen port” is defined for the interface) it is allowed to define more than one peer with the same public key. In such case the peer name in Status → WireGuard menu might not be detected correctly because the code will only compare the public key of a peer and take the first match. To fix the issue it is required to check not only the public key of a peer, but also its endpoint_host and endpoint_port.


Possible solution (doesn’t work with FQDNs - see comments below):

Replace line 79 in luci/protocols/luci-proto-wireguard/root/usr/share/rpcd/ucode/luci.wireguard file:

if (s.public_key == record[1])

with the following:

if (s.public_key == record[1] && s.endpoint_host + ":" + s.endpoint_port == record[3])

The solution is tested and works if the endpoint_host is an IP address. ~I didn’t test it if the endpoint_host is an FQDN-name.~ UPD: Tested FQDN - doesn’t work. See comments below.

Steps to reproduce:

  1. Go to: Network → Interfaces → add a new WireGuard interface. The interface should not contain listen port, i.e. act as a client. Fill all other parameters (private key, ip address) with correct values.
  2. Add a fake peer on the Peers tab with name Incorrect peer 1; set Disabled property true; fill Public key with a real public key value (see further); endpoint host and port with random values.
  3. Optional. Add another fake Peer with the same parameters, but different name, e.x. Incorrect peer 2.
  4. Add a real peer with the same public key (i.e. all peers must have the same public key from the real one) with name Correct peer; set Disabled property false; fill endpoint host and port with correct values.
  5. The order of peers is critical, i.e. create fake peers first and the real one last.
  6. Save and apply.
  7. Set the new Wireguard interface up and running (i.e. connect to the real peer).
  8. Go to Status → WireGuard page.
  9. Observe the issue: the page will show Peer: Incorrect peer 1 and all other parameters from the real peer.

Actual behavior:

The Status → WireGuard page shows incorrect peer name with all other correct parameters.

Expected behavior:

The Status → WireGuard page shows correct peer name and all other correct parameters.

Additional Information:

Doesn’t matter, but here it is:

DISTRIB_ID='OpenWrt'
DISTRIB_RELEASE='SNAPSHOT'
DISTRIB_REVISION='r27859-f9da81d32f'
DISTRIB_TARGET='mediatek/filogic'
DISTRIB_ARCH='aarch64_cortex-a53'
DISTRIB_DESCRIPTION='OpenWrt SNAPSHOT r27859-f9da81d32f'
DISTRIB_TAINTS='no-all'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

@systemcrash , thank you for all the advices and help! 😃