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
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
#include "EdhocCredentialManager.h"
|
|
2
|
+
|
|
1
3
|
#include <exception>
|
|
2
4
|
#include <future>
|
|
3
5
|
#include <iostream>
|
|
4
6
|
#include <stdexcept>
|
|
5
7
|
|
|
6
|
-
#include "EdhocCredentialManager.h"
|
|
7
8
|
#include "UserContext.h"
|
|
8
9
|
#include "Utils.h"
|
|
9
10
|
|
|
@@ -19,41 +20,35 @@ static constexpr const char* kCertificates = "certificates";
|
|
|
19
20
|
static constexpr const char* kX5t = "x5t";
|
|
20
21
|
static constexpr const char* kHash = "hash";
|
|
21
22
|
static constexpr const char* kHashAlgorithm = "hashAlgorithm";
|
|
22
|
-
|
|
23
|
-
static constexpr const char*
|
|
24
|
-
|
|
25
|
-
static constexpr const char*
|
|
26
|
-
|
|
27
|
-
static constexpr const char* kInvalidInputDataErrorKid =
|
|
28
|
-
"Invalid input data for Key ID";
|
|
29
|
-
static constexpr const char* kInvalidInputDataErrorX509Chain =
|
|
30
|
-
"Invalid input data for X.509 chain";
|
|
31
|
-
static constexpr const char* kInvalidInputDataErrorX509Hash =
|
|
32
|
-
"Invalid input data for X.509 hash";
|
|
23
|
+
static constexpr const char* kUnsupportedCredentialTypeError = "Unsupported credential type specified";
|
|
24
|
+
static constexpr const char* kInvalidInputCredentialTypeError = "Invalid credentials object specified";
|
|
25
|
+
static constexpr const char* kInvalidInputDataErrorKid = "Invalid input data for Key ID";
|
|
26
|
+
static constexpr const char* kInvalidInputDataErrorX509Chain = "Invalid input data for X.509 chain";
|
|
27
|
+
static constexpr const char* kInvalidInputDataErrorX509Hash = "Invalid input data for X.509 hash";
|
|
33
28
|
static constexpr const char* kErrorObjectExpected = "Object expected";
|
|
34
29
|
static constexpr const char* kErrorFunctionExpected = "Function expected";
|
|
35
30
|
static constexpr const char* kFetch = "fetch";
|
|
36
31
|
static constexpr const char* kVerify = "verify";
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
/*
|
|
34
|
+
* Convert a JavaScript object to an edhoc_auth_cred_key_id
|
|
35
|
+
*/
|
|
36
|
+
void convert_js_to_edhoc_kid(const Napi::Object& jsObject, struct edhoc_auth_creds* credentials) {
|
|
40
37
|
Napi::Object kidObj = jsObject.Get(kKid).As<Napi::Object>();
|
|
41
38
|
if (!kidObj.Has(kIsCBOR) || !kidObj.Has(kKid) || !kidObj.Has(kCredentials)) {
|
|
42
|
-
throw
|
|
39
|
+
throw std::runtime_error(kInvalidInputDataErrorKid);
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
credentials->label = EDHOC_COSE_HEADER_KID;
|
|
46
43
|
|
|
47
44
|
if (kidObj.Get(kKid).IsNumber()) {
|
|
48
45
|
int64_t numeric = kidObj.Get(kKid).As<Napi::Number>().Int64Value();
|
|
49
|
-
if (numeric >= ONE_BYTE_CBOR_INT_MIN_VALUE &&
|
|
50
|
-
numeric <= ONE_BYTE_CBOR_INT_MAX_VALUE) {
|
|
46
|
+
if (numeric >= ONE_BYTE_CBOR_INT_MIN_VALUE && numeric <= ONE_BYTE_CBOR_INT_MAX_VALUE) {
|
|
51
47
|
credentials->key_id.encode_type = EDHOC_ENCODE_TYPE_INTEGER;
|
|
52
48
|
credentials->key_id.key_id_int = (int32_t)numeric;
|
|
53
49
|
} else {
|
|
54
50
|
size_t length = 0;
|
|
55
|
-
Utils::EncodeInt64ToBuffer(
|
|
56
|
-
numeric, credentials->key_id.key_id_bstr, &length);
|
|
51
|
+
Utils::EncodeInt64ToBuffer(numeric, credentials->key_id.key_id_bstr, &length);
|
|
57
52
|
credentials->key_id.encode_type = EDHOC_ENCODE_TYPE_BYTE_STRING;
|
|
58
53
|
credentials->key_id.key_id_bstr_length = length;
|
|
59
54
|
}
|
|
@@ -63,22 +58,22 @@ void convert_js_to_edhoc_kid(const Napi::Object& jsObject,
|
|
|
63
58
|
credentials->key_id.key_id_bstr_length = buffer.Length();
|
|
64
59
|
memcpy(credentials->key_id.key_id_bstr, buffer.Data(), buffer.Length());
|
|
65
60
|
} else {
|
|
66
|
-
throw
|
|
61
|
+
throw std::runtime_error(kInvalidInputDataErrorKid);
|
|
67
62
|
}
|
|
68
63
|
|
|
69
|
-
Napi::Buffer<uint8_t> credBuffer =
|
|
70
|
-
kidObj.Get(kCredentials).As<Napi::Buffer<uint8_t>>();
|
|
64
|
+
Napi::Buffer<uint8_t> credBuffer = kidObj.Get(kCredentials).As<Napi::Buffer<uint8_t>>();
|
|
71
65
|
credentials->key_id.cred = credBuffer.Data();
|
|
72
66
|
credentials->key_id.cred_len = credBuffer.Length();
|
|
73
|
-
credentials->key_id.cred_is_cbor =
|
|
74
|
-
kidObj.Get(kIsCBOR).As<Napi::Boolean>().Value();
|
|
67
|
+
credentials->key_id.cred_is_cbor = kidObj.Get(kIsCBOR).As<Napi::Boolean>().Value();
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
/*
|
|
71
|
+
* Convert a JavaScript object to an edhoc_auth_cred_x509_chain
|
|
72
|
+
*/
|
|
73
|
+
void convert_js_to_edhoc_x5chain(const Napi::Object& jsObject, struct edhoc_auth_creds* credentials) {
|
|
79
74
|
Napi::Object x5chainObj = jsObject.Get(kX5chain).As<Napi::Object>();
|
|
80
75
|
if (!x5chainObj.Has(kCertificates)) {
|
|
81
|
-
throw
|
|
76
|
+
throw std::runtime_error(kInvalidInputDataErrorX509Chain);
|
|
82
77
|
}
|
|
83
78
|
|
|
84
79
|
credentials->label = EDHOC_COSE_HEADER_X509_CHAIN;
|
|
@@ -94,51 +89,50 @@ void convert_js_to_edhoc_x5chain(const Napi::Object& jsObject,
|
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
/*
|
|
93
|
+
* Convert a JavaScript object to an edhoc_auth_cred_x509_hash
|
|
94
|
+
*/
|
|
95
|
+
void convert_js_to_edhoc_x5t(const Napi::Object& jsObject, struct edhoc_auth_creds* credentials) {
|
|
99
96
|
Napi::Object x5tObj = jsObject.Get(kX5t).As<Napi::Object>();
|
|
100
|
-
if (!x5tObj.Has(kCertificate) || !x5tObj.Has(kHash) ||
|
|
101
|
-
|
|
102
|
-
throw Napi::Error::New(jsObject.Env(), kInvalidInputDataErrorX509Hash);
|
|
97
|
+
if (!x5tObj.Has(kCertificate) || !x5tObj.Has(kHash) || !x5tObj.Has(kHashAlgorithm)) {
|
|
98
|
+
throw std::runtime_error(kInvalidInputDataErrorX509Hash);
|
|
103
99
|
}
|
|
104
100
|
|
|
105
101
|
credentials->label = EDHOC_COSE_HEADER_X509_HASH;
|
|
106
102
|
|
|
107
|
-
Napi::Buffer<uint8_t> certBuffer =
|
|
108
|
-
x5tObj.Get(kCertificate).As<Napi::Buffer<uint8_t>>();
|
|
103
|
+
Napi::Buffer<uint8_t> certBuffer = x5tObj.Get(kCertificate).As<Napi::Buffer<uint8_t>>();
|
|
109
104
|
credentials->x509_hash.cert = certBuffer.Data();
|
|
110
105
|
credentials->x509_hash.cert_len = certBuffer.Length();
|
|
111
106
|
|
|
112
|
-
Napi::Buffer<uint8_t> hashBuffer =
|
|
113
|
-
x5tObj.Get(kHash).As<Napi::Buffer<uint8_t>>();
|
|
107
|
+
Napi::Buffer<uint8_t> hashBuffer = x5tObj.Get(kHash).As<Napi::Buffer<uint8_t>>();
|
|
114
108
|
credentials->x509_hash.cert_fp = hashBuffer.Data();
|
|
115
109
|
credentials->x509_hash.cert_fp_len = hashBuffer.Length();
|
|
116
110
|
|
|
117
111
|
credentials->x509_hash.encode_type = EDHOC_ENCODE_TYPE_INTEGER;
|
|
118
|
-
credentials->x509_hash.alg_int =
|
|
119
|
-
x5tObj.Get(kHashAlgorithm).As<Napi::Number>().Int32Value();
|
|
112
|
+
credentials->x509_hash.alg_int = x5tObj.Get(kHashAlgorithm).As<Napi::Number>().Int32Value();
|
|
120
113
|
}
|
|
121
114
|
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
/*
|
|
116
|
+
* Convert an edhoc_auth_cred_key_id to a JavaScript object
|
|
117
|
+
*/
|
|
118
|
+
Napi::Object convert_edhoc_kid_to_js(const Napi::Env& env, const struct edhoc_auth_cred_key_id& kid) {
|
|
124
119
|
Napi::Object obj = Napi::Object::New(env);
|
|
125
120
|
obj.Set(kIsCBOR, Napi::Boolean::New(env, kid.cred_is_cbor));
|
|
126
121
|
|
|
127
122
|
if (kid.encode_type == EDHOC_ENCODE_TYPE_INTEGER) {
|
|
128
123
|
obj.Set(kKid, Napi::Number::New(env, kid.key_id_int));
|
|
129
124
|
} else {
|
|
130
|
-
obj.Set(kKid,
|
|
131
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
132
|
-
env, kid.key_id_bstr, kid.key_id_bstr_length));
|
|
125
|
+
obj.Set(kKid, Napi::Buffer<uint8_t>::Copy(env, kid.key_id_bstr, kid.key_id_bstr_length));
|
|
133
126
|
}
|
|
134
127
|
|
|
135
|
-
obj.Set(kCredentials,
|
|
136
|
-
Napi::Buffer<uint8_t>::Copy(env, kid.cred, kid.cred_len));
|
|
128
|
+
obj.Set(kCredentials, Napi::Buffer<uint8_t>::Copy(env, kid.cred, kid.cred_len));
|
|
137
129
|
return obj;
|
|
138
130
|
}
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
/*
|
|
133
|
+
* Convert an edhoc_auth_cred_x509_chain to a JavaScript object
|
|
134
|
+
*/
|
|
135
|
+
Napi::Object convert_edhoc_x5chain_to_js(const Napi::Env& env, const struct edhoc_auth_cred_x509_chain& x509_chain) {
|
|
142
136
|
Napi::Object obj = Napi::Object::New(env);
|
|
143
137
|
Napi::Array certArray = Napi::Array::New(env, x509_chain.nr_of_certs);
|
|
144
138
|
|
|
@@ -150,27 +144,22 @@ Napi::Object convert_edhoc_x5chain_to_js(
|
|
|
150
144
|
return obj;
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
/*
|
|
148
|
+
* Convert an edhoc_auth_cred_x509_hash to a JavaScript object
|
|
149
|
+
*/
|
|
150
|
+
Napi::Object convert_edhoc_x5t_to_js(const Napi::Env& env, const struct edhoc_auth_cred_x509_hash& x509_hash) {
|
|
155
151
|
Napi::Object obj = Napi::Object::New(env);
|
|
156
|
-
obj.Set(kCertificate,
|
|
157
|
-
|
|
158
|
-
obj.Set(kHash,
|
|
159
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
160
|
-
env, x509_hash.cert_fp, x509_hash.cert_fp_len));
|
|
152
|
+
obj.Set(kCertificate, Napi::Buffer<uint8_t>::Copy(env, x509_hash.cert, x509_hash.cert_len));
|
|
153
|
+
obj.Set(kHash, Napi::Buffer<uint8_t>::Copy(env, x509_hash.cert_fp, x509_hash.cert_fp_len));
|
|
161
154
|
obj.Set(kHashAlgorithm, Napi::Number::New(env, x509_hash.alg_int));
|
|
162
155
|
return obj;
|
|
163
156
|
}
|
|
164
157
|
|
|
165
|
-
EdhocCredentialManager::EdhocCredentialManager(
|
|
166
|
-
Napi::Object& jsCredentialManager) {
|
|
158
|
+
EdhocCredentialManager::EdhocCredentialManager(Napi::Object& jsCredentialManager) {
|
|
167
159
|
if (!jsCredentialManager.IsObject()) {
|
|
168
|
-
Napi::Error::New(jsCredentialManager.Env(), kErrorObjectExpected)
|
|
169
|
-
.ThrowAsJavaScriptException();
|
|
160
|
+
Napi::Error::New(jsCredentialManager.Env(), kErrorObjectExpected).ThrowAsJavaScriptException();
|
|
170
161
|
}
|
|
171
162
|
credentialManagerRef = Napi::Persistent(jsCredentialManager);
|
|
172
|
-
SetFunction(kFetch, fetchTsfn);
|
|
173
|
-
SetFunction(kVerify, verifyTsfn);
|
|
174
163
|
|
|
175
164
|
credentials.fetch = FetchCredentials;
|
|
176
165
|
credentials.verify = VerifyCredentials;
|
|
@@ -178,182 +167,166 @@ EdhocCredentialManager::EdhocCredentialManager(
|
|
|
178
167
|
|
|
179
168
|
EdhocCredentialManager::~EdhocCredentialManager() {
|
|
180
169
|
credentialManagerRef.Reset();
|
|
181
|
-
fetchTsfn.Release();
|
|
182
|
-
verifyTsfn.Release();
|
|
183
170
|
for (auto& ref : credentialReferences) {
|
|
184
171
|
ref.Reset();
|
|
185
172
|
}
|
|
186
173
|
credentialReferences.clear();
|
|
187
174
|
}
|
|
188
175
|
|
|
189
|
-
void EdhocCredentialManager::
|
|
190
|
-
|
|
176
|
+
void EdhocCredentialManager::SetupAsyncFunctions() {
|
|
177
|
+
SetFunction(kFetch, fetchTsfn);
|
|
178
|
+
SetFunction(kVerify, verifyTsfn);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
void EdhocCredentialManager::CleanupAsyncFunctions() {
|
|
182
|
+
fetchTsfn.Release();
|
|
183
|
+
verifyTsfn.Release();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
void EdhocCredentialManager::SetFunction(const char* name, Napi::ThreadSafeFunction& tsfn) {
|
|
191
187
|
Napi::Env env = credentialManagerRef.Env();
|
|
192
188
|
Napi::HandleScope scope(env);
|
|
193
|
-
Napi::Function jsFunction =
|
|
194
|
-
credentialManagerRef.Value().Get(name).As<Napi::Function>();
|
|
189
|
+
Napi::Function jsFunction = credentialManagerRef.Value().Get(name).As<Napi::Function>();
|
|
195
190
|
if (!jsFunction.IsFunction()) {
|
|
196
191
|
Napi::Error::New(env, kErrorFunctionExpected).ThrowAsJavaScriptException();
|
|
197
192
|
}
|
|
198
193
|
tsfn = Napi::ThreadSafeFunction::New(env, jsFunction, name, 0, 1);
|
|
199
194
|
}
|
|
200
195
|
|
|
201
|
-
int EdhocCredentialManager::FetchCredentials(
|
|
202
|
-
void* user_context, struct edhoc_auth_creds* credentials) {
|
|
196
|
+
int EdhocCredentialManager::FetchCredentials(void* user_context, struct edhoc_auth_creds* credentials) {
|
|
203
197
|
UserContext* context = static_cast<UserContext*>(user_context);
|
|
204
198
|
EdhocCredentialManager* manager = context->GetCredentialManager();
|
|
205
199
|
return manager->callFetchCredentials(context, credentials);
|
|
206
200
|
}
|
|
207
201
|
|
|
208
|
-
int EdhocCredentialManager::VerifyCredentials(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
size_t* public_key_length) {
|
|
202
|
+
int EdhocCredentialManager::VerifyCredentials(void* user_context,
|
|
203
|
+
struct edhoc_auth_creds* credentials,
|
|
204
|
+
const uint8_t** public_key_reference,
|
|
205
|
+
size_t* public_key_length) {
|
|
213
206
|
UserContext* context = static_cast<UserContext*>(user_context);
|
|
214
207
|
EdhocCredentialManager* manager = context->GetCredentialManager();
|
|
215
|
-
return manager->callVerifyCredentials(
|
|
216
|
-
context, credentials, public_key_reference, public_key_length);
|
|
208
|
+
return manager->callVerifyCredentials(context, credentials, public_key_reference, public_key_length);
|
|
217
209
|
}
|
|
218
210
|
|
|
219
|
-
int EdhocCredentialManager::callFetchCredentials(
|
|
220
|
-
const void* user_context, struct edhoc_auth_creds* credentials) {
|
|
211
|
+
int EdhocCredentialManager::callFetchCredentials(const void* user_context, struct edhoc_auth_creds* credentials) {
|
|
221
212
|
std::promise<int> promise;
|
|
222
213
|
std::future<int> future = promise.get_future();
|
|
223
214
|
|
|
224
|
-
|
|
225
|
-
Napi::Env env, Napi::Function jsCallback) {
|
|
215
|
+
auto successHandler = [this, &promise, &credentials](Napi::Env env, Napi::Value result) {
|
|
226
216
|
Napi::HandleScope scope(env);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
217
|
+
auto credsObj = result.As<Napi::Object>();
|
|
218
|
+
credentialReferences.push_back(Napi::Persistent(credsObj));
|
|
219
|
+
|
|
220
|
+
if (credsObj.IsObject() == false || credsObj.Has(kFormat) == false) {
|
|
221
|
+
throw std::runtime_error(kInvalidInputCredentialTypeError);
|
|
222
|
+
}
|
|
223
|
+
int label = credsObj.Get(kFormat).As<Napi::Number>().Int32Value();
|
|
224
|
+
|
|
225
|
+
switch (label) {
|
|
226
|
+
case EDHOC_COSE_HEADER_KID:
|
|
227
|
+
convert_js_to_edhoc_kid(credsObj, credentials);
|
|
228
|
+
break;
|
|
229
|
+
case EDHOC_COSE_HEADER_X509_CHAIN:
|
|
230
|
+
convert_js_to_edhoc_x5chain(credsObj, credentials);
|
|
231
|
+
break;
|
|
232
|
+
case EDHOC_COSE_HEADER_X509_HASH:
|
|
233
|
+
convert_js_to_edhoc_x5t(credsObj, credentials);
|
|
234
|
+
break;
|
|
235
|
+
case EDHOC_COSE_ANY:
|
|
236
|
+
default:
|
|
237
|
+
throw std::runtime_error(kUnsupportedCredentialTypeError);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (credsObj.Has(kPrivateKeyId) && !credsObj.Get(kPrivateKeyId).IsNull()) {
|
|
241
|
+
Napi::Buffer<uint8_t> privKeyIdBuffer = credsObj.Get(kPrivateKeyId).As<Napi::Buffer<uint8_t>>();
|
|
242
|
+
memcpy(credentials->priv_key_id, privKeyIdBuffer.Data(), privKeyIdBuffer.Length());
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
auto blockingCallHandler = [this, &user_context, &successHandler, &promise](Napi::Env env,
|
|
249
|
+
Napi::Function jsCallback) {
|
|
250
|
+
Napi::HandleScope scope(env);
|
|
251
|
+
std::vector<napi_value> arguments = {static_cast<const UserContext*>(user_context)->parent.Value()};
|
|
252
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
253
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, credentialManagerRef.Value(), jsCallback, arguments, successHandler,
|
|
254
|
+
errorHandler);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
fetchTsfn.BlockingCall(blockingCallHandler);
|
|
271
258
|
|
|
272
259
|
future.wait();
|
|
273
260
|
return future.get();
|
|
274
261
|
}
|
|
275
262
|
|
|
276
|
-
int EdhocCredentialManager::callVerifyCredentials(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
size_t* public_key_length) {
|
|
263
|
+
int EdhocCredentialManager::callVerifyCredentials(const void* user_context,
|
|
264
|
+
struct edhoc_auth_creds* credentials,
|
|
265
|
+
const uint8_t** public_key_reference,
|
|
266
|
+
size_t* public_key_length) {
|
|
281
267
|
std::promise<int> promise;
|
|
282
268
|
std::future<int> future = promise.get_future();
|
|
283
269
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
270
|
+
auto successHandler = [this, &promise, &credentials, &public_key_reference, &public_key_length](Napi::Env env,
|
|
271
|
+
Napi::Value result) {
|
|
272
|
+
Napi::HandleScope scope(env);
|
|
273
|
+
Napi::Object credsObj = result.As<Napi::Object>();
|
|
274
|
+
credentialReferences.push_back(Napi::Persistent(credsObj));
|
|
275
|
+
if (credsObj.IsObject() == false) {
|
|
276
|
+
throw std::runtime_error(kInvalidInputCredentialTypeError);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
int label = credsObj.Get(kFormat).As<Napi::Number>().Int32Value();
|
|
280
|
+
switch (label) {
|
|
281
|
+
case EDHOC_COSE_HEADER_KID:
|
|
282
|
+
convert_js_to_edhoc_kid(credsObj, credentials);
|
|
283
|
+
break;
|
|
284
|
+
case EDHOC_COSE_HEADER_X509_CHAIN:
|
|
285
|
+
convert_js_to_edhoc_x5chain(credsObj, credentials);
|
|
286
|
+
break;
|
|
287
|
+
case EDHOC_COSE_HEADER_X509_HASH:
|
|
288
|
+
convert_js_to_edhoc_x5t(credsObj, credentials);
|
|
289
|
+
break;
|
|
290
|
+
default:
|
|
291
|
+
throw std::runtime_error(kUnsupportedCredentialTypeError);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (credsObj.Has(kPublicKey) && !credsObj.Get(kPublicKey).IsNull()) {
|
|
295
|
+
Napi::Buffer<uint8_t> publicKeyBuffer = credsObj.Get(kPublicKey).As<Napi::Buffer<uint8_t>>();
|
|
296
|
+
*public_key_reference = publicKeyBuffer.Data();
|
|
297
|
+
*public_key_length = publicKeyBuffer.Length();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
auto blockingCallHandler = [this, &user_context, &credentials, &successHandler, &promise](Napi::Env env,
|
|
304
|
+
Napi::Function jsCallback) {
|
|
291
305
|
Napi::HandleScope scope(env);
|
|
292
306
|
Napi::Object resultObject = Napi::Object::New(env);
|
|
293
307
|
resultObject.Set(kFormat, Napi::Number::New(env, credentials->label));
|
|
294
308
|
|
|
295
309
|
switch (credentials->label) {
|
|
296
310
|
case EDHOC_COSE_HEADER_KID:
|
|
297
|
-
resultObject.Set(kKid,
|
|
298
|
-
convert_edhoc_kid_to_js(env, credentials->key_id));
|
|
311
|
+
resultObject.Set(kKid, convert_edhoc_kid_to_js(env, credentials->key_id));
|
|
299
312
|
break;
|
|
300
313
|
case EDHOC_COSE_HEADER_X509_CHAIN:
|
|
301
|
-
resultObject.Set(
|
|
302
|
-
kX5chain,
|
|
303
|
-
convert_edhoc_x5chain_to_js(env, credentials->x509_chain));
|
|
314
|
+
resultObject.Set(kX5chain, convert_edhoc_x5chain_to_js(env, credentials->x509_chain));
|
|
304
315
|
break;
|
|
305
316
|
case EDHOC_COSE_HEADER_X509_HASH:
|
|
306
|
-
resultObject.Set(kX5t,
|
|
307
|
-
convert_edhoc_x5t_to_js(env, credentials->x509_hash));
|
|
317
|
+
resultObject.Set(kX5t, convert_edhoc_x5t_to_js(env, credentials->x509_hash));
|
|
308
318
|
break;
|
|
309
319
|
default:
|
|
310
|
-
throw
|
|
320
|
+
throw std::runtime_error(kUnsupportedCredentialTypeError);
|
|
311
321
|
}
|
|
312
322
|
|
|
313
|
-
std::vector<napi_value> arguments = {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
jsCallback,
|
|
321
|
-
arguments,
|
|
322
|
-
[this, &promise, &credentials, &public_key_reference, &public_key_length](
|
|
323
|
-
Napi::Env env, Napi::Value result) {
|
|
324
|
-
Napi::HandleScope scope(env);
|
|
325
|
-
Napi::Object credsObj = result.As<Napi::Object>();
|
|
326
|
-
credentialReferences.push_back(Napi::Persistent(credsObj));
|
|
327
|
-
if (credsObj.IsObject() == false) {
|
|
328
|
-
promise.set_value(EDHOC_ERROR_CREDENTIALS_FAILURE);
|
|
329
|
-
throw Napi::Error::New(env, kInvalidInputCredentialTypeError);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
int label = credsObj.Get(kFormat).As<Napi::Number>().Int32Value();
|
|
333
|
-
switch (label) {
|
|
334
|
-
case EDHOC_COSE_HEADER_KID:
|
|
335
|
-
convert_js_to_edhoc_kid(credsObj, credentials);
|
|
336
|
-
break;
|
|
337
|
-
case EDHOC_COSE_HEADER_X509_CHAIN:
|
|
338
|
-
convert_js_to_edhoc_x5chain(credsObj, credentials);
|
|
339
|
-
break;
|
|
340
|
-
case EDHOC_COSE_HEADER_X509_HASH:
|
|
341
|
-
convert_js_to_edhoc_x5t(credsObj, credentials);
|
|
342
|
-
break;
|
|
343
|
-
default:
|
|
344
|
-
throw Napi::Error::New(env, kUnsupportedCredentialTypeError);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (credsObj.Has(kPublicKey) && !credsObj.Get(kPublicKey).IsNull()) {
|
|
348
|
-
Napi::Buffer<uint8_t> publicKeyBuffer =
|
|
349
|
-
credsObj.Get(kPublicKey).As<Napi::Buffer<uint8_t>>();
|
|
350
|
-
*public_key_reference = publicKeyBuffer.Data();
|
|
351
|
-
*public_key_length = publicKeyBuffer.Length();
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
355
|
-
});
|
|
356
|
-
});
|
|
323
|
+
std::vector<napi_value> arguments = {static_cast<const UserContext*>(user_context)->parent.Value(), resultObject};
|
|
324
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
325
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, credentialManagerRef.Value(), jsCallback, arguments, successHandler,
|
|
326
|
+
errorHandler);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
verifyTsfn.BlockingCall(blockingCallHandler);
|
|
357
330
|
|
|
358
331
|
future.wait();
|
|
359
332
|
return future.get();
|