From 83d5a53c666620d9ba0a80cbd36db2a11b45a8e7 Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Wed, 14 Dec 2022 15:59:13 +0100 Subject: [PATCH] Allow empty lines and comments in peer-fingerprint blocks Signed-off-by: Heiko Hund --- openvpn/ssl/peer_fingerprint.hpp | 11 ++++++++++- test/unittests/test_peer_fingerprint.cpp | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/openvpn/ssl/peer_fingerprint.hpp b/openvpn/ssl/peer_fingerprint.hpp index e5006a589..6a7eddaa6 100644 --- a/openvpn/ssl/peer_fingerprint.hpp +++ b/openvpn/ssl/peer_fingerprint.hpp @@ -104,7 +104,16 @@ struct PeerFingerprints { opt[i].touch(); while (std::getline(fps, fp)) - fingerprints_.emplace_back(PeerFingerprint(fp, fp_size)); + { + // Ignore empty lines and comments in fingerprint blocks + std::string trimmed = string::trim_copy(fp); + if (trimmed.empty() || + string::starts_with(trimmed, "#") || + string::starts_with(trimmed, ";")) + continue; + + fingerprints_.emplace_back(PeerFingerprint(fp, fp_size)); + } } } diff --git a/test/unittests/test_peer_fingerprint.cpp b/test/unittests/test_peer_fingerprint.cpp index ea9036531..d2ccfed89 100644 --- a/test/unittests/test_peer_fingerprint.cpp +++ b/test/unittests/test_peer_fingerprint.cpp @@ -39,8 +39,11 @@ TEST(PeerFingerprint, parse_config) { cfg.parse_from_config( "peer-fingerprint 01:F5:A6:4D:4A:CB:65:E1:8A:9F:55:89:7F:77:A0:79:AA:FB:CC:A1:37:2F:D8:B3:47:AA:9D:E3:D0:76:B1:44\n" "\n" + " \n" "02:F5:A6:4D:4A:CB:65:E1:8A:9F:55:89:7F:77:A0:79:AA:FB:CC:A1:37:2F:D8:B3:47:AA:9D:E3:D0:76:B1:44\n" + "# comment\n" "03:F5:A6:4D:4A:CB:65:E1:8A:9F:55:89:7F:77:A0:79:AA:FB:CC:A1:37:2F:D8:B3:47:AA:9D:E3:D0:76:B1:44 \n" + " ; comment\n" "04:F5:A6:4D:4A:CB:65:E1:8A:9F:55:89:7F:77:A0:79:AA:FB:CC:A1:37:2F:D8:B3:47:AA:9D:E3:D0:76:B1:44 \n" "\n" "peer-fingerprint 05:F5:A6:4D:4A:CB:65:E1:8A:9F:55:89:7F:77:A0:79:AA:FB:CC:A1:37:2F:D8:B3:47:AA:9D:E3:D0:76:B1:44 \n"