edhoc 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +170 -0
- package/binding.gyp +13 -11
- package/dist/crypto.d.ts +9 -2
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +112 -84
- package/dist/edhoc.d.ts +31 -9
- package/dist/edhoc.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/x509credentials.d.ts +20 -0
- package/dist/x509credentials.d.ts.map +1 -0
- package/dist/x509credentials.js +140 -0
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_types.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_ead_decode.h +2 -2
- package/external/libedhoc/backends/cbor/include/backend_cbor_ead_encode.h +2 -2
- package/external/libedhoc/backends/cbor/include/backend_cbor_edhoc_types.h +48 -43
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_types.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_info_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_info_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_types.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_decode.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_encode.h +3 -3
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_decode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_encode.h +1 -1
- package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_types.h +4 -4
- package/external/libedhoc/backends/cbor/include/backend_cbor_x509_types.h +93 -83
- package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_ead_decode.c +27 -32
- package/external/libedhoc/backends/cbor/src/backend_cbor_ead_encode.c +27 -32
- package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_decode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_encode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_decode.c +63 -52
- package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_encode.c +62 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_info_decode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_info_encode.c +14 -23
- package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_decode.c +54 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_encode.c +54 -51
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_decode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_encode.c +11 -20
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_decode.c +36 -37
- package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_encode.c +36 -37
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_decode.c +103 -80
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_encode.c +102 -79
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_decode.c +99 -76
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_encode.c +98 -75
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_decode.c +40 -41
- package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_encode.c +40 -41
- package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_decode.c +15 -24
- package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_encode.c +15 -24
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode.c +69 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode2.c +38 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
- package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode.c +71 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode2.c +40 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +16 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/all_tests.c +19 -0
- package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.c +17 -0
- package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.h +19 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode.c +69 -0
- package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode2.c +38 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.c +31 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.h +10 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.c +18 -0
- package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.h +9 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode.c +70 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode2.c +42 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
- package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
- package/external/libedhoc/externals/Unity/examples/unity_config.h +251 -0
- package/external/libedhoc/externals/Unity/extras/bdd/src/unity_bdd.h +44 -0
- package/external/libedhoc/externals/Unity/extras/bdd/test/test_bdd.c +129 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.c +310 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.h +95 -0
- package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture_internals.h +51 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/main/AllTests.c +20 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/template_fixture_tests.c +40 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_Test.c +246 -0
- package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_TestRunner.c +33 -0
- package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.c +203 -0
- package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.h +61 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_Test.c +326 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_TestRunner.c +50 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.c +57 -0
- package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.h +17 -0
- package/external/libedhoc/externals/Unity/src/unity.c +2501 -0
- package/external/libedhoc/externals/Unity/src/unity.h +698 -0
- package/external/libedhoc/externals/Unity/src/unity_internals.h +1183 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_cmd.c +61 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_def.c +57 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.c +55 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.h +15 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_def.c +76 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.c +75 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.h +13 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new1.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new2.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_param.c +77 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run1.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run2.c +89 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_new1.c +67 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_new2.c +70 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_param.c +58 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_run1.c +67 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_run2.c +70 -0
- package/external/libedhoc/externals/Unity/test/expectdata/testsample_yaml.c +71 -0
- package/external/libedhoc/externals/Unity/test/testdata/CException.h +18 -0
- package/external/libedhoc/externals/Unity/test/testdata/Defs.h +16 -0
- package/external/libedhoc/externals/Unity/test/testdata/cmock.h +21 -0
- package/external/libedhoc/externals/Unity/test/testdata/mockMock.h +20 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGenerator.c +204 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorSmall.c +73 -0
- package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorWithMocks.c +200 -0
- package/external/libedhoc/externals/Unity/test/tests/self_assessment_utils.h +151 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_arrays.c +2941 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_core.c +375 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_doubles.c +1285 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_floats.c +1395 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_integers.c +2863 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_integers_64.c +783 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_memory.c +82 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterized.c +309 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterizedDemo.c +28 -0
- package/external/libedhoc/externals/Unity/test/tests/test_unity_strings.c +330 -0
- package/external/libedhoc/externals/Unity/test/tests/types_for_test.h +21 -0
- package/external/libedhoc/externals/zcbor/include/zcbor_common.h +147 -60
- package/external/libedhoc/externals/zcbor/include/zcbor_decode.h +291 -202
- package/external/libedhoc/externals/zcbor/include/zcbor_encode.h +100 -156
- package/external/libedhoc/externals/zcbor/include/zcbor_print.h +165 -0
- package/external/libedhoc/externals/zcbor/samples/hello_world/src/main.c +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_decode.h +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_encode.h +1 -1
- package/external/libedhoc/externals/zcbor/samples/pet/include/pet_types.h +4 -4
- package/external/libedhoc/externals/zcbor/samples/pet/src/main.c +4 -4
- package/external/libedhoc/externals/zcbor/samples/pet/src/pet_decode.c +15 -24
- package/external/libedhoc/externals/zcbor/samples/pet/src/pet_encode.c +14 -23
- package/external/libedhoc/externals/zcbor/src/zcbor_common.c +202 -29
- package/external/libedhoc/externals/zcbor/src/zcbor_decode.c +633 -173
- package/external/libedhoc/externals/zcbor/src/zcbor_encode.c +71 -184
- package/external/libedhoc/externals/zcbor/tests/decode/test1_suit_old_formats/src/main.c +152 -153
- package/external/libedhoc/externals/zcbor/tests/decode/test2_suit/src/main.c +64 -64
- package/external/libedhoc/externals/zcbor/tests/decode/test3_simple/src/main.c +15 -16
- package/external/libedhoc/externals/zcbor/tests/decode/test5_corner_cases/src/main.c +228 -84
- package/external/libedhoc/externals/zcbor/tests/decode/test7_suit9_simple/src/main.c +9 -9
- package/external/libedhoc/externals/zcbor/tests/decode/test8_suit12/src/main.c +0 -1
- package/external/libedhoc/externals/zcbor/tests/decode/test9_manifest14/src/main.c +172 -173
- package/external/libedhoc/externals/zcbor/tests/encode/test1_suit/src/main.c +73 -73
- package/external/libedhoc/externals/zcbor/tests/encode/test2_simple/src/main.c +1 -2
- package/external/libedhoc/externals/zcbor/tests/encode/test3_corner_cases/src/main.c +83 -56
- package/external/libedhoc/externals/zcbor/tests/encode/test4_senml/src/main.c +15 -16
- package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_everything.c +12 -0
- package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_manifest12.c +69 -69
- package/external/libedhoc/externals/zcbor/tests/unit/test1_unit_tests/src/main.c +448 -55
- package/external/libedhoc/externals/zcbor/tests/unit/test3_float16/src/main.c +49 -48
- package/external/libedhoc/include/edhoc.h +348 -54
- package/external/libedhoc/include/edhoc_common.h +289 -0
- package/external/libedhoc/include/edhoc_context.h +60 -35
- package/external/libedhoc/include/edhoc_credentials.h +55 -7
- package/external/libedhoc/include/edhoc_crypto.h +10 -10
- package/external/libedhoc/include/edhoc_ead.h +13 -10
- package/external/libedhoc/include/edhoc_macros.h +20 -11
- package/external/libedhoc/include/edhoc_values.h +2 -2
- package/external/libedhoc/library/edhoc.c +70 -36
- package/external/libedhoc/library/edhoc_common.c +1314 -0
- package/external/libedhoc/library/edhoc_exporter.c +45 -46
- package/external/libedhoc/library/edhoc_message_1.c +107 -72
- package/external/libedhoc/library/edhoc_message_2.c +396 -1693
- package/external/libedhoc/library/edhoc_message_3.c +465 -1656
- package/external/libedhoc/library/edhoc_message_4.c +93 -91
- package/external/libedhoc/library/edhoc_message_error.c +41 -41
- package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_0.h → cipher_suite_0.h} +131 -134
- package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_2.h → cipher_suite_2.h} +139 -140
- package/external/libedhoc/tests/include/{edhoc_trace_1/test_vector_1.h → test_vector_rfc9529_chapter_2.h} +786 -738
- package/external/libedhoc/tests/include/{edhoc_trace_2/test_vector_2.h → test_vector_rfc9529_chapter_3.h} +14 -10
- package/external/libedhoc/tests/include/{x509_chain_cs_0/test_vector_x5chain_cs_0.h → test_vector_x5chain_sign_keys_suite_0.h} +137 -140
- package/external/libedhoc/tests/include/{x509_chain_cs_2/test_vector_x5chain_cs_2.h → test_vector_x5chain_sign_keys_suite_2.h} +7 -8
- package/external/libedhoc/tests/include/{x509_chain_cs_2_static_dh/test_vector_x5chain_cs_2_static_dh.h → test_vector_x5chain_static_dh_keys_suite_2.h} +7 -8
- package/external/libedhoc/tests/include/{x509_hash_cs_2/test_vector_x5t_cs_2.h → test_vector_x5t_sign_keys_suite_2.h} +6 -7
- package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_0.c → cipher_suite_0.c} +445 -447
- package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_2.c → cipher_suite_2.c} +600 -600
- package/external/libedhoc/tests/src/module_test_api.c +430 -0
- package/external/libedhoc/tests/src/module_test_cipher_suite_0.c +395 -0
- package/external/libedhoc/tests/src/module_test_cipher_suite_2.c +392 -0
- package/external/libedhoc/tests/src/{error_message/test_edhoc_error_message.c → module_test_error_message.c} +94 -69
- package/external/libedhoc/tests/src/module_test_main.c +49 -0
- package/external/libedhoc/tests/src/{cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.c → module_test_rfc9528_suites_negotiation.c} +224 -227
- package/external/libedhoc/tests/src/module_test_rfc9529_chapter_2.c +2681 -0
- package/external/libedhoc/tests/src/module_test_rfc9529_chapter_3.c +1635 -0
- package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_0.c +1135 -0
- package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_2.c +1249 -0
- package/external/libedhoc/tests/src/module_test_x5chain_static_dh_keys_suite_2.c +798 -0
- package/external/libedhoc/tests/src/module_test_x5t_sign_keys_suite_2.c +956 -0
- package/include/EdhocComposeAsyncWorker.h +8 -6
- package/include/EdhocCredentialManager.h +16 -11
- package/include/EdhocCryptoManager.h +28 -21
- package/include/EdhocEadManager.h +3 -6
- package/include/{EdhocExportAsyncWorker.h → EdhocExportOscoreAsyncWorker.h} +20 -17
- package/include/EdhocKeyExporterAsyncWorker.h +76 -0
- package/include/EdhocKeyUpdateAsyncWorker.h +72 -0
- package/include/EdhocProcessAsyncWorker.h +14 -10
- package/include/LibEDHOC.h +44 -20
- package/include/UserContext.h +7 -9
- package/include/Utils.h +31 -27
- package/package.json +14 -3
- package/prebuilds/android-arm/edhoc.armv7.node +0 -0
- package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
- package/prebuilds/darwin-arm64/edhoc.node +0 -0
- package/prebuilds/darwin-x64/edhoc.node +0 -0
- package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
- package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
- package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
- package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
- package/prebuilds/linux-x64/edhoc.musl.node +0 -0
- package/prebuilds/win32-ia32/edhoc.node +0 -0
- package/prebuilds/win32-x64/edhoc.node +0 -0
- package/src/EdhocComposeAsyncWorker.cpp +18 -35
- package/src/EdhocCredentialManager.cpp +160 -187
- package/src/EdhocCryptoManager.cpp +386 -586
- package/src/EdhocEadManager.cpp +10 -18
- package/src/EdhocExportOscoreAsyncWorker.cpp +77 -0
- package/src/EdhocKeyExporterAsyncWorker.cpp +49 -0
- package/src/EdhocKeyUpdateAsyncWorker.cpp +41 -0
- package/src/EdhocProcessAsyncWorker.cpp +72 -19
- package/src/LibEDHOC.cpp +213 -174
- package/src/Suites.cpp +39 -72
- package/src/Utils.cpp +32 -56
- package/test/basic.test.ts +64 -0
- package/test/vectors.test.ts +111 -0
- package/dist/credentials.d.ts +0 -16
- package/dist/credentials.d.ts.map +0 -1
- package/dist/credentials.js +0 -84
- package/external/libedhoc/externals/zcbor/include/zcbor_debug.h +0 -69
- package/external/libedhoc/tests/include/cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.h +0 -37
- package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_0.h +0 -48
- package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_2.h +0 -48
- package/external/libedhoc/tests/include/edhoc_trace_1/authentication_credentials_1.h +0 -60
- package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_1.h +0 -208
- package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_ead_1.h +0 -59
- package/external/libedhoc/tests/include/edhoc_trace_2/authentication_credentials_2.h +0 -60
- package/external/libedhoc/tests/include/edhoc_trace_2/test_edhoc_handshake_2.h +0 -199
- package/external/libedhoc/tests/include/error_message/test_edhoc_error_message.h +0 -48
- package/external/libedhoc/tests/include/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.h +0 -92
- package/external/libedhoc/tests/include/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.h +0 -96
- package/external/libedhoc/tests/include/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.h +0 -58
- package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.h +0 -56
- package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.h +0 -57
- package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.h +0 -59
- package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.h +0 -57
- package/external/libedhoc/tests/include/x509_hash_cs_2/authentication_credentials_x5t_cs_2.h +0 -60
- package/external/libedhoc/tests/include/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.h +0 -57
- package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_0.c +0 -475
- package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_2.c +0 -473
- package/external/libedhoc/tests/src/edhoc_trace_1/authentication_credentials_1.c +0 -252
- package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_1.c +0 -1829
- package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_ead_1.c +0 -1247
- package/external/libedhoc/tests/src/edhoc_trace_2/authentication_credentials_2.c +0 -170
- package/external/libedhoc/tests/src/edhoc_trace_2/test_edhoc_handshake_2.c +0 -1783
- package/external/libedhoc/tests/src/tests.c +0 -228
- package/external/libedhoc/tests/src/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.c +0 -332
- package/external/libedhoc/tests/src/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.c +0 -936
- package/external/libedhoc/tests/src/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.c +0 -166
- package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.c +0 -587
- package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.c +0 -917
- package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.c +0 -186
- package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.c +0 -743
- package/external/libedhoc/tests/src/x509_hash_cs_2/authentication_credentials_x5t_cs_2.c +0 -261
- package/external/libedhoc/tests/src/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.c +0 -854
- package/src/EdhocExportAsyncWorker.cpp +0 -82
package/src/LibEDHOC.cpp
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
|
+
#include "LibEDHOC.h"
|
|
2
|
+
|
|
1
3
|
#include <iostream>
|
|
2
4
|
#include <thread>
|
|
3
5
|
|
|
4
6
|
#include "EdhocComposeAsyncWorker.h"
|
|
5
|
-
#include "
|
|
7
|
+
#include "EdhocExportOscoreAsyncWorker.h"
|
|
8
|
+
#include "EdhocKeyExporterAsyncWorker.h"
|
|
9
|
+
#include "EdhocKeyUpdateAsyncWorker.h"
|
|
6
10
|
#include "EdhocProcessAsyncWorker.h"
|
|
7
|
-
#include "LibEDHOC.h"
|
|
8
11
|
#include "Suites.h"
|
|
9
12
|
#include "Utils.h"
|
|
10
13
|
|
|
11
|
-
static constexpr const char* kErrorFailedToInitializeEdhocContext =
|
|
12
|
-
|
|
13
|
-
static constexpr const char*
|
|
14
|
-
|
|
15
|
-
static constexpr const char*
|
|
16
|
-
|
|
17
|
-
static constexpr const char*
|
|
18
|
-
|
|
19
|
-
static constexpr const char*
|
|
20
|
-
"Invalid cipher suite index";
|
|
21
|
-
static constexpr const char* kErrorFailedToSetCipherSuites =
|
|
22
|
-
"Failed to set cipher suites";
|
|
23
|
-
static constexpr const char* kErrorExpectedFirstArgumentToBeBuffer =
|
|
24
|
-
"Expected first argument to be a Buffer";
|
|
14
|
+
static constexpr const char* kErrorFailedToInitializeEdhocContext = "Failed to initialize EDHOC context.";
|
|
15
|
+
static constexpr const char* kErrorFailedToSetEdhocConnectionId = "Failed to set EDHOC Connection ID.";
|
|
16
|
+
static constexpr const char* kErrorFailedToSetEdhocMethod = "Failed to set EDHOC Method.";
|
|
17
|
+
static constexpr const char* kErrorArraySuiteIndexesExpected = "Array of suite indexes expected";
|
|
18
|
+
static constexpr const char* kErrorArrayMethodIndexesExpected = "Array of method indexes expected";
|
|
19
|
+
static constexpr const char* kErrorInvalidCipherSuiteIndex = "Invalid cipher suite index";
|
|
20
|
+
static constexpr const char* kErrorFailedToSetCipherSuites = "Failed to set cipher suites";
|
|
21
|
+
static constexpr const char* kErrorExpectedFirstArgumentToBeBuffer = "Expected first argument to be a Buffer";
|
|
22
|
+
static constexpr const char* kErrorExpectedArgumentToBeNumber = "Expected argument to be a number";
|
|
25
23
|
static constexpr const char* kErrorExpectedAFunction = "Expected a function";
|
|
26
24
|
static constexpr const char* kClassNameLibEDHOC = "EDHOC";
|
|
27
25
|
static constexpr const char* kMethodComposeMessage1 = "composeMessage1";
|
|
@@ -33,73 +31,64 @@ static constexpr const char* kMethodProcessMessage3 = "processMessage3";
|
|
|
33
31
|
static constexpr const char* kMethodComposeMessage4 = "composeMessage4";
|
|
34
32
|
static constexpr const char* kMethodProcessMessage4 = "processMessage4";
|
|
35
33
|
static constexpr const char* kMethodExportOSCORE = "exportOSCORE";
|
|
34
|
+
static constexpr const char* kMethodExportKey = "exportKey";
|
|
35
|
+
static constexpr const char* kMethodKeyUpdate = "keyUpdate";
|
|
36
36
|
static constexpr const char* kJsPropertyConnectionID = "connectionID";
|
|
37
37
|
static constexpr const char* kJsPropertyPeerConnectionID = "peerConnectionID";
|
|
38
|
-
static constexpr const char*
|
|
38
|
+
static constexpr const char* kJsPropertyMethods = "methods";
|
|
39
|
+
static constexpr const char* kJsPropertySelectedMethod = "selectedMethod";
|
|
39
40
|
static constexpr const char* kJsPropertyCipherSuites = "cipherSuites";
|
|
40
41
|
static constexpr const char* kJsPropertySelectedCipherSuite = "selectedSuite";
|
|
41
42
|
static constexpr const char* kJsPropertyLogger = "logger";
|
|
42
43
|
static constexpr const char* kLogggerFunctionName = "Logger";
|
|
43
44
|
|
|
44
|
-
LibEDHOC::LibEDHOC(const Napi::CallbackInfo& info)
|
|
45
|
-
: Napi::ObjectWrap<LibEDHOC>(info) {
|
|
45
|
+
LibEDHOC::LibEDHOC(const Napi::CallbackInfo& info) : Napi::ObjectWrap<LibEDHOC>(info) {
|
|
46
46
|
Napi::Env env = info.Env();
|
|
47
47
|
Napi::HandleScope scope(env);
|
|
48
48
|
|
|
49
|
-
int ret = EDHOC_ERROR_GENERIC_ERROR;
|
|
50
|
-
|
|
51
49
|
// Initialize EDHOC context
|
|
52
50
|
context = {};
|
|
53
|
-
|
|
51
|
+
if (edhoc_context_init(&context) != EDHOC_SUCCESS) {
|
|
52
|
+
throw Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext);
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
// Connection ID
|
|
55
|
+
// Connection ID, Methods, and Suites
|
|
56
56
|
SetCID(info, info[0]);
|
|
57
|
-
|
|
58
|
-
// Method
|
|
59
|
-
SetMethod(info, info[1]);
|
|
60
|
-
|
|
61
|
-
// Suites
|
|
57
|
+
SetMethods(info, info[1]);
|
|
62
58
|
SetCipherSuites(info, info[2]);
|
|
63
59
|
|
|
64
60
|
// Crypto Manager
|
|
65
61
|
Napi::Object jsCryptoManager = info[4].As<Napi::Object>();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Keys
|
|
69
|
-
ret = edhoc_bind_keys(&context, cryptoManager.get()->keys);
|
|
70
|
-
|
|
71
|
-
// Crypto
|
|
72
|
-
ret = edhoc_bind_crypto(&context, cryptoManager.get()->crypto);
|
|
62
|
+
auto cryptoManager = std::make_shared<EdhocCryptoManager>(jsCryptoManager);
|
|
73
63
|
|
|
74
64
|
// Credentials
|
|
75
65
|
Napi::Object jsCredentialManager = info[3].As<Napi::Object>();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
ret = edhoc_bind_credentials(&context, credentialManager.get()->credentials);
|
|
79
|
-
|
|
66
|
+
auto credentialManager = std::make_shared<EdhocCredentialManager>(jsCredentialManager);
|
|
80
67
|
// EAD
|
|
81
|
-
std::
|
|
82
|
-
|
|
83
|
-
|
|
68
|
+
auto eadManager = std::make_shared<EdhocEadManager>();
|
|
69
|
+
|
|
70
|
+
// Bind all managers
|
|
71
|
+
if (edhoc_bind_keys(&context, &cryptoManager->keys) != EDHOC_SUCCESS ||
|
|
72
|
+
edhoc_bind_crypto(&context, &cryptoManager->crypto) != EDHOC_SUCCESS ||
|
|
73
|
+
edhoc_bind_credentials(&context, &credentialManager->credentials) != EDHOC_SUCCESS ||
|
|
74
|
+
edhoc_bind_ead(&context, &eadManager->ead) != EDHOC_SUCCESS) {
|
|
75
|
+
throw Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext);
|
|
76
|
+
}
|
|
84
77
|
|
|
85
78
|
// Logger
|
|
86
79
|
context.logger = LibEDHOC::Logger;
|
|
87
80
|
|
|
88
81
|
// User Context
|
|
89
|
-
userContext = std::make_shared<UserContext>(
|
|
90
|
-
|
|
91
|
-
userContext->parent =
|
|
92
|
-
Reference<Napi::Object>::New(info.This().As<Napi::Object>());
|
|
93
|
-
|
|
94
|
-
ret = edhoc_set_user_context(&context, static_cast<void*>(userContext.get()));
|
|
82
|
+
userContext = std::make_shared<UserContext>(cryptoManager, eadManager, credentialManager);
|
|
83
|
+
userContext->parent = Reference<Napi::Object>::New(info.This().As<Napi::Object>());
|
|
95
84
|
|
|
96
|
-
if (
|
|
97
|
-
Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext)
|
|
98
|
-
.ThrowAsJavaScriptException();
|
|
85
|
+
if (edhoc_set_user_context(&context, static_cast<void*>(userContext.get())) != EDHOC_SUCCESS) {
|
|
86
|
+
throw Napi::TypeError::New(env, kErrorFailedToInitializeEdhocContext);
|
|
99
87
|
}
|
|
100
88
|
}
|
|
101
89
|
|
|
102
90
|
LibEDHOC::~LibEDHOC() {
|
|
91
|
+
userContext.reset();
|
|
103
92
|
context = {};
|
|
104
93
|
}
|
|
105
94
|
|
|
@@ -107,65 +96,74 @@ Napi::Value LibEDHOC::GetCID(const Napi::CallbackInfo& info) {
|
|
|
107
96
|
return Utils::CreateJsValueFromEdhocCid(info.Env(), cid);
|
|
108
97
|
}
|
|
109
98
|
|
|
110
|
-
void LibEDHOC::SetCID(const Napi::CallbackInfo& info,
|
|
111
|
-
const Napi::Value& value) {
|
|
99
|
+
void LibEDHOC::SetCID(const Napi::CallbackInfo& info, const Napi::Value& value) {
|
|
112
100
|
cid = Utils::ConvertJsValueToEdhocCid(value);
|
|
113
|
-
int result = edhoc_set_connection_id(&context, cid);
|
|
101
|
+
int result = edhoc_set_connection_id(&context, &cid);
|
|
114
102
|
if (result != EDHOC_SUCCESS) {
|
|
115
|
-
Napi::TypeError::New(info.Env(), kErrorFailedToSetEdhocConnectionId)
|
|
116
|
-
.ThrowAsJavaScriptException();
|
|
103
|
+
Napi::TypeError::New(info.Env(), kErrorFailedToSetEdhocConnectionId).ThrowAsJavaScriptException();
|
|
117
104
|
}
|
|
118
105
|
}
|
|
119
106
|
|
|
120
107
|
Napi::Value LibEDHOC::GetPeerCID(const Napi::CallbackInfo& info) {
|
|
121
|
-
return Utils::CreateJsValueFromEdhocCid(info.Env(),
|
|
122
|
-
context.EDHOC_PRIVATE(peer_cid));
|
|
108
|
+
return Utils::CreateJsValueFromEdhocCid(info.Env(), context.EDHOC_PRIVATE(peer_cid));
|
|
123
109
|
}
|
|
124
110
|
|
|
125
|
-
Napi::Value LibEDHOC::
|
|
126
|
-
|
|
111
|
+
Napi::Value LibEDHOC::GetMethods(const Napi::CallbackInfo& info) {
|
|
112
|
+
Napi::Env env = info.Env();
|
|
113
|
+
Napi::Array result = Napi::Array::New(env, context.EDHOC_PRIVATE(method_len));
|
|
114
|
+
for (size_t i = 0; i < context.EDHOC_PRIVATE(method_len); i++) {
|
|
115
|
+
result.Set(i, Napi::Number::New(env, context.EDHOC_PRIVATE(method)[i]));
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
127
118
|
}
|
|
128
119
|
|
|
129
|
-
void LibEDHOC::
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
120
|
+
void LibEDHOC::SetMethods(const Napi::CallbackInfo& info, const Napi::Value& value) {
|
|
121
|
+
Napi::Env env = info.Env();
|
|
122
|
+
|
|
123
|
+
if (!value.IsArray()) {
|
|
124
|
+
throw Napi::TypeError::New(env, kErrorArrayMethodIndexesExpected);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const auto jsArray = value.As<Napi::Array>();
|
|
128
|
+
std::vector<edhoc_method> methods;
|
|
129
|
+
methods.reserve(jsArray.Length());
|
|
130
|
+
|
|
131
|
+
for (uint32_t i = 0; i < jsArray.Length(); i++) {
|
|
132
|
+
methods.push_back(static_cast<edhoc_method>(jsArray.Get(i).As<Napi::Number>().Int32Value()));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (edhoc_set_methods(&context, methods.data(), methods.size()) != EDHOC_SUCCESS) {
|
|
136
|
+
throw Napi::TypeError::New(env, kErrorFailedToSetEdhocMethod);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
Napi::Value LibEDHOC::GetSelectedMethod(const Napi::CallbackInfo& info) {
|
|
141
|
+
return Napi::Number::New(info.Env(), context.EDHOC_PRIVATE(chosen_method));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
void LibEDHOC::SetCipherSuites(const Napi::CallbackInfo& info, const Napi::Value& value) {
|
|
141
145
|
Napi::Env env = info.Env();
|
|
142
146
|
|
|
143
147
|
if (!value.IsArray()) {
|
|
144
|
-
Napi::TypeError::New(env, kErrorArraySuiteIndexesExpected)
|
|
145
|
-
.ThrowAsJavaScriptException();
|
|
146
|
-
return;
|
|
148
|
+
throw Napi::TypeError::New(env, kErrorArraySuiteIndexesExpected);
|
|
147
149
|
}
|
|
148
150
|
|
|
149
|
-
|
|
150
|
-
std::vector<
|
|
151
|
+
const auto jsArray = value.As<Napi::Array>();
|
|
152
|
+
std::vector<edhoc_cipher_suite> selected_suites;
|
|
153
|
+
selected_suites.reserve(jsArray.Length());
|
|
151
154
|
|
|
152
155
|
for (uint32_t i = 0; i < jsArray.Length(); i++) {
|
|
153
|
-
uint32_t index = jsArray.Get(i).As<Napi::Number>().Uint32Value();
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Napi::RangeError::New(env, kErrorInvalidCipherSuiteIndex)
|
|
158
|
-
.ThrowAsJavaScriptException();
|
|
159
|
-
return;
|
|
156
|
+
const uint32_t index = jsArray.Get(i).As<Napi::Number>().Uint32Value();
|
|
157
|
+
|
|
158
|
+
if (index >= suite_pointers_count || suite_pointers[index] == nullptr) {
|
|
159
|
+
throw Napi::RangeError::New(env, kErrorInvalidCipherSuiteIndex);
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
selected_suites.push_back(*suite_pointers[index]);
|
|
161
163
|
}
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (ret != 0) {
|
|
166
|
-
Napi::TypeError::New(env, kErrorFailedToSetCipherSuites)
|
|
167
|
-
.ThrowAsJavaScriptException();
|
|
168
|
-
return;
|
|
165
|
+
if (edhoc_set_cipher_suites(&context, selected_suites.data(), selected_suites.size()) != 0) {
|
|
166
|
+
throw Napi::TypeError::New(env, kErrorFailedToSetCipherSuites);
|
|
169
167
|
}
|
|
170
168
|
}
|
|
171
169
|
|
|
@@ -173,18 +171,15 @@ Napi::Value LibEDHOC::GetCipherSuites(const Napi::CallbackInfo& info) {
|
|
|
173
171
|
Napi::Env env = info.Env();
|
|
174
172
|
Napi::Array result = Napi::Array::New(env, context.EDHOC_PRIVATE(csuite_len));
|
|
175
173
|
for (size_t i = 0; i < context.EDHOC_PRIVATE(csuite_len); i++) {
|
|
176
|
-
result.Set(i,
|
|
177
|
-
Napi::Number::New(env, context.EDHOC_PRIVATE(csuite)[i].value));
|
|
174
|
+
result.Set(i, Napi::Number::New(env, context.EDHOC_PRIVATE(csuite)[i].value));
|
|
178
175
|
}
|
|
179
176
|
return result;
|
|
180
177
|
}
|
|
181
178
|
|
|
182
179
|
Napi::Value LibEDHOC::GetSelectedCipherSuite(const Napi::CallbackInfo& info) {
|
|
183
180
|
Napi::Env env = info.Env();
|
|
184
|
-
Napi::Number suite =
|
|
185
|
-
env,
|
|
186
|
-
context.EDHOC_PRIVATE(csuite)[context.EDHOC_PRIVATE(chosen_csuite_idx)]
|
|
187
|
-
.value);
|
|
181
|
+
Napi::Number suite =
|
|
182
|
+
Napi::Number::New(env, context.EDHOC_PRIVATE(csuite)[context.EDHOC_PRIVATE(chosen_csuite_idx)].value);
|
|
188
183
|
return suite;
|
|
189
184
|
}
|
|
190
185
|
|
|
@@ -192,96 +187,82 @@ Napi::Value LibEDHOC::GetLogger(const Napi::CallbackInfo& info) {
|
|
|
192
187
|
return logger.Value();
|
|
193
188
|
}
|
|
194
189
|
|
|
195
|
-
void LibEDHOC::SetLogger(const Napi::CallbackInfo& info,
|
|
196
|
-
const Napi::Value& value) {
|
|
190
|
+
void LibEDHOC::SetLogger(const Napi::CallbackInfo& info, const Napi::Value& value) {
|
|
197
191
|
if (!info[0].IsFunction()) {
|
|
198
|
-
Napi::TypeError::New(info.Env(), kErrorExpectedAFunction)
|
|
199
|
-
.ThrowAsJavaScriptException();
|
|
192
|
+
Napi::TypeError::New(info.Env(), kErrorExpectedAFunction).ThrowAsJavaScriptException();
|
|
200
193
|
}
|
|
201
194
|
Napi::Function jsCallback = info[0].As<Napi::Function>();
|
|
202
195
|
logger = Napi::Persistent(jsCallback);
|
|
203
|
-
userContext->logger = Napi::ThreadSafeFunction::New(
|
|
204
|
-
info.Env(), jsCallback, kLogggerFunctionName, 0, 1);
|
|
196
|
+
userContext->logger = Napi::ThreadSafeFunction::New(info.Env(), jsCallback, kLogggerFunctionName, 0, 1);
|
|
205
197
|
}
|
|
206
198
|
|
|
207
|
-
void LibEDHOC::Logger(void* usercontext,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
UserContext* context = static_cast<UserContext*>(usercontext);
|
|
212
|
-
if (context->logger == nullptr) {
|
|
213
|
-
return; // No logger available, nothing to do
|
|
199
|
+
void LibEDHOC::Logger(void* usercontext, const char* name, const uint8_t* buffer, size_t buffer_length) {
|
|
200
|
+
auto* context = static_cast<UserContext*>(usercontext);
|
|
201
|
+
if (!context || !context->logger) {
|
|
202
|
+
return;
|
|
214
203
|
}
|
|
215
204
|
|
|
216
|
-
|
|
217
|
-
std::vector<uint8_t> bufferCopy(buffer, buffer + buffer_length);
|
|
205
|
+
const std::vector<uint8_t> bufferCopy(buffer, buffer + buffer_length);
|
|
218
206
|
|
|
219
|
-
context->logger.NonBlockingCall(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
{Napi::String::New(env, name),
|
|
224
|
-
Napi::Buffer<uint8_t>::Copy(env, bufferCopy.data(), bufferCopy.size())});
|
|
225
|
-
});
|
|
207
|
+
context->logger.NonBlockingCall([name = std::string(name), bufferCopy](Napi::Env env, Napi::Function jsCallback) {
|
|
208
|
+
jsCallback.Call(
|
|
209
|
+
{Napi::String::New(env, name), Napi::Buffer<uint8_t>::Copy(env, bufferCopy.data(), bufferCopy.size())});
|
|
210
|
+
});
|
|
226
211
|
}
|
|
227
212
|
|
|
228
|
-
Napi::Value LibEDHOC::ComposeMessage(const Napi::CallbackInfo& info,
|
|
229
|
-
enum edhoc_message messageNumber) {
|
|
213
|
+
Napi::Value LibEDHOC::ComposeMessage(const Napi::CallbackInfo& info, enum edhoc_message messageNumber) {
|
|
230
214
|
Napi::Env env = info.Env();
|
|
231
215
|
Napi::HandleScope scope(env);
|
|
232
216
|
|
|
233
217
|
if (info[0].IsArray()) {
|
|
234
218
|
try {
|
|
235
|
-
userContext->GetEadManager()->StoreEad(messageNumber,
|
|
236
|
-
info[0].As<Napi::Array>());
|
|
219
|
+
userContext->GetEadManager()->StoreEad(messageNumber, info[0].As<Napi::Array>());
|
|
237
220
|
} catch (const Napi::Error& e) {
|
|
238
221
|
e.ThrowAsJavaScriptException();
|
|
239
222
|
return env.Null();
|
|
240
223
|
}
|
|
241
224
|
}
|
|
242
225
|
|
|
243
|
-
|
|
226
|
+
userContext->GetCredentialManager()->SetupAsyncFunctions();
|
|
227
|
+
userContext->GetCryptoManager()->SetupAsyncFunctions();
|
|
244
228
|
|
|
245
|
-
EdhocComposeAsyncWorker::CallbackType callback =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
229
|
+
EdhocComposeAsyncWorker::CallbackType callback = [this, messageNumber](Napi::Env& env) {
|
|
230
|
+
userContext->GetEadManager()->ClearEadByMessage(messageNumber);
|
|
231
|
+
userContext->GetCredentialManager()->CleanupAsyncFunctions();
|
|
232
|
+
userContext->GetCryptoManager()->CleanupAsyncFunctions();
|
|
233
|
+
};
|
|
249
234
|
|
|
250
|
-
EdhocComposeAsyncWorker* worker = new EdhocComposeAsyncWorker(
|
|
251
|
-
env, deferred, context, messageNumber, callback);
|
|
235
|
+
EdhocComposeAsyncWorker* worker = new EdhocComposeAsyncWorker(env, context, messageNumber, callback);
|
|
252
236
|
worker->Queue();
|
|
253
237
|
|
|
254
|
-
return
|
|
238
|
+
return worker->GetPromise();
|
|
255
239
|
}
|
|
256
240
|
|
|
257
|
-
Napi::Value LibEDHOC::ProcessMessage(const Napi::CallbackInfo& info,
|
|
258
|
-
enum edhoc_message messageNumber) {
|
|
241
|
+
Napi::Value LibEDHOC::ProcessMessage(const Napi::CallbackInfo& info, enum edhoc_message messageNumber) {
|
|
259
242
|
Napi::Env env = info.Env();
|
|
260
243
|
Napi::HandleScope scope(env);
|
|
261
244
|
|
|
262
245
|
if (info.Length() < 1 || !info[0].IsBuffer()) {
|
|
263
|
-
Napi::TypeError::New(env, kErrorExpectedFirstArgumentToBeBuffer)
|
|
264
|
-
.ThrowAsJavaScriptException();
|
|
246
|
+
Napi::TypeError::New(env, kErrorExpectedFirstArgumentToBeBuffer).ThrowAsJavaScriptException();
|
|
265
247
|
return env.Null();
|
|
266
248
|
}
|
|
267
|
-
|
|
268
249
|
Napi::Buffer<uint8_t> inputBuffer = info[0].As<Napi::Buffer<uint8_t>>();
|
|
269
250
|
|
|
270
|
-
|
|
251
|
+
userContext->GetCredentialManager()->SetupAsyncFunctions();
|
|
252
|
+
userContext->GetCryptoManager()->SetupAsyncFunctions();
|
|
271
253
|
|
|
272
|
-
EdhocProcessAsyncWorker::CallbackType callback =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
254
|
+
EdhocProcessAsyncWorker::CallbackType callback = [this, messageNumber](Napi::Env& env) {
|
|
255
|
+
Napi::Array EADs = userContext->GetEadManager()->GetEadByMessage(env, messageNumber);
|
|
256
|
+
userContext->GetEadManager()->ClearEadByMessage(messageNumber);
|
|
257
|
+
userContext->GetCredentialManager()->CleanupAsyncFunctions();
|
|
258
|
+
userContext->GetCryptoManager()->CleanupAsyncFunctions();
|
|
259
|
+
return EADs;
|
|
260
|
+
};
|
|
279
261
|
|
|
280
|
-
EdhocProcessAsyncWorker* worker = new EdhocProcessAsyncWorker(
|
|
281
|
-
env, deferred, context, messageNumber, inputBuffer, callback);
|
|
262
|
+
EdhocProcessAsyncWorker* worker = new EdhocProcessAsyncWorker(env, context, messageNumber, inputBuffer, callback);
|
|
282
263
|
worker->Queue();
|
|
283
264
|
|
|
284
|
-
return
|
|
265
|
+
return worker->GetPromise();
|
|
285
266
|
}
|
|
286
267
|
|
|
287
268
|
Napi::Value LibEDHOC::ComposeMessage1(const Napi::CallbackInfo& info) {
|
|
@@ -320,43 +301,101 @@ Napi::Value LibEDHOC::ExportOSCORE(const Napi::CallbackInfo& info) {
|
|
|
320
301
|
Napi::Env env = info.Env();
|
|
321
302
|
Napi::HandleScope scope(env);
|
|
322
303
|
|
|
323
|
-
|
|
304
|
+
userContext->GetCredentialManager()->SetupAsyncFunctions();
|
|
305
|
+
userContext->GetCryptoManager()->SetupAsyncFunctions();
|
|
306
|
+
|
|
307
|
+
EdhocExportOscoreAsyncWorker::CallbackType callback = [this](Napi::Env& env) {
|
|
308
|
+
userContext->GetCredentialManager()->CleanupAsyncFunctions();
|
|
309
|
+
userContext->GetCryptoManager()->CleanupAsyncFunctions();
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
EdhocExportOscoreAsyncWorker* worker = new EdhocExportOscoreAsyncWorker(env, context, callback);
|
|
313
|
+
worker->Queue();
|
|
314
|
+
|
|
315
|
+
return worker->GetPromise();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
Napi::Value LibEDHOC::ExportKey(const Napi::CallbackInfo& info) {
|
|
319
|
+
Napi::Env env = info.Env();
|
|
320
|
+
Napi::HandleScope scope(env);
|
|
321
|
+
|
|
322
|
+
if (info.Length() < 1 || !info[0].IsNumber()) {
|
|
323
|
+
Napi::TypeError::New(env, kErrorExpectedArgumentToBeNumber).ThrowAsJavaScriptException();
|
|
324
|
+
return env.Null();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (info.Length() < 2 || !info[1].IsNumber()) {
|
|
328
|
+
Napi::TypeError::New(env, kErrorExpectedArgumentToBeNumber).ThrowAsJavaScriptException();
|
|
329
|
+
return env.Null();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
uint16_t label = (uint16_t)info[0].As<Napi::Number>().Uint32Value();
|
|
333
|
+
uint8_t desiredLength = (uint8_t)info[1].As<Napi::Number>().Uint32Value();
|
|
334
|
+
|
|
335
|
+
userContext->GetCredentialManager()->SetupAsyncFunctions();
|
|
336
|
+
userContext->GetCryptoManager()->SetupAsyncFunctions();
|
|
337
|
+
|
|
338
|
+
EdhocKeyExporterAsyncWorker::CallbackType callback = [this](Napi::Env& env) {
|
|
339
|
+
userContext->GetCredentialManager()->CleanupAsyncFunctions();
|
|
340
|
+
userContext->GetCryptoManager()->CleanupAsyncFunctions();
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
EdhocKeyExporterAsyncWorker* worker = new EdhocKeyExporterAsyncWorker(env, context, label, desiredLength, callback);
|
|
344
|
+
worker->Queue();
|
|
345
|
+
|
|
346
|
+
return worker->GetPromise();
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
Napi::Value LibEDHOC::KeyUpdate(const Napi::CallbackInfo& info) {
|
|
350
|
+
Napi::Env env = info.Env();
|
|
351
|
+
Napi::HandleScope scope(env);
|
|
352
|
+
|
|
353
|
+
if (info.Length() < 1 || !info[0].IsBuffer()) {
|
|
354
|
+
Napi::TypeError::New(env, kErrorExpectedFirstArgumentToBeBuffer).ThrowAsJavaScriptException();
|
|
355
|
+
return env.Null();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
Napi::Buffer<uint8_t> contextBuffer = info[0].As<Napi::Buffer<uint8_t>>();
|
|
359
|
+
std::vector<uint8_t> contextBufferVector(contextBuffer.Data(), contextBuffer.Data() + contextBuffer.Length());
|
|
360
|
+
|
|
361
|
+
userContext->GetCredentialManager()->SetupAsyncFunctions();
|
|
362
|
+
userContext->GetCryptoManager()->SetupAsyncFunctions();
|
|
363
|
+
|
|
364
|
+
EdhocKeyUpdateAsyncWorker::CallbackType callback = [this](Napi::Env& env) {
|
|
365
|
+
userContext->GetCredentialManager()->CleanupAsyncFunctions();
|
|
366
|
+
userContext->GetCryptoManager()->CleanupAsyncFunctions();
|
|
367
|
+
};
|
|
324
368
|
|
|
325
|
-
|
|
326
|
-
new EdhocExportAsyncWorker(env, deferred, context);
|
|
369
|
+
EdhocKeyUpdateAsyncWorker* worker = new EdhocKeyUpdateAsyncWorker(env, context, contextBufferVector, callback);
|
|
327
370
|
worker->Queue();
|
|
328
371
|
|
|
329
|
-
return
|
|
372
|
+
return worker->GetPromise();
|
|
330
373
|
}
|
|
331
374
|
|
|
332
375
|
Napi::Object LibEDHOC::Init(Napi::Env env, Napi::Object exports) {
|
|
333
376
|
Napi::HandleScope scope(env);
|
|
334
|
-
Napi::Function func =
|
|
335
|
-
env,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
InstanceMethod(kMethodComposeMessage4, &LibEDHOC::ComposeMessage4),
|
|
357
|
-
InstanceMethod(kMethodProcessMessage4, &LibEDHOC::ProcessMessage4),
|
|
358
|
-
InstanceMethod(kMethodExportOSCORE, &LibEDHOC::ExportOSCORE),
|
|
359
|
-
});
|
|
377
|
+
Napi::Function func =
|
|
378
|
+
DefineClass(env, kClassNameLibEDHOC,
|
|
379
|
+
{
|
|
380
|
+
InstanceAccessor(kJsPropertyConnectionID, &LibEDHOC::GetCID, &LibEDHOC::SetCID),
|
|
381
|
+
InstanceAccessor<&LibEDHOC::GetPeerCID>(kJsPropertyPeerConnectionID),
|
|
382
|
+
InstanceAccessor(kJsPropertyMethods, &LibEDHOC::GetMethods, &LibEDHOC::SetMethods),
|
|
383
|
+
InstanceAccessor<&LibEDHOC::GetSelectedMethod>(kJsPropertySelectedMethod),
|
|
384
|
+
InstanceAccessor(kJsPropertyCipherSuites, &LibEDHOC::GetCipherSuites, &LibEDHOC::SetCipherSuites),
|
|
385
|
+
InstanceAccessor<&LibEDHOC::GetSelectedCipherSuite>(kJsPropertySelectedCipherSuite),
|
|
386
|
+
InstanceAccessor(kJsPropertyLogger, &LibEDHOC::GetLogger, &LibEDHOC::SetLogger),
|
|
387
|
+
InstanceMethod(kMethodComposeMessage1, &LibEDHOC::ComposeMessage1),
|
|
388
|
+
InstanceMethod(kMethodProcessMessage1, &LibEDHOC::ProcessMessage1),
|
|
389
|
+
InstanceMethod(kMethodComposeMessage2, &LibEDHOC::ComposeMessage2),
|
|
390
|
+
InstanceMethod(kMethodProcessMessage2, &LibEDHOC::ProcessMessage2),
|
|
391
|
+
InstanceMethod(kMethodComposeMessage3, &LibEDHOC::ComposeMessage3),
|
|
392
|
+
InstanceMethod(kMethodProcessMessage3, &LibEDHOC::ProcessMessage3),
|
|
393
|
+
InstanceMethod(kMethodComposeMessage4, &LibEDHOC::ComposeMessage4),
|
|
394
|
+
InstanceMethod(kMethodProcessMessage4, &LibEDHOC::ProcessMessage4),
|
|
395
|
+
InstanceMethod(kMethodExportOSCORE, &LibEDHOC::ExportOSCORE),
|
|
396
|
+
InstanceMethod(kMethodExportKey, &LibEDHOC::ExportKey),
|
|
397
|
+
InstanceMethod(kMethodKeyUpdate, &LibEDHOC::KeyUpdate),
|
|
398
|
+
});
|
|
360
399
|
|
|
361
400
|
Napi::FunctionReference* constructor = new Napi::FunctionReference();
|
|
362
401
|
*constructor = Napi::Persistent(func);
|
|
@@ -366,4 +405,4 @@ Napi::Object LibEDHOC::Init(Napi::Env env, Napi::Object exports) {
|
|
|
366
405
|
return exports;
|
|
367
406
|
}
|
|
368
407
|
|
|
369
|
-
NODE_API_NAMED_ADDON(addon, LibEDHOC);
|
|
408
|
+
NODE_API_NAMED_ADDON(addon, LibEDHOC);
|