Skip to content

Commit 4a17dcf

Browse files
committed
wireguard: T7246: verify base64 encorded 32byte boundary on keys
It's probably wisest to ignore differences between public keys and private keys and set aside any structure they might have by virtue of being related to elliptic curves, and instead just regard them as 32-byte strings encoded in base64. Not 31 bytes or 33 bytes, but exactly 32. This matters, because 32 does not divide evenly by .75, so there's a padding character and the penultimate character does not include the whole base64 alphabet. 43 base64 chars can represent up to 258bits, which is more than 256bits. So, you can either validate this with a base64 parser and checking that it returns exactly 32 bytes, or you can match against this simple regex: ^[A-Za-z0-9+/]{42}[A|E|I|M|Q|U|Y|c|g|k|o|s|w|4|8|0]=$ Source: https://lists.zx2c4.com/pipermail/wireguard/2020-December/006222.html
1 parent 95af915 commit 4a17dcf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- include start from constraint/wireguard-keys.xml.i -->
2+
<regex>[A-Za-z0-9+/]{42}[A|E|I|M|Q|U|Y|c|g|k|o|s|w|4|8|0]=</regex>
3+
<!-- include end -->

interface-definitions/interfaces_wireguard.xml.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<properties>
5858
<help>Base64 encoded private key</help>
5959
<constraint>
60-
<validator name="base64"/>
60+
#include <include/constraint/wireguard-keys.xml.i>
6161
</constraint>
6262
<constraintErrorMessage>Key is not base64-encoded</constraintErrorMessage>
6363
</properties>
@@ -77,7 +77,7 @@
7777
<properties>
7878
<help>base64 encoded public key</help>
7979
<constraint>
80-
<validator name="base64"/>
80+
#include <include/constraint/wireguard-keys.xml.i>
8181
</constraint>
8282
<constraintErrorMessage>Key is not base64-encoded</constraintErrorMessage>
8383
</properties>
@@ -86,7 +86,7 @@
8686
<properties>
8787
<help>base64 encoded preshared key</help>
8888
<constraint>
89-
<validator name="base64"/>
89+
#include <include/constraint/wireguard-keys.xml.i>
9090
</constraint>
9191
<constraintErrorMessage>Key is not base64-encoded</constraintErrorMessage>
9292
</properties>

0 commit comments

Comments
 (0)