Skip to content

Default sec ctx fixes & unit test#4

Closed
jeronstone wants to merge 11 commits into
mainfrom
default-sec-ctx-fixes-tests
Closed

Default sec ctx fixes & unit test#4
jeronstone wants to merge 11 commits into
mainfrom
default-sec-ctx-fixes-tests

Conversation

@jeronstone
Copy link
Copy Markdown
Contributor

@jeronstone jeronstone commented Jul 8, 2025

Default Sec Ctx:

Mock BPA

  • On bundle encode from CBOR, new bundle blocks now added to block ID map (needed so BCB context can easily get block data for target block for BTSD writing)

Unit tests

  • Adds a few new Default Sec Ctx unit tests, namely to testing BCB at source AND acceptor, including test at acceptor with incorrect ciphertext; adds coverage in decryption functionality
  • Consolidates duplicate code in default sec ctx unit test file using the TEST_CASE unity macro, formally add test vectors to util file
  • Unit test in bundle ctx tests to verify block ID map fix was working (could be removed/moved)

@jeronstone jeronstone requested a review from a team as a code owner July 8, 2025 14:53
@jeronstone
Copy link
Copy Markdown
Contributor Author

TODO squash commits

@jeronstone jeronstone closed this Jul 8, 2025
Copy link
Copy Markdown
Collaborator

@BrianSipos BrianSipos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me. Is there a reason this was closed without merging?

@jeronstone jeronstone deleted the default-sec-ctx-fixes-tests branch July 16, 2025 18:44
iondev33 pushed a commit to iondev33/BSL that referenced this pull request Feb 26, 2026
…MOS#2)

   Bug NASA-AMMOS#2: BSL_BundleCtx_WriteBTSD must call realloc callback before write

   Problem:
   - BSL_BundleCtx_WriteBTSD was calling the write callback directly without
     first ensuring the BTSD buffer was large enough
   - When ION creates extension blocks, they start with length=1 (placeholder)
   - BSL then attempted to write 82 bytes into the 1-byte buffer
   - This caused the ION realloc callback to be called during write, but write
     had already started with insufficient buffer space

   Root Cause:
   - BSL_BundleCtx_WriteBTSD (lines 131-137) immediately called:
       return HostDescriptorTable.block_write_btsd_fn(bundle, block_num, btsd_len);
   - No buffer size check or realloc call before writing
   - The write callback would fail when attempting to write beyond allocated space

   Fix:
   - Added realloc call before write in BSL_BundleCtx_WriteBTSD (lines 138-148)
   - Check if realloc callback is registered and btsd_len > 0
   - Call block_realloc_btsd_fn to expand buffer to needed size
   - Return NULL if realloc fails (with error logging)
   - Only proceed to write if realloc succeeds

   Code:
       /* Ensure the BTSD buffer is large enough before writing */
       if (btsd_len > 0 && HostDescriptorTable.block_realloc_btsd_fn)
       {
           int realloc_result = HostDescriptorTable.block_realloc_btsd_fn(bundle,
   block_num, btsd_len);
           if (realloc_result != 0)
           {
               BSL_LOG_ERR("Failed to realloc BTSD buffer: block=%llu size=%zu
   result=%d",
                           (unsigned long long)block_num, btsd_len, realloc_result);
               return NULL;
           }
       }

   Impact:
   - BSL now properly expands BTSD buffers before writing
   - BCB encryption can now write full encrypted payloads
   - BIB can write full HMAC signatures
   - This is part of a series of fixes enabling BSL BCB encryption in ION

   Related ION integration fixes (separate ION commits):
   - Bug NASA-AMMOS#3: Fix SDR violation in ion_bsl_ReallocBTSD
   - Bug NASA-AMMOS#4: Add payload block special handling in ion_bsl_ReallocBTSD

   Test: ION tests/bpsec/bpsec-all-multinode-test.bsl
   Status: BSL operations now succeed with this fix

WIP: bpsec/bpsec-all-multinode-test.bsl not yet passing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default Sec Ctx BCB Execute function always encrypts

2 participants