aws-crt 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (322) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/VERSION +1 -1
  4. data/aws-crt-ffi/CMakeLists.txt +49 -41
  5. data/aws-crt-ffi/crt/aws-c-auth/CMakeLists.txt +0 -10
  6. data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/credentials.h +3 -2
  7. data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/private/credentials_utils.h +4 -4
  8. data/aws-crt-ffi/crt/aws-c-auth/source/auth.c +1 -14
  9. data/aws-crt-ffi/crt/aws-c-auth/source/aws_imds_client.c +206 -68
  10. data/aws-crt-ffi/crt/aws-c-auth/source/aws_signing.c +5 -0
  11. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_cached.c +6 -6
  12. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_default_chain.c +16 -1
  13. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_ecs.c +0 -1
  14. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_process.c +0 -1
  15. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_sts_web_identity.c +0 -1
  16. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_x509.c +10 -7
  17. data/aws-crt-ffi/crt/aws-c-auth/source/credentials_utils.c +35 -26
  18. data/aws-crt-ffi/crt/aws-c-auth/source/signable_chunk.c +3 -2
  19. data/aws-crt-ffi/crt/aws-c-auth/tests/CMakeLists.txt +3 -2
  20. data/aws-crt-ffi/crt/aws-c-auth/tests/aws_imds_client_test.c +1 -0
  21. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_ecs_tests.c +3 -0
  22. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_process_tests.c +65 -16
  23. data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_tests.c +125 -0
  24. data/aws-crt-ffi/crt/aws-c-auth/tests/sigv4_signing_tests.c +68 -46
  25. data/aws-crt-ffi/crt/aws-c-cal/CMakeLists.txt +8 -3
  26. data/aws-crt-ffi/crt/aws-c-cal/bin/run_x_platform_fuzz_corpus/main.c +9 -0
  27. data/aws-crt-ffi/crt/aws-c-cal/builder.json +11 -3
  28. data/aws-crt-ffi/crt/aws-c-cal/cmake/aws-c-cal-config.cmake +14 -5
  29. data/aws-crt-ffi/crt/aws-c-cal/source/darwin/securityframework_ecc.c +6 -6
  30. data/aws-crt-ffi/crt/aws-c-cal/source/windows/bcrypt_ecc.c +12 -12
  31. data/aws-crt-ffi/crt/aws-c-cal/tests/test_case_helper.h +14 -14
  32. data/aws-crt-ffi/crt/aws-c-common/CMakeLists.txt +21 -1
  33. data/aws-crt-ffi/crt/aws-c-common/README.md +8 -0
  34. data/aws-crt-ffi/crt/aws-c-common/cmake/AwsCFlags.cmake +20 -5
  35. data/aws-crt-ffi/crt/aws-c-common/cmake/AwsFeatureTests.cmake +7 -1
  36. data/aws-crt-ffi/crt/aws-c-common/format-check.sh +1 -1
  37. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/byte_buf.h +14 -0
  38. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/config.h.in +1 -0
  39. data/aws-crt-ffi/crt/{aws-c-auth/include/aws/auth → aws-c-common/include/aws/common}/external/cJSON.h +82 -74
  40. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/json.h +335 -0
  41. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/logging.h +1 -0
  42. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/math.inl +2 -2
  43. data/aws-crt-ffi/crt/aws-c-common/include/aws/common/private/json_impl.h +22 -0
  44. data/aws-crt-ffi/crt/aws-c-common/include/aws/testing/aws_test_harness.h +2 -0
  45. data/aws-crt-ffi/crt/aws-c-common/source/byte_buf.c +36 -0
  46. data/aws-crt-ffi/crt/aws-c-common/source/common.c +5 -2
  47. data/aws-crt-ffi/crt/aws-c-common/source/external/cJSON.c +3113 -0
  48. data/aws-crt-ffi/crt/aws-c-common/source/file.c +9 -0
  49. data/aws-crt-ffi/crt/aws-c-common/source/json.c +348 -0
  50. data/aws-crt-ffi/crt/aws-c-common/source/logging.c +7 -2
  51. data/aws-crt-ffi/crt/aws-c-common/source/posix/system_info.c +8 -0
  52. data/aws-crt-ffi/crt/aws-c-common/source/ref_count.c +3 -1
  53. data/aws-crt-ffi/crt/aws-c-common/source/windows/file.c +47 -0
  54. data/aws-crt-ffi/crt/aws-c-common/source/windows/system_info.c +2 -1
  55. data/aws-crt-ffi/crt/aws-c-common/tests/CMakeLists.txt +5 -0
  56. data/aws-crt-ffi/crt/aws-c-common/tests/byte_buf_test.c +69 -0
  57. data/aws-crt-ffi/crt/aws-c-common/tests/json_test.c +134 -0
  58. data/aws-crt-ffi/crt/aws-c-common/tests/memtrace_test.c +6 -2
  59. data/aws-crt-ffi/crt/aws-c-event-stream/README.md +18 -35
  60. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream.h +21 -2
  61. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_client.h +14 -2
  62. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_server.h +13 -0
  63. data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/private/event_stream_rpc_priv.h +7 -7
  64. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream.c +257 -141
  65. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_channel_handler.c +1 -1
  66. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_client.c +31 -8
  67. data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_server.c +63 -10
  68. data/aws-crt-ffi/crt/aws-c-event-stream/tests/CMakeLists.txt +2 -0
  69. data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_client_connection_test.c +157 -106
  70. data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_server_connection_test.c +168 -1
  71. data/aws-crt-ffi/crt/aws-c-event-stream/tests/message_deserializer_test.c +4 -2
  72. data/aws-crt-ffi/crt/aws-c-http/CMakeLists.txt +1 -0
  73. data/aws-crt-ffi/crt/aws-c-http/README.md +8 -0
  74. data/aws-crt-ffi/crt/aws-c-http/bin/elasticurl/main.c +1 -1
  75. data/aws-crt-ffi/crt/aws-c-http/builder.json +4 -3
  76. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection.h +8 -1
  77. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection_manager.h +45 -1
  78. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/http2_stream_manager.h +63 -12
  79. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/connection_impl.h +2 -1
  80. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_connection.h +20 -2
  81. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_frames.h +1 -0
  82. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_stream.h +42 -13
  83. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http2_stream_manager_impl.h +17 -0
  84. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http_impl.h +3 -0
  85. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/random_access_set.h +10 -3
  86. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/request_response_impl.h +3 -17
  87. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/request_response.h +108 -4
  88. data/aws-crt-ffi/crt/aws-c-http/include/aws/http/statistics.h +22 -0
  89. data/aws-crt-ffi/crt/aws-c-http/source/connection.c +8 -3
  90. data/aws-crt-ffi/crt/aws-c-http/source/connection_manager.c +22 -3
  91. data/aws-crt-ffi/crt/aws-c-http/source/connection_monitor.c +32 -14
  92. data/aws-crt-ffi/crt/aws-c-http/source/h1_connection.c +14 -0
  93. data/aws-crt-ffi/crt/aws-c-http/source/h1_encoder.c +7 -4
  94. data/aws-crt-ffi/crt/aws-c-http/source/h2_connection.c +161 -45
  95. data/aws-crt-ffi/crt/aws-c-http/source/h2_decoder.c +37 -8
  96. data/aws-crt-ffi/crt/aws-c-http/source/h2_frames.c +13 -1
  97. data/aws-crt-ffi/crt/aws-c-http/source/h2_stream.c +345 -87
  98. data/aws-crt-ffi/crt/aws-c-http/source/hpack.c +3 -0
  99. data/aws-crt-ffi/crt/aws-c-http/source/http.c +3 -0
  100. data/aws-crt-ffi/crt/aws-c-http/source/http2_stream_manager.c +266 -39
  101. data/aws-crt-ffi/crt/aws-c-http/source/random_access_set.c +9 -3
  102. data/aws-crt-ffi/crt/aws-c-http/source/request_response.c +80 -20
  103. data/aws-crt-ffi/crt/aws-c-http/source/statistics.c +11 -0
  104. data/aws-crt-ffi/crt/aws-c-http/tests/CMakeLists.txt +28 -1
  105. data/aws-crt-ffi/crt/aws-c-http/tests/fuzz/fuzz_h2_decoder_correct.c +5 -3
  106. data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.c +133 -29
  107. data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.h +6 -0
  108. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/README.md +40 -0
  109. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/non_tls_server.py +56 -0
  110. data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/server.py +329 -0
  111. data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_manager.c +1 -1
  112. data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_monitor.c +2 -2
  113. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_client.c +47 -34
  114. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_encoder.c +4 -4
  115. data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_server.c +15 -12
  116. data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_client.c +582 -25
  117. data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_encoder.c +3 -3
  118. data/aws-crt-ffi/crt/aws-c-http/tests/test_localhost_integ.c +530 -0
  119. data/aws-crt-ffi/crt/aws-c-http/tests/test_stream_manager.c +459 -67
  120. data/aws-crt-ffi/crt/aws-c-io/CMakeLists.txt +4 -0
  121. data/aws-crt-ffi/crt/aws-c-io/builder.json +3 -2
  122. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/channel.h +21 -0
  123. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/io.h +3 -0
  124. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/socket.h +6 -0
  125. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/stream.h +35 -5
  126. data/aws-crt-ffi/crt/aws-c-io/include/aws/io/tls_channel_handler.h +211 -15
  127. data/aws-crt-ffi/crt/aws-c-io/source/channel.c +56 -30
  128. data/aws-crt-ffi/crt/aws-c-io/source/darwin/secure_transport_tls_channel_handler.c +0 -24
  129. data/aws-crt-ffi/crt/aws-c-io/source/io.c +9 -0
  130. data/aws-crt-ffi/crt/aws-c-io/source/{pkcs11.c → pkcs11_lib.c} +162 -22
  131. data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_private.h +18 -20
  132. data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_tls_op_handler.c +221 -0
  133. data/aws-crt-ffi/crt/aws-c-io/source/posix/socket.c +135 -81
  134. data/aws-crt-ffi/crt/aws-c-io/source/retry_strategy.c +12 -8
  135. data/aws-crt-ffi/crt/aws-c-io/source/s2n/s2n_tls_channel_handler.c +252 -215
  136. data/aws-crt-ffi/crt/aws-c-io/source/stream.c +65 -82
  137. data/aws-crt-ffi/crt/aws-c-io/source/tls_channel_handler.c +188 -57
  138. data/aws-crt-ffi/crt/aws-c-io/source/windows/iocp/socket.c +271 -256
  139. data/aws-crt-ffi/crt/aws-c-io/tests/CMakeLists.txt +21 -12
  140. data/aws-crt-ffi/crt/aws-c-io/tests/channel_test.c +32 -4
  141. data/aws-crt-ffi/crt/aws-c-io/tests/io_lib_test.c +37 -0
  142. data/aws-crt-ffi/crt/aws-c-io/tests/pkcs11_test.c +412 -93
  143. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.crt +15 -0
  144. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.key +5 -0
  145. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p12 +0 -0
  146. data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p8 +5 -0
  147. data/aws-crt-ffi/crt/aws-c-io/tests/resources/generateCerts.sh +24 -15
  148. data/aws-crt-ffi/crt/aws-c-io/tests/socket_test.c +72 -1
  149. data/aws-crt-ffi/crt/s2n/CMakeLists.txt +6 -1
  150. data/aws-crt-ffi/crt/s2n/bindings/rust/Cargo.toml +1 -0
  151. data/aws-crt-ffi/crt/s2n/bindings/rust/generate/src/main.rs +105 -82
  152. data/aws-crt-ffi/crt/s2n/bindings/rust/generate.sh +1 -0
  153. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/Cargo.toml +2 -2
  154. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/raw/config.rs +1 -1
  155. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/Cargo.toml +1 -1
  156. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/build.rs +84 -30
  157. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/src/lib.rs +4 -0
  158. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/Cargo.toml +21 -0
  159. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/cert.pem +14 -0
  160. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/key.pem +8 -0
  161. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/client.rs +45 -0
  162. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/server.rs +60 -0
  163. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/src/lib.rs +150 -0
  164. data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/tests/handshake.rs +51 -0
  165. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.c +98 -77
  166. data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.h +10 -7
  167. data/aws-crt-ffi/crt/s2n/crypto/s2n_openssl.h +2 -0
  168. data/aws-crt-ffi/crt/s2n/error/s2n_errno.c +1 -1
  169. data/aws-crt-ffi/crt/s2n/error/s2n_errno.h +1 -0
  170. data/aws-crt-ffi/crt/s2n/s2n.mk +7 -0
  171. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/repository.py +233 -0
  172. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup-proof.py +8 -7
  173. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup.py +17 -18
  174. data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/util.py +41 -23
  175. data/aws-crt-ffi/crt/s2n/tests/fuzz/LD_PRELOAD/global_overrides.c +3 -3
  176. data/aws-crt-ffi/crt/s2n/tests/integration/s2n_client_endpoint_handshake_test.py +2 -2
  177. data/aws-crt-ffi/crt/s2n/tests/integrationv2/Makefile +13 -42
  178. data/aws-crt-ffi/crt/s2n/tests/integrationv2/README.md +6 -1
  179. data/aws-crt-ffi/crt/s2n/tests/integrationv2/common.py +118 -53
  180. data/aws-crt-ffi/crt/s2n/tests/integrationv2/configuration.py +108 -88
  181. data/aws-crt-ffi/crt/s2n/tests/integrationv2/conftest.py +6 -3
  182. data/aws-crt-ffi/crt/s2n/tests/integrationv2/constants.py +6 -4
  183. data/aws-crt-ffi/crt/s2n/tests/integrationv2/fixtures.py +21 -12
  184. data/aws-crt-ffi/crt/s2n/tests/integrationv2/global_flags.py +1 -0
  185. data/aws-crt-ffi/crt/s2n/tests/integrationv2/processes.py +62 -19
  186. data/aws-crt-ffi/crt/s2n/tests/integrationv2/providers.py +304 -48
  187. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_client_authentication.py +20 -11
  188. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_cross_compatibility.py +41 -17
  189. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_dynamic_record_sizes.py +6 -3
  190. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_early_data.py +105 -48
  191. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_external_psk.py +160 -76
  192. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_fragmentation.py +59 -26
  193. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_happy_path.py +42 -28
  194. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_hello_retry_requests.py +33 -13
  195. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_key_update.py +29 -11
  196. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_ocsp.py +138 -0
  197. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_pq_handshake.py +103 -36
  198. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_session_resumption.py +52 -25
  199. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_signature_algorithms.py +47 -21
  200. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sni_match.py +13 -9
  201. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sslyze.py +88 -17
  202. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_version_negotiation.py +71 -22
  203. data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_well_known_endpoints.py +4 -3
  204. data/aws-crt-ffi/crt/s2n/tests/integrationv2/tox.ini +1 -0
  205. data/aws-crt-ffi/crt/s2n/tests/integrationv2/utils.py +50 -15
  206. data/aws-crt-ffi/crt/s2n/tests/litani/CHANGELOG +131 -0
  207. data/aws-crt-ffi/crt/s2n/tests/litani/CONTRIBUTING.md +16 -0
  208. data/aws-crt-ffi/crt/s2n/tests/litani/README.md +36 -14
  209. data/aws-crt-ffi/crt/s2n/tests/litani/THIRD-PARTY +205 -41
  210. data/aws-crt-ffi/crt/s2n/tests/litani/doc/bin/build-html-doc +7 -7
  211. data/aws-crt-ffi/crt/s2n/tests/litani/doc/configure +27 -23
  212. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-add-job.scdoc +7 -0
  213. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-dump-run.scdoc +7 -5
  214. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-transform-jobs.scdoc +248 -0
  215. data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani.scdoc +2 -2
  216. data/aws-crt-ffi/crt/s2n/tests/litani/doc/templates/index.jinja.html +4 -0
  217. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/README +12 -0
  218. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/original-run.sh +52 -0
  219. data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/run-all.py +71 -0
  220. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/README +13 -0
  221. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-1.sh +34 -0
  222. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-2.sh +35 -0
  223. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-3.sh +34 -0
  224. data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-all.py +60 -0
  225. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/README.md +10 -0
  226. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/assumptions.html +42 -0
  227. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/file.dat +7 -0
  228. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/histogram.dat +7 -0
  229. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-1.sh +41 -0
  230. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-2.sh +47 -0
  231. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-3.sh +41 -0
  232. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-all.py +34 -0
  233. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib-table.py +40 -0
  234. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.plt +5 -0
  235. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.py +32 -0
  236. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin-output.py +40 -0
  237. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.plt +5 -0
  238. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.py +30 -0
  239. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/fib-table.jinja.html +45 -0
  240. data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/sin-output.jinja.html +30 -0
  241. data/aws-crt-ffi/crt/s2n/tests/litani/lib/add_job.py +55 -0
  242. data/aws-crt-ffi/crt/s2n/tests/litani/lib/graph.py +2 -2
  243. data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani.py +6 -1
  244. data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani_report.py +18 -21
  245. data/aws-crt-ffi/crt/s2n/tests/litani/lib/ninja.py +2 -0
  246. data/aws-crt-ffi/crt/s2n/tests/litani/lib/run_printer.py +26 -7
  247. data/aws-crt-ffi/crt/s2n/tests/litani/lib/transform_jobs.py +84 -0
  248. data/aws-crt-ffi/crt/s2n/tests/litani/litani +28 -33
  249. data/aws-crt-ffi/crt/s2n/tests/litani/script/release +220 -0
  250. data/aws-crt-ffi/crt/s2n/tests/litani/templates/dashboard.jinja.html +78 -15
  251. data/aws-crt-ffi/crt/s2n/tests/litani/templates/pipeline.jinja.html +21 -5
  252. data/aws-crt-ffi/crt/s2n/tests/litani/test/README +15 -0
  253. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/run +56 -33
  254. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/custom_stages.py +1 -0
  255. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/cwd.py +1 -0
  256. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/dump_run.py +1 -0
  257. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/graph_line_break.py +1 -0
  258. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/html_node.py +1 -0
  259. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/job_id_env.py +1 -0
  260. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/multiproc_dump_run.py +1 -0
  261. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize.py +1 -0
  262. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize_graph.py +1 -0
  263. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out.py +1 -0
  264. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ignored.py +1 -0
  265. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ok.py +1 -0
  266. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pipeline_order.py +53 -0
  267. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize.py +1 -0
  268. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize_graph.py +1 -0
  269. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/single_pool.py +1 -0
  270. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out.py +1 -0
  271. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess.py +1 -0
  272. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_multi_shell.py +1 -0
  273. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_shell.py +1 -0
  274. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ignored.py +1 -0
  275. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ok.py +1 -0
  276. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_delete_job.py +54 -0
  277. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_modify_job.py +46 -0
  278. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_no_change_job.py +44 -0
  279. data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/zero_pool.py +1 -0
  280. data/aws-crt-ffi/crt/s2n/tests/litani/test/run +82 -12
  281. data/aws-crt-ffi/crt/s2n/tests/s2n_test.h +58 -33
  282. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_key_schedule_testlib.c +18 -6
  283. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_pq_kat_test_utils.c +4 -4
  284. data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_testlib.h +2 -0
  285. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_client_hello_retry_test.c +66 -2
  286. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_connection_test.c +1 -1
  287. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_drbg_test.c +34 -14
  288. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_fork_generation_number_test.c +28 -5
  289. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_mem_usage_test.c +6 -0
  290. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_override_openssl_random_test.c +1 -1
  291. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_random_test.c +60 -41
  292. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_self_talk_broken_pipe_test.c +2 -2
  293. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_handshake_early_data_test.c +3 -1
  294. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_hybrid_shared_secret_test.c +9 -1
  295. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_rfc8448_test.c +31 -130
  296. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_test.c +2 -4
  297. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_pq_handshake_test.c +11 -6
  298. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_rfc8448_test.c +19 -21
  299. data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_test.c +109 -60
  300. data/aws-crt-ffi/crt/s2n/tls/s2n_config.c +1 -0
  301. data/aws-crt-ffi/crt/s2n/tls/s2n_config.h +1 -1
  302. data/aws-crt-ffi/crt/s2n/tls/s2n_connection.c +29 -24
  303. data/aws-crt-ffi/crt/s2n/tls/s2n_connection.h +5 -5
  304. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_hashes.h +1 -7
  305. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_io.c +2 -0
  306. data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_transcript.c +0 -44
  307. data/aws-crt-ffi/crt/s2n/tls/s2n_internal.h +0 -1
  308. data/aws-crt-ffi/crt/s2n/tls/s2n_quic_support.h +1 -1
  309. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_key_schedule.c +1 -2
  310. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.c +84 -44
  311. data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.h +3 -9
  312. data/aws-crt-ffi/crt/s2n/utils/s2n_blob.h +15 -8
  313. data/aws-crt-ffi/crt/s2n/utils/s2n_fork_detection.c +2 -6
  314. data/aws-crt-ffi/crt/s2n/utils/s2n_random.c +9 -9
  315. data/aws-crt-ffi/src/input_stream.c +32 -15
  316. data/ext/compile.rb +13 -5
  317. data/lib/aws-crt/platforms.rb +14 -5
  318. data/lib/aws-crt/string_blob.rb +3 -3
  319. metadata +61 -7
  320. data/aws-crt-ffi/crt/aws-c-auth/source/external/cJSON.c +0 -2987
  321. data/aws-crt-ffi/crt/aws-c-auth/tests/external/cJSON.c +0 -2986
  322. data/aws-crt-ffi/crt/aws-c-io/tests/error_test.c +0 -20
@@ -43,11 +43,12 @@ struct pkcs11_tester {
43
43
 
44
44
  static struct pkcs11_tester s_pkcs11_tester;
45
45
  const char *TOKEN_LABEL = "my-token";
46
+ const char *TOKEN_LABEL_RSA = "my-rsa-token";
47
+ const char *TOKEN_LABEL_EC = "my-ec-token";
46
48
  const char *SO_PIN = "1111";
47
49
  const char *USER_PIN = "0000";
48
50
  const char *DEFAULT_KEY_LABEL = "my-key";
49
51
  const char *DEFAULT_KEY_ID = "AABBCCDD";
50
- CK_KEY_TYPE SUPPORTED_KEY_TYPE = CKK_RSA;
51
52
 
52
53
  #define TIMEOUT_SEC 10
53
54
  #define TIMEOUT_MILLIS (AWS_TIMESTAMP_MILLIS * TIMEOUT_SEC)
@@ -104,7 +105,8 @@ static int s_pkcs11_clear_softhsm_and_reload(void) {
104
105
  return AWS_OP_SUCCESS;
105
106
  }
106
107
 
107
- static int s_pkcs11_encrypt(
108
+ /* Encryption/Decryption only applies to RSA, not ECC */
109
+ static int s_pkcs11_rsa_encrypt(
108
110
  struct aws_byte_cursor *message,
109
111
  struct aws_byte_buf *cipher_text,
110
112
  CK_SESSION_HANDLE session,
@@ -113,7 +115,6 @@ static int s_pkcs11_encrypt(
113
115
  CK_FUNCTION_LIST *pkcs11_function_list = aws_pkcs11_lib_get_function_list(s_pkcs11_tester.lib);
114
116
  struct aws_allocator *allocator = s_pkcs11_tester.allocator;
115
117
 
116
- /* We only support RSA keys today. */
117
118
  CK_MECHANISM mechanism = {.mechanism = CKM_RSA_PKCS};
118
119
  CK_RV rv = pkcs11_function_list->C_EncryptInit(session, &mechanism, public_key);
119
120
  if (rv != CKR_OK) {
@@ -140,12 +141,12 @@ static int s_pkcs11_verify_signature(
140
141
  struct aws_byte_cursor *message,
141
142
  struct aws_byte_buf *signature,
142
143
  CK_SESSION_HANDLE session,
143
- CK_OBJECT_HANDLE public_key) {
144
+ CK_OBJECT_HANDLE public_key,
145
+ CK_MECHANISM_TYPE mechanism_type) {
144
146
 
145
147
  CK_FUNCTION_LIST *pkcs11_function_list = aws_pkcs11_lib_get_function_list(s_pkcs11_tester.lib);
146
148
 
147
- /* We only support RSA keys today. */
148
- CK_MECHANISM mechanism = {.mechanism = CKM_RSA_PKCS};
149
+ CK_MECHANISM mechanism = {.mechanism = mechanism_type};
149
150
  CK_RV rv = pkcs11_function_list->C_VerifyInit(session, &mechanism, public_key);
150
151
  if (rv != CKR_OK) {
151
152
  FAIL("C_VerifyInit fails: PKCS#11 error: %s (0x%08lX)", aws_pkcs11_ckr_str(rv), rv);
@@ -159,7 +160,7 @@ static int s_pkcs11_verify_signature(
159
160
  return AWS_OP_SUCCESS;
160
161
  }
161
162
 
162
- static int s_pkcs11_create_key(
163
+ static int s_pkcs11_create_rsa_key(
163
164
  struct pkcs11_key_creation_params *params,
164
165
  CK_SESSION_HANDLE session,
165
166
  CK_OBJECT_HANDLE *created_private_key,
@@ -206,6 +207,53 @@ static int s_pkcs11_create_key(
206
207
  return AWS_OP_SUCCESS;
207
208
  }
208
209
 
210
+ static int s_pkcs11_create_ec_key(
211
+ struct pkcs11_key_creation_params *params,
212
+ CK_SESSION_HANDLE session,
213
+ CK_OBJECT_HANDLE *created_private_key,
214
+ CK_OBJECT_HANDLE *created_public_key) {
215
+
216
+ CK_FUNCTION_LIST *pkcs11_function_list = aws_pkcs11_lib_get_function_list(s_pkcs11_tester.lib);
217
+
218
+ CK_MECHANISM smech = {CKM_EC_KEY_PAIR_GEN, NULL, 0};
219
+ /* Define key template */
220
+ static CK_BBOOL truevalue = TRUE;
221
+ static CK_BBOOL falsevalue = FALSE;
222
+ /* DER encoded params for curve P-256 */
223
+ static CK_BYTE ec_params[] = {0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07};
224
+
225
+ CK_ATTRIBUTE publickey_template[] = {
226
+ {CKA_EC_PARAMS, ec_params, sizeof(ec_params)},
227
+ {CKA_VERIFY, &truevalue, sizeof(truevalue)},
228
+ };
229
+
230
+ /* Set private key. The parameters here are kind of random, does not affect the test, but trying
231
+ * to mimic what a real key would look like in terms of attributes */
232
+ CK_ATTRIBUTE privatekey_template[] = {
233
+ {CKA_LABEL, (void *)params->key_label, (CK_ULONG)strlen(params->key_label)},
234
+ {CKA_ID, (void *)params->key_id, (CK_ULONG)strlen(params->key_id)},
235
+ {CKA_SIGN, &truevalue, sizeof(truevalue)},
236
+ {CKA_EXTRACTABLE, &falsevalue, sizeof(falsevalue)},
237
+ };
238
+ CK_OBJECT_HANDLE privatekey, publickey = CK_INVALID_HANDLE;
239
+ /* Generate Key pair for signing/verifying */
240
+ CK_RV rv = pkcs11_function_list->C_GenerateKeyPair(
241
+ session,
242
+ &smech,
243
+ publickey_template,
244
+ AWS_ARRAY_SIZE(publickey_template),
245
+ privatekey_template,
246
+ AWS_ARRAY_SIZE(privatekey_template),
247
+ &publickey,
248
+ &privatekey);
249
+ if (rv != CKR_OK) {
250
+ FAIL("C_GenerateKeyPair fails: PKCS#11 error: %s (0x%08lX)", aws_pkcs11_ckr_str(rv), rv);
251
+ }
252
+ *created_private_key = privatekey;
253
+ *created_public_key = publickey;
254
+ return AWS_OP_SUCCESS;
255
+ }
256
+
209
257
  /* if tokenInfo is set, finds slot with matching token
210
258
  * if tokenInfo is NULL, finds slot with uninitialized token */
211
259
  static int s_pkcs11_find_slot(const CK_TOKEN_INFO *tokenInfo, CK_SLOT_ID *out_slot) {
@@ -386,6 +434,7 @@ static int s_pkcs11_tester_init(struct aws_allocator *allocator) {
386
434
 
387
435
  static int s_pkcs11_tester_init_with_session_login(
388
436
  struct aws_allocator *allocator,
437
+ const char *token_label,
389
438
  CK_SLOT_ID *created_slot,
390
439
  CK_SESSION_HANDLE *session) {
391
440
 
@@ -393,7 +442,7 @@ static int s_pkcs11_tester_init_with_session_login(
393
442
  ASSERT_SUCCESS(s_pkcs11_tester_init(allocator));
394
443
 
395
444
  /* Create a new slot, this reloads the softhsm library but the labels/slots remain intact */
396
- ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(TOKEN_LABEL, SO_PIN, USER_PIN, created_slot));
445
+ ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(token_label, SO_PIN, USER_PIN, created_slot));
397
446
 
398
447
  ASSERT_SUCCESS(aws_pkcs11_lib_open_session(s_pkcs11_tester.lib, *created_slot, session /*out*/));
399
448
 
@@ -627,14 +676,14 @@ static int s_test_pkcs11_login_tests(struct aws_allocator *allocator, void *ctx)
627
676
  }
628
677
  AWS_TEST_CASE(pkcs11_login_tests, s_test_pkcs11_login_tests)
629
678
 
630
- static int s_test_pkcs11_find_private_key_for_different_types(struct aws_allocator *allocator, void *ctx) {
679
+ static int s_test_pkcs11_find_private_key_for_different_rsa_types(struct aws_allocator *allocator, void *ctx) {
631
680
  (void)ctx;
632
681
  /* Reset PKCS#11 tokens and load library */
633
682
  ASSERT_SUCCESS(s_pkcs11_tester_init(allocator));
634
683
 
635
684
  /* Create a new slot, this reloads the softhsm library but the labels/slots remain intact */
636
685
  CK_SLOT_ID created_slot = 0;
637
- ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(TOKEN_LABEL, SO_PIN, USER_PIN, &created_slot));
686
+ ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(TOKEN_LABEL_RSA, SO_PIN, USER_PIN, &created_slot));
638
687
 
639
688
  /* Do not close the session while running a test, objects created by a session are cleaned up
640
689
  * when the session is closed.
@@ -656,7 +705,7 @@ static int s_test_pkcs11_find_private_key_for_different_types(struct aws_allocat
656
705
  char *key_id_1024 = "1024_id";
657
706
  struct pkcs11_key_creation_params params_1024 = {
658
707
  .key_label = key_label_1024, .key_id = key_id_1024, .key_length = 1024};
659
- ASSERT_SUCCESS(s_pkcs11_create_key(&params_1024, session_to_create_key, &created_priv_key, &created_pub_key));
708
+ ASSERT_SUCCESS(s_pkcs11_create_rsa_key(&params_1024, session_to_create_key, &created_priv_key, &created_pub_key));
660
709
 
661
710
  /* Find key */
662
711
  CK_OBJECT_HANDLE pkey_handle = CK_INVALID_HANDLE;
@@ -673,7 +722,7 @@ static int s_test_pkcs11_find_private_key_for_different_types(struct aws_allocat
673
722
  char *key_id_2048 = "2048_id";
674
723
  struct pkcs11_key_creation_params params_2048 = {
675
724
  .key_label = key_label_2048, .key_id = key_id_2048, .key_length = 2048};
676
- ASSERT_SUCCESS(s_pkcs11_create_key(&params_2048, session_to_create_key, &created_key_2048, &created_pub_key));
725
+ ASSERT_SUCCESS(s_pkcs11_create_rsa_key(&params_2048, session_to_create_key, &created_key_2048, &created_pub_key));
677
726
 
678
727
  /* Find key */
679
728
  struct aws_string *key_label_str_2048 = aws_string_new_from_c_str(allocator, key_label_2048);
@@ -688,7 +737,7 @@ static int s_test_pkcs11_find_private_key_for_different_types(struct aws_allocat
688
737
  char *key_id_4096 = "4096_id";
689
738
  struct pkcs11_key_creation_params params_4096 = {
690
739
  .key_label = key_label_4096, .key_id = key_id_4096, .key_length = 4096};
691
- ASSERT_SUCCESS(s_pkcs11_create_key(&params_4096, session_to_create_key, &created_key_4096, &created_pub_key));
740
+ ASSERT_SUCCESS(s_pkcs11_create_rsa_key(&params_4096, session_to_create_key, &created_key_4096, &created_pub_key));
692
741
 
693
742
  /* Find key */
694
743
  struct aws_string *key_label_str_4096 = aws_string_new_from_c_str(allocator, key_label_4096);
@@ -705,7 +754,56 @@ static int s_test_pkcs11_find_private_key_for_different_types(struct aws_allocat
705
754
  s_pkcs11_tester_clean_up();
706
755
  return AWS_OP_SUCCESS;
707
756
  }
708
- AWS_TEST_CASE(pkcs11_find_private_key_for_different_types, s_test_pkcs11_find_private_key_for_different_types)
757
+ AWS_TEST_CASE(pkcs11_find_private_key_for_different_rsa_types, s_test_pkcs11_find_private_key_for_different_rsa_types)
758
+
759
+ static int s_test_pkcs11_find_private_key_for_ec(struct aws_allocator *allocator, void *ctx) {
760
+ (void)ctx;
761
+ /* Reset PKCS#11 tokens and load library */
762
+ ASSERT_SUCCESS(s_pkcs11_tester_init(allocator));
763
+
764
+ /* Create a new slot, this reloads the softhsm library but the labels/slots remain intact */
765
+ CK_SLOT_ID created_slot = 0;
766
+ ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(TOKEN_LABEL, SO_PIN, USER_PIN, &created_slot));
767
+
768
+ /* Do not close the session while running a test, objects created by a session are cleaned up
769
+ * when the session is closed.
770
+ * http://docs.oasis-open.org/pkcs11/pkcs11-ug/v2.40/cn02/pkcs11-ug-v2.40-cn02.html#_Toc386027485
771
+ * */
772
+ /* Open a different session to access the created key, and a different one to create */
773
+ CK_SESSION_HANDLE session_to_access_key;
774
+ CK_SESSION_HANDLE session_to_create_key;
775
+ ASSERT_SUCCESS(aws_pkcs11_lib_open_session(s_pkcs11_tester.lib, created_slot, &session_to_access_key /*out*/));
776
+ ASSERT_SUCCESS(aws_pkcs11_lib_open_session(s_pkcs11_tester.lib, created_slot, &session_to_create_key /*out*/));
777
+
778
+ /* Login user */
779
+ struct aws_string *user_pin = aws_string_new_from_c_str(allocator, USER_PIN);
780
+ ASSERT_SUCCESS(aws_pkcs11_lib_login_user(s_pkcs11_tester.lib, session_to_access_key, user_pin));
781
+
782
+ /* Create an EC key */
783
+ CK_OBJECT_HANDLE created_pub_key = CK_INVALID_HANDLE;
784
+ CK_OBJECT_HANDLE created_key_ec_256 = CK_INVALID_HANDLE;
785
+ char *key_label_ec_256 = "EC_256_Key";
786
+ char *key_id_ec_256 = "EC_256_id";
787
+ struct pkcs11_key_creation_params params_ec_256 = {.key_label = key_label_ec_256, .key_id = key_id_ec_256};
788
+ ASSERT_SUCCESS(
789
+ s_pkcs11_create_ec_key(&params_ec_256, session_to_create_key, &created_key_ec_256, &created_pub_key));
790
+
791
+ /* Find key */
792
+ CK_OBJECT_HANDLE pkey_handle = CK_INVALID_HANDLE;
793
+ CK_KEY_TYPE pkey_type;
794
+ struct aws_string *key_label_str_ec_256 = aws_string_new_from_c_str(allocator, key_label_ec_256);
795
+ ASSERT_SUCCESS(aws_pkcs11_lib_find_private_key(
796
+ s_pkcs11_tester.lib, session_to_access_key, key_label_str_ec_256, &pkey_handle, &pkey_type));
797
+ ASSERT_INT_EQUALS(created_key_ec_256, pkey_handle);
798
+ ASSERT_INT_EQUALS(CKK_EC, pkey_type);
799
+
800
+ /* Clean up */
801
+ aws_string_destroy(user_pin);
802
+ aws_string_destroy(key_label_str_ec_256);
803
+ s_pkcs11_tester_clean_up();
804
+ return AWS_OP_SUCCESS;
805
+ }
806
+ AWS_TEST_CASE(pkcs11_find_private_key_for_ec, s_test_pkcs11_find_private_key_for_ec)
709
807
 
710
808
  static int s_test_pkcs11_find_multiple_private_key(struct aws_allocator *allocator, void *ctx) {
711
809
  (void)ctx;
@@ -740,8 +838,8 @@ static int s_test_pkcs11_find_multiple_private_key(struct aws_allocator *allocat
740
838
  CK_OBJECT_HANDLE created_pub_key = CK_INVALID_HANDLE;
741
839
  struct pkcs11_key_creation_params params_1 = {.key_label = key_label_1, .key_id = key_id_1, .key_length = 1024};
742
840
  struct pkcs11_key_creation_params params_2 = {.key_label = key_label_2, .key_id = key_id_2, .key_length = 1024};
743
- ASSERT_SUCCESS(s_pkcs11_create_key(&params_1, session_to_create_key_1, &created_key_1, &created_pub_key));
744
- ASSERT_SUCCESS(s_pkcs11_create_key(&params_2, session_to_create_key_2, &created_key_2, &created_pub_key));
841
+ ASSERT_SUCCESS(s_pkcs11_create_rsa_key(&params_1, session_to_create_key_1, &created_key_1, &created_pub_key));
842
+ ASSERT_SUCCESS(s_pkcs11_create_rsa_key(&params_2, session_to_create_key_2, &created_key_2, &created_pub_key));
745
843
 
746
844
  /* Since there are 2 keys, a lookup without label should fail */
747
845
  struct aws_string *key_label_str = aws_string_new_from_c_str(allocator, key_label_1);
@@ -810,7 +908,7 @@ static int s_test_pkcs11_find_private_key(struct aws_allocator *allocator, void
810
908
  CK_OBJECT_HANDLE created_key = CK_INVALID_HANDLE;
811
909
  CK_OBJECT_HANDLE created_pub_key = CK_INVALID_HANDLE;
812
910
  struct pkcs11_key_creation_params params = {.key_label = key_label_1, .key_id = key_id_1, .key_length = 1024};
813
- ASSERT_SUCCESS(s_pkcs11_create_key(&params, session_to_create_key, &created_key, &created_pub_key));
911
+ ASSERT_SUCCESS(s_pkcs11_create_rsa_key(&params, session_to_create_key, &created_key, &created_pub_key));
814
912
 
815
913
  /* Find key */
816
914
  CK_OBJECT_HANDLE pkey_handle = CK_INVALID_HANDLE;
@@ -1009,89 +1107,88 @@ static int s_test_pkcs11_find_slot_many_tokens(struct aws_allocator *allocator,
1009
1107
  }
1010
1108
  AWS_TEST_CASE(pkcs11_find_slot_many_tokens, s_test_pkcs11_find_slot_many_tokens)
1011
1109
 
1012
- static int s_test_pkcs11_decrypt(struct aws_allocator *allocator, void *ctx) {
1110
+ static int s_test_pkcs11_prepare_rsa_2048_sign(
1111
+ CK_SESSION_HANDLE session,
1112
+ CK_OBJECT_HANDLE *pri_key,
1113
+ CK_OBJECT_HANDLE *pub_key) {
1114
+ struct pkcs11_key_creation_params params = {
1115
+ .key_label = DEFAULT_KEY_LABEL, .key_id = DEFAULT_KEY_ID, .key_length = 2048};
1116
+ return s_pkcs11_create_rsa_key(&params, session, pri_key, pub_key);
1117
+ }
1118
+
1119
+ static int s_test_pkcs11_prepare_ec_256_sign(
1120
+ CK_SESSION_HANDLE session,
1121
+ CK_OBJECT_HANDLE *pri_key,
1122
+ CK_OBJECT_HANDLE *pub_key) {
1123
+ struct pkcs11_key_creation_params params = {
1124
+ .key_label = DEFAULT_KEY_LABEL, .key_id = DEFAULT_KEY_ID, .key_length = 256};
1125
+ return s_pkcs11_create_ec_key(&params, session, pri_key, pub_key);
1126
+ }
1127
+
1128
+ /* Encryption/Decryption only applies to RSA, not ECC */
1129
+ static int s_test_pkcs11_rsa_decrypt(struct aws_allocator *allocator, void *ctx) {
1013
1130
  (void)ctx;
1014
1131
  /* Reset PKCS#11 tokens, load library */
1015
1132
  CK_SLOT_ID created_slot = 0;
1016
1133
  CK_SESSION_HANDLE session = CK_INVALID_HANDLE;
1017
- s_pkcs11_tester_init_with_session_login(allocator, &created_slot, &session);
1134
+ s_pkcs11_tester_init_with_session_login(allocator, TOKEN_LABEL_RSA, &created_slot, &session);
1018
1135
 
1019
1136
  CK_OBJECT_HANDLE created_key = CK_INVALID_HANDLE;
1020
1137
  CK_OBJECT_HANDLE created_pub_key = CK_INVALID_HANDLE;
1021
- struct pkcs11_key_creation_params params = {
1022
- .key_label = DEFAULT_KEY_LABEL, .key_id = DEFAULT_KEY_ID, .key_length = 2048};
1023
- ASSERT_SUCCESS(s_pkcs11_create_key(&params, session, &created_key, &created_pub_key));
1138
+ ASSERT_SUCCESS(s_test_pkcs11_prepare_rsa_2048_sign(session, &created_key, &created_pub_key));
1024
1139
 
1025
1140
  struct aws_byte_cursor input_cursor = aws_byte_cursor_from_c_str("ABCDEFGHIJKL");
1026
1141
  struct aws_byte_buf output_buf; /* initialized later */
1027
1142
  AWS_ZERO_STRUCT(output_buf);
1028
1143
 
1029
1144
  /* Encrypt our text */
1030
- ASSERT_SUCCESS(s_pkcs11_encrypt(&input_cursor, &output_buf, session, created_pub_key));
1145
+ ASSERT_SUCCESS(s_pkcs11_rsa_encrypt(&input_cursor, &output_buf, session, created_pub_key));
1031
1146
 
1032
1147
  struct aws_byte_cursor cipher_text = aws_byte_cursor_from_buf(&output_buf);
1033
1148
  struct aws_byte_buf output_decrypted; /* initialized later */
1034
1149
  AWS_ZERO_STRUCT(output_decrypted);
1035
1150
  ASSERT_SUCCESS(aws_pkcs11_lib_decrypt(
1036
- s_pkcs11_tester.lib, session, created_key, SUPPORTED_KEY_TYPE, cipher_text, allocator, &output_decrypted));
1151
+ s_pkcs11_tester.lib, session, created_key, CKK_RSA, cipher_text, allocator, &output_decrypted));
1037
1152
 
1038
1153
  ASSERT_BIN_ARRAYS_EQUALS(output_decrypted.buffer, output_decrypted.len, input_cursor.ptr, input_cursor.len);
1039
1154
 
1040
- /* Assert that sign fails for non RSA key type */
1041
- CK_KEY_TYPE unsupported_key_type = CKK_EC;
1155
+ /* Assert that sign fails for invalid / mismatch key type */
1156
+ /* TODO: Move ASSERT_FAILS to ASSERT_ERROR */
1157
+ CK_KEY_TYPE unsupported_key_type = CKK_GENERIC_SECRET;
1042
1158
  aws_byte_buf_clean_up(&output_decrypted);
1043
1159
  ASSERT_FAILS(aws_pkcs11_lib_decrypt(
1044
1160
  s_pkcs11_tester.lib, session, created_key, unsupported_key_type, cipher_text, allocator, &output_decrypted));
1045
1161
 
1046
1162
  /* Invalid session handle should fail */
1047
1163
  ASSERT_FAILS(aws_pkcs11_lib_decrypt(
1048
- s_pkcs11_tester.lib,
1049
- CK_INVALID_HANDLE,
1050
- created_key,
1051
- SUPPORTED_KEY_TYPE,
1052
- cipher_text,
1053
- allocator,
1054
- &output_decrypted));
1164
+ s_pkcs11_tester.lib, CK_INVALID_HANDLE, created_key, CKK_RSA, cipher_text, allocator, &output_decrypted));
1055
1165
 
1056
1166
  /* Invalid key handle should fail */
1057
1167
  ASSERT_FAILS(aws_pkcs11_lib_decrypt(
1058
- s_pkcs11_tester.lib,
1059
- session,
1060
- CK_INVALID_HANDLE,
1061
- SUPPORTED_KEY_TYPE,
1062
- cipher_text,
1063
- allocator,
1064
- &output_decrypted));
1168
+ s_pkcs11_tester.lib, session, CK_INVALID_HANDLE, CKK_RSA, cipher_text, allocator, &output_decrypted));
1065
1169
 
1066
1170
  struct aws_byte_cursor empty_message_to_decrypt = aws_byte_cursor_from_c_str("");
1067
1171
  ASSERT_FAILS(aws_pkcs11_lib_decrypt(
1068
- s_pkcs11_tester.lib,
1069
- session,
1070
- created_key,
1071
- SUPPORTED_KEY_TYPE,
1072
- empty_message_to_decrypt,
1073
- allocator,
1074
- &output_decrypted));
1172
+ s_pkcs11_tester.lib, session, created_key, CKK_RSA, empty_message_to_decrypt, allocator, &output_decrypted));
1075
1173
  /* Clean up */
1076
1174
  aws_byte_buf_clean_up(&output_buf);
1077
1175
  aws_byte_buf_clean_up(&output_decrypted);
1078
1176
  s_pkcs11_tester_clean_up();
1079
1177
  return AWS_OP_SUCCESS;
1080
1178
  }
1081
- AWS_TEST_CASE(pkcs11_decrypt, s_test_pkcs11_decrypt)
1082
1179
 
1083
- static int s_test_pkcs11_sign(struct aws_allocator *allocator, void *ctx, int digest_alg) {
1180
+ AWS_TEST_CASE(pkcs11_rsa_decrypt, s_test_pkcs11_rsa_decrypt)
1181
+
1182
+ static int s_test_pkcs11_sign_rsa(struct aws_allocator *allocator, void *ctx, enum aws_tls_hash_algorithm digest_alg) {
1084
1183
  (void)ctx;
1085
1184
  /* Reset PKCS#11 tokens, load library */
1086
1185
  CK_SLOT_ID created_slot = 0;
1087
1186
  CK_SESSION_HANDLE session = CK_INVALID_HANDLE;
1088
- s_pkcs11_tester_init_with_session_login(allocator, &created_slot, &session);
1187
+ s_pkcs11_tester_init_with_session_login(allocator, TOKEN_LABEL_RSA, &created_slot, &session);
1089
1188
 
1090
1189
  CK_OBJECT_HANDLE created_key = CK_INVALID_HANDLE;
1091
1190
  CK_OBJECT_HANDLE created_pub_key = CK_INVALID_HANDLE;
1092
- struct pkcs11_key_creation_params params = {
1093
- .key_label = DEFAULT_KEY_LABEL, .key_id = DEFAULT_KEY_ID, .key_length = 2048};
1094
- ASSERT_SUCCESS(s_pkcs11_create_key(&params, session, &created_key, &created_pub_key));
1191
+ ASSERT_SUCCESS(s_test_pkcs11_prepare_rsa_2048_sign(session, &created_key, &created_pub_key));
1095
1192
 
1096
1193
  struct aws_byte_cursor message_to_sign = aws_byte_cursor_from_c_str("ABCDEFGHIJKL");
1097
1194
  struct aws_byte_buf signature; /* initialized later */
@@ -1102,28 +1199,29 @@ static int s_test_pkcs11_sign(struct aws_allocator *allocator, void *ctx, int di
1102
1199
  s_pkcs11_tester.lib,
1103
1200
  session,
1104
1201
  created_key,
1105
- SUPPORTED_KEY_TYPE,
1202
+ CKK_RSA,
1106
1203
  message_to_sign,
1107
1204
  allocator,
1108
1205
  digest_alg,
1109
1206
  AWS_TLS_SIGNATURE_RSA,
1110
1207
  &signature));
1111
1208
 
1209
+ struct aws_byte_buf prefixed_input;
1112
1210
  /* There is no good way to validate without this, as we append this prefix internally before signing. */
1113
1211
  struct aws_byte_cursor prefix;
1114
1212
  ASSERT_SUCCESS(aws_get_prefix_to_rsa_sig(digest_alg, &prefix));
1115
1213
 
1116
- struct aws_byte_buf prefixed_input;
1117
1214
  aws_byte_buf_init(&prefixed_input, allocator, message_to_sign.len + prefix.len); /* cannot fail */
1118
1215
  aws_byte_buf_write(&prefixed_input, prefix.ptr, prefix.len);
1119
1216
  aws_byte_buf_write_from_whole_cursor(&prefixed_input, message_to_sign);
1120
1217
  struct aws_byte_cursor input_message_to_verify = aws_byte_cursor_from_buf(&prefixed_input);
1121
1218
 
1122
1219
  /* Verify the signature */
1123
- ASSERT_SUCCESS(s_pkcs11_verify_signature(&input_message_to_verify, &signature, session, created_pub_key));
1220
+ ASSERT_SUCCESS(
1221
+ s_pkcs11_verify_signature(&input_message_to_verify, &signature, session, created_pub_key, CKM_RSA_PKCS));
1124
1222
 
1125
- /* Assert that sign fails for non RSA key type */
1126
- CK_KEY_TYPE unsupported_key_type = CKK_EC;
1223
+ /* Assert that sign fails for invalid key type */
1224
+ CK_KEY_TYPE unsupported_key_type = CKK_GENERIC_SECRET;
1127
1225
  aws_byte_buf_clean_up(&signature);
1128
1226
  ASSERT_FAILS(aws_pkcs11_lib_sign(
1129
1227
  s_pkcs11_tester.lib,
@@ -1141,7 +1239,7 @@ static int s_test_pkcs11_sign(struct aws_allocator *allocator, void *ctx, int di
1141
1239
  s_pkcs11_tester.lib,
1142
1240
  CK_INVALID_HANDLE,
1143
1241
  created_key,
1144
- SUPPORTED_KEY_TYPE,
1242
+ CKK_RSA,
1145
1243
  message_to_sign,
1146
1244
  allocator,
1147
1245
  digest_alg,
@@ -1153,7 +1251,7 @@ static int s_test_pkcs11_sign(struct aws_allocator *allocator, void *ctx, int di
1153
1251
  s_pkcs11_tester.lib,
1154
1252
  session,
1155
1253
  CK_INVALID_HANDLE,
1156
- SUPPORTED_KEY_TYPE,
1254
+ CKK_RSA,
1157
1255
  message_to_sign,
1158
1256
  allocator,
1159
1257
  digest_alg,
@@ -1167,30 +1265,231 @@ static int s_test_pkcs11_sign(struct aws_allocator *allocator, void *ctx, int di
1167
1265
  return AWS_OP_SUCCESS;
1168
1266
  }
1169
1267
 
1170
- static int s_test_pkcs11_sign_sha1(struct aws_allocator *allocator, void *ctx) {
1171
- return s_test_pkcs11_sign(allocator, ctx, AWS_TLS_HASH_SHA1);
1268
+ static int s_test_pkcs11_sign_rsa_sha1(struct aws_allocator *allocator, void *ctx) {
1269
+ return s_test_pkcs11_sign_rsa(allocator, ctx, AWS_TLS_HASH_SHA1);
1270
+ }
1271
+ AWS_TEST_CASE(pkcs11_sign_rsa_sha1, s_test_pkcs11_sign_rsa_sha1)
1272
+
1273
+ static int s_test_pkcs11_sign_rsa_sha512(struct aws_allocator *allocator, void *ctx) {
1274
+ return s_test_pkcs11_sign_rsa(allocator, ctx, AWS_TLS_HASH_SHA512);
1275
+ }
1276
+ AWS_TEST_CASE(pkcs11_sign_rsa_sha512, s_test_pkcs11_sign_rsa_sha512)
1277
+
1278
+ static int s_test_pkcs11_sign_rsa_sha384(struct aws_allocator *allocator, void *ctx) {
1279
+ return s_test_pkcs11_sign_rsa(allocator, ctx, AWS_TLS_HASH_SHA384);
1172
1280
  }
1173
- AWS_TEST_CASE(pkcs11_sign_sha1, s_test_pkcs11_sign_sha1)
1281
+ AWS_TEST_CASE(pkcs11_sign_rsa_sha384, s_test_pkcs11_sign_rsa_sha384)
1174
1282
 
1175
- static int s_test_pkcs11_sign_sha512(struct aws_allocator *allocator, void *ctx) {
1176
- return s_test_pkcs11_sign(allocator, ctx, AWS_TLS_HASH_SHA512);
1283
+ static int s_test_pkcs11_sign_rsa_sha256(struct aws_allocator *allocator, void *ctx) {
1284
+ return s_test_pkcs11_sign_rsa(allocator, ctx, AWS_TLS_HASH_SHA256);
1177
1285
  }
1178
- AWS_TEST_CASE(pkcs11_sign_sha512, s_test_pkcs11_sign_sha512)
1286
+ AWS_TEST_CASE(pkcs11_sign_rsa_sha256, s_test_pkcs11_sign_rsa_sha256)
1179
1287
 
1180
- static int s_test_pkcs11_sign_sha384(struct aws_allocator *allocator, void *ctx) {
1181
- return s_test_pkcs11_sign(allocator, ctx, AWS_TLS_HASH_SHA384);
1288
+ static int s_test_pkcs11_sign_rsa_sha224(struct aws_allocator *allocator, void *ctx) {
1289
+ return s_test_pkcs11_sign_rsa(allocator, ctx, AWS_TLS_HASH_SHA224);
1182
1290
  }
1183
- AWS_TEST_CASE(pkcs11_sign_sha384, s_test_pkcs11_sign_sha384)
1291
+ AWS_TEST_CASE(pkcs11_sign_rsa_sha224, s_test_pkcs11_sign_rsa_sha224)
1184
1292
 
1185
- static int s_test_pkcs11_sign_sha256(struct aws_allocator *allocator, void *ctx) {
1186
- return s_test_pkcs11_sign(allocator, ctx, AWS_TLS_HASH_SHA256);
1293
+ static int s_verify_bigint(
1294
+ struct aws_allocator *allocator,
1295
+ uint8_t *ptr,
1296
+ size_t len_in,
1297
+ uint8_t *ptr_out,
1298
+ size_t len_out) {
1299
+ struct aws_byte_buf buffer;
1300
+ struct aws_byte_cursor src_array = aws_byte_cursor_from_array(ptr, len_in);
1301
+ aws_byte_buf_init(&buffer, allocator, len_in + 4);
1302
+ ASSERT_SUCCESS(aws_pkcs11_asn1_enc_ubigint(&buffer, src_array));
1303
+ ASSERT_INT_EQUALS(len_out, buffer.len);
1304
+ for (size_t i = 0; i < len_out; i++) {
1305
+ ASSERT_HEX_EQUALS(ptr_out[i], buffer.buffer[i], "Mismatch at position %zu", i);
1306
+ }
1307
+ aws_byte_buf_clean_up(&buffer);
1308
+ return AWS_OP_SUCCESS;
1187
1309
  }
1188
- AWS_TEST_CASE(pkcs11_sign_sha256, s_test_pkcs11_sign_sha256)
1189
1310
 
1190
- static int s_test_pkcs11_sign_sha224(struct aws_allocator *allocator, void *ctx) {
1191
- return s_test_pkcs11_sign(allocator, ctx, AWS_TLS_HASH_SHA224);
1311
+ static int s_test_pkcs11_asn1_bigint(struct aws_allocator *allocator, void *ctx) {
1312
+ (void)ctx;
1313
+ /*
1314
+ * ECDSA relies on this working correct, so test this first to avoid intermittent failures
1315
+ */
1316
+ uint8_t pos_int_1_in[4] = {0x12, 0x34, 0x56, 0x78};
1317
+ uint8_t pos_int_1_out[6] = {0x02, 0x04, 0x12, 0x34, 0x56, 0x78};
1318
+ ASSERT_SUCCESS(
1319
+ s_verify_bigint(allocator, pos_int_1_in, sizeof(pos_int_1_in), pos_int_1_out, sizeof(pos_int_1_out)));
1320
+ uint8_t pos_int_2_in[4] = {0x00, 0x34, 0x56, 0x78};
1321
+ uint8_t pos_int_2_out[5] = {0x02, 0x03, 0x34, 0x56, 0x78};
1322
+ ASSERT_SUCCESS(
1323
+ s_verify_bigint(allocator, pos_int_2_in, sizeof(pos_int_2_in), pos_int_2_out, sizeof(pos_int_2_out)));
1324
+ uint8_t pos_int_3_in[4] = {0x00, 0x00, 0x56, 0x78};
1325
+ uint8_t pos_int_3_out[4] = {0x02, 0x02, 0x56, 0x78};
1326
+ ASSERT_SUCCESS(
1327
+ s_verify_bigint(allocator, pos_int_3_in, sizeof(pos_int_3_in), pos_int_3_out, sizeof(pos_int_3_out)));
1328
+ uint8_t pos_int_4_in[4] = {0x00, 0x00, 0x00, 0x78};
1329
+ uint8_t pos_int_4_out[3] = {0x02, 0x01, 0x78};
1330
+ ASSERT_SUCCESS(
1331
+ s_verify_bigint(allocator, pos_int_4_in, sizeof(pos_int_4_in), pos_int_4_out, sizeof(pos_int_4_out)));
1332
+ uint8_t pos_int_5_in[4] = {0x00, 0x00, 0x00, 0x00};
1333
+ uint8_t pos_int_5_out[3] = {0x02, 0x01, 0x00};
1334
+ ASSERT_SUCCESS(
1335
+ s_verify_bigint(allocator, pos_int_5_in, sizeof(pos_int_5_in), pos_int_5_out, sizeof(pos_int_5_out)));
1336
+ uint8_t pos_int_6_in[1] = {0}; // actually we specify 0-length, but not all compilers support empty array
1337
+ uint8_t pos_int_6_out[3] = {0x02, 0x01, 0x00};
1338
+ ASSERT_SUCCESS(s_verify_bigint(allocator, pos_int_6_in, 0, pos_int_6_out, sizeof(pos_int_6_out)));
1339
+ uint8_t pos_int_7_in[4] = {0x00, 0x84, 0x56, 0x78};
1340
+ uint8_t pos_int_7_out[6] = {0x02, 0x04, 0x00, 0x84, 0x56, 0x78};
1341
+ ASSERT_SUCCESS(
1342
+ s_verify_bigint(allocator, pos_int_7_in, sizeof(pos_int_7_in), pos_int_7_out, sizeof(pos_int_7_out)));
1343
+ uint8_t pos_int_8_in[4] = {0x82, 0x34, 0x56, 0x78};
1344
+ uint8_t pos_int_8_out[7] = {0x02, 0x05, 0x00, 0x82, 0x34, 0x56, 0x78};
1345
+ ASSERT_SUCCESS(
1346
+ s_verify_bigint(allocator, pos_int_8_in, sizeof(pos_int_8_in), pos_int_8_out, sizeof(pos_int_8_out)));
1347
+
1348
+ return AWS_OP_SUCCESS;
1349
+ }
1350
+ AWS_TEST_CASE(pkcs11_asn1_bigint, s_test_pkcs11_asn1_bigint)
1351
+
1352
+ static int s_decode_asn1(struct aws_byte_cursor *src, uint8_t *identifier, struct aws_byte_cursor *split) {
1353
+ ASSERT_TRUE(src->len >= 2, "ASN1 structure too small for header, length=%u", src->len);
1354
+ *identifier = src->ptr[0];
1355
+ uint8_t small_len = src->ptr[1];
1356
+ src->ptr += 2;
1357
+ src->len -= 2;
1358
+ ASSERT_TRUE(small_len < 0x80, "ASN1 multi-byte length specified: %u", small_len);
1359
+ ASSERT_TRUE(small_len <= src->len, "ASN1 length too big: %u > %u", small_len, src->len);
1360
+ *split = aws_byte_cursor_from_array(src->ptr, small_len);
1361
+ src->ptr += small_len;
1362
+ src->len -= small_len;
1363
+ return AWS_OP_SUCCESS;
1364
+ }
1365
+
1366
+ static int s_write_bigint(struct aws_byte_buf *buf, struct aws_byte_cursor *num, size_t len) {
1367
+ if (num->len > len && num->len > 1 && num->ptr[0] == 0x00 && (num->ptr[1] & 0x80) != 0) {
1368
+ // only scenario we allow length to be bigger
1369
+ num->ptr++;
1370
+ num->len--;
1371
+ }
1372
+ ASSERT_TRUE(num->len <= len, "ASN1 number is too big: %u > %u", num->len, len);
1373
+ if (num->len < len) {
1374
+ uint8_t fill = num->ptr[0] & 0x80 ? 0xff : 0x00;
1375
+ while (len > num->len) {
1376
+ aws_byte_buf_write(buf, &fill, 1);
1377
+ len--;
1378
+ }
1379
+ }
1380
+ aws_byte_buf_write_from_whole_cursor(buf, *num);
1381
+ return AWS_OP_SUCCESS;
1192
1382
  }
1193
- AWS_TEST_CASE(pkcs11_sign_sha224, s_test_pkcs11_sign_sha224)
1383
+
1384
+ static int s_test_pkcs11_sign_ec(
1385
+ struct aws_allocator *allocator,
1386
+ void *ctx,
1387
+ int sig_len,
1388
+ int (*prepare)(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE *pri_key, CK_OBJECT_HANDLE *pub_key)) {
1389
+ (void)ctx;
1390
+ /* Reset PKCS#11 tokens, load library */
1391
+ CK_SLOT_ID created_slot = 0;
1392
+ CK_SESSION_HANDLE session = CK_INVALID_HANDLE;
1393
+ s_pkcs11_tester_init_with_session_login(allocator, TOKEN_LABEL_EC, &created_slot, &session);
1394
+
1395
+ CK_OBJECT_HANDLE created_key = CK_INVALID_HANDLE;
1396
+ CK_OBJECT_HANDLE created_pub_key = CK_INVALID_HANDLE;
1397
+ ASSERT_SUCCESS(prepare(session, &created_key, &created_pub_key));
1398
+
1399
+ struct aws_byte_cursor message_to_sign = aws_byte_cursor_from_c_str("ABCDEFGHIJKL");
1400
+ struct aws_byte_buf signature; /* initialized later */
1401
+ struct aws_byte_buf sig_verify; /* initialized later */
1402
+ AWS_ZERO_STRUCT(signature);
1403
+ AWS_ZERO_STRUCT(sig_verify);
1404
+
1405
+ /* Sign a message */
1406
+ ASSERT_SUCCESS(aws_pkcs11_lib_sign(
1407
+ s_pkcs11_tester.lib,
1408
+ session,
1409
+ created_key,
1410
+ CKK_EC,
1411
+ message_to_sign,
1412
+ allocator,
1413
+ AWS_TLS_HASH_UNKNOWN, // digest handled entirely by S2N
1414
+ AWS_TLS_SIGNATURE_ECDSA,
1415
+ &signature));
1416
+
1417
+ /*
1418
+ * Verify we have a structure of 2 ASN1 encoded integers
1419
+ */
1420
+ uint8_t identifier;
1421
+ struct aws_byte_cursor sig_curs = aws_byte_cursor_from_buf(&signature);
1422
+ struct aws_byte_cursor struct_body;
1423
+ ASSERT_SUCCESS(s_decode_asn1(&sig_curs, &identifier, &struct_body));
1424
+ ASSERT_HEX_EQUALS(0x30, identifier); // compound structure
1425
+ ASSERT_INT_EQUALS(sig_curs.len, 0);
1426
+ struct aws_byte_cursor r;
1427
+ struct aws_byte_cursor s;
1428
+ ASSERT_SUCCESS(s_decode_asn1(&struct_body, &identifier, &r));
1429
+ ASSERT_HEX_EQUALS(0x02, identifier); // integer
1430
+ ASSERT_SUCCESS(s_decode_asn1(&struct_body, &identifier, &s));
1431
+ ASSERT_HEX_EQUALS(0x02, identifier); // integer
1432
+ ASSERT_INT_EQUALS(struct_body.len, 0);
1433
+ // rewrite signature in format PKCS11 expects
1434
+ aws_byte_buf_init(&sig_verify, allocator, sig_len * 2);
1435
+ s_write_bigint(&sig_verify, &r, sig_len);
1436
+ s_write_bigint(&sig_verify, &s, sig_len);
1437
+ struct aws_byte_cursor message_to_verify = aws_byte_cursor_from_c_str("ABCDEFGHIJKL");
1438
+
1439
+ /* Verify the signature */
1440
+ ASSERT_SUCCESS(s_pkcs11_verify_signature(&message_to_verify, &sig_verify, session, created_pub_key, CKM_ECDSA));
1441
+
1442
+ aws_byte_buf_clean_up(&signature);
1443
+ aws_byte_buf_clean_up(&sig_verify);
1444
+
1445
+ /* Assert that sign fails for invalid key type */
1446
+ CK_KEY_TYPE unsupported_key_type = CKK_GENERIC_SECRET;
1447
+ ASSERT_FAILS(aws_pkcs11_lib_sign(
1448
+ s_pkcs11_tester.lib,
1449
+ session,
1450
+ created_key,
1451
+ unsupported_key_type,
1452
+ message_to_sign,
1453
+ allocator,
1454
+ AWS_TLS_HASH_UNKNOWN,
1455
+ AWS_TLS_SIGNATURE_ECDSA,
1456
+ &signature));
1457
+
1458
+ /* Invalid session handle should fail */
1459
+ ASSERT_FAILS(aws_pkcs11_lib_sign(
1460
+ s_pkcs11_tester.lib,
1461
+ CK_INVALID_HANDLE,
1462
+ created_key,
1463
+ CKK_EC,
1464
+ message_to_sign,
1465
+ allocator,
1466
+ AWS_TLS_HASH_UNKNOWN,
1467
+ AWS_TLS_SIGNATURE_ECDSA,
1468
+ &signature));
1469
+
1470
+ /* Invalid key handle should fail */
1471
+ ASSERT_FAILS(aws_pkcs11_lib_sign(
1472
+ s_pkcs11_tester.lib,
1473
+ session,
1474
+ CK_INVALID_HANDLE,
1475
+ CKK_EC,
1476
+ message_to_sign,
1477
+ allocator,
1478
+ AWS_TLS_HASH_UNKNOWN,
1479
+ AWS_TLS_SIGNATURE_ECDSA,
1480
+ &signature));
1481
+
1482
+ /* Clean up */
1483
+ aws_byte_buf_clean_up(&signature);
1484
+ aws_pkcs11_lib_close_session(s_pkcs11_tester.lib, session);
1485
+ s_pkcs11_tester_clean_up();
1486
+ return AWS_OP_SUCCESS;
1487
+ }
1488
+
1489
+ static int s_test_pkcs11_sign_ec_256(struct aws_allocator *allocator, void *ctx) {
1490
+ return s_test_pkcs11_sign_ec(allocator, ctx, 32, s_test_pkcs11_prepare_ec_256_sign);
1491
+ }
1492
+ AWS_TEST_CASE(pkcs11_sign_ec_256, s_test_pkcs11_sign_ec_256)
1194
1493
 
1195
1494
  #ifndef BYO_CRYPTO
1196
1495
 
@@ -1246,7 +1545,7 @@ static void s_on_tls_client_channel_setup(
1246
1545
  (void)user_data;
1247
1546
  AWS_LOGF_INFO(AWS_LS_IO_PKCS11, "TLS test client setup. error_code=%s", aws_error_name(error_code));
1248
1547
 
1249
- /* if negotiation succeds: shutdown channel nicely
1548
+ /* if negotiation succeeds: shutdown channel nicely
1250
1549
  * if negotiation fails: store error code and notify main thread */
1251
1550
  if (error_code == 0) {
1252
1551
  aws_channel_shutdown(channel, 0);
@@ -1325,14 +1624,18 @@ static void s_on_tls_server_channel_shutdown(
1325
1624
  }
1326
1625
 
1327
1626
  /* Connect a client client and server, where the client is using PKCS#11 for private key operations */
1328
- static int s_test_pkcs11_tls_negotiation_succeeds(struct aws_allocator *allocator, void *ctx) {
1329
- (void)ctx;
1627
+ static int s_test_pkcs11_tls_negotiation_succeeds_common(
1628
+ struct aws_allocator *allocator,
1629
+ const char *token_label,
1630
+ const char *p8key_path,
1631
+ const char *cert_path,
1632
+ const char *pkey_path) {
1330
1633
  ASSERT_SUCCESS(s_pkcs11_tester_init(allocator));
1331
1634
 
1332
- /* Create token with RSA key */
1635
+ /* Create token for provided key */
1333
1636
 
1334
1637
  CK_SLOT_ID slot = 0;
1335
- ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(TOKEN_LABEL, SO_PIN, USER_PIN, &slot));
1638
+ ASSERT_SUCCESS(s_pkcs11_softhsm_create_slot(token_label, SO_PIN, USER_PIN, &slot));
1336
1639
 
1337
1640
  aws_pkcs11_lib_release(s_pkcs11_tester.lib);
1338
1641
  s_pkcs11_tester.lib = NULL;
@@ -1340,7 +1643,7 @@ static int s_test_pkcs11_tls_negotiation_succeeds(struct aws_allocator *allocato
1340
1643
  /* use softhsm2-util to import key */
1341
1644
  ASSERT_SUCCESS(s_run_cmd(
1342
1645
  "softhsm2-util --import %s --module \"%s\" --slot %lu --label %s --id %s --pin %s",
1343
- "unittests.p8",
1646
+ p8key_path,
1344
1647
  aws_string_c_str(s_pkcs11_tester.shared_lib_path),
1345
1648
  slot,
1346
1649
  DEFAULT_KEY_LABEL,
@@ -1385,12 +1688,12 @@ static int s_test_pkcs11_tls_negotiation_succeeds(struct aws_allocator *allocato
1385
1688
  /* Set up a server that does mutual TLS. The server will not use PKCS#11 */
1386
1689
 
1387
1690
  struct aws_tls_ctx_options server_tls_opts;
1388
- ASSERT_SUCCESS(aws_tls_ctx_options_init_default_server_from_path(
1389
- &server_tls_opts, allocator, "unittests.crt", "unittests.key"));
1691
+ ASSERT_SUCCESS(
1692
+ aws_tls_ctx_options_init_default_server_from_path(&server_tls_opts, allocator, cert_path, pkey_path));
1390
1693
 
1391
1694
  /* trust the client's self-signed certificate */
1392
- ASSERT_SUCCESS(aws_tls_ctx_options_override_default_trust_store_from_path(
1393
- &server_tls_opts, NULL /*ca_path*/, "unittests.crt"));
1695
+ ASSERT_SUCCESS(
1696
+ aws_tls_ctx_options_override_default_trust_store_from_path(&server_tls_opts, NULL /*ca_path*/, cert_path));
1394
1697
 
1395
1698
  aws_tls_ctx_options_set_verify_peer(&server_tls_opts, true);
1396
1699
 
@@ -1424,21 +1727,20 @@ static int s_test_pkcs11_tls_negotiation_succeeds(struct aws_allocator *allocato
1424
1727
  # if 1 /* Toggle this to run without actually using PKCS#11. Useful for debugging this test. */
1425
1728
  struct aws_tls_ctx_pkcs11_options client_pkcs11_tls_opts = {
1426
1729
  .pkcs11_lib = s_pkcs11_tester.lib,
1427
- .token_label = aws_byte_cursor_from_c_str(TOKEN_LABEL),
1730
+ .token_label = aws_byte_cursor_from_c_str(token_label),
1428
1731
  .user_pin = aws_byte_cursor_from_c_str(USER_PIN),
1429
1732
  .private_key_object_label = aws_byte_cursor_from_c_str(DEFAULT_KEY_LABEL),
1430
- .cert_file_path = aws_byte_cursor_from_c_str("unittests.crt"),
1733
+ .cert_file_path = aws_byte_cursor_from_c_str(cert_path),
1431
1734
  };
1432
1735
  ASSERT_SUCCESS(
1433
1736
  aws_tls_ctx_options_init_client_mtls_with_pkcs11(&client_tls_opts, allocator, &client_pkcs11_tls_opts));
1434
1737
  # else
1435
- ASSERT_SUCCESS(
1436
- aws_tls_ctx_options_init_client_mtls_from_path(&client_tls_opts, allocator, "unittests.crt", "unittests.key"));
1738
+ ASSERT_SUCCESS(aws_tls_ctx_options_init_client_mtls_from_path(&client_tls_opts, allocator, cert_path, pkey_path));
1437
1739
  # endif
1438
1740
 
1439
1741
  /* trust the server's self-signed certificate */
1440
- ASSERT_SUCCESS(aws_tls_ctx_options_override_default_trust_store_from_path(
1441
- &client_tls_opts, NULL /*ca_path*/, "unittests.crt"));
1742
+ ASSERT_SUCCESS(
1743
+ aws_tls_ctx_options_override_default_trust_store_from_path(&client_tls_opts, NULL /*ca_path*/, cert_path));
1442
1744
 
1443
1745
  struct aws_tls_ctx *client_tls_ctx = aws_tls_client_ctx_new(allocator, &client_tls_opts);
1444
1746
  ASSERT_NOT_NULL(client_tls_ctx);
@@ -1517,5 +1819,22 @@ static int s_test_pkcs11_tls_negotiation_succeeds(struct aws_allocator *allocato
1517
1819
  s_pkcs11_tester_clean_up();
1518
1820
  return AWS_OP_SUCCESS;
1519
1821
  }
1520
- AWS_TEST_CASE(pkcs11_tls_negotiation_succeeds, s_test_pkcs11_tls_negotiation_succeeds)
1521
- #endif /* BYO_CRYPTO */
1822
+
1823
+ /* Connect a client and server, where the client is using PKCS#11 RSA certificate for private key operations */
1824
+ static int s_test_pkcs11_tls_rsa_negotiation_succeeds(struct aws_allocator *allocator, void *ctx) {
1825
+ (void)ctx;
1826
+
1827
+ return s_test_pkcs11_tls_negotiation_succeeds_common(
1828
+ allocator, TOKEN_LABEL_RSA, "unittests.p8", "unittests.crt", "unittests.key");
1829
+ }
1830
+ AWS_TEST_CASE(pkcs11_tls_rsa_negotiation_succeeds, s_test_pkcs11_tls_rsa_negotiation_succeeds)
1831
+
1832
+ /* Connect a client and server, where the client is using PKCS#11 EC certificate for private key operations */
1833
+ static int s_test_pkcs11_tls_ec_negotiation_succeeds(struct aws_allocator *allocator, void *ctx) {
1834
+ (void)ctx;
1835
+
1836
+ return s_test_pkcs11_tls_negotiation_succeeds_common(
1837
+ allocator, TOKEN_LABEL_EC, "ec_unittests.p8", "ec_unittests.crt", "ec_unittests.key");
1838
+ }
1839
+ AWS_TEST_CASE(pkcs11_tls_ec_negotiation_succeeds, s_test_pkcs11_tls_ec_negotiation_succeeds)
1840
+ #endif /* !BYO_CRYPTO */