edhoc 1.0.4 → 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.
Files changed (314) hide show
  1. package/README.md +170 -0
  2. package/binding.gyp +13 -11
  3. package/dist/bindings.d.ts +5 -0
  4. package/dist/bindings.d.ts.map +1 -0
  5. package/dist/bindings.js +10 -0
  6. package/dist/crypto.d.ts +29 -0
  7. package/dist/crypto.d.ts.map +1 -0
  8. package/dist/crypto.js +205 -0
  9. package/dist/edhoc.d.ts +368 -0
  10. package/dist/edhoc.d.ts.map +1 -0
  11. package/dist/edhoc.js +76 -0
  12. package/dist/index.d.ts +4 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +19 -0
  15. package/dist/x509credentials.d.ts +20 -0
  16. package/dist/x509credentials.d.ts.map +1 -0
  17. package/dist/x509credentials.js +140 -0
  18. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_decode.h +1 -1
  19. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_encode.h +1 -1
  20. package/external/libedhoc/backends/cbor/include/backend_cbor_bstr_type_types.h +1 -1
  21. package/external/libedhoc/backends/cbor/include/backend_cbor_ead_decode.h +2 -2
  22. package/external/libedhoc/backends/cbor/include/backend_cbor_ead_encode.h +2 -2
  23. package/external/libedhoc/backends/cbor/include/backend_cbor_edhoc_types.h +48 -43
  24. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_decode.h +1 -1
  25. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_encode.h +1 -1
  26. package/external/libedhoc/backends/cbor/include/backend_cbor_enc_structure_types.h +3 -3
  27. package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_decode.h +1 -1
  28. package/external/libedhoc/backends/cbor/include/backend_cbor_id_cred_x_encode.h +1 -1
  29. package/external/libedhoc/backends/cbor/include/backend_cbor_info_decode.h +1 -1
  30. package/external/libedhoc/backends/cbor/include/backend_cbor_info_encode.h +1 -1
  31. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_decode.h +1 -1
  32. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_encode.h +1 -1
  33. package/external/libedhoc/backends/cbor/include/backend_cbor_int_type_types.h +1 -1
  34. package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_decode.h +1 -1
  35. package/external/libedhoc/backends/cbor/include/backend_cbor_message_1_encode.h +1 -1
  36. package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_decode.h +1 -1
  37. package/external/libedhoc/backends/cbor/include/backend_cbor_message_2_encode.h +1 -1
  38. package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_decode.h +1 -1
  39. package/external/libedhoc/backends/cbor/include/backend_cbor_message_3_encode.h +1 -1
  40. package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_decode.h +1 -1
  41. package/external/libedhoc/backends/cbor/include/backend_cbor_message_4_encode.h +1 -1
  42. package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_decode.h +1 -1
  43. package/external/libedhoc/backends/cbor/include/backend_cbor_message_error_encode.h +1 -1
  44. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_decode.h +1 -1
  45. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_2_encode.h +1 -1
  46. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_decode.h +1 -1
  47. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_3_encode.h +1 -1
  48. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_decode.h +3 -3
  49. package/external/libedhoc/backends/cbor/include/backend_cbor_plaintext_4_encode.h +3 -3
  50. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_decode.h +1 -1
  51. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_encode.h +1 -1
  52. package/external/libedhoc/backends/cbor/include/backend_cbor_sig_structure_types.h +4 -4
  53. package/external/libedhoc/backends/cbor/include/backend_cbor_x509_types.h +93 -83
  54. package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_decode.c +11 -20
  55. package/external/libedhoc/backends/cbor/src/backend_cbor_bstr_type_encode.c +11 -20
  56. package/external/libedhoc/backends/cbor/src/backend_cbor_ead_decode.c +27 -32
  57. package/external/libedhoc/backends/cbor/src/backend_cbor_ead_encode.c +27 -32
  58. package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_decode.c +14 -23
  59. package/external/libedhoc/backends/cbor/src/backend_cbor_enc_structure_encode.c +14 -23
  60. package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_decode.c +63 -52
  61. package/external/libedhoc/backends/cbor/src/backend_cbor_id_cred_x_encode.c +62 -51
  62. package/external/libedhoc/backends/cbor/src/backend_cbor_info_decode.c +14 -23
  63. package/external/libedhoc/backends/cbor/src/backend_cbor_info_encode.c +14 -23
  64. package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_decode.c +11 -20
  65. package/external/libedhoc/backends/cbor/src/backend_cbor_int_type_encode.c +11 -20
  66. package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_decode.c +54 -51
  67. package/external/libedhoc/backends/cbor/src/backend_cbor_message_1_encode.c +54 -51
  68. package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_decode.c +11 -20
  69. package/external/libedhoc/backends/cbor/src/backend_cbor_message_2_encode.c +11 -20
  70. package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_decode.c +11 -20
  71. package/external/libedhoc/backends/cbor/src/backend_cbor_message_3_encode.c +11 -20
  72. package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_decode.c +11 -20
  73. package/external/libedhoc/backends/cbor/src/backend_cbor_message_4_encode.c +11 -20
  74. package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_decode.c +36 -37
  75. package/external/libedhoc/backends/cbor/src/backend_cbor_message_error_encode.c +36 -37
  76. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_decode.c +103 -80
  77. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_2_encode.c +102 -79
  78. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_decode.c +99 -76
  79. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_3_encode.c +98 -75
  80. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_decode.c +40 -41
  81. package/external/libedhoc/backends/cbor/src/backend_cbor_plaintext_4_encode.c +40 -41
  82. package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_decode.c +15 -24
  83. package/external/libedhoc/backends/cbor/src/backend_cbor_sig_structure_encode.c +15 -24
  84. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.c +31 -0
  85. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode.h +10 -0
  86. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.c +18 -0
  87. package/external/libedhoc/externals/Unity/examples/example_1/src/ProductionCode2.h +9 -0
  88. package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode.c +69 -0
  89. package/external/libedhoc/externals/Unity/examples/example_1/test/TestProductionCode2.c +38 -0
  90. package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
  91. package/external/libedhoc/externals/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
  92. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.c +31 -0
  93. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode.h +10 -0
  94. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.c +18 -0
  95. package/external/libedhoc/externals/Unity/examples/example_2/src/ProductionCode2.h +9 -0
  96. package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode.c +71 -0
  97. package/external/libedhoc/externals/Unity/examples/example_2/test/TestProductionCode2.c +40 -0
  98. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +16 -0
  99. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +18 -0
  100. package/external/libedhoc/externals/Unity/examples/example_2/test/test_runners/all_tests.c +19 -0
  101. package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.c +17 -0
  102. package/external/libedhoc/externals/Unity/examples/example_3/helper/UnityHelper.h +19 -0
  103. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.c +31 -0
  104. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode.h +10 -0
  105. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.c +18 -0
  106. package/external/libedhoc/externals/Unity/examples/example_3/src/ProductionCode2.h +9 -0
  107. package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode.c +69 -0
  108. package/external/libedhoc/externals/Unity/examples/example_3/test/TestProductionCode2.c +38 -0
  109. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.c +31 -0
  110. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode.h +10 -0
  111. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.c +18 -0
  112. package/external/libedhoc/externals/Unity/examples/example_4/src/ProductionCode2.h +9 -0
  113. package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode.c +70 -0
  114. package/external/libedhoc/externals/Unity/examples/example_4/test/TestProductionCode2.c +42 -0
  115. package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode2_Runner.c +53 -0
  116. package/external/libedhoc/externals/Unity/examples/example_4/test/test_runners/TestProductionCode_Runner.c +57 -0
  117. package/external/libedhoc/externals/Unity/examples/unity_config.h +251 -0
  118. package/external/libedhoc/externals/Unity/extras/bdd/src/unity_bdd.h +44 -0
  119. package/external/libedhoc/externals/Unity/extras/bdd/test/test_bdd.c +129 -0
  120. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.c +310 -0
  121. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture.h +95 -0
  122. package/external/libedhoc/externals/Unity/extras/fixture/src/unity_fixture_internals.h +51 -0
  123. package/external/libedhoc/externals/Unity/extras/fixture/test/main/AllTests.c +20 -0
  124. package/external/libedhoc/externals/Unity/extras/fixture/test/template_fixture_tests.c +40 -0
  125. package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_Test.c +246 -0
  126. package/external/libedhoc/externals/Unity/extras/fixture/test/unity_fixture_TestRunner.c +33 -0
  127. package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.c +203 -0
  128. package/external/libedhoc/externals/Unity/extras/memory/src/unity_memory.h +61 -0
  129. package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_Test.c +326 -0
  130. package/external/libedhoc/externals/Unity/extras/memory/test/unity_memory_TestRunner.c +50 -0
  131. package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.c +57 -0
  132. package/external/libedhoc/externals/Unity/extras/memory/test/unity_output_Spy.h +17 -0
  133. package/external/libedhoc/externals/Unity/src/unity.c +2501 -0
  134. package/external/libedhoc/externals/Unity/src/unity.h +698 -0
  135. package/external/libedhoc/externals/Unity/src/unity_internals.h +1183 -0
  136. package/external/libedhoc/externals/Unity/test/expectdata/testsample_cmd.c +61 -0
  137. package/external/libedhoc/externals/Unity/test/expectdata/testsample_def.c +57 -0
  138. package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.c +55 -0
  139. package/external/libedhoc/externals/Unity/test/expectdata/testsample_head1.h +15 -0
  140. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_cmd.c +80 -0
  141. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_def.c +76 -0
  142. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.c +75 -0
  143. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_head1.h +13 -0
  144. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new1.c +89 -0
  145. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_new2.c +89 -0
  146. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_param.c +77 -0
  147. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run1.c +89 -0
  148. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_run2.c +89 -0
  149. package/external/libedhoc/externals/Unity/test/expectdata/testsample_mock_yaml.c +90 -0
  150. package/external/libedhoc/externals/Unity/test/expectdata/testsample_new1.c +67 -0
  151. package/external/libedhoc/externals/Unity/test/expectdata/testsample_new2.c +70 -0
  152. package/external/libedhoc/externals/Unity/test/expectdata/testsample_param.c +58 -0
  153. package/external/libedhoc/externals/Unity/test/expectdata/testsample_run1.c +67 -0
  154. package/external/libedhoc/externals/Unity/test/expectdata/testsample_run2.c +70 -0
  155. package/external/libedhoc/externals/Unity/test/expectdata/testsample_yaml.c +71 -0
  156. package/external/libedhoc/externals/Unity/test/testdata/CException.h +18 -0
  157. package/external/libedhoc/externals/Unity/test/testdata/Defs.h +16 -0
  158. package/external/libedhoc/externals/Unity/test/testdata/cmock.h +21 -0
  159. package/external/libedhoc/externals/Unity/test/testdata/mockMock.h +20 -0
  160. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGenerator.c +204 -0
  161. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorSmall.c +73 -0
  162. package/external/libedhoc/externals/Unity/test/testdata/testRunnerGeneratorWithMocks.c +200 -0
  163. package/external/libedhoc/externals/Unity/test/tests/self_assessment_utils.h +151 -0
  164. package/external/libedhoc/externals/Unity/test/tests/test_unity_arrays.c +2941 -0
  165. package/external/libedhoc/externals/Unity/test/tests/test_unity_core.c +375 -0
  166. package/external/libedhoc/externals/Unity/test/tests/test_unity_doubles.c +1285 -0
  167. package/external/libedhoc/externals/Unity/test/tests/test_unity_floats.c +1395 -0
  168. package/external/libedhoc/externals/Unity/test/tests/test_unity_integers.c +2863 -0
  169. package/external/libedhoc/externals/Unity/test/tests/test_unity_integers_64.c +783 -0
  170. package/external/libedhoc/externals/Unity/test/tests/test_unity_memory.c +82 -0
  171. package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterized.c +309 -0
  172. package/external/libedhoc/externals/Unity/test/tests/test_unity_parameterizedDemo.c +28 -0
  173. package/external/libedhoc/externals/Unity/test/tests/test_unity_strings.c +330 -0
  174. package/external/libedhoc/externals/Unity/test/tests/types_for_test.h +21 -0
  175. package/external/libedhoc/externals/zcbor/include/zcbor_common.h +147 -60
  176. package/external/libedhoc/externals/zcbor/include/zcbor_decode.h +291 -202
  177. package/external/libedhoc/externals/zcbor/include/zcbor_encode.h +100 -156
  178. package/external/libedhoc/externals/zcbor/include/zcbor_print.h +165 -0
  179. package/external/libedhoc/externals/zcbor/samples/hello_world/src/main.c +1 -1
  180. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_decode.h +1 -1
  181. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_encode.h +1 -1
  182. package/external/libedhoc/externals/zcbor/samples/pet/include/pet_types.h +4 -4
  183. package/external/libedhoc/externals/zcbor/samples/pet/src/main.c +4 -4
  184. package/external/libedhoc/externals/zcbor/samples/pet/src/pet_decode.c +15 -24
  185. package/external/libedhoc/externals/zcbor/samples/pet/src/pet_encode.c +14 -23
  186. package/external/libedhoc/externals/zcbor/src/zcbor_common.c +202 -29
  187. package/external/libedhoc/externals/zcbor/src/zcbor_decode.c +633 -173
  188. package/external/libedhoc/externals/zcbor/src/zcbor_encode.c +71 -184
  189. package/external/libedhoc/externals/zcbor/tests/decode/test1_suit_old_formats/src/main.c +152 -153
  190. package/external/libedhoc/externals/zcbor/tests/decode/test2_suit/src/main.c +64 -64
  191. package/external/libedhoc/externals/zcbor/tests/decode/test3_simple/src/main.c +15 -16
  192. package/external/libedhoc/externals/zcbor/tests/decode/test5_corner_cases/src/main.c +228 -84
  193. package/external/libedhoc/externals/zcbor/tests/decode/test7_suit9_simple/src/main.c +9 -9
  194. package/external/libedhoc/externals/zcbor/tests/decode/test8_suit12/src/main.c +0 -1
  195. package/external/libedhoc/externals/zcbor/tests/decode/test9_manifest14/src/main.c +172 -173
  196. package/external/libedhoc/externals/zcbor/tests/encode/test1_suit/src/main.c +73 -73
  197. package/external/libedhoc/externals/zcbor/tests/encode/test2_simple/src/main.c +1 -2
  198. package/external/libedhoc/externals/zcbor/tests/encode/test3_corner_cases/src/main.c +83 -56
  199. package/external/libedhoc/externals/zcbor/tests/encode/test4_senml/src/main.c +15 -16
  200. package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_everything.c +12 -0
  201. package/external/libedhoc/externals/zcbor/tests/fuzz/fuzz_manifest12.c +69 -69
  202. package/external/libedhoc/externals/zcbor/tests/unit/test1_unit_tests/src/main.c +448 -55
  203. package/external/libedhoc/externals/zcbor/tests/unit/test3_float16/src/main.c +49 -48
  204. package/external/libedhoc/include/edhoc.h +348 -54
  205. package/external/libedhoc/include/edhoc_common.h +289 -0
  206. package/external/libedhoc/include/edhoc_context.h +60 -35
  207. package/external/libedhoc/include/edhoc_credentials.h +55 -7
  208. package/external/libedhoc/include/edhoc_crypto.h +10 -10
  209. package/external/libedhoc/include/edhoc_ead.h +13 -10
  210. package/external/libedhoc/include/edhoc_macros.h +20 -11
  211. package/external/libedhoc/include/edhoc_values.h +2 -2
  212. package/external/libedhoc/library/edhoc.c +70 -36
  213. package/external/libedhoc/library/edhoc_common.c +1314 -0
  214. package/external/libedhoc/library/edhoc_exporter.c +45 -46
  215. package/external/libedhoc/library/edhoc_message_1.c +107 -72
  216. package/external/libedhoc/library/edhoc_message_2.c +396 -1693
  217. package/external/libedhoc/library/edhoc_message_3.c +465 -1656
  218. package/external/libedhoc/library/edhoc_message_4.c +93 -91
  219. package/external/libedhoc/library/edhoc_message_error.c +41 -41
  220. package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_0.h → cipher_suite_0.h} +131 -134
  221. package/external/libedhoc/tests/include/{cipher_suites/cipher_suite_2.h → cipher_suite_2.h} +139 -140
  222. package/external/libedhoc/tests/include/{edhoc_trace_1/test_vector_1.h → test_vector_rfc9529_chapter_2.h} +786 -738
  223. package/external/libedhoc/tests/include/{edhoc_trace_2/test_vector_2.h → test_vector_rfc9529_chapter_3.h} +14 -10
  224. 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
  225. 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
  226. 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
  227. 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
  228. package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_0.c → cipher_suite_0.c} +445 -447
  229. package/external/libedhoc/tests/src/{cipher_suites/cipher_suite_2.c → cipher_suite_2.c} +600 -600
  230. package/external/libedhoc/tests/src/module_test_api.c +430 -0
  231. package/external/libedhoc/tests/src/module_test_cipher_suite_0.c +395 -0
  232. package/external/libedhoc/tests/src/module_test_cipher_suite_2.c +392 -0
  233. package/external/libedhoc/tests/src/{error_message/test_edhoc_error_message.c → module_test_error_message.c} +94 -69
  234. package/external/libedhoc/tests/src/module_test_main.c +49 -0
  235. package/external/libedhoc/tests/src/{cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.c → module_test_rfc9528_suites_negotiation.c} +224 -227
  236. package/external/libedhoc/tests/src/module_test_rfc9529_chapter_2.c +2681 -0
  237. package/external/libedhoc/tests/src/module_test_rfc9529_chapter_3.c +1635 -0
  238. package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_0.c +1135 -0
  239. package/external/libedhoc/tests/src/module_test_x5chain_sign_keys_suite_2.c +1249 -0
  240. package/external/libedhoc/tests/src/module_test_x5chain_static_dh_keys_suite_2.c +798 -0
  241. package/external/libedhoc/tests/src/module_test_x5t_sign_keys_suite_2.c +956 -0
  242. package/include/EdhocComposeAsyncWorker.h +8 -6
  243. package/include/EdhocCredentialManager.h +16 -11
  244. package/include/EdhocCryptoManager.h +28 -21
  245. package/include/EdhocEadManager.h +3 -6
  246. package/include/{EdhocExportAsyncWorker.h → EdhocExportOscoreAsyncWorker.h} +20 -17
  247. package/include/EdhocKeyExporterAsyncWorker.h +76 -0
  248. package/include/EdhocKeyUpdateAsyncWorker.h +72 -0
  249. package/include/EdhocProcessAsyncWorker.h +14 -10
  250. package/include/LibEDHOC.h +44 -20
  251. package/include/UserContext.h +7 -9
  252. package/include/Utils.h +31 -27
  253. package/package.json +14 -3
  254. package/prebuilds/android-arm/edhoc.armv7.node +0 -0
  255. package/prebuilds/android-arm64/edhoc.armv8.node +0 -0
  256. package/prebuilds/darwin-arm64/edhoc.node +0 -0
  257. package/prebuilds/darwin-x64/edhoc.node +0 -0
  258. package/prebuilds/linux-arm/edhoc.armv6.node +0 -0
  259. package/prebuilds/linux-arm/edhoc.armv7.node +0 -0
  260. package/prebuilds/linux-arm64/edhoc.armv8.node +0 -0
  261. package/prebuilds/linux-x64/edhoc.glibc.node +0 -0
  262. package/prebuilds/linux-x64/edhoc.musl.node +0 -0
  263. package/prebuilds/win32-ia32/edhoc.node +0 -0
  264. package/prebuilds/win32-x64/edhoc.node +0 -0
  265. package/src/EdhocComposeAsyncWorker.cpp +18 -35
  266. package/src/EdhocCredentialManager.cpp +160 -187
  267. package/src/EdhocCryptoManager.cpp +386 -586
  268. package/src/EdhocEadManager.cpp +10 -18
  269. package/src/EdhocExportOscoreAsyncWorker.cpp +77 -0
  270. package/src/EdhocKeyExporterAsyncWorker.cpp +49 -0
  271. package/src/EdhocKeyUpdateAsyncWorker.cpp +41 -0
  272. package/src/EdhocProcessAsyncWorker.cpp +72 -19
  273. package/src/LibEDHOC.cpp +213 -174
  274. package/src/Suites.cpp +39 -72
  275. package/src/Utils.cpp +32 -56
  276. package/test/basic.test.ts +64 -0
  277. package/test/vectors.test.ts +111 -0
  278. package/external/libedhoc/externals/zcbor/include/zcbor_debug.h +0 -69
  279. package/external/libedhoc/tests/include/cipher_suite_negotiation/test_edhoc_cipher_suite_negotiation.h +0 -37
  280. package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_0.h +0 -48
  281. package/external/libedhoc/tests/include/cipher_suites/test_cipher_suite_2.h +0 -48
  282. package/external/libedhoc/tests/include/edhoc_trace_1/authentication_credentials_1.h +0 -60
  283. package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_1.h +0 -208
  284. package/external/libedhoc/tests/include/edhoc_trace_1/test_edhoc_handshake_ead_1.h +0 -59
  285. package/external/libedhoc/tests/include/edhoc_trace_2/authentication_credentials_2.h +0 -60
  286. package/external/libedhoc/tests/include/edhoc_trace_2/test_edhoc_handshake_2.h +0 -199
  287. package/external/libedhoc/tests/include/error_message/test_edhoc_error_message.h +0 -48
  288. package/external/libedhoc/tests/include/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.h +0 -92
  289. package/external/libedhoc/tests/include/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.h +0 -96
  290. package/external/libedhoc/tests/include/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.h +0 -58
  291. package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.h +0 -56
  292. package/external/libedhoc/tests/include/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.h +0 -57
  293. package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.h +0 -59
  294. package/external/libedhoc/tests/include/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.h +0 -57
  295. package/external/libedhoc/tests/include/x509_hash_cs_2/authentication_credentials_x5t_cs_2.h +0 -60
  296. package/external/libedhoc/tests/include/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.h +0 -57
  297. package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_0.c +0 -475
  298. package/external/libedhoc/tests/src/cipher_suites/test_cipher_suite_2.c +0 -473
  299. package/external/libedhoc/tests/src/edhoc_trace_1/authentication_credentials_1.c +0 -252
  300. package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_1.c +0 -1829
  301. package/external/libedhoc/tests/src/edhoc_trace_1/test_edhoc_handshake_ead_1.c +0 -1247
  302. package/external/libedhoc/tests/src/edhoc_trace_2/authentication_credentials_2.c +0 -170
  303. package/external/libedhoc/tests/src/edhoc_trace_2/test_edhoc_handshake_2.c +0 -1783
  304. package/external/libedhoc/tests/src/tests.c +0 -228
  305. package/external/libedhoc/tests/src/x509_chain_cs_0/authentication_credentials_x5chain_cs_0.c +0 -332
  306. package/external/libedhoc/tests/src/x509_chain_cs_0/test_edhoc_handshake_x5chain_cs_0.c +0 -936
  307. package/external/libedhoc/tests/src/x509_chain_cs_2/authentication_credentials_x5chain_cs_2.c +0 -166
  308. package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2.c +0 -587
  309. package/external/libedhoc/tests/src/x509_chain_cs_2/test_edhoc_handshake_x5chain_cs_2_ead.c +0 -917
  310. package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/authentication_credentials_x5chain_cs_2_static_dh.c +0 -186
  311. package/external/libedhoc/tests/src/x509_chain_cs_2_static_dh/test_edhoc_handshake_x5chain_cs_2_static_dh_ead.c +0 -743
  312. package/external/libedhoc/tests/src/x509_hash_cs_2/authentication_credentials_x5t_cs_2.c +0 -261
  313. package/external/libedhoc/tests/src/x509_hash_cs_2/test_edhoc_handshake_x5t_cs_2_ead.c +0 -854
  314. package/src/EdhocExportAsyncWorker.cpp +0 -82
@@ -0,0 +1,368 @@
1
+ /**
2
+ * Enumerates the types of credential formats that can be used with EDHOC.
3
+ */
4
+ export declare enum EdhocCredentialsFormat {
5
+ kid = 4,// Represents a key identifier.
6
+ x5chain = 33,// Represents an X.509 certificate chain.
7
+ x5t = 34
8
+ }
9
+ /**
10
+ * Base interface for EDHOC credentials.
11
+ */
12
+ export interface EdhocCredentials {
13
+ format: EdhocCredentialsFormat;
14
+ privateKeyID?: Buffer;
15
+ publicKey?: Buffer;
16
+ }
17
+ /**
18
+ * Extends EdhocCredentials for credentials using a key identifier (KID).
19
+ */
20
+ export interface EdhocCredentialsKID extends EdhocCredentials {
21
+ format: EdhocCredentialsFormat.kid;
22
+ kid: {
23
+ kid: number | Buffer;
24
+ credentials?: Buffer;
25
+ isCBOR?: boolean;
26
+ };
27
+ }
28
+ /**
29
+ * Extends EdhocCredentials for credentials using an X.509 certificate chain.
30
+ */
31
+ export interface EdhocCredentialsCertificateChain extends EdhocCredentials {
32
+ format: EdhocCredentialsFormat.x5chain;
33
+ x5chain: {
34
+ certificates: Buffer[];
35
+ };
36
+ }
37
+ /**
38
+ * Extends EdhocCredentials for credentials using a hashed X.509 certificate.
39
+ */
40
+ export interface EdhocCredentialsCertificateHash extends EdhocCredentials {
41
+ format: EdhocCredentialsFormat.x5t;
42
+ x5t: {
43
+ certificate?: Buffer;
44
+ hash: Buffer;
45
+ hashAlgorithm: EdhocCredentialsCertificateHashAlgorithm;
46
+ };
47
+ }
48
+ /**
49
+ * Enumerates the types of hash algorithms that can be used with hashed X.509 certificates.
50
+ */
51
+ export declare enum EdhocCredentialsCertificateHashAlgorithm {
52
+ Sha256 = -16,// SHA-256 hash algorithm.
53
+ Sha256_64 = -15
54
+ }
55
+ /**
56
+ * Provides methods for managing EDHOC credentials.
57
+ */
58
+ export interface EdhocCredentialManager {
59
+ /**
60
+ * Fetches EDHOC credentials based on the provided EDHOC context.
61
+ * @param edhoc The EDHOC context for which to fetch credentials.
62
+ * @return A promise that resolves to the fetched EdhocCredentials or throws an error if not successful.
63
+ */
64
+ fetch(edhoc: EDHOC): Promise<EdhocCredentials> | EdhocCredentials | never;
65
+ /**
66
+ * Verifies EDHOC credentials based on the provided EDHOC context and credentials.
67
+ * @param edhoc The EDHOC context against which to verify credentials.
68
+ * @param credentials The credentials to verify.
69
+ * @return A promise that resolves to the verified EdhocCredentials or throws an error if not successful.
70
+ */
71
+ verify(edhoc: EDHOC, credentials: EdhocCredentials, callback: (error: Error | null, credentials: EdhocCredentials) => void): void;
72
+ }
73
+ /**
74
+ * Enumerates the types of cryptographic operations that can be performed with EDHOC.
75
+ */
76
+ export declare enum EdhocKeyType {
77
+ MakeKeyPair = 0,// Used to generate a key pair.
78
+ KeyAgreement = 1,// Used for key agreement operations.
79
+ Signature = 2,// Used for creating digital signatures.
80
+ Verify = 3,// Used for verifying digital signatures.
81
+ Extract = 4,// Used for extracting key material.
82
+ Expand = 5,// Used for expanding key material.
83
+ Encrypt = 6,// Used for encrypting data.
84
+ Decrypt = 7
85
+ }
86
+ /**
87
+ * Type representing a public key in buffer format.
88
+ */
89
+ export type EdhocPublicKey = Buffer;
90
+ /**
91
+ * Type representing a private key in buffer format.
92
+ */
93
+ export type EdhocPrivateKey = Buffer;
94
+ /**
95
+ * Represents a tuple of public and private keys.
96
+ */
97
+ export interface PublicPrivateTuple {
98
+ publicKey: EdhocPublicKey;
99
+ privateKey: EdhocPrivateKey;
100
+ }
101
+ /**
102
+ * Manages cryptographic functions necessary for the operation of EDHOC protocols.
103
+ */
104
+ export interface EdhocCryptoManager {
105
+ /**
106
+ * Imports a cryptographic key of the specified type.
107
+ * @param edhoc The EDHOC session context.
108
+ * @param keyType The type of key to import, as defined in EdhocKeyType.
109
+ * @param key Optional buffer containing seed or related data if necessary.
110
+ * @return A promise resolving to a Buffer containing the imported key.
111
+ */
112
+ importKey(edhoc: EDHOC, keyType: EdhocKeyType, key: Buffer): Promise<Buffer> | Buffer | never;
113
+ /**
114
+ * Destroys a cryptographic key identified by the keyID.
115
+ * @param edhoc The EDHOC session context.
116
+ * @param keyID Buffer identifying the key to destroy.
117
+ * @return A promise resolving to true if the key was successfully destroyed.
118
+ */
119
+ destroyKey(edhoc: EDHOC, keyID: Buffer): Promise<boolean> | boolean | never;
120
+ /**
121
+ * Generates a public-private key pair.
122
+ * @param edhoc The EDHOC session context.
123
+ * @param keyID Buffer to identify the key pair for future operations.
124
+ * @param privateKeySize Size in bytes for the private key.
125
+ * @param publicKeySize Size in bytes for the public key.
126
+ * @return A promise resolving to a PublicPrivateTuple containing both keys.
127
+ // */
128
+ makeKeyPair(edhoc: EDHOC, keyID: Buffer, privateKeySize: number, publicKeySize: number): Promise<PublicPrivateTuple> | PublicPrivateTuple | never;
129
+ /**
130
+ * Performs a key agreement operation using a public and a private key.
131
+ * @param edhoc The EDHOC session context.
132
+ * @param keyID Buffer identifying the key agreement process.
133
+ * @param publicKey The public key of the other party.
134
+ * @param privateKeySize Size of the private key used in the key agreement.
135
+ * @return A promise resolving to the resultant private key.
136
+ */
137
+ keyAgreement(edhoc: EDHOC, keyID: Buffer, publicKey: EdhocPublicKey, privateKeySize: number): Promise<Buffer> | Buffer | never;
138
+ /**
139
+ * Signs data using a specified key.
140
+ * @param edhoc The EDHOC session context.
141
+ * @param keyID Buffer identifying the key to use for signing.
142
+ * @param input Buffer containing the data to sign.
143
+ * @param signatureSize The desired size of the signature.
144
+ * @return A promise resolving to the signature.
145
+ */
146
+ sign(edhoc: EDHOC, keyID: Buffer, input: Buffer, signatureSize: number): Promise<Buffer> | Buffer | never;
147
+ /**
148
+ * Verifies a signature against the provided data.
149
+ * @param edhoc The EDHOC session context.
150
+ * @param keyID Buffer identifying the key to use for verification.
151
+ * @param input Buffer containing the original data that was signed.
152
+ * @param signature Buffer containing the signature to verify.
153
+ * @return A promise resolving to true if the signature is valid.
154
+ */
155
+ verify(edhoc: EDHOC, keyID: Buffer, input: Buffer, signature: Buffer): Promise<boolean> | boolean | never;
156
+ /**
157
+ * Extracts a key using a salt.
158
+ * @param edhoc The EDHOC session context.
159
+ * @param keyID Buffer identifying the extraction process.
160
+ * @param salt Buffer containing the salt used in the extraction.
161
+ * @param keySize The desired size of the key to extract.
162
+ * @return A promise resolving to the extracted key.
163
+ */
164
+ extract(edhoc: EDHOC, keyID: Buffer, salt: Buffer, keySize: number): Promise<Buffer> | Buffer | never;
165
+ /**
166
+ * Expands a key using provided information.
167
+ * @param edhoc The EDHOC session context.
168
+ * @param keyID Buffer identifying the expansion process.
169
+ * @param info Buffer containing information used for key expansion.
170
+ * @param keySize The desired size of the key after expansion.
171
+ * @return A promise resolving to the expanded key.
172
+ */
173
+ expand(edhoc: EDHOC, keyID: Buffer, info: Buffer, keySize: number): Promise<Buffer> | Buffer | never;
174
+ /**
175
+ * Encrypts plaintext using a specified key and nonce.
176
+ * @param edhoc The EDHOC session context.
177
+ * @param keyID Buffer identifying the key to use for encryption.
178
+ * @param nonce Buffer containing the nonce to use in the encryption process.
179
+ * @param aad Buffer containing additional authenticated data.
180
+ * @param plaintext Buffer containing the data to encrypt.
181
+ * @param size The size of the output buffer.
182
+ * @return A promise resolving to the ciphertext.
183
+ */
184
+ encrypt(edhoc: EDHOC, keyID: Buffer, nonce: Buffer, aad: Buffer, plaintext: Buffer, size: number): Promise<Buffer> | Buffer | never;
185
+ /**
186
+ * Decrypts ciphertext using a specified key and nonce.
187
+ * @param edhoc The EDHOC session context.
188
+ * @param keyID Buffer identifying the key to use for decryption.
189
+ * @param nonce Buffer containing the nonce to use in the decryption process.
190
+ * @param aad Buffer containing additional authenticated data.
191
+ * @param ciphertext Buffer containing the data to decrypt.
192
+ * @param size The size of the output buffer.
193
+ * @return A promise resolving to the plaintext.
194
+ */
195
+ decrypt(edhoc: EDHOC, keyID: Buffer, nonce: Buffer, aad: Buffer, ciphertext: Buffer, size: number): Promise<Buffer> | Buffer | never;
196
+ /**
197
+ * Computes a hash of the given data.
198
+ * @param edhoc The EDHOC session context.
199
+ * @param data Buffer containing the data to hash.
200
+ * @param hashSize The size of the hash to compute.
201
+ * @return A promise resolving to the hash.
202
+ */
203
+ hash(edhoc: EDHOC, data: Buffer, hashSize: number): Promise<Buffer> | Buffer | never;
204
+ }
205
+ /**
206
+ * Represents an EDHOC connection identifier which can be either a number or a Buffer.
207
+ */
208
+ export type EdhocConnectionID = number | Buffer;
209
+ /**
210
+ * Enumerates the methods available for EDHOC protocol exchanges.
211
+ * Each method corresponds to different authentication mechanisms.
212
+ */
213
+ export declare enum EdhocMethod {
214
+ Method0 = 0,
215
+ Method1 = 1,
216
+ Method2 = 2,
217
+ Method3 = 3
218
+ }
219
+ /**
220
+ * Enumerates the cipher suites available for EDHOC protocol operations.
221
+ * Each suite represents a set of cryptographic algorithms.
222
+ */
223
+ export declare enum EdhocSuite {
224
+ Suite0 = 0,
225
+ Suite1 = 1,
226
+ Suite2 = 2,
227
+ Suite3 = 3,
228
+ Suite4 = 4,
229
+ Suite5 = 5,
230
+ Suite6 = 6,
231
+ Suite24 = 24,
232
+ Suite25 = 25
233
+ }
234
+ /**
235
+ * Represents an External Authorization Data (EAD) object used in EDHOC protocol exchanges.
236
+ * EAD objects carry additional authorization information relevant to the session.
237
+ */
238
+ export interface EdhocEAD {
239
+ label: number;
240
+ value: Buffer;
241
+ }
242
+ /**
243
+ * Describes the context for OSCORE (Object Security for Constrained RESTful Environments) derived from EDHOC.
244
+ * OSCORE contexts are used to securely communicate over constrained networks.
245
+ */
246
+ export interface EdhocOscoreContext {
247
+ masterSecret: Buffer;
248
+ masterSalt: Buffer;
249
+ senderId: Buffer;
250
+ recipientId: Buffer;
251
+ }
252
+ /**
253
+ * The EDHOC class encapsulates the EDHOC protocol logic, managing the lifecycle of an EDHOC session.
254
+ */
255
+ export declare class EDHOC {
256
+ /**
257
+ * The connection ID used by the local entity for this EDHOC session.
258
+ */
259
+ connectionID: EdhocConnectionID;
260
+ /**
261
+ * The connection ID used by the peer entity, which is read-only and set during the EDHOC message exchange.
262
+ */
263
+ readonly peerConnectionID: EdhocConnectionID;
264
+ /**
265
+ * The methods of authentication to be used in this EDHOC session, as defined in EdhocMethod.
266
+ */
267
+ methods: EdhocMethod[];
268
+ /**
269
+ * The selected method of authentication to be used in this EDHOC session, as defined in EdhocMethod.
270
+ */
271
+ selectedMethod: EdhocMethod;
272
+ /**
273
+ * A list of cipher suites supported by this session, providing flexibility in cryptographic negotiations.
274
+ */
275
+ cipherSuites: EdhocSuite[];
276
+ /**
277
+ * Represents the selected EDHOC cipher suite.
278
+ */
279
+ selectedSuite: EdhocSuite;
280
+ /**
281
+ * A logging function to log operational data during the EDHOC protocol execution.
282
+ * @param name The name or description of the log entry.
283
+ * @param data The data to be logged, typically related to protocol messages or internal state.
284
+ */
285
+ logger: (name: string, data: Buffer) => void;
286
+ /**
287
+ * Constructs an EDHOC protocol handler.
288
+ * @param connectionID The identifier for this connection.
289
+ * @param method The EDHOC method to be used for the session.
290
+ * @param suite An array of supported cipher suites.
291
+ * @param credentials A manager for handling credentials related to EDHOC.
292
+ * @param crypto A crypto manager to handle cryptographic functions.
293
+ */
294
+ constructor(connectionID: EdhocConnectionID, methods: EdhocMethod[], suites: EdhocSuite[], credentials: EdhocCredentialManager, crypto: EdhocCryptoManager);
295
+ /**
296
+ * Composes the first EDHOC message.
297
+ * @param ead Optional array of EAD objects to include in the message.
298
+ * @return A promise that resolves to the composed message buffer.
299
+ */
300
+ composeMessage1(ead?: EdhocEAD[]): Promise<Buffer> | never;
301
+ /**
302
+ * Processes the received first EDHOC message.
303
+ * @param message The received message buffer.
304
+ * @return A promise that resolves to an array of EAD objects extracted from the message.
305
+ * @throws Error if processing fails, optionally including peerCipherSuites.
306
+ */
307
+ processMessage1(message: Buffer): Promise<EdhocEAD[]> | never;
308
+ /**
309
+ * Composes the second EDHOC message.
310
+ * @param ead Optional array of EAD objects to include in the message.
311
+ * @return A promise that resolves to the composed message buffer.
312
+ */
313
+ composeMessage2(ead?: EdhocEAD[]): Promise<Buffer> | never;
314
+ /**
315
+ * Processes the received second EDHOC message.
316
+ * @param message The received message buffer.
317
+ * @return A promise that resolves to an array of EAD objects extracted from the message.
318
+ * @throws Error if processing fails, optionally including peerCipherSuites.
319
+ */
320
+ processMessage2(message: Buffer): Promise<EdhocEAD[]> | never;
321
+ /**
322
+ * Composes the third EDHOC message.
323
+ * @param ead Optional array of EAD objects to include in the message.
324
+ * @return A promise that resolves to the composed message buffer.
325
+ */
326
+ composeMessage3(ead?: EdhocEAD[]): Promise<Buffer> | never;
327
+ /**
328
+ * Processes the received third EDHOC message.
329
+ * @param message The received message buffer.
330
+ * @return A promise that resolves to an array of EAD objects extracted from the message.
331
+ * @throws Error if processing fails, optionally including peerCipherSuites.
332
+ */
333
+ processMessage3(message: Buffer): Promise<EdhocEAD[]> | never;
334
+ /**
335
+ * Composes the fourth and final EDHOC message.
336
+ * @param ead Optional array of EAD objects to include in the message.
337
+ * @return A promise that resolves to the composed message buffer.
338
+ */
339
+ composeMessage4(ead?: EdhocEAD[]): Promise<Buffer> | never;
340
+ /**
341
+ * Processes the received fourth EDHOC message.
342
+ * @param message The received message buffer.
343
+ * @return A promise that resolves to an array of EAD objects extracted from the message.
344
+ * @throws Error if processing fails, optionally including peerCipherSuites.
345
+ */
346
+ processMessage4(message: Buffer): Promise<EdhocEAD[]> | never;
347
+ /**
348
+ * Exports the OSCORE context derived from the EDHOC session.
349
+ * @return A promise that resolves to the OSCORE context used for secured communication in constrained environments.
350
+ */
351
+ exportOSCORE(): Promise<EdhocOscoreContext> | never;
352
+ /**
353
+ * Exports the key derived from the EDHOC session using the EDHOC_Exporter interface.
354
+ * @param exporterLabel The label of the key to export, as a registered uint from the "EDHOC Exporter Labels" registry.
355
+ * @param length The desired length of the key to export.
356
+ * @return A promise that resolves to the exported key.
357
+ */
358
+ exportKey(exporterLabel: number, length: number): Promise<Buffer> | never;
359
+ /**
360
+ * Key update for the new OSCORE security session
361
+ * Read Appendix H of RFC 9528 - https://www.rfc-editor.org/rfc/rfc9528.html#appendix-H
362
+ * @param context Buffer containing the entropy for key update.
363
+ * @return A promise that resolves to void.
364
+ */
365
+ keyUpdate(context: Buffer): Promise<void> | never;
366
+ }
367
+ export * from './bindings';
368
+ //# sourceMappingURL=edhoc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edhoc.d.ts","sourceRoot":"","sources":["../lib/edhoc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,sBA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G,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK;IAEhF;;;;;OAKG;IACI,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK;CAC3D;AAED,cAAc,YAAY,CAAC"}
package/dist/edhoc.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EdhocSuite = exports.EdhocMethod = exports.EdhocKeyType = exports.EdhocCredentialsCertificateHashAlgorithm = exports.EdhocCredentialsFormat = void 0;
18
+ /**
19
+ * Enumerates the types of credential formats that can be used with EDHOC.
20
+ */
21
+ var EdhocCredentialsFormat;
22
+ (function (EdhocCredentialsFormat) {
23
+ EdhocCredentialsFormat[EdhocCredentialsFormat["kid"] = 4] = "kid";
24
+ EdhocCredentialsFormat[EdhocCredentialsFormat["x5chain"] = 33] = "x5chain";
25
+ EdhocCredentialsFormat[EdhocCredentialsFormat["x5t"] = 34] = "x5t"; // Represents a hashed X.509 certificate.
26
+ })(EdhocCredentialsFormat || (exports.EdhocCredentialsFormat = EdhocCredentialsFormat = {}));
27
+ /**
28
+ * Enumerates the types of hash algorithms that can be used with hashed X.509 certificates.
29
+ */
30
+ var EdhocCredentialsCertificateHashAlgorithm;
31
+ (function (EdhocCredentialsCertificateHashAlgorithm) {
32
+ EdhocCredentialsCertificateHashAlgorithm[EdhocCredentialsCertificateHashAlgorithm["Sha256"] = -16] = "Sha256";
33
+ EdhocCredentialsCertificateHashAlgorithm[EdhocCredentialsCertificateHashAlgorithm["Sha256_64"] = -15] = "Sha256_64"; // SHA-256 truncated to 64 bits.
34
+ })(EdhocCredentialsCertificateHashAlgorithm || (exports.EdhocCredentialsCertificateHashAlgorithm = EdhocCredentialsCertificateHashAlgorithm = {}));
35
+ /**
36
+ * Enumerates the types of cryptographic operations that can be performed with EDHOC.
37
+ */
38
+ var EdhocKeyType;
39
+ (function (EdhocKeyType) {
40
+ EdhocKeyType[EdhocKeyType["MakeKeyPair"] = 0] = "MakeKeyPair";
41
+ EdhocKeyType[EdhocKeyType["KeyAgreement"] = 1] = "KeyAgreement";
42
+ EdhocKeyType[EdhocKeyType["Signature"] = 2] = "Signature";
43
+ EdhocKeyType[EdhocKeyType["Verify"] = 3] = "Verify";
44
+ EdhocKeyType[EdhocKeyType["Extract"] = 4] = "Extract";
45
+ EdhocKeyType[EdhocKeyType["Expand"] = 5] = "Expand";
46
+ EdhocKeyType[EdhocKeyType["Encrypt"] = 6] = "Encrypt";
47
+ EdhocKeyType[EdhocKeyType["Decrypt"] = 7] = "Decrypt";
48
+ })(EdhocKeyType || (exports.EdhocKeyType = EdhocKeyType = {}));
49
+ /**
50
+ * Enumerates the methods available for EDHOC protocol exchanges.
51
+ * Each method corresponds to different authentication mechanisms.
52
+ */
53
+ var EdhocMethod;
54
+ (function (EdhocMethod) {
55
+ EdhocMethod[EdhocMethod["Method0"] = 0] = "Method0";
56
+ EdhocMethod[EdhocMethod["Method1"] = 1] = "Method1";
57
+ EdhocMethod[EdhocMethod["Method2"] = 2] = "Method2";
58
+ EdhocMethod[EdhocMethod["Method3"] = 3] = "Method3";
59
+ })(EdhocMethod || (exports.EdhocMethod = EdhocMethod = {}));
60
+ /**
61
+ * Enumerates the cipher suites available for EDHOC protocol operations.
62
+ * Each suite represents a set of cryptographic algorithms.
63
+ */
64
+ var EdhocSuite;
65
+ (function (EdhocSuite) {
66
+ EdhocSuite[EdhocSuite["Suite0"] = 0] = "Suite0";
67
+ EdhocSuite[EdhocSuite["Suite1"] = 1] = "Suite1";
68
+ EdhocSuite[EdhocSuite["Suite2"] = 2] = "Suite2";
69
+ EdhocSuite[EdhocSuite["Suite3"] = 3] = "Suite3";
70
+ EdhocSuite[EdhocSuite["Suite4"] = 4] = "Suite4";
71
+ EdhocSuite[EdhocSuite["Suite5"] = 5] = "Suite5";
72
+ EdhocSuite[EdhocSuite["Suite6"] = 6] = "Suite6";
73
+ EdhocSuite[EdhocSuite["Suite24"] = 24] = "Suite24";
74
+ EdhocSuite[EdhocSuite["Suite25"] = 25] = "Suite25";
75
+ })(EdhocSuite || (exports.EdhocSuite = EdhocSuite = {}));
76
+ __exportStar(require("./bindings"), exports);
@@ -0,0 +1,4 @@
1
+ export * from "./edhoc";
2
+ export * from "./crypto";
3
+ export * from "./x509credentials";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./edhoc"), exports);
18
+ __exportStar(require("./crypto"), exports);
19
+ __exportStar(require("./x509credentials"), exports);
@@ -0,0 +1,20 @@
1
+ import { EDHOC, EdhocCredentialManager, EdhocCredentials, EdhocCredentialsFormat } from './edhoc';
2
+ import { X509Certificate } from 'crypto';
3
+ export declare class X509CertificateCredentialManager implements EdhocCredentialManager {
4
+ private certificates;
5
+ private peerCertificates;
6
+ private trustedCAs;
7
+ private cryptoKeyID;
8
+ fetchFormat: EdhocCredentialsFormat;
9
+ constructor(credentials: X509Certificate[] | Buffer[], cryptoKeyID: Buffer);
10
+ addPeerCertificate(certificate: X509Certificate | Buffer): void;
11
+ addTrustedCA(certificate: X509Certificate | Buffer): void;
12
+ private convertAndValidateCredentials;
13
+ private convertAndValidateSingleCredential;
14
+ fetch(edhoc: EDHOC): Promise<EdhocCredentials>;
15
+ verify(edhoc: EDHOC, credentials: EdhocCredentials): Promise<EdhocCredentials>;
16
+ private verifyCertificateChain;
17
+ private verifyAgainstTrustRoots;
18
+ private extractPublicKey;
19
+ }
20
+ //# sourceMappingURL=x509credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x509credentials.d.ts","sourceRoot":"","sources":["../lib/x509credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,sBAAsB,EAA+G,MAAM,SAAS,CAAC;AAC/M,OAAO,EAAc,eAAe,EAAE,MAAM,QAAQ,CAAC;AAErD,qBAAa,gCAAiC,YAAW,sBAAsB;IAE3E,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,gBAAgB,CAAyB;IACjD,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,WAAW,CAAS;IAE5B,WAAW,EAAE,sBAAsB,CAAkC;gBAEzD,WAAW,EAAE,eAAe,EAAE,GAAG,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM;IAK1E,kBAAkB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM;IAIxD,YAAY,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM;IAIlD,OAAO,CAAC,6BAA6B;IAIrC,OAAO,CAAC,kCAAkC;IAUpC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAmC9C,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,gBAAgB;IAwCxD,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,gBAAgB;CAY3B"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.X509CertificateCredentialManager = void 0;
4
+ const edhoc_1 = require("./edhoc");
5
+ const crypto_1 = require("crypto");
6
+ class X509CertificateCredentialManager {
7
+ certificates = [];
8
+ peerCertificates = [];
9
+ trustedCAs = [];
10
+ cryptoKeyID;
11
+ fetchFormat = edhoc_1.EdhocCredentialsFormat.x5chain;
12
+ constructor(credentials, cryptoKeyID) {
13
+ this.cryptoKeyID = cryptoKeyID;
14
+ this.certificates = this.convertAndValidateCredentials(credentials);
15
+ }
16
+ addPeerCertificate(certificate) {
17
+ this.peerCertificates.push(this.convertAndValidateSingleCredential(certificate));
18
+ }
19
+ addTrustedCA(certificate) {
20
+ this.trustedCAs.push(this.convertAndValidateSingleCredential(certificate));
21
+ }
22
+ convertAndValidateCredentials(credentials) {
23
+ return credentials.map(cred => this.convertAndValidateSingleCredential(cred));
24
+ }
25
+ convertAndValidateSingleCredential(cred) {
26
+ if (cred instanceof crypto_1.X509Certificate) {
27
+ return cred;
28
+ }
29
+ else if (cred instanceof Buffer) {
30
+ return new crypto_1.X509Certificate(cred);
31
+ }
32
+ else {
33
+ throw new Error('Invalid credentials');
34
+ }
35
+ }
36
+ async fetch(edhoc) {
37
+ if (this.certificates.length === 0) {
38
+ throw new Error('No certificates found');
39
+ }
40
+ switch (this.fetchFormat) {
41
+ case edhoc_1.EdhocCredentialsFormat.x5chain: {
42
+ const chain = {
43
+ format: edhoc_1.EdhocCredentialsFormat.x5chain,
44
+ privateKeyID: this.cryptoKeyID,
45
+ x5chain: {
46
+ certificates: this.certificates.map(cert => cert.raw)
47
+ }
48
+ };
49
+ return chain;
50
+ }
51
+ case edhoc_1.EdhocCredentialsFormat.x5t: {
52
+ if (this.certificates.length > 1) {
53
+ throw new Error('x5t format only supports a single certificate');
54
+ }
55
+ const hash = {
56
+ format: edhoc_1.EdhocCredentialsFormat.x5t,
57
+ privateKeyID: this.cryptoKeyID,
58
+ x5t: {
59
+ certificate: this.certificates[0].raw,
60
+ hash: Buffer.from(this.certificates[0].fingerprint256.replace(/:/g, ''), 'hex').subarray(0, 8),
61
+ hashAlgorithm: edhoc_1.EdhocCredentialsCertificateHashAlgorithm.Sha256_64
62
+ }
63
+ };
64
+ return hash;
65
+ }
66
+ default:
67
+ throw new Error('Unsupported credentials format');
68
+ }
69
+ }
70
+ async verify(edhoc, credentials) {
71
+ if (credentials.format !== edhoc_1.EdhocCredentialsFormat.x5chain &&
72
+ credentials.format !== edhoc_1.EdhocCredentialsFormat.x5t) {
73
+ throw new Error('Credentials format not supported');
74
+ }
75
+ let certificates = [];
76
+ if (credentials.format === edhoc_1.EdhocCredentialsFormat.x5chain) {
77
+ const x5chain = credentials.x5chain;
78
+ certificates = x5chain.certificates;
79
+ }
80
+ else if (credentials.format === edhoc_1.EdhocCredentialsFormat.x5t) {
81
+ const x5t = credentials.x5t;
82
+ certificates = this.peerCertificates
83
+ .filter(certificate => {
84
+ const checksum = Buffer.from(certificate.fingerprint256.replace(/:/g, ''), 'hex');
85
+ if (x5t.hashAlgorithm == edhoc_1.EdhocCredentialsCertificateHashAlgorithm.Sha256_64) {
86
+ return checksum.subarray(0, 8).equals(x5t.hash);
87
+ }
88
+ else if (x5t.hashAlgorithm == edhoc_1.EdhocCredentialsCertificateHashAlgorithm.Sha256) {
89
+ return checksum.equals(x5t.hash);
90
+ }
91
+ else {
92
+ throw new Error('Unsupported hash algorithm');
93
+ }
94
+ })
95
+ .flatMap(certificate => certificate.raw);
96
+ x5t.certificate = certificates[0];
97
+ }
98
+ if (certificates.length < 1) {
99
+ throw new Error('Certificate chain must contain at least one certificate.');
100
+ }
101
+ this.verifyCertificateChain(certificates);
102
+ this.verifyAgainstTrustRoots(certificates[certificates.length - 1]);
103
+ const token = new crypto_1.X509Certificate(certificates[0]).publicKey.export({ format: 'jwk' });
104
+ credentials.publicKey = this.extractPublicKey(token);
105
+ return credentials;
106
+ }
107
+ verifyCertificateChain(certificates) {
108
+ for (let i = 0; i < certificates.length - 1; i++) {
109
+ const currentCert = new crypto_1.X509Certificate(certificates[i]);
110
+ const nextCert = new crypto_1.X509Certificate(certificates[i + 1]);
111
+ if (!currentCert.verify(nextCert.publicKey)) {
112
+ throw new Error(`Verification failed: Certificate at index ${i} is not signed by the next certificate in the chain.`);
113
+ }
114
+ }
115
+ }
116
+ verifyAgainstTrustRoots(lastCertBuffer) {
117
+ const lastCert = new crypto_1.X509Certificate(lastCertBuffer);
118
+ for (const trustRoot of this.trustedCAs) {
119
+ if (lastCert.verify(trustRoot.publicKey)) {
120
+ return;
121
+ }
122
+ }
123
+ throw new Error('Certificate chain not verified');
124
+ }
125
+ extractPublicKey(token) {
126
+ if (token.crv === 'P-256') {
127
+ return Buffer.concat([
128
+ Buffer.from(token.x, 'base64'),
129
+ Buffer.from(token.y, 'base64')
130
+ ]);
131
+ }
132
+ else if (token.crv === 'Ed25519') {
133
+ return Buffer.from(token.x, 'base64');
134
+ }
135
+ else {
136
+ throw new Error('Unsupported curve');
137
+ }
138
+ }
139
+ }
140
+ exports.X509CertificateCredentialManager = X509CertificateCredentialManager;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Generated using zcbor version 0.7.0
2
+ * Generated using zcbor version 0.8.1
3
3
  * https://github.com/NordicSemiconductor/zcbor
4
4
  * Generated with a --default-max-qty of 3
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Generated using zcbor version 0.7.0
2
+ * Generated using zcbor version 0.8.1
3
3
  * https://github.com/NordicSemiconductor/zcbor
4
4
  * Generated with a --default-max-qty of 3
5
5
  */