|
30 | 30 | #include "sv_internal.h" // set_hash_list_size() |
31 | 31 | #include "sv_openssl_internal.h" // openssl_read_pubkey_from_private_key() |
32 | 32 | #include "sv_tlv.h" // sv_write_byte_many() |
33 | | -#include "test_helpers.h" // sv_setting, create_signed_stream() |
| 33 | +#include "test_helpers.h" // sv_setting, create_signed_stream(), validation_stats, validate_stream() |
34 | 34 | #include "test_stream.h" // test_stream_create() |
35 | 35 |
|
36 | 36 | #define TMP_FIX_TO_ALLOW_TWO_INVALID_SEIS_AT_STARTUP true |
@@ -61,182 +61,6 @@ teardown() |
61 | 61 | * TODO: Currently, validation is triggered already on the second I-frame, which triggers an |
62 | 62 | * unsigned GOP. |
63 | 63 | */ |
64 | | - |
65 | | -/* Struct to accumulate validation results used to compare against expected values. */ |
66 | | -struct validation_stats { |
67 | | - int valid_gops; |
68 | | - int valid_gops_with_missing_info; |
69 | | - int invalid_gops; |
70 | | - int unsigned_gops; |
71 | | - int missed_bu; |
72 | | - int pending_bu; |
73 | | - int has_signature; |
74 | | - bool public_key_has_changed; |
75 | | - bool has_no_timestamp; |
76 | | - signed_video_accumulated_validation_t *final_validation; |
77 | | -}; |
78 | | - |
79 | | -/* General comments to the validation tests. |
80 | | - * All tests loop through the settings in settings[NUM_SETTINGS]; See signed_video_helpers.h. The |
81 | | - * index in the loop is _i and something the check test framework provides. |
82 | | - */ |
83 | | - |
84 | | -/* validate_stream(...) |
85 | | - * |
86 | | - * Helper function to validate the authentication result. |
87 | | - * It takes a test stream |list| as input together with |expected| values of |
88 | | - * valid gops |
89 | | - * invalid gops |
90 | | - * unsigned gops, that is gops without signature |
91 | | - * missed number of gops |
92 | | - * etc |
93 | | - * |
94 | | - * Note that the items in the |list| are consumed, that is, deleted after usage. |
95 | | - * |
96 | | - * If a NULL pointer |list| is passed in no action is taken. |
97 | | - * If a NULL pointer |sv| is passed in a new session is created. This is |
98 | | - * convenient if there are no other actions to take on |sv| outside this scope, |
99 | | - * like reset. |
100 | | - */ |
101 | | -static void |
102 | | -validate_stream(signed_video_t *sv, |
103 | | - test_stream_t *list, |
104 | | - struct validation_stats expected, |
105 | | - bool check_version) |
106 | | -{ |
107 | | - if (!list) return; |
108 | | - |
109 | | - bool internal_sv = false; |
110 | | - if (!sv) { |
111 | | - sv = signed_video_create(list->codec); |
112 | | - internal_sv = true; |
113 | | - } |
114 | | - |
115 | | - signed_video_authenticity_t *auth_report = NULL; |
116 | | - signed_video_latest_validation_t *latest = NULL; |
117 | | - |
118 | | - int valid_gops = 0; |
119 | | - int valid_gops_with_missing_info = 0; |
120 | | - int invalid_gops = 0; |
121 | | - int unsigned_gops = 0; |
122 | | - int missed_bu = 0; |
123 | | - int pending_bu = 0; |
124 | | - int has_signature = 0; |
125 | | - bool public_key_has_changed = false; |
126 | | - bool has_timestamp = false; |
127 | | - // Loop through all items in the stream |
128 | | - test_stream_item_t *item = list->first_item; |
129 | | - while (item) { |
130 | | - SignedVideoReturnCode rc = |
131 | | - signed_video_add_nalu_and_authenticate(sv, item->data, item->data_size, &auth_report); |
132 | | - ck_assert_int_eq(rc, SV_OK); |
133 | | - |
134 | | - if (auth_report) { |
135 | | - latest = &(auth_report->latest_validation); |
136 | | - ck_assert(latest); |
137 | | - if (latest->number_of_expected_picture_nalus >= 0) { |
138 | | - missed_bu += |
139 | | - latest->number_of_expected_picture_nalus - latest->number_of_received_picture_nalus; |
140 | | - } |
141 | | - pending_bu += latest->number_of_pending_picture_nalus; |
142 | | - switch (latest->authenticity) { |
143 | | - case SV_AUTH_RESULT_OK_WITH_MISSING_INFO: |
144 | | - valid_gops_with_missing_info++; |
145 | | - break; |
146 | | - case SV_AUTH_RESULT_OK: |
147 | | - valid_gops++; |
148 | | - break; |
149 | | - case SV_AUTH_RESULT_NOT_OK: |
150 | | - invalid_gops++; |
151 | | - break; |
152 | | - case SV_AUTH_RESULT_SIGNATURE_PRESENT: |
153 | | - has_signature++; |
154 | | - break; |
155 | | - case SV_AUTH_RESULT_NOT_SIGNED: |
156 | | - unsigned_gops++; |
157 | | - break; |
158 | | - default: |
159 | | - break; |
160 | | - } |
161 | | - public_key_has_changed |= latest->public_key_has_changed; |
162 | | - has_timestamp |= latest->has_timestamp; |
163 | | - |
164 | | - if (latest->has_timestamp) { |
165 | | - if (sv->onvif || sv->legacy_sv) { |
166 | | - // Media Signing and Legacy code only have one timestamp |
167 | | - ck_assert_int_eq(latest->start_timestamp, latest->end_timestamp); |
168 | | - } else { |
169 | | - ck_assert_int_lt(latest->start_timestamp, latest->end_timestamp); |
170 | | - } |
171 | | - } |
172 | | - |
173 | | - // Check if product_info has been received and set correctly. |
174 | | - if ((latest->authenticity != SV_AUTH_RESULT_NOT_SIGNED) && |
175 | | - (latest->authenticity != SV_AUTH_RESULT_SIGNATURE_PRESENT)) { |
176 | | -#ifdef NO_ONVIF_MEDIA_SIGNING |
177 | | - ck_assert_int_eq(strcmp(auth_report->product_info.hardware_id, HW_ID), 0); |
178 | | - ck_assert_int_eq(strcmp(auth_report->product_info.address, ADDR), 0); |
179 | | -#endif |
180 | | - ck_assert_int_eq(strcmp(auth_report->product_info.firmware_version, FW_VER), 0); |
181 | | - ck_assert_int_eq(strcmp(auth_report->product_info.serial_number, SER_NO), 0); |
182 | | - ck_assert_int_eq(strcmp(auth_report->product_info.manufacturer, MANUFACT), 0); |
183 | | - |
184 | | - // Check if code version used when signing the video is equal to the code version used when |
185 | | - // validating the authenticity. |
186 | | - if (check_version && strlen(auth_report->version_on_signing_side) != 0) { |
187 | | - ck_assert(!signed_video_compare_versions( |
188 | | - auth_report->version_on_signing_side, auth_report->this_version)); |
189 | | - } |
190 | | - } |
191 | | - // Get an authenticity report from separate API and compare accumulated results. |
192 | | - signed_video_authenticity_t *extra_auth_report = signed_video_get_authenticity_report(sv); |
193 | | - ck_assert_int_eq( |
194 | | - memcmp(&auth_report->accumulated_validation, &extra_auth_report->accumulated_validation, |
195 | | - sizeof(signed_video_accumulated_validation_t)), |
196 | | - 0); |
197 | | - signed_video_authenticity_report_free(extra_auth_report); |
198 | | - |
199 | | - // We are done with auth_report. |
200 | | - latest = NULL; |
201 | | - signed_video_authenticity_report_free(auth_report); |
202 | | - } |
203 | | - // Move to next Bitstream Unit. |
204 | | - item = item->next; |
205 | | - } |
206 | | - // Check GOP statistics against expected. |
207 | | - ck_assert_int_eq(valid_gops, expected.valid_gops); |
208 | | - ck_assert_int_eq(valid_gops_with_missing_info, expected.valid_gops_with_missing_info); |
209 | | - ck_assert_int_eq(invalid_gops, expected.invalid_gops); |
210 | | - ck_assert_int_eq(unsigned_gops, expected.unsigned_gops); |
211 | | - ck_assert_int_eq(missed_bu, expected.missed_bu); |
212 | | - ck_assert_int_eq(pending_bu, expected.pending_bu); |
213 | | - ck_assert_int_eq(has_signature, expected.has_signature); |
214 | | - ck_assert_int_eq(public_key_has_changed, expected.public_key_has_changed); |
215 | | - ck_assert_int_eq(has_timestamp, !expected.has_no_timestamp); |
216 | | - |
217 | | - // Get the authenticity report and compare the stats against expected. |
218 | | - if (expected.final_validation) { |
219 | | - auth_report = signed_video_get_authenticity_report(sv); |
220 | | - ck_assert_int_eq( |
221 | | - auth_report->accumulated_validation.authenticity, expected.final_validation->authenticity); |
222 | | - ck_assert_int_eq(auth_report->accumulated_validation.public_key_has_changed, |
223 | | - expected.final_validation->public_key_has_changed); |
224 | | - ck_assert_int_eq(auth_report->accumulated_validation.number_of_received_nalus, |
225 | | - expected.final_validation->number_of_received_nalus); |
226 | | - ck_assert_int_eq(auth_report->accumulated_validation.number_of_validated_nalus, |
227 | | - expected.final_validation->number_of_validated_nalus); |
228 | | - ck_assert_int_eq(auth_report->accumulated_validation.number_of_pending_nalus, |
229 | | - expected.final_validation->number_of_pending_nalus); |
230 | | - ck_assert_int_eq(auth_report->accumulated_validation.public_key_validation, |
231 | | - expected.final_validation->public_key_validation); |
232 | | - ck_assert_int_eq(auth_report->accumulated_validation.has_timestamp, |
233 | | - expected.final_validation->has_timestamp); |
234 | | - signed_video_authenticity_report_free(auth_report); |
235 | | - } |
236 | | - |
237 | | - if (internal_sv) signed_video_free(sv); |
238 | | -} |
239 | | - |
240 | 64 | /* Test description |
241 | 65 | * The public API signed_video_add_nalu_and_authenticate(...) is checked for invalid parameters, and |
242 | 66 | * invalid Bitstream Units. |
|
0 commit comments