diff --git a/src/Command.cpp b/src/Command.cpp index 8c9ffa0..b8ae3e8 100644 --- a/src/Command.cpp +++ b/src/Command.cpp @@ -142,12 +142,16 @@ ParsedCommand parseCommand(const std::string &raw) { ParsedCommand out; std::string first{Void::Str::trim(parts[0])}; - // The command name is the first whitespace-delimited token. + // Notifications and protocol commands start with a command name, while + // ServerQuery-style data replies are bare key=value records. Preserve the + // first field of those replies instead of mistaking it for a command name. std::string body; auto sp = first.find(' '); - if (sp == std::string::npos) { + const auto firstToken = first.substr(0, sp); + if (firstToken.find('=') != std::string::npos) { + body = first; + } else if (sp == std::string::npos) { out.name = tsUnescape(first); - body = ""; } else { out.name = tsUnescape(first.substr(0, sp)); body = first.substr(sp + 1); diff --git a/src/Identity.cpp b/src/Identity.cpp index 137d7cc..7051c4e 100644 --- a/src/Identity.cpp +++ b/src/Identity.cpp @@ -253,20 +253,31 @@ namespace Void::TeamSpeak::Protocol } // Uncompressed EC point (0x04 || x || y) from a public EVP_PKEY. + // OpenSSL 3.0 may return OSSL_PKEY_PARAM_PUB_KEY in the key's current + // conversion format (including compressed form), while newer releases + // commonly return uncompressed form. Reading the affine coordinates + // directly keeps identity generation/import stable across providers. Bytes pubPoint(EVP_PKEY* pkey) { - size_t len = 0; - if (EVP_PKEY_get_octet_string_param( - pkey, OSSL_PKEY_PARAM_PUB_KEY, nullptr, 0, &len) != 1) { - fail("cannot read public point length"); + BIGNUM* x = nullptr; + BIGNUM* y = nullptr; + if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_EC_PUB_X, &x) != 1 || + EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_EC_PUB_Y, &y) != 1) { + BN_free(x); + BN_free(y); + fail("cannot read public point coordinates"); } - Bytes buf(len, 0); - if (EVP_PKEY_get_octet_string_param(pkey, OSSL_PKEY_PARAM_PUB_KEY, - buf.data(), len, &len) != 1) { - fail("cannot read public point"); + Bytes point(65, 0); + point.front() = 0x04; + const bool encoded = + BN_bn2binpad(x, point.data() + 1, 32) == 32 && + BN_bn2binpad(y, point.data() + 33, 32) == 32; + BN_free(x); + BN_free(y); + if (!encoded) { + fail("cannot encode public point coordinates"); } - buf.resize(len); - return buf; + return point; } int countLeadingZeroBits(Crypto::ByteView data) diff --git a/tests/test_command.cpp b/tests/test_command.cpp index 943969e..f9dff99 100644 --- a/tests/test_command.cpp +++ b/tests/test_command.cpp @@ -53,3 +53,16 @@ TEST_CASE(parse_pipe_groups) CHECK_EQ(pc.groups[1]["cid"], std::string("2")); CHECK_EQ(pc.groups[1]["channel_name"], std::string("Talk")); } + +TEST_CASE(parse_bare_response_groups_preserves_first_field) +{ + auto pc = parseCommand("cid=3 pid=0 channel_name=Default|cid=4 pid=0 " + "channel_name=Games"); + CHECK(pc.name.empty()); + CHECK_EQ(pc.groups.size(), size_t(2)); + CHECK_EQ(pc.groups[0]["cid"], std::string("3")); + CHECK_EQ(pc.groups[0]["pid"], std::string("0")); + CHECK_EQ(pc.groups[0]["channel_name"], std::string("Default")); + CHECK_EQ(pc.groups[1]["cid"], std::string("4")); + CHECK_EQ(pc.groups[1]["channel_name"], std::string("Games")); +}