Skip to content

Commit

Permalink
Merge branch 'prevent-upgrade'
Browse files Browse the repository at this point in the history
  • Loading branch information
osm committed Sep 30, 2024
2 parents 2e305c2 + daf4cb0 commit b07d76d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Line wrap the file at 100 chars. Th
* **Fixed**: for any bug fixes.
* **Security**: in case of vulnerabilities.

## [1.0.4] - 2024-10-01
### Changed
- Prevent upgrading an already upgraded tunnel.


## [1.0.3] - 2024-07-04
### Changed
Expand Down
2 changes: 2 additions & 0 deletions cmd/mullvad-upgrade-tunnel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func main() {
if err := wgephemeralpeer.Connect(*iface, kems...); err != nil {
if err == context.DeadlineExceeded {
fmt.Fprintf(os.Stderr, "unable to connect to relay, ensure you are able to connect to 10.64.0.1 on TCP port 1337\n")
} else if err == wgephemeralpeer.ErrPeerAlreadyUpgraded {
fmt.Fprintf(os.Stderr, "unable to upgrade tunnel, %v\n", err)
} else {
fmt.Fprintf(os.Stderr, "unable to connect ephemeral peer, %v\n", err)
}
Expand Down
8 changes: 8 additions & 0 deletions wg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
var (
ErrDeviceDoesNotExist = errors.New("device does not exist")
ErrInvalidNumberOfPeers = errors.New("invalid number of peers")
ErrPeerAlreadyUpgraded = errors.New("peer has already been upgraded")
)

func (ep *ephemeralPeer) getPublicKey(iface string) (*wgtypes.Key, error) {
Expand All @@ -28,6 +29,13 @@ func (ep *ephemeralPeer) getPublicKey(iface string) (*wgtypes.Key, error) {
return nil, err
}

var zeroKey wgtypes.Key
for _, p := range device.Peers {
if p.PresharedKey != zeroKey {
return nil, ErrPeerAlreadyUpgraded
}
}

publicKey := device.PrivateKey.PublicKey()
return &publicKey, nil
}
Expand Down

0 comments on commit b07d76d

Please sign in to comment.