Skip to content

Commit 1c22a8d

Browse files
committed
[fix] Add missing full_clean() to VPN server auto-cert creation
AbstractVpn._auto_create_cert() was saving the server certificate without calling full_clean(), bypassing Django model validation. The client-side equivalent in AbstractVpnClient._auto_create_cert() correctly calls full_clean() before save(). Also delete any stale certificate with the same common name and CA before creating a new one, to avoid unique constraint violations when the VPN backend is changed (e.g. from WireGuard back to OpenVPN).
1 parent d60ec13 commit 1c22a8d

File tree

1 file changed

+5
-0
lines changed
  • openwisp_controller/config/base

1 file changed

+5
-0
lines changed

openwisp_controller/config/base/vpn.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ def _auto_create_cert(self):
417417
{"name": "nsCertType", "value": "server", "critical": False}
418418
]
419419
cert_model = self.__class__.cert.field.related_model
420+
# Delete any existing certificate with the same common name and CA
421+
# to avoid unique constraint violations when the VPN backend is
422+
# changed (e.g. from WireGuard back to OpenVPN).
423+
cert_model.objects.filter(common_name=common_name, ca=self.ca).delete()
420424
cert = cert_model(
421425
name=self.name,
422426
ca=self.ca,
@@ -431,6 +435,7 @@ def _auto_create_cert(self):
431435
extensions=server_extensions,
432436
)
433437
cert = self._auto_create_cert_extra(cert)
438+
cert.full_clean()
434439
cert.save()
435440
return cert
436441

0 commit comments

Comments
 (0)