QUIC QLOG: Record implementation version

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22037)
This commit is contained in:
Hugo Landau 2024-01-29 14:20:01 +00:00
parent 24132503b3
commit 26e4bac4db
4 changed files with 38 additions and 5 deletions

View File

@ -35,6 +35,7 @@ typedef struct qlog_trace_info_st {
OSSL_TIME (*now_cb)(void *arg);
void *now_cb_arg;
uint64_t override_process_id;
const char *override_impl_name;
} QLOG_TRACE_INFO;
QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info);

View File

@ -67,15 +67,20 @@ QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info)
if (info->title != NULL
&& (qlog->info.title = OPENSSL_strdup(info->title)) == NULL)
goto err;
goto err;
if (info->description != NULL
&& (qlog->info.description = OPENSSL_strdup(info->description)) == NULL)
goto err;
goto err;
if (info->group_id != NULL
&& (qlog->info.group_id = OPENSSL_strdup(info->group_id)) == NULL)
goto err;
goto err;
if (info->override_impl_name != NULL
&& (qlog->info.override_impl_name
= OPENSSL_strdup(info->override_impl_name)) == NULL)
goto err;
if (!ossl_json_init(&qlog->json, NULL,
OSSL_JSON_FLAG_IJSON | OSSL_JSON_FLAG_SEQ))
@ -91,6 +96,7 @@ err:
OPENSSL_free((char *)qlog->info.title);
OPENSSL_free((char *)qlog->info.description);
OPENSSL_free((char *)qlog->info.group_id);
OPENSSL_free((char *)qlog->info.override_impl_name);
OPENSSL_free(qlog);
}
return NULL;
@ -162,6 +168,7 @@ void ossl_qlog_free(QLOG *qlog)
OPENSSL_free((char *)qlog->info.title);
OPENSSL_free((char *)qlog->info.description);
OPENSSL_free((char *)qlog->info.group_id);
OPENSSL_free((char *)qlog->info.override_impl_name);
OPENSSL_free(qlog);
}
@ -323,9 +330,23 @@ static void qlog_event_seq_header(QLOG *qlog)
ossl_json_key(&qlog->json, "vantage_point");
ossl_json_object_begin(&qlog->json);
{
char buf[128];
const char *p = buf;
if (qlog->info.override_impl_name != NULL) {
p = qlog->info.override_impl_name;
} else {
snprintf(buf, sizeof(buf), "OpenSSL/%s (%s)",
OpenSSL_version(OPENSSL_FULL_VERSION_STRING),
OpenSSL_version(OPENSSL_PLATFORM) + 10);
}
ossl_json_key(&qlog->json, "type");
ossl_json_str(&qlog->json, qlog->info.is_server
? "server" : "client");
ossl_json_key(&qlog->json, "name");
ossl_json_str(&qlog->json, p);
} /* vantage_point */
ossl_json_object_end(&qlog->json);
} /* trace */

View File

@ -15,7 +15,8 @@ static const char expected[] =
"\"test title\",\"description\":\"test description\",\"trace\":{"
"\"common_fields\":{\"time_format\":\"delta\",\"protocol_type\":"
"[\"QUIC\"],\"group_id\":\"test group ID\",\"system_info\":{"
"\"process_id\":123}},\"vantage_point\":{\"type\":\"client\"}}}\n"
"\"process_id\":123}},\"vantage_point\":{\"type\":\"client\","
"\"name\":\"OpenSSL/x.y.z\"}}}\n"
"\x1e{\"name\":\"transport:packet_sent\",\"data\":{\"field1\":\"foo\","
"\"field2\":\"bar\",\"field3\":42,\"field4\":\"1152921504606846976\","
@ -59,6 +60,7 @@ static int test_qlog(void)
qti.group_id = "test group ID";
qti.override_process_id = 123;
qti.now_cb = now;
qti.override_impl_name = "OpenSSL/x.y.z";
if (!TEST_ptr(qlog = ossl_qlog_new(&qti)))
goto err;

View File

@ -6,7 +6,9 @@
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
import sys, os, os.path, glob, json
import sys, os, os.path, glob, json, re
re_version = re.compile(r'''^OpenSSL/[0-9]+\.[0-9]\.[0-9](-[^ ]+)? ([^)]+)''')
class Unexpected(Exception):
def __init__(self, filename, msg):
@ -46,6 +48,13 @@ def check_header(filename, hdr):
if hdr_trace["vantage_point"].get('type') not in ('client', 'server'):
raise Unexpected(filename, "unexpected vantage_point")
vp_name = hdr_trace["vantage_point"].get('name')
if type(vp_name) != str:
raise Unexpected(filename, "expected vantage_point name")
if not re_version.match(vp_name):
raise Unexpected(filename, "expected correct vantage_point format")
hdr_common_fields = hdr_trace["common_fields"]
if hdr_common_fields.get("time_format") != "delta":
raise Unexpected(filename, "must have expected time_format")