diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index d049e504..493a8d77 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -106,9 +106,7 @@ jobs: name: ${{github.job}}-${{matrix.os}}-${{matrix.compiler}}-coverage path: build/default/coverage* - name: Report coverage - run: | - SRC_COV_PERC=$(xmlstarlet sel -t -v 'floor(/coverage/packages/package[@name="src"]/@line-rate * 100)' -n build/default/coverage-xml.xml) - echo "Source coverage: ${SRC_COV_PERC}%" >> $GITHUB_STEP_SUMMARY + run: ./build.sh coverage-summary >> $GITHUB_STEP_SUMMARY mock-bpa-test: strategy: @@ -178,6 +176,4 @@ jobs: name: ${{github.job}}-${{matrix.os}}-gcc-coverage path: build/default/coverage* - name: Report coverage - run: | - SRC_COV_PERC=$(xmlstarlet sel -t -v 'floor(/coverage/packages/package[@name="src"]/@line-rate * 100)' -n build/default/coverage-xml.xml) - echo "Source coverage: ${SRC_COV_PERC}%" >> $GITHUB_STEP_SUMMARY + run: ./build.sh coverage-summary >> $GITHUB_STEP_SUMMARY diff --git a/build.sh b/build.sh index c25691b0..395ef890 100755 --- a/build.sh +++ b/build.sh @@ -75,6 +75,14 @@ function cmd_coverage { cmake --build ${BUILDDIR} -j1 --target \ coverage-html coverage-xml } +function cmd_coverage_summary { + for DIRNAME in backend crypto policy_provider security_context mock_bpa + do + COV_XPATH="format-number(/coverage/packages/package[@name='src.${DIRNAME}']/@line-rate * 100, '#.0')" + COV_PERC=$(xmlstarlet sel -t -v "${COV_XPATH}" -n build/default/coverage-xml.xml 2>/dev/null) + echo "Source ${DIRNAME} coverage: ${COV_PERC}%" + done +} function cmd_deps { ./resources/deps.sh @@ -194,6 +202,9 @@ case "$1" in coverage) cmd_coverage ;; + coverage-summary) + cmd_coverage_summary + ;; deps) cmd_deps ;; diff --git a/docs/api/10-bsl-developers.md b/docs/api/10-bsl-developers.md index 370bc12b..6d125efc 100644 --- a/docs/api/10-bsl-developers.md +++ b/docs/api/10-bsl-developers.md @@ -128,7 +128,7 @@ DICT_DEF2(BSL_SecCtxDict, uint64_t, M_BASIC_OPLIST, BSL_SecCtxDesc_t, M_POD_OPLI ## Citations and References -For definitions from rfc's and other sources, `@cite [source]` in the Doxygen header. +For definitions from IETF RFCs and other sources, `@cite [source]` in the Doxygen header. If possible (e.g. for RFCs) include the document number in the text for convenience, as in ```RFC XXXX @cite rfcXXXX```. # File Naming diff --git a/docs/api/dictionary.txt b/docs/api/dictionary.txt index c391bd08..90eb3b47 100644 --- a/docs/api/dictionary.txt +++ b/docs/api/dictionary.txt @@ -22,9 +22,12 @@ backends Backends BCB BCBs +Berners BIB's +Birkholz Birrane Bitwise +Bormann bpa BPA's BPSec @@ -33,6 +36,7 @@ BPv BSL BSLs BSLX +bstr BTSD BundleCtx Burleigh @@ -42,10 +46,12 @@ bytestream bytestring bytestrings callee's +Carsten CBOR cek centric CFE +Christoph ciphertext CLA clin @@ -90,6 +96,7 @@ frontend Frontend GCM Heiner +Henk hmac html IANA @@ -102,6 +109,7 @@ ipn IPN IPPT IsInt +isspace JHU Josefsson JPL @@ -113,6 +121,7 @@ lifecycle Lifecycles malloc MALLOC +Masinter McKeever md mem @@ -173,17 +182,24 @@ SWaP syslog Todo TODO +tstr typedef UDPCL uint un Uncategorized underlayer +Unescape +unicode unix +uri +URI +url validator verifier Verifier VERIFIER +Vigano VxWorks whitespace Whitespace diff --git a/docs/api/refs.bib b/docs/api/refs.bib index 4b4334f6..237b9e7f 100644 --- a/docs/api/refs.bib +++ b/docs/api/refs.bib @@ -22,6 +22,34 @@ @misc{iana:bundle title = {{Bundle Protocol registry}}, url = {https://www.iana.org/assignments/bundle/bundle.xhtml}, } +@misc{rfc3339, + series = {Request for Comments}, + number = 3339, + howpublished = {RFC 3339}, + publisher = {RFC Editor}, + doi = {10.17487/RFC3339}, + url = {https://www.rfc-editor.org/info/rfc3339}, + author = {Chris Newman and Graham Klyne}, + title = {{Date and Time on the Internet: Timestamps}}, + pagetotal = 18, + year = 2002, + month = jul, + abstract = {This document defines a date and time format for use in Internet protocols that is a profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar.}, +} +@misc{rfc3986, + series = {Request for Comments}, + number = 3986, + howpublished = {RFC 3986}, + publisher = {RFC Editor}, + doi = {10.17487/RFC3986}, + url = {https://www.rfc-editor.org/info/rfc3986}, + author = {Tim Berners-Lee and Roy T. Fielding and Larry M Masinter}, + title = {{Uniform Resource Identifier (URI): Generic Syntax}}, + pagetotal = 61, + year = 2005, + month = jan, + abstract = {A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource. This specification defines the generic URI syntax and a process for resolving URI references that might be in relative form, along with guidelines and security considerations for the use of URIs on the Internet. The URI syntax defines a grammar that is a superset of all valid URIs, allowing an implementation to parse the common components of a URI reference without knowing the scheme-specific requirements of every possible identifier. This specification does not define a generative grammar for URIs; that task is performed by the individual specifications of each URI scheme. {[}STANDARDS-TRACK{]}}, +} @misc{rfc4648, series = {Request for Comments}, number = 4648, @@ -50,6 +78,34 @@ @misc{rfc7517 month = may, abstract = {A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. This specification also defines a JWK Set JSON data structure that represents a set of JWKs. Cryptographic algorithms and identifiers for use with this specification are described in the separate JSON Web Algorithms (JWA) specification and IANA registries established by that specification.}, } +@misc{rfc8259, + series = {Request for Comments}, + number = 8259, + howpublished = {RFC 8259}, + publisher = {RFC Editor}, + doi = {10.17487/RFC8259}, + url = {https://www.rfc-editor.org/info/rfc8259}, + author = {Tim Bray}, + title = {{The JavaScript Object Notation (JSON) Data Interchange Format}}, + pagetotal = 16, + year = 2017, + month = dec, + abstract = {JavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data. This document removes inconsistencies with other specifications of JSON, repairs specification errors, and offers experience-based interoperability guidance.}, +} +@misc{rfc8610, + series = {Request for Comments}, + number = 8610, + howpublished = {RFC 8610}, + publisher = {RFC Editor}, + doi = {10.17487/RFC8610}, + url = {https://www.rfc-editor.org/info/rfc8610}, + author = {Henk Birkholz and Christoph Vigano and Carsten Bormann}, + title = {{Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures}}, + pagetotal = 64, + year = 2019, + month = jun, + abstract = {This document proposes a notational convention to express Concise Binary Object Representation (CBOR) data structures (RFC 7049). Its main goal is to provide an easy and unambiguous way to express structures for protocol messages and data formats that use CBOR or JSON.}, +} @misc{rfc9171, series = {Request for Comments}, number = 9171, diff --git a/docs/api/spellcheck.xsl b/docs/api/spellcheck.xsl index 5ef959ff..64d3caa6 100644 --- a/docs/api/spellcheck.xsl +++ b/docs/api/spellcheck.xsl @@ -27,6 +27,7 @@ + diff --git a/src/backend/SecParam.h b/src/backend/SecParam.h index 4f426c11..823fcc71 100644 --- a/src/backend/SecParam.h +++ b/src/backend/SecParam.h @@ -26,7 +26,7 @@ * * @details * - * The details from the RFC are as follows: + * The details from the RFC Section 3.6 @cite rfc9172 are as follows: * *
* This field captures one or more security context parameters that should be used @@ -47,8 +47,6 @@ * *
* - * @cite https://www.rfc-editor.org/rfc/rfc9172.html#section-3.6-3.10.1 - * * @author Bill.Van.Besien@jhuapl.edu */ /** @file diff --git a/src/mock_bpa/CMakeLists.txt b/src/mock_bpa/CMakeLists.txt index 14db2aac..213ea4d1 100644 --- a/src/mock_bpa/CMakeLists.txt +++ b/src/mock_bpa/CMakeLists.txt @@ -25,35 +25,32 @@ target_compile_options(bsl_mock_bpa PRIVATE -Wshadow -Wpointer-arith -Wstrict-pr target_sources( bsl_mock_bpa PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa.h - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_crc.h - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_eid.h - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_eidpat.h - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_encode.h - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_decode.h - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_policy_config.h - ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa_policy_params.h - ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa_policy_registry.h - ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa_ctr.h - ${CMAKE_CURRENT_SOURCE_DIR}/BPSecLib_MockBPA.h + ${CMAKE_CURRENT_SOURCE_DIR}/agent.h + ${CMAKE_CURRENT_SOURCE_DIR}/crc.h + ${CMAKE_CURRENT_SOURCE_DIR}/eid.h + ${CMAKE_CURRENT_SOURCE_DIR}/eidpat.h + ${CMAKE_CURRENT_SOURCE_DIR}/encode.h + ${CMAKE_CURRENT_SOURCE_DIR}/decode.h + ${CMAKE_CURRENT_SOURCE_DIR}/text_util.h + ${CMAKE_CURRENT_SOURCE_DIR}/policy_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/policy_params.h + ${CMAKE_CURRENT_SOURCE_DIR}/policy_registry.h + ${CMAKE_CURRENT_SOURCE_DIR}/ctr.h + ${CMAKE_CURRENT_SOURCE_DIR}/MockBPA.h ) target_sources( bsl_mock_bpa PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa.c - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_crc.c - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_eid.c - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_eidpat.c - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_encode.c - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_decode.c - ${CMAKE_CURRENT_SOURCE_DIR}/bsl_mock_bpa_policy_config.c - ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa_policy_params.c - ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa_policy_registry.c - ${CMAKE_CURRENT_SOURCE_DIR}/mock_bpa_ctr.c -) -target_include_directories( - bsl_mock_bpa PUBLIC - $ - $/include/bsl> + ${CMAKE_CURRENT_SOURCE_DIR}/agent.c + ${CMAKE_CURRENT_SOURCE_DIR}/crc.c + ${CMAKE_CURRENT_SOURCE_DIR}/eid.c + ${CMAKE_CURRENT_SOURCE_DIR}/eidpat.c + ${CMAKE_CURRENT_SOURCE_DIR}/encode.c + ${CMAKE_CURRENT_SOURCE_DIR}/decode.c + ${CMAKE_CURRENT_SOURCE_DIR}/text_util.c + ${CMAKE_CURRENT_SOURCE_DIR}/policy_config.c + ${CMAKE_CURRENT_SOURCE_DIR}/policy_params.c + ${CMAKE_CURRENT_SOURCE_DIR}/policy_registry.c + ${CMAKE_CURRENT_SOURCE_DIR}/ctr.c ) set_target_properties(bsl_mock_bpa PROPERTIES @@ -63,11 +60,11 @@ set_target_properties(bsl_mock_bpa target_link_libraries(bsl_mock_bpa PUBLIC MLIB::mlib) target_link_libraries(bsl_mock_bpa PUBLIC QCBOR::qcbor) target_link_libraries(bsl_mock_bpa PUBLIC Jansson::Jansson) -target_link_libraries(bsl_mock_bpa PUBLIC bsl_front bsl_default_sc bsl_sample_pp) +target_link_libraries(bsl_mock_bpa PUBLIC bsl_front bsl_dynamic bsl_default_sc bsl_sample_pp) add_executable(bsl-mock-bpa) target_sources(bsl-mock-bpa PRIVATE mock_bpa.c) -target_link_libraries(bsl-mock-bpa PUBLIC bsl_mock_bpa bsl_dynamic bsl_default_sc bsl_sample_pp bsl_crypto) +target_link_libraries(bsl-mock-bpa PUBLIC bsl_mock_bpa bsl_crypto) target_link_libraries(bsl-mock-bpa PUBLIC Threads::Threads) # Installation config diff --git a/src/mock_bpa/BPSecLib_MockBPA.h b/src/mock_bpa/MockBPA.h similarity index 77% rename from src/mock_bpa/BPSecLib_MockBPA.h rename to src/mock_bpa/MockBPA.h index 7e6b8150..bb031689 100644 --- a/src/mock_bpa/BPSecLib_MockBPA.h +++ b/src/mock_bpa/MockBPA.h @@ -19,13 +19,13 @@ * the prime contract 80NM0018D0004 between the Caltech and NASA under * subcontract 1700763. */ -#ifndef _BSL_MockBPA_BPSECLIB_MockBPA_H_ -#define _BSL_MockBPA_BPSECLIB_MockBPA_H_ +#ifndef _BSL_MockBPA_MockBPA_H_ +#define _BSL_MockBPA_MockBPA_H_ -#include "bsl_mock_bpa_crc.h" -#include "bsl_mock_bpa_encode.h" -#include "bsl_mock_bpa_decode.h" -#include "bsl_mock_bpa_eidpat.h" -#include "bsl_mock_bpa.h" +#include "crc.h" +#include "encode.h" +#include "decode.h" +#include "agent.h" +#include "eidpat.h" -#endif //_BSL_MockBPA_BPSECLIB_MockBPA_H_ +#endif //_BSL_MockBPA_MockBPA_H_ diff --git a/src/mock_bpa/bsl_mock_bpa.c b/src/mock_bpa/agent.c similarity index 97% rename from src/mock_bpa/bsl_mock_bpa.c rename to src/mock_bpa/agent.c index 41722516..95e94d8d 100644 --- a/src/mock_bpa/bsl_mock_bpa.c +++ b/src/mock_bpa/agent.c @@ -27,11 +27,11 @@ #include #include #include -#include "bsl_mock_bpa.h" -#include "bsl_mock_bpa_eid.h" -#include "bsl_mock_bpa_eidpat.h" -#include "bsl_mock_bpa_encode.h" -#include "bsl_mock_bpa_decode.h" +#include "agent.h" +#include "eid.h" +#include "eidpat.h" +#include "encode.h" +#include "decode.h" int MockBPA_Bundle_Deinit(MockBPA_Bundle_t *bundle) { @@ -261,7 +261,7 @@ int MockBPA_DeleteBundle(BSL_BundleRef_t *bundle_ref) return 0; } -int bsl_mock_bpa_init(void) +int bsl_mock_bpa_agent_init(void) { uint8_t *state = BSL_MALLOC(999); @@ -292,7 +292,7 @@ int bsl_mock_bpa_init(void) return BSL_HostDescriptors_Set(bpa); } -void bsl_mock_bpa_deinit(void) +void bsl_mock_bpa_agent_deinit(void) { BSL_HostDescriptors_t bpa; BSL_HostDescriptors_Get(&bpa); diff --git a/src/mock_bpa/bsl_mock_bpa.h b/src/mock_bpa/agent.h similarity index 97% rename from src/mock_bpa/bsl_mock_bpa.h rename to src/mock_bpa/agent.h index 048871e7..e22240c1 100644 --- a/src/mock_bpa/bsl_mock_bpa.h +++ b/src/mock_bpa/agent.h @@ -97,11 +97,11 @@ int MockBPA_DeleteBundle(BSL_BundleRef_t *bundle_ref); /** Register this mock BPA for the current process. * @return Zero if successful. */ -int bsl_mock_bpa_init(void); +int bsl_mock_bpa_agent_init(void); /** Clean up the mock BPA for the current process. */ -void bsl_mock_bpa_deinit(void); +void bsl_mock_bpa_agent_deinit(void); #ifdef __cplusplus } // extern C diff --git a/src/mock_bpa/bsl_mock_bpa_crc.c b/src/mock_bpa/crc.c similarity index 99% rename from src/mock_bpa/bsl_mock_bpa_crc.c rename to src/mock_bpa/crc.c index 6a34bd45..2eead850 100644 --- a/src/mock_bpa/bsl_mock_bpa_crc.c +++ b/src/mock_bpa/crc.c @@ -25,7 +25,7 @@ * Declarations for BPv7 block CRC handling. */ -#include "bsl_mock_bpa_crc.h" +#include "crc.h" #include #include #include diff --git a/src/mock_bpa/bsl_mock_bpa_crc.h b/src/mock_bpa/crc.h similarity index 100% rename from src/mock_bpa/bsl_mock_bpa_crc.h rename to src/mock_bpa/crc.h diff --git a/src/mock_bpa/mock_bpa_ctr.c b/src/mock_bpa/ctr.c similarity index 97% rename from src/mock_bpa/mock_bpa_ctr.c rename to src/mock_bpa/ctr.c index deccb0dd..62765fdc 100644 --- a/src/mock_bpa/mock_bpa_ctr.c +++ b/src/mock_bpa/ctr.c @@ -21,9 +21,9 @@ */ #include -#include "mock_bpa_ctr.h" -#include "bsl_mock_bpa_decode.h" -#include "bsl_mock_bpa_encode.h" +#include "ctr.h" +#include "decode.h" +#include "encode.h" void mock_bpa_ctr_init(mock_bpa_ctr_t *ctr) { diff --git a/src/mock_bpa/mock_bpa_ctr.h b/src/mock_bpa/ctr.h similarity index 98% rename from src/mock_bpa/mock_bpa_ctr.h rename to src/mock_bpa/ctr.h index 889afab6..94de9cf8 100644 --- a/src/mock_bpa/mock_bpa_ctr.h +++ b/src/mock_bpa/ctr.h @@ -26,7 +26,7 @@ #include #include -#include "bsl_mock_bpa.h" +#include "agent.h" /// A container for encoded and decoded bundle data typedef struct diff --git a/src/mock_bpa/bsl_mock_bpa_decode.c b/src/mock_bpa/decode.c similarity index 98% rename from src/mock_bpa/bsl_mock_bpa_decode.c rename to src/mock_bpa/decode.c index 03c8c064..3ea49275 100644 --- a/src/mock_bpa/bsl_mock_bpa_decode.c +++ b/src/mock_bpa/decode.c @@ -24,9 +24,9 @@ * Definitions for bundle and block decoding. * @ingroup mock_bpa */ -#include "bsl_mock_bpa.h" -#include "bsl_mock_bpa_decode.h" -#include "bsl_mock_bpa_crc.h" +#include "decode.h" +#include "agent.h" +#include "crc.h" #include #include diff --git a/src/mock_bpa/bsl_mock_bpa_decode.h b/src/mock_bpa/decode.h similarity index 98% rename from src/mock_bpa/bsl_mock_bpa_decode.h rename to src/mock_bpa/decode.h index 1b04ae28..2aa98953 100644 --- a/src/mock_bpa/bsl_mock_bpa_decode.h +++ b/src/mock_bpa/decode.h @@ -27,7 +27,8 @@ #ifndef BSL_MOCK_BPA_DECODE_H_ #define BSL_MOCK_BPA_DECODE_H_ -#include "bsl_mock_bpa_eid.h" +#include "agent.h" +#include "eid.h" #include #include diff --git a/src/mock_bpa/bsl_mock_bpa_eid.c b/src/mock_bpa/eid.c similarity index 99% rename from src/mock_bpa/bsl_mock_bpa_eid.c rename to src/mock_bpa/eid.c index 4cec5b1f..2c1f2026 100644 --- a/src/mock_bpa/bsl_mock_bpa_eid.c +++ b/src/mock_bpa/eid.c @@ -24,7 +24,7 @@ * @ingroup mock_bpa * Definitions for EID handling. */ -#include "bsl_mock_bpa_eid.h" +#include "eid.h" #include #include diff --git a/src/mock_bpa/bsl_mock_bpa_eid.h b/src/mock_bpa/eid.h similarity index 100% rename from src/mock_bpa/bsl_mock_bpa_eid.h rename to src/mock_bpa/eid.h diff --git a/src/mock_bpa/bsl_mock_bpa_eidpat.c b/src/mock_bpa/eidpat.c similarity index 99% rename from src/mock_bpa/bsl_mock_bpa_eidpat.c rename to src/mock_bpa/eidpat.c index 596c5042..7c73820b 100644 --- a/src/mock_bpa/bsl_mock_bpa_eidpat.c +++ b/src/mock_bpa/eidpat.c @@ -19,7 +19,7 @@ * the prime contract 80NM0018D0004 between the Caltech and NASA under * subcontract 1700763. */ -#include "bsl_mock_bpa_eidpat.h" +#include "eidpat.h" #include #include diff --git a/src/mock_bpa/bsl_mock_bpa_eidpat.h b/src/mock_bpa/eidpat.h similarity index 99% rename from src/mock_bpa/bsl_mock_bpa_eidpat.h rename to src/mock_bpa/eidpat.h index 1023f32a..0a7ffd83 100644 --- a/src/mock_bpa/bsl_mock_bpa_eidpat.h +++ b/src/mock_bpa/eidpat.h @@ -34,7 +34,7 @@ #include -#include "bsl_mock_bpa_eid.h" +#include "eid.h" #ifdef __cplusplus extern "C" { diff --git a/src/mock_bpa/bsl_mock_bpa_encode.c b/src/mock_bpa/encode.c similarity index 98% rename from src/mock_bpa/bsl_mock_bpa_encode.c rename to src/mock_bpa/encode.c index f126e5c0..f93bbe25 100644 --- a/src/mock_bpa/bsl_mock_bpa_encode.c +++ b/src/mock_bpa/encode.c @@ -26,9 +26,9 @@ */ #include -#include "bsl_mock_bpa.h" -#include "bsl_mock_bpa_encode.h" -#include "bsl_mock_bpa_crc.h" +#include "encode.h" +#include "agent.h" +#include "crc.h" int bsl_mock_encode_eid(QCBOREncodeContext *enc, const BSL_HostEID_t *eid) { diff --git a/src/mock_bpa/bsl_mock_bpa_encode.h b/src/mock_bpa/encode.h similarity index 97% rename from src/mock_bpa/bsl_mock_bpa_encode.h rename to src/mock_bpa/encode.h index 5e4ce18e..35636a16 100644 --- a/src/mock_bpa/bsl_mock_bpa_encode.h +++ b/src/mock_bpa/encode.h @@ -27,8 +27,8 @@ #ifndef BSL_MOCK_BPA_ENCODE_H_ #define BSL_MOCK_BPA_ENCODE_H_ -#include "bsl_mock_bpa.h" -#include "bsl_mock_bpa_eid.h" +#include "eid.h" +#include "agent.h" #include #ifdef __cplusplus diff --git a/src/mock_bpa/key_set_1.json b/src/mock_bpa/key_set_1.json index 2d1cb558..70f4517c 100644 --- a/src/mock_bpa/key_set_1.json +++ b/src/mock_bpa/key_set_1.json @@ -3,17 +3,17 @@ { "kty": "oct", "kid": "9100", - "k": "1a2b1a2b1a2b1a2b1a2b1a2b1a2b1a2b" + "k": "GisaKxorGisaKxorGisaKw==" }, { "kty": "oct", "kid": "9102", - "k": "71776572747975696f70617364666768" + "k": "cXdlcnR5dWlvcGFzZGZnaA==" }, { "kty": "oct", "kid": "9103", - "k": "6162636465666768696a6b6c6d6e6f70" + "k": "YWJjZGVmZ2hpamtsbW5vcA==" } ] } diff --git a/src/mock_bpa/mock_bpa.c b/src/mock_bpa/mock_bpa.c index 7cf56693..121d7187 100644 --- a/src/mock_bpa/mock_bpa.c +++ b/src/mock_bpa/mock_bpa.c @@ -39,10 +39,10 @@ #include #include -#include "bsl_mock_bpa.h" -#include "mock_bpa_ctr.h" -#include "bsl_mock_bpa_policy_config.h" -#include "mock_bpa_policy_registry.h" +#include "agent.h" +#include "ctr.h" +#include "policy_config.h" +#include "policy_registry.h" static atomic_bool stop_state; @@ -635,7 +635,7 @@ int main(int argc, char **argv) atomic_init(&stop_state, false); - if (bsl_mock_bpa_init()) + if (bsl_mock_bpa_agent_init()) { BSL_LOG_ERR("Failed to initialize mock BPA"); retval = 2; @@ -773,7 +773,7 @@ int main(int argc, char **argv) } BSL_CryptoDeinit(); - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); free(bsl); return retval; diff --git a/src/mock_bpa/bsl_mock_bpa_policy_config.c b/src/mock_bpa/policy_config.c similarity index 93% rename from src/mock_bpa/bsl_mock_bpa_policy_config.c rename to src/mock_bpa/policy_config.c index db35e476..c2cd4704 100644 --- a/src/mock_bpa/bsl_mock_bpa_policy_config.c +++ b/src/mock_bpa/policy_config.c @@ -25,40 +25,8 @@ * @ingroup mock_bpa */ -#include "bsl_mock_bpa_policy_config.h" - -int mock_bpa_hexchar_to_int(char c) -{ - if ('0' <= c && c <= '9') - return c - '0'; - if ('a' <= c && c <= 'f') - return c - 'a' + 10; - if ('A' <= c && c <= 'F') - return c - 'A' + 10; - return -1; -} - -int mock_bpa_hexstring_to_bytes(const char *hexstr, uint8_t *out, size_t out_size) -{ - size_t len = strlen(hexstr); - if (len % 2 != 0 || out_size < len / 2) - { - return -1; - } - - for (size_t i = 0; i < len / 2; ++i) - { - int high = mock_bpa_hexchar_to_int(hexstr[2 * i]); - int low = mock_bpa_hexchar_to_int(hexstr[2 * i + 1]); - if (high == -1 || low == -1) - { - return -1; - } - out[i] = (high << 4) | low; - } - - return (int)(len / 2); -} +#include "policy_config.h" +#include "text_util.h" static BSL_HostEIDPattern_t mock_bpa_util_get_eid_pattern_from_text(const char *text) { @@ -633,7 +601,7 @@ int mock_bpa_key_registry_init(const char *pp_cfg_file_path) size_t n = json_array_size(keys); printf("Found %zu key objects\n\n", n); - for (size_t i = 0; i < n; ++i) + for (size_t i = 0; !retval && (i < n); ++i) { json_t *key_obj = json_array_get(keys, i); if (!json_is_object(key_obj)) @@ -672,28 +640,22 @@ int mock_bpa_key_registry_init(const char *pp_cfg_file_path) const char *k_str = json_string_value(k); BSL_LOG_DEBUG("k: %s\n", k_str); - uint8_t key_buf[strlen(k_str) / 2]; - mock_bpa_hexstring_to_bytes(k_str, key_buf, sizeof(key_buf)); - - retval = BSL_Crypto_AddRegistryKey(kid_str, key_buf, strlen(k_str) / 2); + m_string_t k_text; + m_string_init_set_cstr(k_text, k_str); + m_bstring_t k_data; + m_bstring_init(k_data); - // char cmd[100]; - // sprintf(cmd,"echo \"%s\" | basenc --decode --base64url | basenc --base16 --wrap=0", k_str); - // FILE *pipe = popen(cmd, "r"); - // if (pipe == NULL) - // { - // BSL_LOG_ERR("Failed to establish pipe"); - // return 1; - // } + retval = mock_bpa_base64_decode(k_data, k_text); - // uint8_t kstr_buf[1024]; - // while (fgets((char *) kstr_buf, sizeof(kstr_buf), pipe) != NULL) - // { - // BSL_LOG_DEBUG("%s", kstr_buf); + if (!retval) + { + const size_t k_len = m_bstring_size(k_data); + const uint8_t *k_ptr = m_bstring_view(k_data, 0, k_len); - // retval = BSL_Crypto_AddRegistryKey(kid_str, kstr_buf, sizeof(kstr_buf)); - // } - // pclose(pipe); + retval = BSL_Crypto_AddRegistryKey(kid_str, k_ptr, k_len); + } + m_bstring_clear(k_data); + m_string_clear(k_text); } json_decref(root); diff --git a/src/mock_bpa/bsl_mock_bpa_policy_config.h b/src/mock_bpa/policy_config.h similarity index 96% rename from src/mock_bpa/bsl_mock_bpa_policy_config.h rename to src/mock_bpa/policy_config.h index d6a3f059..01e68998 100644 --- a/src/mock_bpa/bsl_mock_bpa_policy_config.h +++ b/src/mock_bpa/policy_config.h @@ -37,7 +37,7 @@ #include #include -#include "mock_bpa_policy_registry.h" +#include "policy_registry.h" #ifdef __cplusplus extern "C" { @@ -79,9 +79,6 @@ void mock_bpa_handle_policy_config_from_json(const char *pp_cfg_file_path, BSLP_ int mock_bpa_key_registry_init(const char *pp_cfg_file_path); -int mock_bpa_hexchar_to_int(char c); - -int mock_bpa_hexstring_to_bytes(const char *hexstr, uint8_t *out, size_t out_size); int bsl_mock_bpa_rfc9173_bcb_cek(unsigned char *buf, int len); #ifdef __cplusplus diff --git a/src/mock_bpa/mock_bpa_policy_params.c b/src/mock_bpa/policy_params.c similarity index 98% rename from src/mock_bpa/mock_bpa_policy_params.c rename to src/mock_bpa/policy_params.c index e645f61a..e33a2888 100644 --- a/src/mock_bpa/mock_bpa_policy_params.c +++ b/src/mock_bpa/policy_params.c @@ -25,7 +25,7 @@ * @ingroup mock_bpa */ -#include "mock_bpa_policy_params.h" +#include "policy_params.h" void mock_bpa_policy_params_init(mock_bpa_policy_params_t *params, int policy_num) { diff --git a/src/mock_bpa/mock_bpa_policy_params.h b/src/mock_bpa/policy_params.h similarity index 100% rename from src/mock_bpa/mock_bpa_policy_params.h rename to src/mock_bpa/policy_params.h diff --git a/src/mock_bpa/mock_bpa_policy_registry.c b/src/mock_bpa/policy_registry.c similarity index 98% rename from src/mock_bpa/mock_bpa_policy_registry.c rename to src/mock_bpa/policy_registry.c index c9532bfa..f4ce713d 100644 --- a/src/mock_bpa/mock_bpa_policy_registry.c +++ b/src/mock_bpa/policy_registry.c @@ -25,7 +25,7 @@ * @ingroup mock_bpa */ -#include "mock_bpa_policy_registry.h" +#include "policy_registry.h" void mock_bpa_policy_registry_init(mock_bpa_policy_registry_t *registry) { diff --git a/src/mock_bpa/mock_bpa_policy_registry.h b/src/mock_bpa/policy_registry.h similarity index 98% rename from src/mock_bpa/mock_bpa_policy_registry.h rename to src/mock_bpa/policy_registry.h index 1f5f8e00..219e1622 100644 --- a/src/mock_bpa/mock_bpa_policy_registry.h +++ b/src/mock_bpa/policy_registry.h @@ -30,7 +30,7 @@ #include -#include "mock_bpa_policy_params.h" +#include "policy_params.h" #ifdef __cplusplus extern "C" { diff --git a/src/mock_bpa/text_util.c b/src/mock_bpa/text_util.c new file mode 100644 index 00000000..b51d100e --- /dev/null +++ b/src/mock_bpa/text_util.c @@ -0,0 +1,707 @@ +/* + * Copyright (c) 2025 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Bundle Protocol Security Library (BSL). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work was performed for the Jet Propulsion Laboratory, California + * Institute of Technology, sponsored by the United States Government under + * the prime contract 80NM0018D0004 between the Caltech and NASA under + * subcontract 1700763. + */ +#include "text_util.h" +#include +#include +#include +#include +#include +#include + +static int take_hex_1byte(uint8_t *out, const char **curs, const char *end) +{ + if (*curs + 2 > end) + { + return 1; + } + + char buf[] = { *((*curs)++), *((*curs)++), 0 }; + char *numend; + *out = strtoul(buf, &numend, 16); + if (numend < buf + 2) + { + return 2; + } + return 0; +} + +static int take_hex_2byte(uint16_t *out, const char **curs, const char *end) +{ + if (*curs + 4 > end) + { + return 1; + } + + char buf[] = { *((*curs)++), *((*curs)++), *((*curs)++), *((*curs)++), 0 }; + char *numend; + *out = strtoul(buf, &numend, 16); + if (numend < buf + 4) + { + return 2; + } + return 0; +} + +/** Set of unreserved characters from Section 2.3 of RFC 3986 @cite rfc3986. + */ +static const char *unreserved = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~"; + +int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char *safe) +{ + CHKERR1(out); + CHKERR1(in); + + const size_t in_len = m_string_size(in); + const char *curs = m_string_get_cstr(in); + const char *end = curs + in_len; + + m_string_t allsafe; + m_string_init(allsafe); + m_string_cat_cstr(allsafe, unreserved); + if (safe) + { + m_string_cat_cstr(allsafe, safe); + } + + // assume no more than half of the input chars are escaped, + // which gives total output size of: 0.5 + 0.5 * 3 => 2 + m_string_reserve(out, m_string_size(out) + 2 * in_len); + + int retval = 0; + while (curs < end) + { + const size_t partlen = strspn(curs, m_string_get_cstr(allsafe)); + + if (partlen) + { + m_string_cat_printf(out, "%.*s", (int)partlen, curs); + } + curs += partlen; + + if (curs >= end) + { + // no unsafe char and no more text + break; + } + + const uint8_t chr = *(curs++); + m_string_cat_printf(out, "%%%02X", chr); + } + + m_string_clear(allsafe); + return retval; +} + +int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in) +{ + CHKERR1(out); + CHKERR1(in); + + const size_t in_len = m_string_size(in); + const char *curs = m_string_get_cstr(in); + const char *end = curs + in_len; + + // potentially no escaping used + m_string_reserve(out, m_string_size(out) + in_len); + + while (curs < end) + { + const char *partend = strchr(curs, '%'); + if (partend == NULL) + { + partend = end; + } + const size_t partlen = partend - curs; + + if (partlen) + { + m_string_cat_printf(out, "%.*s", (int)partlen, curs); + } + curs += partlen + 1; + + if (curs > end) + { + // no percent and no more text + break; + } + + // cursor is on the percent char + uint8_t val; + if (take_hex_1byte(&val, &curs, end)) + { + return 2; + } + m_string_push_back(out, val); + } + + return 0; +} + +int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote) +{ + CHKERR1(out); + CHKERR1(in); + + // unicode iterator + m_string_it_t it; + for (m_string_it(it, in); !m_string_end_p(it); m_string_next(it)) + { + const m_string_unicode_t *chr = m_string_cref(it); + if (*chr == (m_string_unicode_t)quote) + { + m_string_push_back(out, '\\'); + m_string_push_back(out, quote); + } + else if (*chr == 0x08) + { + m_string_cat_cstr(out, "\\b"); + } + else if (*chr == 0x0C) + { + m_string_cat_cstr(out, "\\f"); + } + else if (*chr == 0x0A) + { + m_string_cat_cstr(out, "\\n"); + } + else if (*chr == 0x0D) + { + m_string_cat_cstr(out, "\\r"); + } + else if (*chr == 0x09) + { + m_string_cat_cstr(out, "\\t"); + } + else if ((*chr <= 0xFF) && isprint(*chr)) + { + m_string_push_u(out, *chr); + } + else if ((*chr <= 0xD7FF) || ((*chr >= 0xE000) && (*chr <= 0xFFFF))) + { + const uint16_t uprime = *chr; + m_string_cat_printf(out, "\\u%04" PRIX16, uprime); + } + else + { + // surrogate pair creation + const uint32_t uprime = *chr - 0x10000; + const uint16_t high = 0xD800 + (uprime >> 10); + const uint16_t low = 0xDC00 + (uprime & 0x03FF); + m_string_cat_printf(out, "\\u%04" PRIX16 "\\u%04" PRIX16, high, low); + } + } + return 0; +} + +int mock_bpa_slash_unescape(m_string_t out, const m_string_t in) +{ + CHKERR1(out); + CHKERR1(in); + + const size_t in_len = m_string_size(in); + if (in_len == 0) + { + return 0; + } + + // potentially no escaping used + m_string_reserve(out, m_string_size(out) + in_len); + + const char *curs = m_string_get_cstr(in); + const char *end = curs + in_len; + int retval = 0; + while (curs < end) + { + const char *partend = strchr(curs, '\\'); + if (partend == NULL) + { + partend = end; + } + const size_t partlen = partend - curs; + + if (partlen) + { + m_string_cat_printf(out, "%.*s", (int)partlen, curs); + } + curs += partlen + 1; + + if (curs > end) + { + // no backslash and no more text + break; + } + else if (curs == end) + { + // backslash with no trailing character + retval = 3; + break; + } + + if (*curs == 'b') + { + m_string_push_back(out, 0x08); + curs += 1; + } + else if (*curs == 'f') + { + m_string_push_back(out, 0x0C); + curs += 1; + } + else if (*curs == 'n') + { + m_string_push_back(out, 0x0A); + curs += 1; + } + else if (*curs == 'r') + { + m_string_push_back(out, 0x0D); + curs += 1; + } + else if (*curs == 't') + { + m_string_push_back(out, 0x09); + curs += 1; + } + else if (*curs == 'u') + { + ++curs; + + uint16_t val; + if (take_hex_2byte(&val, &curs, end)) + { + retval = 5; + break; + } + + m_string_unicode_t unival; + if ((val >= 0xD800) && (val <= 0xDFFF)) + { + // surrogate pair removal + unival = (val - 0xD800) << 10; + + if (curs + 2 >= end) + { + retval = 5; + break; + } + if (*curs != '\\') + { + retval = 5; + break; + } + ++curs; + if (*curs != 'u') + { + retval = 5; + break; + } + ++curs; + + if (take_hex_2byte(&val, &curs, end)) + { + retval = 5; + break; + } + unival |= val - 0xDC00; + + unival += 0x10000; + } + else + { + unival = val; + } + + m_string_push_u(out, unival); + } + else + { + m_string_push_back(out, *curs); + curs += 1; + } + } + + return retval; +} + +static void strip_chars(m_string_t out, const char *in, size_t in_len, const char *chars) +{ + const char *curs = in; + const char *end = curs + in_len; + size_t plen; + + // likely no removal + m_string_reserve(out, in_len); + + while (curs < end) + { + plen = strcspn(curs, chars); + m_string_cat_printf(out, "%.*s", (int)plen, curs); + curs += plen; + + plen = strspn(curs, chars); + curs += plen; + } +} + +void mock_bpa_strip_space(m_string_t out, const char *in, size_t in_len) +{ + strip_chars(out, in, in_len, " \b\f\n\r\t"); +} + +void mock_bpa_string_tolower(m_string_t out) +{ + CHKVOID(out); + size_t len = m_string_size(out); + for (size_t i = 0; i < len; i++) + { + m_string_set_char(out, i, tolower(m_string_get_char(out, i))); + } +} + +void mock_bpa_string_toupper(m_string_t out) +{ + CHKVOID(out); + size_t len = m_string_size(out); + for (size_t i = 0; i < len; i++) + { + m_string_set_char(out, i, toupper(m_string_get_char(out, i))); + } +} + +int mock_bpa_base16_encode(m_string_t out, const m_bstring_t in, bool uppercase) +{ + const char *fmt = uppercase ? "%02X" : "%02x"; + + const size_t in_len = m_bstring_size(in); + const uint8_t *curs = m_bstring_view(in, 0, in_len); + const uint8_t *end = curs + in_len; + for (; curs < end; ++curs) + { + m_string_cat_printf(out, fmt, *curs); + } + return 0; +} + +/// Size of the base16_decode_table +static const size_t base16_decode_lim = 0x80; +// clang-format off +/// Decode table for base16 +static const int base16_decode_table[0x80] = +{ + -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -1, -1, -2, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; +// clang-format on + +/** Decode a single character. + * + * @param chr The character to decode. + * @return If positive, the decoded value. + * -1 to indicate error. + * -2 to indicate whitespace. + */ +static int base16_decode_char(uint8_t chr) +{ + if (chr >= base16_decode_lim) + { + return -1; + } + return base16_decode_table[chr]; +} + +int mock_bpa_base16_decode(m_bstring_t out, const m_string_t in) +{ + CHKERR1(out); + CHKERR1(in); + + const size_t in_len = m_string_size(in); + if (in_len % 2 != 0) + { + return 1; + } + const char *curs = m_string_get_cstr(in); + const char *end = curs + in_len; + + const size_t out_len = in_len / 2; + m_bstring_resize(out, out_len); + uint8_t *out_curs = m_bstring_acquire_access(out, 0, out_len); + ; + + int retval = 0; + while (curs < end) + { + const int high = base16_decode_char(*(curs++)); + const int low = base16_decode_char(*(curs++)); + if ((high < 0) || (low < 0)) + { + retval = 3; + break; + } + + const uint8_t byte = (high << 4) | low; + *(out_curs++) = byte; + } + + m_bstring_release_access(out); + return retval; +} + +// clang-format off +static const char *base64_alphabet = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; +static const char *base64url_alphabet = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789-_"; +// clang-format on + +int mock_bpa_base64_encode(m_string_t out, const m_bstring_t in, bool useurl, bool usepad) +{ + size_t in_len = m_bstring_size(in); + const uint8_t *curs = m_bstring_view(in, 0, in_len); + const uint8_t *end = curs + in_len; + + const char *const abet = useurl ? base64url_alphabet : base64_alphabet; + + // output length is the ceiling of ratio 8/6 + size_t out_len = ((in_len + 2) / 3) * 4; + m_string_reserve(out, m_string_size(out) + out_len); + + for (; curs < end; curs += 3) + { + uint8_t byte = (curs[0] >> 2) & 0x3F; + char chr = abet[byte]; + m_string_push_back(out, chr); + --in_len; + if (--out_len == 0) + { + break; + } + + byte = ((curs[0] << 4) | (in_len ? curs[1] >> 4 : 0)) & 0x3F; + chr = abet[byte]; + m_string_push_back(out, chr); + if (--out_len == 0) + { + break; + } + + if (in_len) + { + --in_len; + byte = ((curs[1] << 2) | (in_len ? curs[2] >> 6 : 0)) & 0x3F; + chr = abet[byte]; + } + else + { + chr = '='; + } + if (usepad || (chr != '=')) + { + m_string_push_back(out, chr); + } + if (--out_len == 0) + { + break; + } + + if (in_len) + { + --in_len; + byte = curs[2] & 0x3F; + chr = abet[byte]; + } + else + { + chr = '='; + } + if (usepad || (chr != '=')) + { + m_string_push_back(out, chr); + } + if (--out_len == 0) + { + break; + } + } + return 0; +} + +/// Size of the base16_decode_table +static const size_t base64_decode_lim = 0x80; +// clang-format off +/// Decode table for base64 and base64uri +static const int base64_decode_table[0x80] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, +}; +// clang-format on + +/** Decode a single character. + * + * @param chr The character to decode. + * @return If positive, the decoded value. + * -1 to indicate error. + * -2 to indicate whitespace. + */ +static int base64_decode_char(uint8_t chr) +{ + if (chr >= base64_decode_lim) + { + return -1; + } + return base64_decode_table[chr]; +} + +int mock_bpa_base64_decode(m_bstring_t out, const m_string_t in) +{ + CHKERR1(out); + CHKERR1(in); + + size_t in_len = m_string_size(in); + const char *curs = m_string_get_cstr(in); + + size_t out_len = (in_len / 4) * 3 + 2; + m_bstring_resize(out, out_len); + uint8_t *out_curs = m_bstring_acquire_access(out, 0, out_len); + + int retval = 0; + for (; in_len >= 2; curs += 4, in_len -= 4) + { + // ignoring excess padding + if (curs[0] == '=') + { + break; + } + + const int seg0 = base64_decode_char(curs[0]); + const int seg1 = base64_decode_char(curs[1]); + if ((seg0 < 0) || (seg1 < 0)) + { + retval = 3; + break; + } + + if (out_len) + { + const uint8_t byte = (seg0 << 2) | (seg1 >> 4); + *(out_curs++) = byte; + --out_len; + } + + if (in_len == 2) + { + // allow omitted padding + in_len = 0; + break; + } + else if (curs[2] == '=') + { + if (in_len != 4) + { + break; + } + if (curs[3] != '=') + { + break; + } + } + else + { + const int seg2 = base64_decode_char(curs[2]); + if (seg2 < 0) + { + retval = 3; + break; + } + + if (out_len) + { + const uint8_t byte = ((seg1 << 4) & 0xF0) | (seg2 >> 2); + *(out_curs++) = byte; + --out_len; + } + + if (in_len == 3) + { + // allow omitted padding + in_len = 0; + break; + } + else if (curs[3] == '=') + { + if (in_len != 4) + { + break; + } + } + else + { + const int seg3 = base64_decode_char(curs[3]); + if (seg3 < 0) + { + retval = 3; + break; + } + + if (out_len) + { + const uint8_t byte = ((seg2 << 6) & 0xC0) | seg3; + *(out_curs++) = byte; + --out_len; + } + } + } + } + + // trim if necessary + m_bstring_release_access(out); + m_bstring_resize(out, m_bstring_size(out) - out_len); + + if (retval) + { + return retval; + } + + // Per Section 3.3 of RFC 4648, ignoring excess padding + while ((in_len > 0) && (*curs == '=')) + { + ++curs; + --in_len; + } + + return (in_len > 0) ? 4 : 0; +} diff --git a/src/mock_bpa/text_util.h b/src/mock_bpa/text_util.h new file mode 100644 index 00000000..09b22790 --- /dev/null +++ b/src/mock_bpa/text_util.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2025 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Bundle Protocol Security Library (BSL). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work was performed for the Jet Propulsion Laboratory, California + * Institute of Technology, sponsored by the United States Government under + * the prime contract 80NM0018D0004 between the Caltech and NASA under + * subcontract 1700763. + */ +/** @file + * This file contains definitions for text CODEC functions. + * @ingroup mock_bpa + */ +#ifndef MOCK_BPA_TEXT_UTIL_H_ +#define MOCK_BPA_TEXT_UTIL_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Encode to URI percent-encoding text form. + * This is defined in Section 2.1 of RFC 3986 @cite rfc3986. + * The set of unreserved characters are alpha, digits, and _.-~ characters. + * in accordance with Section 2.3 of RFC 3986 @cite rfc3986. + * + * @param[out] out The output buffer, which will be appended to. + * @param in The input encoded text which is null-terminated. + * @param safe A set of additional safe characters to not be encoded, + * which is null-terminated. + * @return Zero upon success. + */ +int mock_bpa_uri_percent_encode(m_string_t out, const m_string_t in, const char *safe); + +/** Decode from URI percent-encoding text form. + * This is defined in Section 2.1 of RFC 3986 @cite rfc3986. + * + * @param[out] out The output buffer, which will be appended to. + * @param[in] in The input encoded text which may be null-terminated. + * @return Zero upon success. + */ +int mock_bpa_uri_percent_decode(m_string_t out, const m_string_t in); + +/** Escape backslashes in tstr or bstr text form. + * This is defined in Section G.2 of RFC 8610 @cite rfc8610 + * and Section 7 of RFC 8259 @cite rfc8259. + * + * @param[out] out The output buffer, which will be appended to. + * @param in The input buffer to read, which must be null terminated. + * @param quote The character used to quote the string. + * @return Zero upon success. + */ +int mock_bpa_slash_escape(m_string_t out, const m_string_t in, const char quote); + +/** Unescape backslashes in tstr/bstr text form. + * This is defined in Section G.2 of RFC8610 @cite rfc8610. + * + * @param[out] out The output buffer, which will be appended to. + * @param in The input buffer to read, which may be null terminated. + * @return Zero upon success. + */ +int mock_bpa_slash_unescape(m_string_t out, const m_string_t in); + +/** Remove whitespace characters from a text string. + * This is based on isspace() inspection. + * + * @param[out] out The output buffer, which will be replaced. + * @param[in] in The input text to read. + * @param in_len The length of text not including null terminator. + */ +void mock_bpa_strip_space(m_string_t out, const char *in, size_t in_len); + +/** Convert a text string to lowercase. + * This is written to work on byte strings, not unicode. + * + * @param[out] out The output buffer, which will be replaced. + */ +void mock_bpa_string_tolower(m_string_t out); + +/** Convert a text string to uppercase. + * This is written to work on byte strings, not unicode. + * + * @param[out] out The output buffer, which will be replaced. + */ +void mock_bpa_string_toupper(m_string_t out); + +/** Encode to base16 text form. + * This is defined in Section 8 of RFC 4648 @cite rfc4648. + * + * @param[out] out The output buffer, which will be appended to. + * @param[in] in The input buffer to read. + * @param uppercase True to use upper-case letters, false to use lower-case. + * @return Zero upon success. + */ +int mock_bpa_base16_encode(m_string_t out, const m_bstring_t in, bool uppercase); + +/** Decode base16 text form. + * This is defined in Section 8 of RFC 4648 @cite rfc4648. + * + * @param[out] out The output buffer, which will be sized to its data. + * @param[in] in The input buffer to read, which must be null terminated. + * Whitespace in the input must have already been removed with strip_space(). + * @return Zero upon success. + */ +int mock_bpa_base16_decode(m_bstring_t out, const m_string_t in); + +/** Encode base64 and base64url text forms. + * These is defined in Section 4 and 5 of RFC 4648 @cite rfc4648. + * + * @param[out] out The output buffer, which will be appended to. + * @param[in] in The input buffer to read. + * @param useurl True to use the base64url alphabet, false to use the base64 + * alphabet. + * @param usepad True to include padding characters (=), false to not + * use padding. + * @return Zero upon success. + */ +int mock_bpa_base64_encode(m_string_t out, const m_bstring_t in, bool useurl, bool usepad); + +/** Decode base64 and base64url text forms. + * These is defined in Section 4 and 5 of RFC 4648 @cite rfc4648. + * + * @param[out] out The output buffer, which will be sized to its data. + * @param[in] in The input buffer to read, which must be null terminated. + * Whitespace in the input must have already been removed with strip_space(). + * @return Zero upon success. + */ +int mock_bpa_base64_decode(m_bstring_t out, const m_string_t in); + +#ifdef __cplusplus +} +#endif + +#endif /* MOCK_BPA_TEXT_UTIL_H_ */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7d2c7a42..23e65872 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -50,6 +50,9 @@ install( set(LIB_ORDERED bsl_front bsl_dynamic bsl_mock_bpa bsl_test_utils) +add_unity_test(SOURCE test_MockBPA_text_util.c) +target_link_libraries(test_MockBPA_text_util PUBLIC bsl_mock_bpa) + add_unity_test(SOURCE test_MockBPA_EID.c) target_link_libraries(test_MockBPA_EID PUBLIC ${LIB_ORDERED}) diff --git a/test/bsl_test_utils.c b/test/bsl_test_utils.c index dfe47aee..22e0e0a9 100644 --- a/test/bsl_test_utils.c +++ b/test/bsl_test_utils.c @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/test/bsl_test_utils.h b/test/bsl_test_utils.h index dc0b1940..6c0e74a0 100644 --- a/test/bsl_test_utils.h +++ b/test/bsl_test_utils.h @@ -30,7 +30,7 @@ #include #include -#include +#include /// @brief Key ID for the Appendix A1 key in OpenSSL #define RFC9173_EXAMPLE_A1_KEY "9100" diff --git a/test/test_BackendPolicyProvider.c b/test/test_BackendPolicyProvider.c index 831366e2..ec8085c5 100644 --- a/test/test_BackendPolicyProvider.c +++ b/test/test_BackendPolicyProvider.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include @@ -46,7 +46,7 @@ void setUp(void) { BSL_openlog(); memset(&LocalTestCtx, 0, sizeof(LocalTestCtx)); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); setenv("BSL_TEST_LOCAL_IPN_EID", "ipn:2.1", 1); TEST_ASSERT_EQUAL(0, BSL_API_InitLib(&LocalTestCtx.bsl)); @@ -64,7 +64,7 @@ void tearDown(void) { mock_bpa_ctr_deinit(&LocalTestCtx.mock_bpa_ctr); TEST_ASSERT_EQUAL(0, BSL_API_DeinitLib(&LocalTestCtx.bsl)); - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); } diff --git a/test/test_BackendSecurityContext.c b/test/test_BackendSecurityContext.c index b62e788c..cfbe50b0 100644 --- a/test/test_BackendSecurityContext.c +++ b/test/test_BackendSecurityContext.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include #include @@ -47,12 +47,12 @@ static BSL_TestContext_t LocalTestCtx; void suiteSetUp(void) { BSL_openlog(); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); } int suiteTearDown(int failures) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); return failures; } diff --git a/test/test_DefaultSecurityContext.c b/test/test_DefaultSecurityContext.c index b457cb8c..6136e826 100644 --- a/test/test_DefaultSecurityContext.c +++ b/test/test_DefaultSecurityContext.c @@ -37,7 +37,7 @@ #include #include -#include +#include #include #include @@ -52,12 +52,12 @@ static BSL_TestContext_t LocalTestCtx; void suiteSetUp(void) { BSL_openlog(); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); } int suiteTearDown(int failures) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); return failures; } diff --git a/test/test_MockBPA_Codecs.c b/test/test_MockBPA_Codecs.c index 258c3661..44b32585 100644 --- a/test/test_MockBPA_Codecs.c +++ b/test/test_MockBPA_Codecs.c @@ -23,11 +23,10 @@ #include #include -#include -#include -#include +#include +#include +#include -#include "bsl_mock_bpa.h" #include "bsl_test_utils.h" // allow parameterized cases @@ -55,12 +54,12 @@ static void printencoded(const uint8_t *pEncoded, size_t nLen) void suiteSetUp(void) { BSL_openlog(); - TEST_ASSERT_EQUAL_INT(0, bsl_mock_bpa_init()); + TEST_ASSERT_EQUAL_INT(0, bsl_mock_bpa_agent_init()); } int suiteTearDown(int failures) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); return failures; } diff --git a/test/test_MockBPA_EID.c b/test/test_MockBPA_EID.c index 789bdb8b..c8599ff9 100644 --- a/test/test_MockBPA_EID.c +++ b/test/test_MockBPA_EID.c @@ -21,9 +21,9 @@ */ #include -#include -#include -#include +#include +#include +#include // allow parameterized cases #define TEST_CASE(...) @@ -31,12 +31,12 @@ void suiteSetUp(void) { BSL_openlog(); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); } int suiteTearDown(int failures) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); return failures; } diff --git a/test/test_MockBPA_text_util.c b/test/test_MockBPA_text_util.c new file mode 100644 index 00000000..236d03ce --- /dev/null +++ b/test/test_MockBPA_text_util.c @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2025 The Johns Hopkins University Applied Physics + * Laboratory LLC. + * + * This file is part of the Bundle Protocol Security Library (BSL). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This work was performed for the Jet Propulsion Laboratory, California + * Institute of Technology, sponsored by the United States Government under + * the prime contract 80NM0018D0004 between the Caltech and NASA under + * subcontract 1700763. + */ +/** @file + * Test the text_util.h interfaces. + */ +#include +#include +#include + +#define TEST_CASE(...) + +TEST_CASE("", "", "") +TEST_CASE("hi", "", "hi") +TEST_CASE("h i", "", "h%20i") +TEST_CASE("h$i", "", "h%24i") +TEST_CASE("h$i", "$", "h$i") +void test_mock_bpa_uri_percent_encode_valid(const char *text, const char *safe, const char *expect) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_string_t out_text; + m_string_init(out_text); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_uri_percent_encode(out_text, in_text, safe)); + + TEST_ASSERT_EQUAL_STRING(expect, m_string_get_cstr(out_text)); + + m_string_clear(out_text); + m_string_clear(in_text); +} + +TEST_CASE("", "") +TEST_CASE("hi", "hi") +TEST_CASE("h%20i", "h i") +TEST_CASE("h%7ei", "h~i") +void test_mock_bpa_uri_percent_decode_valid(const char *text, const char *expect) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_string_t out_text; + m_string_init(out_text); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_uri_percent_decode(out_text, in_text)); + + TEST_ASSERT_EQUAL_STRING(expect, m_string_get_cstr(out_text)); + + m_string_clear(out_text); + m_string_clear(in_text); +} + +TEST_CASE("%") +TEST_CASE("%1") +void test_mock_bpa_uri_percent_decode_invalid(const char *text) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_string_t out_text; + m_string_init(out_text); + TEST_ASSERT_NOT_EQUAL_INT(0, mock_bpa_uri_percent_decode(out_text, in_text)); + m_string_clear(out_text); + m_string_clear(in_text); +} + +TEST_CASE("", '"', "") +TEST_CASE("hi", '"', "hi") +TEST_CASE("h\"i", '"', "h\\\"i") +TEST_CASE("h'i", '"', "h'i") +TEST_CASE("h \b\f\n\r\ti", '\"', "h \\b\\f\\n\\r\\ti") +TEST_CASE("hi\u1234", '"', "hi\\u1234") +TEST_CASE("hi\U0001D11E", '"', "hi\\uD834\\uDD1E") +TEST_CASE("h'i", '\'', "h\\'i") +TEST_CASE("hi\u1234", '\'', "hi\\u1234") +void test_mock_bpa_slash_escape_valid(const char *text, const char quote, const char *expect) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_string_t out_text; + m_string_init(out_text); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_slash_escape(out_text, in_text, quote)); + + if (expect) + { + TEST_ASSERT_EQUAL_STRING(expect, m_string_get_cstr(out_text)); + } + else + { + TEST_ASSERT_EQUAL_INT(0, m_string_size(out_text)); + } + m_string_clear(out_text); + m_string_clear(in_text); +} + +TEST_CASE("", NULL) +TEST_CASE("hi", "hi") +TEST_CASE("h\\'i", "h'i") +TEST_CASE("h\\\"i", "h\"i") +TEST_CASE("h \\b\\f\\n\\r\\ti", "h \b\f\n\r\ti") +TEST_CASE("hi\\u1234", "hi\u1234") +TEST_CASE("hi\\uD834\\uDD1E", "hi\U0001D11E") +void test_mock_bpa_slash_unescape_valid(const char *text, const char *expect) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_string_t out_text; + m_string_init(out_text); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_slash_unescape(out_text, in_text)); + + if (expect) + { + TEST_ASSERT_EQUAL_STRING(expect, m_string_get_cstr(out_text)); + } + else + { + TEST_ASSERT_EQUAL_INT(0, m_string_size(out_text)); + } + m_string_clear(out_text); + m_string_clear(in_text); +} + +TEST_CASE("\\") +void test_mock_bpa_slash_unescape_invalid(const char *text) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_string_t out_text; + m_string_init(out_text); + TEST_ASSERT_NOT_EQUAL_INT(0, mock_bpa_slash_unescape(out_text, in_text)); + m_string_clear(out_text); + m_string_clear(in_text); +} + +TEST_CASE("", 0, false, "") +TEST_CASE("hi", 2, false, "6869") +void test_mock_bpa_base16_encode(const char *data, size_t data_len, bool uppercase, const char *expect) +{ + m_bstring_t in_data; + m_bstring_init(in_data); + if (data_len) + { + m_bstring_push_back_bytes(in_data, data_len, data); + } + + m_string_t out; + m_string_init(out); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_base16_encode(out, in_data, uppercase)); + + TEST_ASSERT_EQUAL_STRING(expect, m_string_get_cstr(out)); + m_string_clear(out); + m_bstring_clear(in_data); +} + +TEST_CASE("", NULL, 0) +TEST_CASE("00", "\x00", 1) +TEST_CASE("6869", "hi", 2) +void test_mock_bpa_base16_decode_valid(const char *text, const char *expect, size_t expect_len) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_bstring_t out_data; + m_bstring_init(out_data); + TEST_ASSERT_EQUAL_INT_MESSAGE(0, mock_bpa_base16_decode(out_data, in_text), "mock_bpa_base16_decode() failed"); + + TEST_ASSERT_EQUAL_INT(expect_len, m_bstring_size(out_data)); + if (expect) + { + TEST_ASSERT_EQUAL_MEMORY(expect, m_bstring_view(out_data, 0, expect_len), expect_len); + } + + m_bstring_clear(out_data); + m_string_clear(in_text); +} + +TEST_CASE("1") +TEST_CASE("asd") +void test_mock_bpa_base16_decode_invalid(const char *text) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_bstring_t out_data; + m_bstring_init(out_data); + TEST_ASSERT_NOT_EQUAL_INT(0, mock_bpa_base16_decode(out_data, in_text)); + + m_bstring_clear(out_data); + m_string_clear(in_text); +} + +// vectors from Section 10 of RFC 4648 +TEST_CASE("", 0, false, true, "") +TEST_CASE("f", 1, false, true, "Zg==") +TEST_CASE("fo", 2, false, true, "Zm8=") +TEST_CASE("foo", 3, false, true, "Zm9v") +TEST_CASE("foob", 4, false, true, "Zm9vYg==") +TEST_CASE("fooba", 5, false, true, "Zm9vYmE=") +TEST_CASE("foobar", 6, false, true, "Zm9vYmFy") +// example from Section 9 of RFC 4648 +TEST_CASE("\x14\xfb\x9c\x03\xd9\x7e", 6, false, true, "FPucA9l+") +// random cases to use last two characters of alphabet +TEST_CASE("\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16, false, true, + "wQTEz7d3D/C+uqLpX7wsGA==") +TEST_CASE("\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16, false, false, + "wQTEz7d3D/C+uqLpX7wsGA") +TEST_CASE("\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16, true, true, + "wQTEz7d3D_C-uqLpX7wsGA==") +TEST_CASE("\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16, true, false, "wQTEz7d3D_C-uqLpX7wsGA") +void test_mock_bpa_base64_encode(const char *data, size_t data_len, bool useurl, bool usepad, const char *expect) +{ + m_bstring_t in_data; + m_bstring_init(in_data); + if (data_len) + { + m_bstring_push_back_bytes(in_data, data_len, data); + } + + m_string_t out; + m_string_init(out); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_base64_encode(out, in_data, useurl, usepad)); + + TEST_ASSERT_EQUAL_STRING(expect, m_string_get_cstr(out)); + m_string_clear(out); + m_bstring_clear(in_data); +} + +// vectors from Section 10 of RFC 4648 +TEST_CASE("", NULL, 0) +TEST_CASE("Zg==", "f", 1) +TEST_CASE("Zm8=", "fo", 2) +TEST_CASE("Zm9v", "foo", 3) +TEST_CASE("Zm9vYg==", "foob", 4) +TEST_CASE("Zm9vYmE=", "fooba", 5) +TEST_CASE("Zm9vYmFy", "foobar", 6) +// removed padding +TEST_CASE("Zg", "f", 1) +TEST_CASE("Zm8", "fo", 2) +// excess padding is okay +TEST_CASE("Zm9vYmFy====", "foobar", 6) +TEST_CASE("====", NULL, 0) +// random cases to use last two characters of alphabet +TEST_CASE("wQTEz7d3D/C+uqLpX7wsGA==", "\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16) +TEST_CASE("wQTEz7d3D/C+uqLpX7wsGA", "\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16) +TEST_CASE("wQTEz7d3D_C-uqLpX7wsGA==", "\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16) +TEST_CASE("wQTEz7d3D_C-uqLpX7wsGA", "\xc1\x04\xc4\xcf\xb7\x77\x0f\xf0\xbe\xba\xa2\xe9\x5f\xbc\x2c\x18", 16) +void test_mock_bpa_base64_decode_valid(const char *text, const char *expect, size_t expect_len) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + + m_bstring_t out_data; + m_bstring_init(out_data); + TEST_ASSERT_EQUAL_INT(0, mock_bpa_base64_decode(out_data, in_text)); + + TEST_ASSERT_EQUAL_INT(expect_len, m_bstring_size(out_data)); + if (expect) + { + TEST_ASSERT_EQUAL_MEMORY(expect, m_bstring_view(out_data, 0, expect_len), expect_len); + } + m_bstring_clear(out_data); + m_string_clear(in_text); +} + +TEST_CASE(".") +TEST_CASE("A.") +TEST_CASE("AB.") +TEST_CASE("ABC.") +void test_mock_bpa_base64_decode_invalid(const char *text) +{ + m_string_t in_text; + m_string_init_set_cstr(in_text, text); + m_bstring_t out_data; + m_bstring_init(out_data); + TEST_ASSERT_NOT_EQUAL_INT(0, mock_bpa_base64_decode(out_data, in_text)); + m_bstring_clear(out_data); + m_string_clear(in_text); +} diff --git a/test/test_PublicInterfaceImpl.c b/test/test_PublicInterfaceImpl.c index cb22c9be..a6ecfc80 100644 --- a/test/test_PublicInterfaceImpl.c +++ b/test/test_PublicInterfaceImpl.c @@ -35,12 +35,12 @@ static BSL_TestContext_t LocalTestCtx = { 0 }; void suiteSetUp(void) { BSL_openlog(); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); } int suiteTearDown(int failures) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); return failures; } diff --git a/test/test_SamplePolicyProvider.c b/test/test_SamplePolicyProvider.c index 19ffa8e5..f3848946 100644 --- a/test/test_SamplePolicyProvider.c +++ b/test/test_SamplePolicyProvider.c @@ -31,9 +31,7 @@ #include -#include -#include -#include +#include #include "bsl_test_utils.h" #include @@ -43,7 +41,7 @@ static BSL_TestContext_t LocalTestCtx; void setUp(void) { BSL_openlog(); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); setenv("BSL_TEST_LOCAL_IPN_EID", "ipn:2.1", 1); memset(&LocalTestCtx, 0, sizeof(LocalTestCtx)); TEST_ASSERT_EQUAL(0, BSL_API_InitLib(&LocalTestCtx.bsl)); @@ -55,7 +53,7 @@ void tearDown(void) mock_bpa_ctr_deinit(&LocalTestCtx.mock_bpa_ctr); // BSL_BundleCtx_Deinit(LocalTestCtx.bundle); TEST_ASSERT_EQUAL(0, BSL_API_DeinitLib(&LocalTestCtx.bsl)); - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); } diff --git a/test/test_SecurityTypes.c b/test/test_SecurityTypes.c index 1a5b912f..98cba936 100644 --- a/test/test_SecurityTypes.c +++ b/test/test_SecurityTypes.c @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -37,12 +37,12 @@ void setUp(void) { BSL_openlog(); - assert(0 == bsl_mock_bpa_init()); + assert(0 == bsl_mock_bpa_agent_init()); } void tearDown(void) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); } diff --git a/test/test_mock_bpa_ctr.c b/test/test_mock_bpa_ctr.c index d7c54a0f..2457b4b3 100644 --- a/test/test_mock_bpa_ctr.c +++ b/test/test_mock_bpa_ctr.c @@ -22,7 +22,7 @@ #include #include #include "bsl_test_utils.h" -#include +#include // allow parameterized cases #define TEST_CASE(...) @@ -30,12 +30,12 @@ void suiteSetUp(void) { BSL_openlog(); - TEST_ASSERT_EQUAL_INT(0, bsl_mock_bpa_init()); + TEST_ASSERT_EQUAL_INT(0, bsl_mock_bpa_agent_init()); } int suiteTearDown(int failures) { - bsl_mock_bpa_deinit(); + bsl_mock_bpa_agent_deinit(); BSL_closelog(); return failures; }