Skip to content

Commit 5d4c457

Browse files
authored
The first_validation is updated to rely on sei_in_sync (#496)
Special operations on the first validation is taken if the SEI is not in sync. All validation has to be rewinded if so. So far this decision has been made based on the validation results. Now it is based on wether the SEI is in sync or not. Co-authored-by: bjornvolcker <[email protected]>
1 parent 72f68c5 commit 5d4c457

File tree

2 files changed

+9
-31
lines changed

2 files changed

+9
-31
lines changed

lib/src/sv_auth.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -784,29 +784,14 @@ validate_authenticity(signed_video_t *self, bu_list_item_t *sei)
784784
}
785785
}
786786

787-
// If we lose an entire GOP (part from the associated SEI) it will be seen as valid. Here we fix
788-
// it afterwards.
789-
// TODO: Move this inside the verify_hashes_ functions. We should not need to perform any special
790-
// actions on the output.
791-
// TODO: Investigate if this part is actually needed.
792-
// if (!validation_flags->is_first_validation) {
793-
// if ((valid == SV_AUTH_RESULT_OK) && (num_expected > 1) && (num_missed >= num_expected)) {
794-
// valid = SV_AUTH_RESULT_NOT_OK;
795-
// }
796-
// }
797787
// The very first validation needs to be handled separately. If this is truly the start of a
798788
// stream we have all necessary information to successfully validate the authenticity. It can be
799789
// interpreted as being in sync with its signing counterpart. If this session validates the
800790
// authenticity of a segment of a stream, e.g., an exported file, we start out of sync. The first
801791
// SEI may be associated with a GOP prior to this segment.
802-
if (validation_flags->is_first_validation) {
803-
// Change status from SV_AUTH_RESULT_OK to SV_AUTH_RESULT_SIGNATURE_PRESENT if no valid BUs
804-
// were found when collecting stats.
805-
if ((valid == SV_AUTH_RESULT_OK) && !has_valid_bu && (sei && sei->bu->is_signed)) {
806-
valid = SV_AUTH_RESULT_SIGNATURE_PRESENT;
807-
}
792+
if (validation_flags->is_first_validation && !validation_flags->sei_in_sync) {
808793
// If validation was successful, the |current_partial_gop| is in sync.
809-
if (valid != SV_AUTH_RESULT_OK) {
794+
if (valid != SV_AUTH_RESULT_OK && !has_valid_bu) {
810795
// We have validated the authenticity based on one single BU, but failed. A success can only
811796
// happen if we are at the beginning of the original stream. For all other cases, for example,
812797
// if we validate the authenticity of an exported file, the first SEI may be associated with a
@@ -821,7 +806,7 @@ validate_authenticity(signed_video_t *self, bu_list_item_t *sei)
821806
num_received = -1;
822807
// If no valid Bitstream Units were found, reset validation to be able to make more
823808
// attepts to synchronize the SEIs.
824-
validation_flags->reset_first_validation = !has_valid_bu;
809+
validation_flags->reset_first_validation = true;
825810
}
826811
}
827812
if (latest->public_key_has_changed) valid = SV_AUTH_RESULT_NOT_OK;
@@ -869,7 +854,7 @@ remove_sei_association(bu_list_t *bu_list, const bu_list_item_t *sei)
869854
bu_list_item_t *item = bu_list->first_item;
870855
while (item) {
871856
if (sei && item->associated_sei == sei) {
872-
if (item->validation_status == 'M') {
857+
if (item->tmp_validation_status == 'M') {
873858
const bu_list_item_t *item_to_remove = item;
874859
item = item->next;
875860
bu_list_remove_and_free_item(bu_list, item_to_remove);
@@ -1200,8 +1185,7 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12001185
while (has_pending_partial_gop(self) && !stop_validating && max_loop > 0) {
12011186
bu_list_item_t *sei = NULL;
12021187
// Initialize latest validation if not validating intermediate GOPs.
1203-
if (!validation_flags->waiting_for_signature &&
1204-
(!validation_flags->has_auth_result || validation_flags->is_first_validation)) {
1188+
if (!validation_flags->waiting_for_signature && !validation_flags->has_auth_result) {
12051189
latest->authenticity = SV_AUTH_RESULT_SIGNATURE_PRESENT;
12061190
latest->number_of_expected_picture_nalus = 0;
12071191
latest->number_of_received_picture_nalus = 0;
@@ -1223,7 +1207,7 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12231207
validate_authenticity(self, sei);
12241208
}
12251209

1226-
if (validation_flags->is_first_validation && (latest->authenticity != SV_AUTH_RESULT_OK)) {
1210+
if (validation_flags->is_first_validation && !validation_flags->sei_in_sync) {
12271211
// Fetch the |tmp_validation_status| for later use.
12281212
update_sei_in_validation(self, false, &sei_validation_status, NULL);
12291213
}

tests/check/check_signed_video_auth.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,8 @@ START_TEST(modify_one_p_frame)
510510
// ISP P.P (invalid, 3 pending)
511511
signed_video_accumulated_validation_t final_validation = {
512512
SV_AUTH_RESULT_NOT_OK, false, 15, 12, 3, SV_PUBKEY_VALIDATION_NOT_FEASIBLE, true, 0, 0};
513-
struct validation_stats expected = {.valid_gops = 0, // 2,
514-
.valid_gops_with_missing_info = 1, // 0,
515-
.invalid_gops = 2, // 1,
516-
.pending_bu = 2, // 3,
517-
.missed_bu = 1, // 0,
518-
.final_validation = &final_validation};
513+
struct validation_stats expected = {
514+
.valid_gops = 2, .invalid_gops = 1, .pending_bu = 3, .final_validation = &final_validation};
519515
if (settings[_i].auth_level == SV_AUTHENTICITY_LEVEL_GOP) {
520516
// When in low bitrate mode the first validation fails and it is not possible to
521517
// know if it is due to a modified BU (SEI is in sync), or if the SEI is out of sync
@@ -2084,9 +2080,7 @@ START_TEST(no_public_key_in_sei_and_bad_public_key_on_validation_side)
20842080
ck_assert_int_eq(sv_rc, SV_OK);
20852081
ck_assert(auth_report);
20862082

2087-
// TODO: This test is correct but currently one SEI is not enough. The state "signature
2088-
// present" will be used until the bug is fixed.
2089-
ck_assert_int_eq(auth_report->latest_validation.authenticity, SV_AUTH_RESULT_SIGNATURE_PRESENT);
2083+
ck_assert_int_eq(auth_report->latest_validation.authenticity, SV_AUTH_RESULT_NOT_OK);
20902084

20912085
signed_video_authenticity_report_free(auth_report);
20922086
// Free bu_list_item and session.

0 commit comments

Comments
 (0)