# Pritunl Wireguard connection configurations (public key lifetime)

**URL:** <https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761>\
**Category:** Pritunl VPN\
**Tags:** pritunl\
**Created:** [January 30, 2024, 8:02am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761 "2024-01-30T08:02:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [January 30, 2024, 8:02am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/1 "2024-01-30T08:02:21Z")

</div>

Hi team.  
I am using Pritunl Enterprise and connecting the servers to the Pritunl VPN using a Wireguard connection. And as luck would have it, the Wireguard key expires at inopportune moments (for example, when I restore a database from a backup via VPN)  
I looked through all Wireguard settings in the Pritunl Web UI and couldn’t find a setting for the public key lifetime for Wiregurad.  
Would it make sense to add settings for wireguard in the Web interface?

Can I turn off the lifetime for the Wireguard public key altogether?

I found in configuration file parameter ‘wg\_public\_key\_ttl’: 604800

> <https://github.com/pritunl/pritunl/blob/master/pritunl/settings/app.py#L67>

And sometimes Pritunl will update the key in less than the specified time. Can you tell me why?  
Correct me if I’m wrong, but I read that there is some kind of limit on the number of files that can be transferred via Wireguard connection. Is it possible that because of this, the key for wireguard connection can be reissued earlier? If yes, how can I increase this parameter?

Many thanks!

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [January 30, 2024, 11:11am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/2 "2024-01-30T11:11:42Z")

</div>

Pritunl has a lot of authentication methods that are expected to be enforced on every user connection. WireGuard uses a connection-less design that would have broken this requirement. To fix this in the Pritunl implementation a new WireGuard key is generated for every connection and the client sends keepalive requests. If requests are not received for a few minutes the key is removed. There is more information in the [**WireGuard**](https://docs.pritunl.com/docs/wireguard) documentation section.

The `wg_public_key_ttl` set by `sudo pritunl set app.wg_public_key_ttl 604800` sets the maximum time that a WireGuard connection can exist, which defaults to 7 days. Changing this requires restarting at least one host to update the MongoDB index. I will increase this default to 90 days in the next release. There’s currently nothing that removes the unused documents before the expiration so there has to be an expiration but it could be significantly higher for most use cases.

---

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [January 30, 2024, 11:37am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/3 "2024-01-30T11:37:36Z")

</div>

Thanks for your reply. If we look at the user logs from the Pritunl server, we can see that in most cases the keys are updated after 7 days, but in some cases it triggers earlier. In the pritunl server and pritunl client logs there is a wireguard key re-acquisition. Why does it happen earlier than 7 days?  
Could this be due to [Transport Message Limits](https://www.wireguard.com/papers/wireguard.pdf)?  
If so, how do you set it up to be as big as possible?

Many thanks!

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [January 30, 2024, 12:10pm UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/4 "2024-01-30T12:10:39Z")

</div>

If the device goes to sleep or something disrupts the connection that will create a new connection with a new key.

---

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [January 30, 2024, 1:12pm UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/5 "2024-01-30T13:12:29Z")

</div>

Thanks for reply. This sometimes happens when I restore a database from a backup via a Wireguard connection.  
This means that the server could not have fallen asleep during the files transferring.  
The size of databases sometimes exceeds 10 Gb.  
Could this affect reconnections to Pritunl?

Are there any file transfer size limits at all through Pritunl VPN server using Wireguard?

Or for Wireguard, is the restriction only on public key time? (what can be a connection failure until the client is authorized with a new key?)

Many thanks!

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [January 30, 2024, 2:02pm UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/6 "2024-01-30T14:02:51Z")

</div>

The service logs on the client would show any failure in the keep alive for the Pritunl connection management. There’s nothing related to data sent that should cause a connection to be dropped. The document you linked is referencing a data channel key similar to the Diffie–Hellman key exchange used in OpenVPN, that mechanism would not expire or effect the key that is stored in Pritunl to authenticate the connection.

---

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [January 31, 2024, 9:45am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/7 "2024-01-31T09:45:58Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [January 31, 2024, 3:10pm UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/8 "2024-01-31T15:10:49Z")

</div>

@zach  
here is logs from pritunl-client

[2024-01-31 14:10:38][INFO] ▶ profile: Connecting ◆ device\_auth=false ◆ disable\_dns=false ◆ disable\_gateway=false ◆ dynamic\_firewall=false ◆ force\_dns=false ◆ mode=“wg” ◆ profile\_id=“iocruraomhld2lmf” ◆ reconnect=true ◆ sso\_auth=false  
[2024-01-31 14:10:57][INFO] ▶ profile: Reconnecting ◆ profile\_id=“iocruraomhld2lmf”  
[2024-01-31 14:10:57][INFO] ▶ profile: Disconnected ◆ profile\_id=“iocruraomhld2lmf”  
[2024-01-31 14:10:57][INFO] ▶ profile: Connecting ◆ device\_auth=false ◆ disable\_dns=false ◆ disable\_gateway=false ◆ dynamic\_firewall=false ◆ force\_dns=false ◆ mode=“wg” ◆ profile\_id=“iocruraomhld2lmf” ◆ reconnect=true ◆ sso\_auth=false

And user Audit from pritunl server

 ![Selection_535](https://forum-static.pritunl.com/original/1X/31d9f239e31bb9e99b968cbb383f412eee168cc0.png)

Do you have any idea why this is happening?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [February 1, 2024, 3:39am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/9 "2024-02-01T03:39:18Z")

</div>

That is from a handshake timeout. Once the connection is authenticated the client will watch `sudo wg show $WG_INTERFACE_NAME latest-handshakes` for 15 seconds for a successful handshake in WireGuard. If it doesn’t occur in 15 seconds the connection is restarted.

---

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [February 1, 2024, 7:33am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/10 "2024-02-01T07:33:33Z")

</div>

@zach thanks for your reply.  
Could you please tell me can we increase this value?  
If yes, how?

In general, is there any documentation that describes what parameters should be applied (enable, disable, increase) so that there are no gaps (reconnections)?

We have a problem with that. Sometimes it is necessary to restore PostgreSQL database via Pritunl VPN (Wireguard type). As the database is not small, it can take about 1–2 hours of time. Sometimes it breaks (reconnects) after 40–50 minutes when it is almost over.  
Maybe you can give us recommendations?

Anyway, thanks a lot!

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [February 2, 2024, 6:11pm UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/11 "2024-02-02T18:11:32Z")

</div>

This is the code in [**pritunl-client-electron/service/profile/profile.go**](https://github.com/pritunl/pritunl-client-electron/blob/master/service/profile/profile.go#L3744) where the error occurs. It is hard coded for 30 iterations with a 0.5 second delay. After you connect to the server quickly run `sudo wg show $WG_INTERFACE_NAME latest-handshakes` and check for any issues with the output. I haven’t seen this issue occur and it’s unlikely it would take more than 15 seconds if it were going to work at all.

I did do a few large tests over WireGuard to look for any limitations on total data sent. A 2 TB iperf between a Fedora client and Oracle Linux 8 server didn’t have any issues.

You need to check the service logs for other errors, the handshake timeout mentioned above is only for the connection. It’s possible the network traffic is slowing the ping checks to the server, the timeout which is only a 6 second timeout on the request. It is retried 4 times with a 1 second delay between each attempt before restarting the connection. This would show `profile: Keepalive failed` in the logs.

I will look into adding options to change the timeouts. If it’s a Linux client you can modify timeouts in the code and manually run it with the commands below.

```auto
go install github.com/pritunl/pritunl-client-electron/service@latest
cd ~/go/pkg/mod/github.com/pritunl/pritunl-client-electron@*/service
nano profile/profile.go
# edit Timeout: 6 * time.Second in clientInsecure
go build -v
sudo systemctl stop pritunl-client
sudo ./service

```

---

<div class="post-metadata">

**Author:** ![StanislavRud](https://forum.pritunl.com/user_avatar/forum.pritunl.com/stanislavrud/32/721_2.png) [@StanislavRud](https://forum.pritunl.com/u/StanislavRud)\
**Post date:** [February 5, 2024, 9:05am UTC](https://forum.pritunl.com/t/pritunl-wireguard-connection-configurations-public-key-lifetime/1761/12 "2024-02-05T09:05:06Z")

</div>

@zach Thanks a lot!
