Protocol: normalize query rows and identity points
This commit is contained in:
1 parent
cb43116da6
commit
5c0c0c525f
3 files changed
+41
-13
No files matched your search
+7
-3
@@ -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);
|
||||
|
||||
+21
-10
@@ -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)
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
Reference in new issue
Block a user