Skip to content

Commit 6fb1036

Browse files
committed
Enforce block ordering and numbering constraints
1 parent 92f5716 commit 6fb1036

5 files changed

Lines changed: 58 additions & 15 deletions

File tree

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Editor files
22
*~
3-
.vscode
4-
.project
5-
.cproject
6-
.pydevproject
3+
/.vscode
4+
/.project
5+
/.cproject
6+
/.pydevproject
7+
/.externalToolBuilders/
78

89
# Build files
910
/deps/build/

src/mock_bpa/decode.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,49 @@ int bsl_mock_decode_bundle(QCBORDecodeContext *dec, MockBPA_Bundle_t *bundle)
337337
return 3;
338338
}
339339

340-
MockBPA_BlockByNum_set_at(bundle->blocks_num, blk->blk_num, blk);
340+
bool valid = true;
341+
if (blk->blk_type == 0)
342+
{
343+
BSL_LOG_WARNING("Invalid block type 0, ignoring the block");
344+
valid = false;
345+
}
346+
if (blk->blk_num == 0)
347+
{
348+
BSL_LOG_WARNING("Invalid block number 0, ignoring the block");
349+
valid = false;
350+
}
351+
if (MockBPA_BlockByNum_cget(bundle->blocks_num, blk->blk_num))
352+
{
353+
BSL_LOG_WARNING("Duplicate block number %" PRIu64 " present, ignoring the duplicate");
354+
valid = false;
355+
}
356+
357+
if (valid)
358+
{
359+
MockBPA_BlockByNum_set_at(bundle->blocks_num, blk->blk_num, blk);
360+
}
361+
else
362+
{
363+
MockBPA_BlockList_pop_back(NULL, bundle->blocks);
364+
}
365+
}
366+
367+
MockBPA_CanonicalBlock_t *const *pyld_ptr = MockBPA_BlockByNum_cget(bundle->blocks_num, 1);
368+
if (!pyld_ptr)
369+
{
370+
BSL_LOG_ERR("No payload block present, at least a payload block must be present to be valid");
371+
return 3;
372+
}
373+
MockBPA_CanonicalBlock_t *pyld = *pyld_ptr;
374+
if (pyld != MockBPA_BlockList_back(bundle->blocks))
375+
{
376+
BSL_LOG_ERR("The payload block must be the last block to be valid");
377+
return 3;
378+
}
379+
if (pyld->blk_num != 1)
380+
{
381+
BSL_LOG_ERR("The payload block must have block number 1");
382+
return 3;
341383
}
342384

343385
BSL_LOG_DEBUG("exiting array (at %zd)", QCBORDecode_Tell(dec));

test/test_DefaultSecurityContext.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,15 @@ TEST_MATRIX([ true, false ])
465465
void test_sec_accept_keyunwrap(bool bib)
466466
{
467467

468-
const char *bundle_bib = ("9F88070000820282010282028202018202820201820018281A000F424085010100005823526561647920746F"
469-
"2067656E657261746520612033322D62797465207061796C6F6164850B020000585681010101820282020182"
470-
"820107820300818182015840756D484ED764AEF06A35C53D6033B5311258EE21748B5FD53A53C8F55793D7A6"
471-
"B021E0CEC4A5C461CA6C179649EC7BBFC1EA89639409B809086B820216EFCF7BFF");
468+
const char *bundle_bib = "9F88070000820282010282028202018202820201820018281A000F4240850B02000058568101010182028202"
469+
"0182820107820300818182015840756D484ED764AEF06A35C53D6033B5311258EE21748B5FD53A53C8F55793"
470+
"D7A6B021E0CEC4A5C461CA6C179649EC7BBFC1EA89639409B809086B820216EFCF7B85010100005823526561"
471+
"647920746F2067656E657261746520612033322D62797465207061796C6F6164FF";
472472

473473
const char *bundle_bcb =
474-
("9F88070000820282010282028202018202820201820018281A000F42408501010000582315585E19F60C0978EDE4105E529F9B0006C13"
475-
"C9804A9C75AB46D4ED46F1097CFA03967850C02010058508101020182028202018482014C5477656C7665313231323132820201820358"
476-
"1869C411276FECDDC4780DF42C8A2AF89296FABF34D7FAE7008204008181820150F6DC43C2EE046C7AE713F0531B2BCB48FF");
474+
"9F88070000820282010282028202018202820201820018281A000F4240850C02010058508101020182028202018482014C5477656C766"
475+
"53132313231328202018203581869C411276FECDDC4780DF42C8A2AF89296FABF34D7FAE7008204008181820150F6DC43C2EE046C7AE7"
476+
"13F0531B2BCB488501010000582315585E19F60C0978EDE4105E529F9B0006C13C9804A9C75AB46D4ED46F1097CFA03967FF";
477477

478478
string_t kek_str;
479479
string_init_set_str(kek_str, "000102030405060708090A0B0C0D0E0F");

test/test_MockBPA_Codecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void test_bsl_loopback_eid(const char *hexdata)
376376
string_clear(in_text);
377377
}
378378

379-
TEST_CASE("9f88070000820282030482028201028202820000821903e81903e900850a182d000043010203ff")
379+
TEST_CASE("9f88070000820282030482028201028202820000821903e81903e900850101000043010203ff")
380380
void test_bsl_loopback_bundle(const char *hexdata)
381381
{
382382
BSL_Data_t in_data;

test/test_mock_bpa_ctr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ int suiteTearDown(int failures)
3939
return failures;
4040
}
4141

42-
TEST_CASE("9f88070000820282030482028201028202820000821903e81903e900850a182d000043010203ff")
42+
TEST_CASE("9f88070000820282030482028201028202820000821903e81903e900850101000043010203ff")
4343
// random large payload
4444
TEST_CASE(
45-
"9F88070000820282030482028201028202820000821903E81903E900850A182D00005903E8E059257BAE6D2D4AB0FB90EEF5FA695D8B07A466"
45+
"9F88070000820282030482028201028202820000821903E81903E90085010100005903E8E059257BAE6D2D4AB0FB90EEF5FA695D8B07A466"
4646
"51CC45E5DE4E66F26EE329751A85D9C357DBEBF6D5EF38BA18629E7C17DF2D511ECE2FB2C99B3BD6C12E5746C530888F105D4835C3952DF922"
4747
"1EE17E51E9663FADC00194FBF0332BAF8025C6313B5922C39FB9A5C68EC20FA1717D0B224219417BD930CE1C6356F0044DF3989C47971E30A2"
4848
"94232A6E31CE6B05125A49CEB0AD606A0361658001AEA5A2D715F1D17CB2203E347D64DDF8CF8B9864B90541DB790EF1E9E97A6E042C7A4D48"

0 commit comments

Comments
 (0)