Skip to content

Commit 7e35e75

Browse files
authored
Adds validation flag waiting_for_signature (#439)
This flag makes sure to avoid updating authenticity reports upon unsigned SEIs. Further, a counter has been added to avoid running into a deadlock.
1 parent c0f6002 commit 7e35e75

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lib/src/sv_auth.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ prepare_for_validation(signed_video_t *self, bu_list_item_t **sei)
10031003
} else {
10041004
self->gop_info->verified_signature_hash = 1;
10051005
}
1006+
validation_flags->waiting_for_signature = !(*sei)->bu->is_signed;
10061007

10071008
SV_CATCH()
10081009
SV_DONE(status)
@@ -1209,15 +1210,18 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12091210

12101211
svrc_t status = SV_UNKNOWN_FAILURE;
12111212
SV_TRY()
1213+
// TODO: Keep a safe guard for infinite loops until "safe". Then remove.
1214+
int max_loop = 10;
12121215
bool update_validation_status = false;
12131216
bool public_key_has_changed = false;
12141217
char sei_validation_status = 'U';
12151218
// Keep validating as long as there are pending GOPs.
12161219
bool stop_validating = false;
1217-
while (has_pending_partial_gop(self) && !stop_validating) {
1220+
while (has_pending_partial_gop(self) && !stop_validating && max_loop > 0) {
12181221
bu_list_item_t *sei = NULL;
1219-
// Initialize latest validation.
1220-
if (!self->validation_flags.has_auth_result || validation_flags->is_first_validation) {
1222+
// Initialize latest validation if not validating intermediate GOPs.
1223+
if (!validation_flags->waiting_for_signature &&
1224+
(!validation_flags->has_auth_result || validation_flags->is_first_validation)) {
12211225
latest->authenticity = SV_AUTH_RESULT_SIGNATURE_PRESENT;
12221226
latest->number_of_expected_picture_nalus = 0;
12231227
latest->number_of_received_picture_nalus = 0;
@@ -1254,8 +1258,10 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12541258
} else {
12551259
update_validation_status = true;
12561260
}
1257-
self->gop_info->verified_signature_hash = -1;
1258-
validation_flags->has_auth_result = true;
1261+
if (!validation_flags->waiting_for_signature) {
1262+
self->gop_info->verified_signature_hash = -1;
1263+
validation_flags->has_auth_result = true;
1264+
}
12591265
if (latest->authenticity == SV_AUTH_RESULT_NOT_SIGNED) {
12601266
// Only report "stream is unsigned" in the accumulated report.
12611267
validation_flags->has_auth_result = false;
@@ -1266,6 +1272,10 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12661272
latest->authenticity != self->accumulated_validation->authenticity;
12671273
}
12681274
public_key_has_changed |= latest->public_key_has_changed; // Pass on public key failure.
1275+
max_loop--;
1276+
}
1277+
if (max_loop <= 0) {
1278+
DEBUG_LOG("Validation aborted after reaching max number of loops");
12691279
}
12701280

12711281
SV_THROW(bu_list_update_status(bu_list, update_validation_status));
@@ -1275,12 +1285,16 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12751285
reset_linked_hash(self);
12761286
}
12771287

1278-
// All statistics but pending BUs have already been collected.
1279-
latest->number_of_pending_picture_nalus = bu_list_num_pending_items(bu_list);
1280-
DEBUG_LOG("Validated GOP as %s", kAuthResultValidStr[latest->authenticity]);
1281-
DEBUG_LOG("Expected number of Bitstream Units = %d", latest->number_of_expected_picture_nalus);
1282-
DEBUG_LOG("Received number of Bitstream Units = %d", latest->number_of_received_picture_nalus);
1283-
DEBUG_LOG("Number of pending Bitstream Units = %d", latest->number_of_pending_picture_nalus);
1288+
if (!validation_flags->waiting_for_signature) {
1289+
// All statistics but pending BUs have already been collected.
1290+
latest->number_of_pending_picture_nalus = bu_list_num_pending_items(bu_list);
1291+
DEBUG_LOG("Validated GOP as %s", kAuthResultValidStr[latest->authenticity]);
1292+
DEBUG_LOG(
1293+
"Expected number of Bitstream Units = %d", latest->number_of_expected_picture_nalus);
1294+
DEBUG_LOG(
1295+
"Received number of Bitstream Units = %d", latest->number_of_received_picture_nalus);
1296+
DEBUG_LOG("Number of pending Bitstream Units = %d", latest->number_of_pending_picture_nalus);
1297+
}
12841298
SV_CATCH()
12851299
SV_DONE(status)
12861300

lib/src/sv_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ typedef struct {
210210
bool hash_algo_known; // Information on what hash algorithm to use has been received.
211211

212212
// GOP-related flags.
213+
bool waiting_for_signature; // Validating a GOP with a SEI without signature.
213214
bool has_lost_sei; // Has detected a lost SEI since last validation.
214215
} validation_flags_t;
215216

0 commit comments

Comments
 (0)