summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2025-03-20 22:05:04 +0100
committerGitHub <noreply@github.com>2025-03-20 22:05:04 +0100
commitf2d427bd6b2a2a39d6eb086dd0abdfa099b78cdd (patch)
tree89fa2eb4d29ed11892934ae8fc859a011f55cd94 /src
parent7eec4583bf7feb900fad02e009b9ded11b52fd5d (diff)
parent8021bdd62e4142caf4a5e82000c8ca3da99fcae4 (diff)
downloadvyos-1x-f2d427bd6b2a2a39d6eb086dd0abdfa099b78cdd.tar.gz
vyos-1x-f2d427bd6b2a2a39d6eb086dd0abdfa099b78cdd.zip
Merge pull request #4402 from c-po/wireguard-key-T7246
wireguard: T7246: verify Base64 encoded 32byte boundary on keys
Diffstat (limited to 'src')
-rwxr-xr-xsrc/validators/base6422
1 files changed, 13 insertions, 9 deletions
diff --git a/src/validators/base64 b/src/validators/base64
index e2b1e730d..a54168ef7 100755
--- a/src/validators/base64
+++ b/src/validators/base64
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2021 VyOS maintainers and contributors
+# Copyright (C) 2021-2025 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -15,13 +15,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
-from sys import argv
+import argparse
-if __name__ == '__main__':
- if len(argv) != 2:
- exit(1)
- try:
- base64.b64decode(argv[1])
- except:
+parser = argparse.ArgumentParser(description="Validate base64 input.")
+parser.add_argument("base64", help="Base64 encoded string to validate")
+parser.add_argument("--decoded-len", type=int, help="Optional list of valid lengths for the decoded input")
+args = parser.parse_args()
+
+try:
+ decoded = base64.b64decode(args.base64)
+ if args.decoded_len and len(decoded) != args.decoded_len:
exit(1)
- exit(0)
+except:
+ exit(1)
+exit(0)