Skip to content

Commit 45ca14b

Browse files
fix: don't check wg peer key format if it's empty #581
1 parent e98f4cf commit 45ca14b

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/WireGuardPeer.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class WireGuardPeer extends Model {
9494
*/
9595
public function validate_presharedkey(string $presharedkey): string {
9696
# Throw an error if this value is not a valid WireGuard key
97-
if (!wg_is_valid_key($presharedkey)) {
97+
if ($presharedkey and !wg_is_valid_key($presharedkey)) {
9898
throw new ValidationError(
9999
message: 'Field `presharedkey` must be a valid WireGuard pre-shared key.',
100100
response_id: 'WIREGUARD_PEER_PRESHAREDKEY_INVALID',

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsWireGuardPeerTestCase.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ class APIModelsWireGuardPeerTestCase extends TestCase {
5050
$peer->validate();
5151
},
5252
);
53+
54+
# Ensure empty PSK does not throw an error
55+
$this->assert_does_not_throw(
56+
callable: function () {
57+
$peer = new WireGuardPeer(publickey: 'KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=', presharedkey: '');
58+
$peer->validate();
59+
},
60+
);
5361
}
5462

5563
/**

0 commit comments

Comments
 (0)