diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-08-27 04:17:54 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-08-27 15:35:13 -0500 |
commit | 7605b2ab5ea2cdd619fafbe5eea981f689865676 (patch) | |
tree | 1bcd75bfe08fd60fed60a6f2f558ccfa2f8c4a30 /src/wg2nd.cpp | |
parent | 0e8737b3afe1dc5410b45761b7c9e38e022292f6 (diff) | |
download | wg2nd-7605b2ab5ea2cdd619fafbe5eea981f689865676.tar.xz wg2nd-7605b2ab5ea2cdd619fafbe5eea981f689865676.zip |
Encode key in base32 to exclude the Unix path sep
Diffstat (limited to 'src/wg2nd.cpp')
-rw-r--r-- | src/wg2nd.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/wg2nd.cpp b/src/wg2nd.cpp index cbe3c29..9397a0b 100644 --- a/src/wg2nd.cpp +++ b/src/wg2nd.cpp @@ -25,11 +25,11 @@ constexpr char const * SYMMETRIC_KEY_SUFFIX = ".symkey"; namespace wg2nd { std::string private_keyfile_name(std::string const & priv_key) { - char pub_key[WG_KEY_LEN_BASE64]; + char pub_key[WG_KEY_LEN_BASE32]; // Derive public key - if(wg_pubkey_base64(priv_key.c_str(), pub_key)) { - throw ParsingException("Private key is formatted improperly"); + if(wg_pubkey_base32(priv_key.c_str(), pub_key)) { + throw ParsingException("Private key is formatted improperly"); } std::string keyfile_name { pub_key }; @@ -38,6 +38,19 @@ namespace wg2nd { return keyfile_name; } + std::string public_keyfile_name(std::string const & pub_key) { + char pub_key32[WG_KEY_LEN_BASE32]; + + if(wg_key_convert_base32(pub_key.c_str(), pub_key32)) { + throw ParsingException("Public key for [Peer] " + pub_key + " is formatted improperly"); + } + + std::string keyfile_name { pub_key32 }; + keyfile_name.append(SYMMETRIC_KEY_SUFFIX); + + return keyfile_name; + } + uint32_t deterministic_fwmark(std::string const & interface_name) { constexpr uint8_t const SIP_KEY[8] = { 0x90, 0x08, 0x82, 0xd7, @@ -409,7 +422,7 @@ namespace wg2nd { } if(!peer.preshared_key.empty()) { - std::string filename = peer.public_key + SYMMETRIC_KEY_SUFFIX; + std::string filename = public_keyfile_name(peer.public_key); symmetric_keyfiles.push_back(SystemdFilespec { .name = filename, |