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,50 +1,36 @@
|
|
|
1
|
+
#include "EdhocCryptoManager.h"
|
|
2
|
+
|
|
1
3
|
#include <exception>
|
|
2
4
|
#include <future>
|
|
3
5
|
#include <iostream>
|
|
4
6
|
#include <stdexcept>
|
|
7
|
+
#include <thread>
|
|
5
8
|
|
|
6
|
-
#include "EdhocCryptoManager.h"
|
|
7
9
|
#include "UserContext.h"
|
|
8
10
|
#include "Utils.h"
|
|
9
11
|
|
|
10
|
-
static constexpr const char* kErrorInvalidUint8ArrayLength =
|
|
11
|
-
|
|
12
|
-
static constexpr const char*
|
|
13
|
-
|
|
14
|
-
static constexpr const char*
|
|
15
|
-
|
|
16
|
-
static constexpr const char*
|
|
17
|
-
|
|
18
|
-
static constexpr const char*
|
|
19
|
-
|
|
20
|
-
static constexpr const char*
|
|
21
|
-
|
|
22
|
-
static constexpr const char* kErrorExpectBooleanVerify =
|
|
23
|
-
"Expected boolean value as a result from verify function";
|
|
24
|
-
static constexpr const char* kErrorSecretLengthExceeds =
|
|
25
|
-
"Returned shared secret length exceeds buffer length.";
|
|
26
|
-
static constexpr const char* kErrorSignatureLengthExceeds =
|
|
27
|
-
"Returned signature length exceeds buffer length.";
|
|
28
|
-
static constexpr const char* kErrorBufferTooSmall =
|
|
29
|
-
"Returned ciphertext length exceeds buffer length.";
|
|
30
|
-
static constexpr const char* kErrorPlaintextLengthExceeds =
|
|
31
|
-
"Returned plaintext length exceeds buffer length.";
|
|
32
|
-
static constexpr const char* kErrorHashLengthExceeds =
|
|
33
|
-
"Returned hash length exceeds buffer length.";
|
|
12
|
+
static constexpr const char* kErrorInvalidUint8ArrayLength = "Returned Uint8Array length exceeds buffer length.";
|
|
13
|
+
static constexpr const char* kErrorEncodedUint32Length = "Encoded uint32 exceeds buffer length.";
|
|
14
|
+
static constexpr const char* kErrorExpectUint8ArrayOrNumber = "Function must return a Uint8Array or a Number.";
|
|
15
|
+
static constexpr const char* kErrorExpectBoolean = "Expected boolean return value from destroyKey function";
|
|
16
|
+
static constexpr const char* kErrorPublicKeyLengthExceeds = "Returned public key length exceeds buffer length.";
|
|
17
|
+
static constexpr const char* kErrorExpectBuffer = "Expected the result to be a Buffer";
|
|
18
|
+
static constexpr const char* kErrorExpectBooleanVerify = "Expected boolean value as a result from verify function";
|
|
19
|
+
static constexpr const char* kErrorSecretLengthExceeds = "Returned shared secret length exceeds buffer length.";
|
|
20
|
+
static constexpr const char* kErrorSignatureLengthExceeds = "Returned signature length exceeds buffer length.";
|
|
21
|
+
static constexpr const char* kErrorBufferTooSmall = "Returned ciphertext length exceeds buffer length.";
|
|
22
|
+
static constexpr const char* kErrorPlaintextLengthExceeds = "Returned plaintext length exceeds buffer length.";
|
|
23
|
+
static constexpr const char* kErrorHashLengthExceeds = "Returned hash length exceeds buffer length.";
|
|
34
24
|
static constexpr const char* kErrorPseudoRandpmLengthExceeds =
|
|
35
25
|
"Returned pseudo random key length exceeds buffer length.";
|
|
36
26
|
static constexpr const char* kErrorKeyingMaterialLengthExceeds =
|
|
37
27
|
"Returned output keying material length exceeds buffer length.";
|
|
38
|
-
static constexpr const char* kErrorResultObjectExpected =
|
|
39
|
-
|
|
40
|
-
static constexpr const char*
|
|
41
|
-
"Expected keys to be buffers.";
|
|
42
|
-
static constexpr const char* kErrorPrivateKeyLengthExceeds =
|
|
43
|
-
"Private key length exceeds buffer size.";
|
|
28
|
+
static constexpr const char* kErrorResultObjectExpected = "Expected result to be an object.";
|
|
29
|
+
static constexpr const char* kErrorKeysExpectedAsBuffers = "Expected keys to be buffers.";
|
|
30
|
+
static constexpr const char* kErrorPrivateKeyLengthExceeds = "Private key length exceeds buffer size.";
|
|
44
31
|
static constexpr const char* kErrorObjectExpected = "Object expected";
|
|
45
32
|
static constexpr const char* kErrorFunctionExpected = "Function expected";
|
|
46
|
-
|
|
47
|
-
static constexpr const char* kGenerateKey = "generateKey";
|
|
33
|
+
static constexpr const char* kImportKey = "importKey";
|
|
48
34
|
static constexpr const char* kDestroyKey = "destroyKey";
|
|
49
35
|
static constexpr const char* kMakeKeyPair = "makeKeyPair";
|
|
50
36
|
static constexpr const char* kKeyAgreement = "keyAgreement";
|
|
@@ -58,23 +44,11 @@ static constexpr const char* kHash = "hash";
|
|
|
58
44
|
|
|
59
45
|
EdhocCryptoManager::EdhocCryptoManager(Napi::Object& jsCryptoManager) {
|
|
60
46
|
if (!jsCryptoManager.IsObject()) {
|
|
61
|
-
Napi::Error::New(jsCryptoManager.Env(), kErrorObjectExpected)
|
|
62
|
-
.ThrowAsJavaScriptException();
|
|
47
|
+
Napi::Error::New(jsCryptoManager.Env(), kErrorObjectExpected).ThrowAsJavaScriptException();
|
|
63
48
|
}
|
|
64
49
|
cryptoManagerRef = Napi::Persistent(jsCryptoManager);
|
|
65
|
-
SetFunction(kGenerateKey, generateTsfn);
|
|
66
|
-
SetFunction(kDestroyKey, destroyTsfn);
|
|
67
|
-
SetFunction(kMakeKeyPair, makeKeyPairTsfn);
|
|
68
|
-
SetFunction(kKeyAgreement, keyAgreementTsfn);
|
|
69
|
-
SetFunction(kSign, signTsfn);
|
|
70
|
-
SetFunction(kVerify, verifyTsfn);
|
|
71
|
-
SetFunction(kExtract, extractTsfn);
|
|
72
|
-
SetFunction(kExpand, expandTsfn);
|
|
73
|
-
SetFunction(kEncrypt, encryptTsfn);
|
|
74
|
-
SetFunction(kDecrypt, decryptTsfn);
|
|
75
|
-
SetFunction(kHash, hashTsfn);
|
|
76
50
|
|
|
77
|
-
keys.
|
|
51
|
+
keys.import_key = &EdhocCryptoManager::ImportKey;
|
|
78
52
|
keys.destroy_key = &EdhocCryptoManager::DestroyKey;
|
|
79
53
|
crypto.make_key_pair = &EdhocCryptoManager::MakeKeyPair;
|
|
80
54
|
crypto.key_agreement = &EdhocCryptoManager::KeyAgreement;
|
|
@@ -89,7 +63,28 @@ EdhocCryptoManager::EdhocCryptoManager(Napi::Object& jsCryptoManager) {
|
|
|
89
63
|
|
|
90
64
|
EdhocCryptoManager::~EdhocCryptoManager() {
|
|
91
65
|
cryptoManagerRef.Reset();
|
|
92
|
-
|
|
66
|
+
for (auto& ref : bufferReferences) {
|
|
67
|
+
ref.Reset();
|
|
68
|
+
}
|
|
69
|
+
bufferReferences.clear();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
void EdhocCryptoManager::SetupAsyncFunctions() {
|
|
73
|
+
SetFunction(kImportKey, importTsfn);
|
|
74
|
+
SetFunction(kDestroyKey, destroyTsfn);
|
|
75
|
+
SetFunction(kMakeKeyPair, makeKeyPairTsfn);
|
|
76
|
+
SetFunction(kKeyAgreement, keyAgreementTsfn);
|
|
77
|
+
SetFunction(kSign, signTsfn);
|
|
78
|
+
SetFunction(kVerify, verifyTsfn);
|
|
79
|
+
SetFunction(kExtract, extractTsfn);
|
|
80
|
+
SetFunction(kExpand, expandTsfn);
|
|
81
|
+
SetFunction(kEncrypt, encryptTsfn);
|
|
82
|
+
SetFunction(kDecrypt, decryptTsfn);
|
|
83
|
+
SetFunction(kHash, hashTsfn);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void EdhocCryptoManager::CleanupAsyncFunctions() {
|
|
87
|
+
importTsfn.Release();
|
|
93
88
|
destroyTsfn.Release();
|
|
94
89
|
makeKeyPairTsfn.Release();
|
|
95
90
|
keyAgreementTsfn.Release();
|
|
@@ -100,33 +95,26 @@ EdhocCryptoManager::~EdhocCryptoManager() {
|
|
|
100
95
|
encryptTsfn.Release();
|
|
101
96
|
decryptTsfn.Release();
|
|
102
97
|
hashTsfn.Release();
|
|
103
|
-
for (auto& ref : bufferReferences) {
|
|
104
|
-
ref.Reset();
|
|
105
|
-
}
|
|
106
|
-
bufferReferences.clear();
|
|
107
98
|
}
|
|
108
99
|
|
|
109
|
-
void EdhocCryptoManager::SetFunction(const char* name,
|
|
110
|
-
Napi::ThreadSafeFunction& tsfn) {
|
|
100
|
+
void EdhocCryptoManager::SetFunction(const char* name, Napi::ThreadSafeFunction& tsfn) {
|
|
111
101
|
Napi::Env env = cryptoManagerRef.Env();
|
|
112
102
|
Napi::HandleScope scope(env);
|
|
113
|
-
Napi::Function jsFunction =
|
|
114
|
-
cryptoManagerRef.Value().Get(name).As<Napi::Function>();
|
|
103
|
+
Napi::Function jsFunction = cryptoManagerRef.Value().Get(name).As<Napi::Function>();
|
|
115
104
|
if (!jsFunction.IsFunction()) {
|
|
116
105
|
Napi::Error::New(env, kErrorFunctionExpected).ThrowAsJavaScriptException();
|
|
117
106
|
}
|
|
118
107
|
tsfn = Napi::ThreadSafeFunction::New(env, jsFunction, name, 0, 1);
|
|
119
108
|
}
|
|
120
109
|
|
|
121
|
-
int EdhocCryptoManager::
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
110
|
+
int EdhocCryptoManager::ImportKey(void* user_context,
|
|
111
|
+
enum edhoc_key_type key_type,
|
|
112
|
+
const uint8_t* raw_key,
|
|
113
|
+
size_t raw_key_length,
|
|
114
|
+
void* key_id) {
|
|
126
115
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
127
116
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
128
|
-
return cryptoManager->
|
|
129
|
-
user_context, key_type, raw_key, raw_key_length, key_id);
|
|
117
|
+
return cryptoManager->callImportKey(user_context, key_type, raw_key, raw_key_length, key_id);
|
|
130
118
|
}
|
|
131
119
|
|
|
132
120
|
int EdhocCryptoManager::DestroyKey(void* user_context, void* key_id) {
|
|
@@ -145,14 +133,8 @@ int EdhocCryptoManager::MakeKeyPair(void* user_context,
|
|
|
145
133
|
size_t* public_key_length) {
|
|
146
134
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
147
135
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
148
|
-
return cryptoManager->callMakeKeyPair(user_context,
|
|
149
|
-
|
|
150
|
-
private_key,
|
|
151
|
-
private_key_size,
|
|
152
|
-
private_key_length,
|
|
153
|
-
public_key,
|
|
154
|
-
public_key_size,
|
|
155
|
-
public_key_length);
|
|
136
|
+
return cryptoManager->callMakeKeyPair(user_context, key_id, private_key, private_key_size, private_key_length,
|
|
137
|
+
public_key, public_key_size, public_key_length);
|
|
156
138
|
}
|
|
157
139
|
|
|
158
140
|
int EdhocCryptoManager::KeyAgreement(void* user_context,
|
|
@@ -164,13 +146,8 @@ int EdhocCryptoManager::KeyAgreement(void* user_context,
|
|
|
164
146
|
size_t* shared_secret_length) {
|
|
165
147
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
166
148
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
167
|
-
return cryptoManager->callKeyAgreement(user_context,
|
|
168
|
-
|
|
169
|
-
peer_public_key,
|
|
170
|
-
peer_public_key_length,
|
|
171
|
-
shared_secret,
|
|
172
|
-
shared_secret_size,
|
|
173
|
-
shared_secret_length);
|
|
149
|
+
return cryptoManager->callKeyAgreement(user_context, key_id, peer_public_key, peer_public_key_length, shared_secret,
|
|
150
|
+
shared_secret_size, shared_secret_length);
|
|
174
151
|
}
|
|
175
152
|
|
|
176
153
|
int EdhocCryptoManager::Sign(void* user_context,
|
|
@@ -182,12 +159,7 @@ int EdhocCryptoManager::Sign(void* user_context,
|
|
|
182
159
|
size_t* signature_length) {
|
|
183
160
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
184
161
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
185
|
-
return cryptoManager->callSign(user_context,
|
|
186
|
-
key_id,
|
|
187
|
-
input,
|
|
188
|
-
input_length,
|
|
189
|
-
signature,
|
|
190
|
-
signature_size,
|
|
162
|
+
return cryptoManager->callSign(user_context, key_id, input, input_length, signature, signature_size,
|
|
191
163
|
signature_length);
|
|
192
164
|
}
|
|
193
165
|
|
|
@@ -199,8 +171,7 @@ int EdhocCryptoManager::Verify(void* user_context,
|
|
|
199
171
|
size_t signature_length) {
|
|
200
172
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
201
173
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
202
|
-
return cryptoManager->callVerify(
|
|
203
|
-
user_context, key_id, input, input_length, signature, signature_length);
|
|
174
|
+
return cryptoManager->callVerify(user_context, key_id, input, input_length, signature, signature_length);
|
|
204
175
|
}
|
|
205
176
|
|
|
206
177
|
int EdhocCryptoManager::Extract(void* user_context,
|
|
@@ -212,12 +183,7 @@ int EdhocCryptoManager::Extract(void* user_context,
|
|
|
212
183
|
size_t* pseudo_random_key_length) {
|
|
213
184
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
214
185
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
215
|
-
return cryptoManager->callExtract(user_context,
|
|
216
|
-
key_id,
|
|
217
|
-
salt,
|
|
218
|
-
salt_len,
|
|
219
|
-
pseudo_random_key,
|
|
220
|
-
pseudo_random_key_size,
|
|
186
|
+
return cryptoManager->callExtract(user_context, key_id, salt, salt_len, pseudo_random_key, pseudo_random_key_size,
|
|
221
187
|
pseudo_random_key_length);
|
|
222
188
|
}
|
|
223
189
|
|
|
@@ -229,11 +195,7 @@ int EdhocCryptoManager::Expand(void* user_context,
|
|
|
229
195
|
size_t output_keying_material_length) {
|
|
230
196
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
231
197
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
232
|
-
return cryptoManager->callExpand(user_context,
|
|
233
|
-
key_id,
|
|
234
|
-
info,
|
|
235
|
-
info_length,
|
|
236
|
-
output_keying_material,
|
|
198
|
+
return cryptoManager->callExpand(user_context, key_id, info, info_length, output_keying_material,
|
|
237
199
|
output_keying_material_length);
|
|
238
200
|
}
|
|
239
201
|
|
|
@@ -250,17 +212,8 @@ int EdhocCryptoManager::Encrypt(void* user_context,
|
|
|
250
212
|
size_t* ciphertext_length) {
|
|
251
213
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
252
214
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
253
|
-
return cryptoManager->callEncrypt(user_context,
|
|
254
|
-
|
|
255
|
-
nonce,
|
|
256
|
-
nonce_length,
|
|
257
|
-
additional_data,
|
|
258
|
-
additional_data_length,
|
|
259
|
-
plaintext,
|
|
260
|
-
plaintext_length,
|
|
261
|
-
ciphertext,
|
|
262
|
-
ciphertext_size,
|
|
263
|
-
ciphertext_length);
|
|
215
|
+
return cryptoManager->callEncrypt(user_context, key_id, nonce, nonce_length, additional_data, additional_data_length,
|
|
216
|
+
plaintext, plaintext_length, ciphertext, ciphertext_size, ciphertext_length);
|
|
264
217
|
}
|
|
265
218
|
|
|
266
219
|
int EdhocCryptoManager::Decrypt(void* user_context,
|
|
@@ -276,17 +229,8 @@ int EdhocCryptoManager::Decrypt(void* user_context,
|
|
|
276
229
|
size_t* plaintext_length) {
|
|
277
230
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
278
231
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
279
|
-
return cryptoManager->callDecrypt(user_context,
|
|
280
|
-
|
|
281
|
-
nonce,
|
|
282
|
-
nonce_length,
|
|
283
|
-
additional_data,
|
|
284
|
-
additional_data_length,
|
|
285
|
-
ciphertext,
|
|
286
|
-
ciphertext_length,
|
|
287
|
-
plaintext,
|
|
288
|
-
plaintext_size,
|
|
289
|
-
plaintext_length);
|
|
232
|
+
return cryptoManager->callDecrypt(user_context, key_id, nonce, nonce_length, additional_data, additional_data_length,
|
|
233
|
+
ciphertext, ciphertext_length, plaintext, plaintext_size, plaintext_length);
|
|
290
234
|
}
|
|
291
235
|
|
|
292
236
|
int EdhocCryptoManager::Hash(void* user_context,
|
|
@@ -297,67 +241,59 @@ int EdhocCryptoManager::Hash(void* user_context,
|
|
|
297
241
|
size_t* hash_length) {
|
|
298
242
|
UserContext* userContext = static_cast<UserContext*>(user_context);
|
|
299
243
|
EdhocCryptoManager* cryptoManager = userContext->GetCryptoManager();
|
|
300
|
-
return cryptoManager->callHash(
|
|
301
|
-
user_context, input, input_length, hash, hash_size, hash_length);
|
|
244
|
+
return cryptoManager->callHash(user_context, input, input_length, hash, hash_size, hash_length);
|
|
302
245
|
}
|
|
303
246
|
|
|
304
|
-
int EdhocCryptoManager::
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
247
|
+
int EdhocCryptoManager::callImportKey(const void* user_context,
|
|
248
|
+
enum edhoc_key_type key_type,
|
|
249
|
+
const uint8_t* raw_key,
|
|
250
|
+
size_t raw_key_length,
|
|
251
|
+
void* key_id_ptr) {
|
|
309
252
|
std::promise<int> promise;
|
|
310
253
|
std::future<int> future = promise.get_future();
|
|
311
254
|
|
|
312
|
-
|
|
313
|
-
&user_context,
|
|
314
|
-
&promise,
|
|
315
|
-
key_type,
|
|
316
|
-
&raw_key,
|
|
317
|
-
raw_key_length,
|
|
318
|
-
&key_id_ptr](Napi::Env env,
|
|
319
|
-
Napi::Function jsCallback) {
|
|
255
|
+
auto successHandler = [&promise, &key_id_ptr](Napi::Env env, Napi::Value result) {
|
|
320
256
|
Napi::HandleScope scope(env);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
257
|
+
uint8_t* key_id = static_cast<uint8_t*>(key_id_ptr);
|
|
258
|
+
|
|
259
|
+
if (result.IsTypedArray()) {
|
|
260
|
+
Napi::Uint8Array resultArray = result.As<Napi::Uint8Array>();
|
|
261
|
+
if (resultArray.ElementLength() > CONFIG_LIBEDHOC_KEY_ID_LEN) {
|
|
262
|
+
throw std::runtime_error(kErrorInvalidUint8ArrayLength);
|
|
263
|
+
}
|
|
264
|
+
memcpy(key_id, resultArray.Data(), resultArray.ElementLength());
|
|
265
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
266
|
+
} else if (result.IsNumber()) {
|
|
267
|
+
uint32_t num = result.As<Napi::Number>().Int64Value();
|
|
268
|
+
uint8_t tempBuffer[CONFIG_LIBEDHOC_KEY_ID_LEN];
|
|
269
|
+
size_t encodedLength = 0;
|
|
270
|
+
Utils::EncodeInt64ToBuffer(num, tempBuffer, &encodedLength);
|
|
271
|
+
|
|
272
|
+
if (encodedLength > CONFIG_LIBEDHOC_KEY_ID_LEN) {
|
|
273
|
+
throw std::runtime_error(kErrorEncodedUint32Length);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
memcpy(key_id, tempBuffer, encodedLength);
|
|
277
|
+
memset(key_id + encodedLength, 0, CONFIG_LIBEDHOC_KEY_ID_LEN - encodedLength);
|
|
278
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
279
|
+
} else {
|
|
280
|
+
throw std::runtime_error(kErrorExpectUint8ArrayOrNumber);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
auto blockingCallHandler = [this, &user_context, &promise, key_type, &raw_key, raw_key_length, successHandler](
|
|
285
|
+
Napi::Env env, Napi::Function jsCallback) {
|
|
286
|
+
Napi::HandleScope scope(env);
|
|
287
|
+
|
|
288
|
+
std::vector<napi_value> args = {static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
289
|
+
Napi::Number::New(env, static_cast<int>(key_type)),
|
|
290
|
+
Napi::Buffer<uint8_t>::New(env, const_cast<uint8_t*>(raw_key), raw_key_length)};
|
|
291
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
292
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
293
|
+
errorHandler);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
importTsfn.BlockingCall(blockingCallHandler);
|
|
361
297
|
|
|
362
298
|
future.wait();
|
|
363
299
|
return future.get();
|
|
@@ -367,29 +303,37 @@ int EdhocCryptoManager::callDestroyKey(const void* user_context, void* key_id) {
|
|
|
367
303
|
std::promise<int> promise;
|
|
368
304
|
std::future<int> future = promise.get_future();
|
|
369
305
|
|
|
370
|
-
|
|
371
|
-
|
|
306
|
+
// Timeout thread to ensure the callback is called
|
|
307
|
+
std::shared_ptr<bool> callbackCompleted = std::make_shared<bool>(false);
|
|
308
|
+
std::thread timeoutThread([callbackCompleted, &promise]() {
|
|
309
|
+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
|
310
|
+
if (!*callbackCompleted) {
|
|
311
|
+
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
timeoutThread.detach();
|
|
315
|
+
|
|
316
|
+
auto successHandler = [&promise](Napi::Env env, Napi::Value result) {
|
|
372
317
|
Napi::HandleScope scope(env);
|
|
373
|
-
|
|
318
|
+
if (!result.IsBoolean()) {
|
|
319
|
+
throw std::runtime_error(kErrorExpectBoolean);
|
|
320
|
+
}
|
|
321
|
+
promise.set_value(result.As<Napi::Boolean>().Value() ? EDHOC_SUCCESS : EDHOC_ERROR_GENERIC_ERROR);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, callbackCompleted, successHandler](
|
|
325
|
+
Napi::Env env, Napi::Function jsCallback) {
|
|
326
|
+
*callbackCompleted = true;
|
|
327
|
+
Napi::HandleScope scope(env);
|
|
328
|
+
std::vector<napi_value> args = {
|
|
374
329
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
375
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
376
|
-
|
|
377
|
-
Utils::InvokeJSFunctionWithPromiseHandling(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
[&promise](Napi::Env env, Napi::Value result) {
|
|
383
|
-
Napi::HandleScope scope(env);
|
|
384
|
-
if (!result.IsBoolean()) {
|
|
385
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
386
|
-
throw Napi::TypeError::New(env, kErrorExpectBoolean);
|
|
387
|
-
}
|
|
388
|
-
promise.set_value(result.As<Napi::Boolean>().Value()
|
|
389
|
-
? EDHOC_SUCCESS
|
|
390
|
-
: EDHOC_ERROR_GENERIC_ERROR);
|
|
391
|
-
});
|
|
392
|
-
});
|
|
330
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN)};
|
|
331
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
332
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
333
|
+
errorHandler);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
destroyTsfn.BlockingCall(blockingCallHandler);
|
|
393
337
|
|
|
394
338
|
future.wait();
|
|
395
339
|
return future.get();
|
|
@@ -406,77 +350,56 @@ int EdhocCryptoManager::callMakeKeyPair(const void* user_context,
|
|
|
406
350
|
std::promise<int> promise;
|
|
407
351
|
std::future<int> future = promise.get_future();
|
|
408
352
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
&promise,
|
|
412
|
-
&key_id,
|
|
413
|
-
&private_key,
|
|
414
|
-
private_key_size,
|
|
415
|
-
&private_key_length,
|
|
416
|
-
&public_key,
|
|
417
|
-
public_key_size,
|
|
418
|
-
&public_key_length](Napi::Env env,
|
|
419
|
-
Napi::Function jsCallback) {
|
|
353
|
+
auto successHandler = [&promise, &private_key, private_key_size, &private_key_length, &public_key, public_key_size,
|
|
354
|
+
&public_key_length](Napi::Env env, Napi::Value result) {
|
|
420
355
|
Napi::HandleScope scope(env);
|
|
421
|
-
|
|
356
|
+
if (!result.IsObject()) {
|
|
357
|
+
throw std::runtime_error(kErrorResultObjectExpected);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
Napi::Object resultObject = result.As<Napi::Object>();
|
|
361
|
+
Napi::Value privateKeyValue = resultObject.Get("privateKey");
|
|
362
|
+
Napi::Value publicKeyValue = resultObject.Get("publicKey");
|
|
363
|
+
|
|
364
|
+
if (!privateKeyValue.IsBuffer() || !publicKeyValue.IsBuffer()) {
|
|
365
|
+
throw std::runtime_error(kErrorKeysExpectedAsBuffers);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
Napi::Buffer<uint8_t> privateKeyBuffer = privateKeyValue.As<Napi::Buffer<uint8_t>>();
|
|
369
|
+
Napi::Buffer<uint8_t> publicKeyBuffer = publicKeyValue.As<Napi::Buffer<uint8_t>>();
|
|
370
|
+
|
|
371
|
+
if (privateKeyBuffer.Length() > private_key_size) {
|
|
372
|
+
throw std::runtime_error(kErrorPrivateKeyLengthExceeds);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (publicKeyBuffer.Length() > public_key_size) {
|
|
376
|
+
throw std::runtime_error(kErrorPublicKeyLengthExceeds);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
memcpy(private_key, privateKeyBuffer.Data(), privateKeyBuffer.Length());
|
|
380
|
+
*private_key_length = privateKeyBuffer.Length();
|
|
381
|
+
memcpy(public_key, publicKeyBuffer.Data(), publicKeyBuffer.Length());
|
|
382
|
+
*public_key_length = publicKeyBuffer.Length();
|
|
383
|
+
|
|
384
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, private_key_size, public_key_size,
|
|
388
|
+
successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
389
|
+
Napi::HandleScope scope(env);
|
|
390
|
+
std::vector<napi_value> args = {
|
|
422
391
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
423
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
424
|
-
env, static_cast<const uint8_t*>(key_id), EDHOC_KID_LEN),
|
|
392
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
425
393
|
Napi::Number::New(env, static_cast<size_t>(private_key_size)),
|
|
426
394
|
Napi::Number::New(env, static_cast<size_t>(public_key_size))};
|
|
395
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
396
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
397
|
+
errorHandler);
|
|
398
|
+
};
|
|
427
399
|
|
|
428
|
-
|
|
429
|
-
env,
|
|
430
|
-
cryptoManagerRef.Value(),
|
|
431
|
-
jsCallback,
|
|
432
|
-
arguments,
|
|
433
|
-
[&promise,
|
|
434
|
-
&private_key,
|
|
435
|
-
private_key_size,
|
|
436
|
-
&private_key_length,
|
|
437
|
-
&public_key,
|
|
438
|
-
public_key_size,
|
|
439
|
-
&public_key_length](Napi::Env env, Napi::Value result) {
|
|
440
|
-
Napi::HandleScope scope(env);
|
|
441
|
-
if (!result.IsObject()) {
|
|
442
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
443
|
-
throw Napi::TypeError::New(env, kErrorResultObjectExpected);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
Napi::Object resultObject = result.As<Napi::Object>();
|
|
447
|
-
Napi::Value privateKeyValue = resultObject.Get("privateKey");
|
|
448
|
-
Napi::Value publicKeyValue = resultObject.Get("publicKey");
|
|
449
|
-
|
|
450
|
-
if (!privateKeyValue.IsBuffer() || !publicKeyValue.IsBuffer()) {
|
|
451
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
452
|
-
throw Napi::TypeError::New(env, kErrorKeysExpectedAsBuffers);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
Napi::Buffer<uint8_t> privateKeyBuffer =
|
|
456
|
-
privateKeyValue.As<Napi::Buffer<uint8_t>>();
|
|
457
|
-
Napi::Buffer<uint8_t> publicKeyBuffer =
|
|
458
|
-
publicKeyValue.As<Napi::Buffer<uint8_t>>();
|
|
459
|
-
|
|
460
|
-
if (privateKeyBuffer.Length() > private_key_size) {
|
|
461
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
462
|
-
throw Napi::TypeError::New(env, kErrorPrivateKeyLengthExceeds);
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (publicKeyBuffer.Length() > public_key_size) {
|
|
466
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
467
|
-
throw Napi::TypeError::New(env, kErrorPublicKeyLengthExceeds);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
memcpy(
|
|
471
|
-
private_key, privateKeyBuffer.Data(), privateKeyBuffer.Length());
|
|
472
|
-
*private_key_length = privateKeyBuffer.Length();
|
|
473
|
-
memcpy(public_key, publicKeyBuffer.Data(), publicKeyBuffer.Length());
|
|
474
|
-
*public_key_length = publicKeyBuffer.Length();
|
|
475
|
-
|
|
476
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
477
|
-
});
|
|
478
|
-
});
|
|
400
|
+
makeKeyPairTsfn.BlockingCall(blockingCallHandler);
|
|
479
401
|
|
|
402
|
+
future.wait();
|
|
480
403
|
return future.get();
|
|
481
404
|
}
|
|
482
405
|
|
|
@@ -490,55 +413,37 @@ int EdhocCryptoManager::callKeyAgreement(const void* user_context,
|
|
|
490
413
|
std::promise<int> promise;
|
|
491
414
|
std::future<int> future = promise.get_future();
|
|
492
415
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
&promise,
|
|
496
|
-
&key_id,
|
|
497
|
-
&peer_public_key,
|
|
498
|
-
peer_public_key_length,
|
|
499
|
-
&shared_secret,
|
|
500
|
-
shared_secret_size,
|
|
501
|
-
&shared_secret_length](
|
|
502
|
-
Napi::Env env, Napi::Function jsCallback) {
|
|
416
|
+
auto successHandler = [&promise, &shared_secret, shared_secret_size, &shared_secret_length](Napi::Env env,
|
|
417
|
+
Napi::Value result) {
|
|
503
418
|
Napi::HandleScope scope(env);
|
|
504
|
-
|
|
419
|
+
if (!result.IsBuffer()) {
|
|
420
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
421
|
+
}
|
|
422
|
+
Napi::Buffer<uint8_t> sharedSecretBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
423
|
+
if (sharedSecretBuffer.Length() > shared_secret_size) {
|
|
424
|
+
throw std::runtime_error(kErrorSecretLengthExceeds);
|
|
425
|
+
}
|
|
426
|
+
memcpy(shared_secret, sharedSecretBuffer.Data(), sharedSecretBuffer.Length());
|
|
427
|
+
*shared_secret_length = sharedSecretBuffer.Length();
|
|
428
|
+
|
|
429
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, &peer_public_key, peer_public_key_length,
|
|
433
|
+
shared_secret_size, successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
434
|
+
Napi::HandleScope scope(env);
|
|
435
|
+
std::vector<napi_value> args = {
|
|
505
436
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
506
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
507
|
-
|
|
508
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
509
|
-
env, peer_public_key, peer_public_key_length),
|
|
437
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
438
|
+
Napi::Buffer<uint8_t>::Copy(env, peer_public_key, peer_public_key_length),
|
|
510
439
|
Napi::Number::New(env, static_cast<size_t>(shared_secret_size)),
|
|
511
440
|
};
|
|
441
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
442
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
443
|
+
errorHandler);
|
|
444
|
+
};
|
|
512
445
|
|
|
513
|
-
|
|
514
|
-
env,
|
|
515
|
-
cryptoManagerRef.Value(),
|
|
516
|
-
jsCallback,
|
|
517
|
-
arguments,
|
|
518
|
-
[&promise, &shared_secret, shared_secret_size, &shared_secret_length](
|
|
519
|
-
Napi::Env env, Napi::Value result) {
|
|
520
|
-
Napi::HandleScope scope(env);
|
|
521
|
-
if (!result.IsBuffer()) {
|
|
522
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
523
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
Napi::Buffer<uint8_t> sharedSecretBuffer =
|
|
527
|
-
result.As<Napi::Buffer<uint8_t>>();
|
|
528
|
-
|
|
529
|
-
if (sharedSecretBuffer.Length() > shared_secret_size) {
|
|
530
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
531
|
-
throw Napi::TypeError::New(env, kErrorSecretLengthExceeds);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
memcpy(shared_secret,
|
|
535
|
-
sharedSecretBuffer.Data(),
|
|
536
|
-
sharedSecretBuffer.Length());
|
|
537
|
-
*shared_secret_length = sharedSecretBuffer.Length();
|
|
538
|
-
|
|
539
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
540
|
-
});
|
|
541
|
-
});
|
|
446
|
+
keyAgreementTsfn.BlockingCall(blockingCallHandler);
|
|
542
447
|
|
|
543
448
|
future.wait();
|
|
544
449
|
return future.get();
|
|
@@ -556,50 +461,35 @@ int EdhocCryptoManager::callSign(const void* user_context,
|
|
|
556
461
|
|
|
557
462
|
const uint8_t* kid = static_cast<const uint8_t*>(key_id);
|
|
558
463
|
|
|
559
|
-
|
|
560
|
-
&user_context,
|
|
561
|
-
&promise,
|
|
562
|
-
kid,
|
|
563
|
-
&input,
|
|
564
|
-
input_length,
|
|
565
|
-
&signature,
|
|
566
|
-
signature_size,
|
|
567
|
-
&signature_length](Napi::Env env,
|
|
568
|
-
Napi::Function jsCallback) {
|
|
464
|
+
auto successHandler = [&promise, &signature, signature_size, &signature_length](Napi::Env env, Napi::Value result) {
|
|
569
465
|
Napi::HandleScope scope(env);
|
|
570
|
-
|
|
466
|
+
if (!result.IsBuffer()) {
|
|
467
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
468
|
+
}
|
|
469
|
+
Napi::Buffer<uint8_t> signatureBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
470
|
+
if (signatureBuffer.Length() > signature_size) {
|
|
471
|
+
throw std::runtime_error(kErrorSignatureLengthExceeds);
|
|
472
|
+
}
|
|
473
|
+
memcpy(signature, signatureBuffer.Data(), signatureBuffer.Length());
|
|
474
|
+
*signature_length = signatureBuffer.Length();
|
|
475
|
+
|
|
476
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
auto blockingCallHandler = [this, &user_context, &promise, kid, &input, input_length, signature_size, successHandler](
|
|
480
|
+
Napi::Env env, Napi::Function jsCallback) {
|
|
481
|
+
Napi::HandleScope scope(env);
|
|
482
|
+
std::vector<napi_value> args = {
|
|
571
483
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
572
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
573
|
-
env, static_cast<const uint8_t*>(kid), EDHOC_KID_LEN),
|
|
484
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(kid), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
574
485
|
Napi::Buffer<uint8_t>::Copy(env, input, input_length),
|
|
575
486
|
Napi::Number::New(env, static_cast<size_t>(signature_size))};
|
|
576
|
-
Utils::
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
Napi::Env env, Napi::Value result) {
|
|
583
|
-
Napi::HandleScope scope(env);
|
|
584
|
-
if (!result.IsBuffer()) {
|
|
585
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
586
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
Napi::Buffer<uint8_t> signatureBuffer =
|
|
590
|
-
result.As<Napi::Buffer<uint8_t>>();
|
|
591
|
-
|
|
592
|
-
if (signatureBuffer.Length() > signature_size) {
|
|
593
|
-
promise.set_value(EDHOC_ERROR_BUFFER_TOO_SMALL);
|
|
594
|
-
throw Napi::TypeError::New(env, kErrorSignatureLengthExceeds);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
memcpy(signature, signatureBuffer.Data(), signatureBuffer.Length());
|
|
598
|
-
*signature_length = signatureBuffer.Length();
|
|
599
|
-
|
|
600
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
601
|
-
});
|
|
602
|
-
});
|
|
487
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
488
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
489
|
+
errorHandler);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
signTsfn.BlockingCall(blockingCallHandler);
|
|
603
493
|
|
|
604
494
|
future.wait();
|
|
605
495
|
return future.get();
|
|
@@ -614,39 +504,29 @@ int EdhocCryptoManager::callVerify(const void* user_context,
|
|
|
614
504
|
std::promise<int> promise;
|
|
615
505
|
std::future<int> future = promise.get_future();
|
|
616
506
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
Napi::HandleScope scope(env);
|
|
641
|
-
if (!result.IsBoolean()) {
|
|
642
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
643
|
-
throw Napi::TypeError::New(env, kErrorExpectBooleanVerify);
|
|
644
|
-
}
|
|
645
|
-
promise.set_value(result.As<Napi::Boolean>().Value()
|
|
646
|
-
? EDHOC_SUCCESS
|
|
647
|
-
: EDHOC_ERROR_CRYPTO_FAILURE);
|
|
648
|
-
});
|
|
649
|
-
});
|
|
507
|
+
auto successHandler = [&promise](Napi::Env env, Napi::Value result) {
|
|
508
|
+
Napi::HandleScope scope(env);
|
|
509
|
+
if (!result.IsBoolean()) {
|
|
510
|
+
throw std::runtime_error(kErrorExpectBooleanVerify);
|
|
511
|
+
}
|
|
512
|
+
promise.set_value(result.As<Napi::Boolean>().Value() ? EDHOC_SUCCESS : EDHOC_ERROR_CRYPTO_FAILURE);
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, &input, input_length, &signature,
|
|
516
|
+
signature_length, successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
517
|
+
Napi::HandleScope scope(env);
|
|
518
|
+
std::vector<napi_value> args = {
|
|
519
|
+
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
520
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
521
|
+
Napi::Buffer<uint8_t>::Copy(env, input, input_length),
|
|
522
|
+
Napi::Buffer<uint8_t>::Copy(env, signature, signature_length),
|
|
523
|
+
};
|
|
524
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
525
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
526
|
+
errorHandler);
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
verifyTsfn.BlockingCall(blockingCallHandler);
|
|
650
530
|
|
|
651
531
|
future.wait();
|
|
652
532
|
return future.get();
|
|
@@ -662,54 +542,36 @@ int EdhocCryptoManager::callExtract(const void* user_context,
|
|
|
662
542
|
std::promise<int> promise;
|
|
663
543
|
std::future<int> future = promise.get_future();
|
|
664
544
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
&promise,
|
|
668
|
-
&key_id,
|
|
669
|
-
&salt,
|
|
670
|
-
salt_len,
|
|
671
|
-
&pseudo_random_key,
|
|
672
|
-
pseudo_random_key_size,
|
|
673
|
-
&pseudo_random_key_length](
|
|
674
|
-
Napi::Env env, Napi::Function jsCallback) {
|
|
545
|
+
auto successHandler = [&promise, &pseudo_random_key, pseudo_random_key_size, &pseudo_random_key_length](
|
|
546
|
+
Napi::Env env, Napi::Value result) {
|
|
675
547
|
Napi::HandleScope scope(env);
|
|
676
|
-
|
|
548
|
+
if (!result.IsBuffer()) {
|
|
549
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
550
|
+
}
|
|
551
|
+
Napi::Buffer<uint8_t> randomKeyBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
552
|
+
if (randomKeyBuffer.Length() > pseudo_random_key_size) {
|
|
553
|
+
throw std::runtime_error(kErrorPseudoRandpmLengthExceeds);
|
|
554
|
+
}
|
|
555
|
+
memcpy(pseudo_random_key, randomKeyBuffer.Data(), randomKeyBuffer.Length());
|
|
556
|
+
*pseudo_random_key_length = randomKeyBuffer.Length();
|
|
557
|
+
|
|
558
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, &salt, salt_len, pseudo_random_key_size,
|
|
562
|
+
successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
563
|
+
Napi::HandleScope scope(env);
|
|
564
|
+
std::vector<napi_value> args = {
|
|
677
565
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
678
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
679
|
-
env, static_cast<const uint8_t*>(key_id), EDHOC_KID_LEN),
|
|
566
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
680
567
|
Napi::Buffer<uint8_t>::Copy(env, salt, salt_len),
|
|
681
568
|
Napi::Number::New(env, static_cast<size_t>(pseudo_random_key_size))};
|
|
682
|
-
Utils::
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
&pseudo_random_key,
|
|
689
|
-
pseudo_random_key_size,
|
|
690
|
-
&pseudo_random_key_length](Napi::Env env, Napi::Value result) {
|
|
691
|
-
Napi::HandleScope scope(env);
|
|
692
|
-
if (!result.IsBuffer()) {
|
|
693
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
694
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
Napi::Buffer<uint8_t> randomKeyBuffer =
|
|
698
|
-
result.As<Napi::Buffer<uint8_t>>();
|
|
699
|
-
|
|
700
|
-
if (randomKeyBuffer.Length() > pseudo_random_key_size) {
|
|
701
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
702
|
-
throw Napi::TypeError::New(env, kErrorPseudoRandpmLengthExceeds);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
memcpy(pseudo_random_key,
|
|
706
|
-
randomKeyBuffer.Data(),
|
|
707
|
-
randomKeyBuffer.Length());
|
|
708
|
-
*pseudo_random_key_length = randomKeyBuffer.Length();
|
|
709
|
-
|
|
710
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
711
|
-
});
|
|
712
|
-
});
|
|
569
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
570
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
571
|
+
errorHandler);
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
extractTsfn.BlockingCall(blockingCallHandler);
|
|
713
575
|
|
|
714
576
|
future.wait();
|
|
715
577
|
return future.get();
|
|
@@ -724,50 +586,35 @@ int EdhocCryptoManager::callExpand(const void* user_context,
|
|
|
724
586
|
std::promise<int> promise;
|
|
725
587
|
std::future<int> future = promise.get_future();
|
|
726
588
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
&promise,
|
|
730
|
-
&key_id,
|
|
731
|
-
&info,
|
|
732
|
-
info_length,
|
|
733
|
-
&output_keying_material,
|
|
734
|
-
output_keying_material_length](
|
|
735
|
-
Napi::Env env, Napi::Function jsCallback) {
|
|
589
|
+
auto successHandler = [&promise, &output_keying_material, output_keying_material_length](Napi::Env env,
|
|
590
|
+
Napi::Value result) {
|
|
736
591
|
Napi::HandleScope scope(env);
|
|
737
|
-
|
|
592
|
+
if (!result.IsBuffer()) {
|
|
593
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
594
|
+
}
|
|
595
|
+
Napi::Buffer<uint8_t> outputBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
596
|
+
if (outputBuffer.Length() > output_keying_material_length) {
|
|
597
|
+
throw std::runtime_error(kErrorKeyingMaterialLengthExceeds);
|
|
598
|
+
}
|
|
599
|
+
memcpy(output_keying_material, outputBuffer.Data(), outputBuffer.Length());
|
|
600
|
+
|
|
601
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, &info, info_length, output_keying_material_length,
|
|
605
|
+
successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
606
|
+
Napi::HandleScope scope(env);
|
|
607
|
+
std::vector<napi_value> args = {
|
|
738
608
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
739
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
740
|
-
env, static_cast<const uint8_t*>(key_id), EDHOC_KID_LEN),
|
|
609
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
741
610
|
Napi::Buffer<uint8_t>::Copy(env, info, info_length),
|
|
742
|
-
Napi::Number::New(env,
|
|
743
|
-
|
|
744
|
-
Utils::InvokeJSFunctionWithPromiseHandling(
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
[&promise, &output_keying_material, output_keying_material_length](
|
|
750
|
-
Napi::Env env, Napi::Value result) {
|
|
751
|
-
Napi::HandleScope scope(env);
|
|
752
|
-
if (!result.IsBuffer()) {
|
|
753
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
754
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
Napi::Buffer<uint8_t> outputBuffer =
|
|
758
|
-
result.As<Napi::Buffer<uint8_t>>();
|
|
759
|
-
if (outputBuffer.Length() > output_keying_material_length) {
|
|
760
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
761
|
-
throw Napi::TypeError::New(env, kErrorKeyingMaterialLengthExceeds);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
memcpy(output_keying_material,
|
|
765
|
-
outputBuffer.Data(),
|
|
766
|
-
outputBuffer.Length());
|
|
767
|
-
|
|
768
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
769
|
-
});
|
|
770
|
-
});
|
|
611
|
+
Napi::Number::New(env, static_cast<size_t>(output_keying_material_length))};
|
|
612
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
613
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
614
|
+
errorHandler);
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
expandTsfn.BlockingCall(blockingCallHandler);
|
|
771
618
|
|
|
772
619
|
future.wait();
|
|
773
620
|
return future.get();
|
|
@@ -787,57 +634,39 @@ int EdhocCryptoManager::callEncrypt(const void* user_context,
|
|
|
787
634
|
std::promise<int> promise;
|
|
788
635
|
std::future<int> future = promise.get_future();
|
|
789
636
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
&promise,
|
|
793
|
-
&key_id,
|
|
794
|
-
&nonce,
|
|
795
|
-
nonce_length,
|
|
796
|
-
&additional_data,
|
|
797
|
-
additional_data_length,
|
|
798
|
-
&plaintext,
|
|
799
|
-
plaintext_length,
|
|
800
|
-
&ciphertext,
|
|
801
|
-
ciphertext_size,
|
|
802
|
-
&ciphertext_length](Napi::Env env,
|
|
803
|
-
Napi::Function jsCallback) {
|
|
637
|
+
auto successHandler = [&promise, &ciphertext, ciphertext_size, &ciphertext_length](Napi::Env env,
|
|
638
|
+
Napi::Value result) {
|
|
804
639
|
Napi::HandleScope scope(env);
|
|
805
|
-
|
|
640
|
+
if (!result.IsBuffer()) {
|
|
641
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
642
|
+
}
|
|
643
|
+
Napi::Buffer<uint8_t> ciphertextBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
644
|
+
if (ciphertextBuffer.Length() > ciphertext_size) {
|
|
645
|
+
throw std::runtime_error(kErrorBufferTooSmall);
|
|
646
|
+
}
|
|
647
|
+
memcpy(ciphertext, ciphertextBuffer.Data(), ciphertextBuffer.Length());
|
|
648
|
+
*ciphertext_length = ciphertextBuffer.Length();
|
|
649
|
+
|
|
650
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, &nonce, nonce_length, &additional_data,
|
|
654
|
+
additional_data_length, &plaintext, plaintext_length, ciphertext_size,
|
|
655
|
+
successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
656
|
+
Napi::HandleScope scope(env);
|
|
657
|
+
std::vector<napi_value> args = {
|
|
806
658
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
807
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
808
|
-
env, static_cast<const uint8_t*>(key_id), EDHOC_KID_LEN),
|
|
659
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
809
660
|
Napi::Buffer<uint8_t>::Copy(env, nonce, nonce_length),
|
|
810
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
811
|
-
env, additional_data, additional_data_length),
|
|
661
|
+
Napi::Buffer<uint8_t>::Copy(env, additional_data, additional_data_length),
|
|
812
662
|
Napi::Buffer<uint8_t>::Copy(env, plaintext, plaintext_length),
|
|
813
663
|
Napi::Number::New(env, static_cast<size_t>(ciphertext_size))};
|
|
814
|
-
Utils::
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
Napi::Env env, Napi::Value result) {
|
|
821
|
-
Napi::HandleScope scope(env);
|
|
822
|
-
if (!result.IsBuffer()) {
|
|
823
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
824
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
Napi::Buffer<uint8_t> ciphertextBuffer =
|
|
828
|
-
result.As<Napi::Buffer<uint8_t>>();
|
|
829
|
-
if (ciphertextBuffer.Length() > ciphertext_size) {
|
|
830
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
831
|
-
throw Napi::TypeError::New(env, kErrorBufferTooSmall);
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
memcpy(
|
|
835
|
-
ciphertext, ciphertextBuffer.Data(), ciphertextBuffer.Length());
|
|
836
|
-
*ciphertext_length = ciphertextBuffer.Length();
|
|
837
|
-
|
|
838
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
839
|
-
});
|
|
840
|
-
});
|
|
664
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
665
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, args, successHandler,
|
|
666
|
+
errorHandler);
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
encryptTsfn.BlockingCall(blockingCallHandler);
|
|
841
670
|
|
|
842
671
|
future.wait();
|
|
843
672
|
return future.get();
|
|
@@ -857,56 +686,38 @@ int EdhocCryptoManager::callDecrypt(const void* user_context,
|
|
|
857
686
|
std::promise<int> promise;
|
|
858
687
|
std::future<int> future = promise.get_future();
|
|
859
688
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
689
|
+
auto successHandler = [&promise, &plaintext, plaintext_size, plaintext_length](Napi::Env env, Napi::Value result) {
|
|
690
|
+
Napi::HandleScope scope(env);
|
|
691
|
+
if (!result.IsBuffer()) {
|
|
692
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
693
|
+
}
|
|
694
|
+
Napi::Buffer<uint8_t> plaintextBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
695
|
+
if (plaintextBuffer.Length() > plaintext_size) {
|
|
696
|
+
throw std::runtime_error(kErrorPlaintextLengthExceeds);
|
|
697
|
+
}
|
|
698
|
+
memcpy(plaintext, plaintextBuffer.Data(), plaintextBuffer.Length());
|
|
699
|
+
*plaintext_length = plaintextBuffer.Length();
|
|
700
|
+
|
|
701
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
auto blockingCallHandler = [this, &user_context, &promise, &key_id, &nonce, nonce_length, &additional_data,
|
|
705
|
+
additional_data_length, &ciphertext, &ciphertext_length, plaintext_size,
|
|
706
|
+
successHandler](Napi::Env env, Napi::Function jsCallback) {
|
|
874
707
|
Napi::HandleScope scope(env);
|
|
875
708
|
std::vector<napi_value> arguments = {
|
|
876
709
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
877
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
878
|
-
env, static_cast<const uint8_t*>(key_id), EDHOC_KID_LEN),
|
|
710
|
+
Napi::Buffer<uint8_t>::Copy(env, static_cast<const uint8_t*>(key_id), CONFIG_LIBEDHOC_KEY_ID_LEN),
|
|
879
711
|
Napi::Buffer<uint8_t>::Copy(env, nonce, nonce_length),
|
|
880
|
-
Napi::Buffer<uint8_t>::Copy(
|
|
881
|
-
env, additional_data, additional_data_length),
|
|
712
|
+
Napi::Buffer<uint8_t>::Copy(env, additional_data, additional_data_length),
|
|
882
713
|
Napi::Buffer<uint8_t>::Copy(env, ciphertext, ciphertext_length),
|
|
883
714
|
Napi::Number::New(env, static_cast<size_t>(plaintext_size))};
|
|
884
|
-
Utils::
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
Napi::Env env, Napi::Value result) {
|
|
891
|
-
Napi::HandleScope scope(env);
|
|
892
|
-
if (!result.IsBuffer()) {
|
|
893
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
894
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
Napi::Buffer<uint8_t> plaintextBuffer =
|
|
898
|
-
result.As<Napi::Buffer<uint8_t>>();
|
|
899
|
-
if (plaintextBuffer.Length() > plaintext_size) {
|
|
900
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
901
|
-
throw Napi::TypeError::New(env, kErrorPlaintextLengthExceeds);
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
memcpy(plaintext, plaintextBuffer.Data(), plaintextBuffer.Length());
|
|
905
|
-
*plaintext_length = plaintextBuffer.Length();
|
|
906
|
-
|
|
907
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
908
|
-
});
|
|
909
|
-
});
|
|
715
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
716
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, arguments, successHandler,
|
|
717
|
+
errorHandler);
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
decryptTsfn.BlockingCall(blockingCallHandler);
|
|
910
721
|
|
|
911
722
|
future.wait();
|
|
912
723
|
return future.get();
|
|
@@ -921,46 +732,35 @@ int EdhocCryptoManager::callHash(const void* user_context,
|
|
|
921
732
|
std::promise<int> promise;
|
|
922
733
|
std::future<int> future = promise.get_future();
|
|
923
734
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
735
|
+
auto successHandler = [&promise, &hash, hash_size, &hash_length](Napi::Env env, Napi::Value result) {
|
|
736
|
+
Napi::HandleScope scope(env);
|
|
737
|
+
if (!result.IsBuffer()) {
|
|
738
|
+
throw std::runtime_error(kErrorExpectBuffer);
|
|
739
|
+
}
|
|
740
|
+
Napi::Buffer<uint8_t> hashBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
741
|
+
if (hashBuffer.Length() > hash_size) {
|
|
742
|
+
throw std::runtime_error(kErrorHashLengthExceeds);
|
|
743
|
+
}
|
|
744
|
+
memcpy(hash, hashBuffer.Data(), hashBuffer.Length());
|
|
745
|
+
*hash_length = hashBuffer.Length();
|
|
746
|
+
|
|
747
|
+
promise.set_value(EDHOC_SUCCESS);
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
auto blockingCallHandler = [this, &user_context, &promise, &input, input_length, hash_size, successHandler](
|
|
751
|
+
Napi::Env env, Napi::Function jsCallback) {
|
|
933
752
|
Napi::HandleScope scope(env);
|
|
934
753
|
std::vector<napi_value> arguments = {
|
|
935
754
|
static_cast<const UserContext*>(user_context)->parent.Value(),
|
|
936
755
|
Napi::Buffer<uint8_t>::Copy(env, input, input_length),
|
|
937
756
|
Napi::Number::New(env, static_cast<size_t>(hash_size)),
|
|
938
757
|
};
|
|
939
|
-
Utils::
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
Napi::Value result) {
|
|
946
|
-
Napi::HandleScope scope(env);
|
|
947
|
-
if (!result.IsBuffer()) {
|
|
948
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
949
|
-
throw Napi::TypeError::New(env, kErrorExpectBuffer);
|
|
950
|
-
}
|
|
951
|
-
Napi::Buffer<uint8_t> hashBuffer = result.As<Napi::Buffer<uint8_t>>();
|
|
952
|
-
|
|
953
|
-
if (hashBuffer.Length() > hash_size) {
|
|
954
|
-
promise.set_value(EDHOC_ERROR_GENERIC_ERROR);
|
|
955
|
-
throw Napi::TypeError::New(env, kErrorHashLengthExceeds);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
memcpy(hash, hashBuffer.Data(), hashBuffer.Length());
|
|
959
|
-
*hash_length = hashBuffer.Length();
|
|
960
|
-
|
|
961
|
-
promise.set_value(EDHOC_SUCCESS);
|
|
962
|
-
});
|
|
963
|
-
});
|
|
758
|
+
auto errorHandler = Utils::CreatePromiseErrorHandler<int>(promise, EDHOC_ERROR_GENERIC_ERROR);
|
|
759
|
+
Utils::InvokeJSFunctionWithPromiseHandling(env, cryptoManagerRef.Value(), jsCallback, arguments, successHandler,
|
|
760
|
+
errorHandler);
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
hashTsfn.BlockingCall(blockingCallHandler);
|
|
964
764
|
|
|
965
765
|
future.wait();
|
|
966
766
|
return future.get();
|