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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/VERSION +1 -1
- data/aws-crt-ffi/CMakeLists.txt +49 -41
- data/aws-crt-ffi/crt/aws-c-auth/CMakeLists.txt +0 -10
- data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/credentials.h +3 -2
- data/aws-crt-ffi/crt/aws-c-auth/include/aws/auth/private/credentials_utils.h +4 -4
- data/aws-crt-ffi/crt/aws-c-auth/source/auth.c +1 -14
- data/aws-crt-ffi/crt/aws-c-auth/source/aws_imds_client.c +206 -68
- data/aws-crt-ffi/crt/aws-c-auth/source/aws_signing.c +5 -0
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_cached.c +6 -6
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_default_chain.c +16 -1
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_ecs.c +0 -1
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_process.c +0 -1
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_sts_web_identity.c +0 -1
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_provider_x509.c +10 -7
- data/aws-crt-ffi/crt/aws-c-auth/source/credentials_utils.c +35 -26
- data/aws-crt-ffi/crt/aws-c-auth/source/signable_chunk.c +3 -2
- data/aws-crt-ffi/crt/aws-c-auth/tests/CMakeLists.txt +3 -2
- data/aws-crt-ffi/crt/aws-c-auth/tests/aws_imds_client_test.c +1 -0
- data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_ecs_tests.c +3 -0
- data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_provider_process_tests.c +65 -16
- data/aws-crt-ffi/crt/aws-c-auth/tests/credentials_tests.c +125 -0
- data/aws-crt-ffi/crt/aws-c-auth/tests/sigv4_signing_tests.c +68 -46
- data/aws-crt-ffi/crt/aws-c-cal/CMakeLists.txt +8 -3
- data/aws-crt-ffi/crt/aws-c-cal/bin/run_x_platform_fuzz_corpus/main.c +9 -0
- data/aws-crt-ffi/crt/aws-c-cal/builder.json +11 -3
- data/aws-crt-ffi/crt/aws-c-cal/cmake/aws-c-cal-config.cmake +14 -5
- data/aws-crt-ffi/crt/aws-c-cal/source/darwin/securityframework_ecc.c +6 -6
- data/aws-crt-ffi/crt/aws-c-cal/source/windows/bcrypt_ecc.c +12 -12
- data/aws-crt-ffi/crt/aws-c-cal/tests/test_case_helper.h +14 -14
- data/aws-crt-ffi/crt/aws-c-common/CMakeLists.txt +21 -1
- data/aws-crt-ffi/crt/aws-c-common/README.md +8 -0
- data/aws-crt-ffi/crt/aws-c-common/cmake/AwsCFlags.cmake +20 -5
- data/aws-crt-ffi/crt/aws-c-common/cmake/AwsFeatureTests.cmake +7 -1
- data/aws-crt-ffi/crt/aws-c-common/format-check.sh +1 -1
- data/aws-crt-ffi/crt/aws-c-common/include/aws/common/byte_buf.h +14 -0
- data/aws-crt-ffi/crt/aws-c-common/include/aws/common/config.h.in +1 -0
- data/aws-crt-ffi/crt/{aws-c-auth/include/aws/auth → aws-c-common/include/aws/common}/external/cJSON.h +82 -74
- data/aws-crt-ffi/crt/aws-c-common/include/aws/common/json.h +335 -0
- data/aws-crt-ffi/crt/aws-c-common/include/aws/common/logging.h +1 -0
- data/aws-crt-ffi/crt/aws-c-common/include/aws/common/math.inl +2 -2
- data/aws-crt-ffi/crt/aws-c-common/include/aws/common/private/json_impl.h +22 -0
- data/aws-crt-ffi/crt/aws-c-common/include/aws/testing/aws_test_harness.h +2 -0
- data/aws-crt-ffi/crt/aws-c-common/source/byte_buf.c +36 -0
- data/aws-crt-ffi/crt/aws-c-common/source/common.c +5 -2
- data/aws-crt-ffi/crt/aws-c-common/source/external/cJSON.c +3113 -0
- data/aws-crt-ffi/crt/aws-c-common/source/file.c +9 -0
- data/aws-crt-ffi/crt/aws-c-common/source/json.c +348 -0
- data/aws-crt-ffi/crt/aws-c-common/source/logging.c +7 -2
- data/aws-crt-ffi/crt/aws-c-common/source/posix/system_info.c +8 -0
- data/aws-crt-ffi/crt/aws-c-common/source/ref_count.c +3 -1
- data/aws-crt-ffi/crt/aws-c-common/source/windows/file.c +47 -0
- data/aws-crt-ffi/crt/aws-c-common/source/windows/system_info.c +2 -1
- data/aws-crt-ffi/crt/aws-c-common/tests/CMakeLists.txt +5 -0
- data/aws-crt-ffi/crt/aws-c-common/tests/byte_buf_test.c +69 -0
- data/aws-crt-ffi/crt/aws-c-common/tests/json_test.c +134 -0
- data/aws-crt-ffi/crt/aws-c-common/tests/memtrace_test.c +6 -2
- data/aws-crt-ffi/crt/aws-c-event-stream/README.md +18 -35
- data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream.h +21 -2
- data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_client.h +14 -2
- data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/event_stream_rpc_server.h +13 -0
- data/aws-crt-ffi/crt/aws-c-event-stream/include/aws/event-stream/private/event_stream_rpc_priv.h +7 -7
- data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream.c +257 -141
- data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_channel_handler.c +1 -1
- data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_client.c +31 -8
- data/aws-crt-ffi/crt/aws-c-event-stream/source/event_stream_rpc_server.c +63 -10
- data/aws-crt-ffi/crt/aws-c-event-stream/tests/CMakeLists.txt +2 -0
- data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_client_connection_test.c +157 -106
- data/aws-crt-ffi/crt/aws-c-event-stream/tests/event_stream_rpc_server_connection_test.c +168 -1
- data/aws-crt-ffi/crt/aws-c-event-stream/tests/message_deserializer_test.c +4 -2
- data/aws-crt-ffi/crt/aws-c-http/CMakeLists.txt +1 -0
- data/aws-crt-ffi/crt/aws-c-http/README.md +8 -0
- data/aws-crt-ffi/crt/aws-c-http/bin/elasticurl/main.c +1 -1
- data/aws-crt-ffi/crt/aws-c-http/builder.json +4 -3
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection.h +8 -1
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/connection_manager.h +45 -1
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/http2_stream_manager.h +63 -12
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/connection_impl.h +2 -1
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_connection.h +20 -2
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_frames.h +1 -0
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/h2_stream.h +42 -13
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http2_stream_manager_impl.h +17 -0
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/http_impl.h +3 -0
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/random_access_set.h +10 -3
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/private/request_response_impl.h +3 -17
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/request_response.h +108 -4
- data/aws-crt-ffi/crt/aws-c-http/include/aws/http/statistics.h +22 -0
- data/aws-crt-ffi/crt/aws-c-http/source/connection.c +8 -3
- data/aws-crt-ffi/crt/aws-c-http/source/connection_manager.c +22 -3
- data/aws-crt-ffi/crt/aws-c-http/source/connection_monitor.c +32 -14
- data/aws-crt-ffi/crt/aws-c-http/source/h1_connection.c +14 -0
- data/aws-crt-ffi/crt/aws-c-http/source/h1_encoder.c +7 -4
- data/aws-crt-ffi/crt/aws-c-http/source/h2_connection.c +161 -45
- data/aws-crt-ffi/crt/aws-c-http/source/h2_decoder.c +37 -8
- data/aws-crt-ffi/crt/aws-c-http/source/h2_frames.c +13 -1
- data/aws-crt-ffi/crt/aws-c-http/source/h2_stream.c +345 -87
- data/aws-crt-ffi/crt/aws-c-http/source/hpack.c +3 -0
- data/aws-crt-ffi/crt/aws-c-http/source/http.c +3 -0
- data/aws-crt-ffi/crt/aws-c-http/source/http2_stream_manager.c +266 -39
- data/aws-crt-ffi/crt/aws-c-http/source/random_access_set.c +9 -3
- data/aws-crt-ffi/crt/aws-c-http/source/request_response.c +80 -20
- data/aws-crt-ffi/crt/aws-c-http/source/statistics.c +11 -0
- data/aws-crt-ffi/crt/aws-c-http/tests/CMakeLists.txt +28 -1
- data/aws-crt-ffi/crt/aws-c-http/tests/fuzz/fuzz_h2_decoder_correct.c +5 -3
- data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.c +133 -29
- data/aws-crt-ffi/crt/aws-c-http/tests/h2_test_helper.h +6 -0
- data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/README.md +40 -0
- data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/non_tls_server.py +56 -0
- data/aws-crt-ffi/crt/aws-c-http/tests/py_localhost/server.py +329 -0
- data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_manager.c +1 -1
- data/aws-crt-ffi/crt/aws-c-http/tests/test_connection_monitor.c +2 -2
- data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_client.c +47 -34
- data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_encoder.c +4 -4
- data/aws-crt-ffi/crt/aws-c-http/tests/test_h1_server.c +15 -12
- data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_client.c +582 -25
- data/aws-crt-ffi/crt/aws-c-http/tests/test_h2_encoder.c +3 -3
- data/aws-crt-ffi/crt/aws-c-http/tests/test_localhost_integ.c +530 -0
- data/aws-crt-ffi/crt/aws-c-http/tests/test_stream_manager.c +459 -67
- data/aws-crt-ffi/crt/aws-c-io/CMakeLists.txt +4 -0
- data/aws-crt-ffi/crt/aws-c-io/builder.json +3 -2
- data/aws-crt-ffi/crt/aws-c-io/include/aws/io/channel.h +21 -0
- data/aws-crt-ffi/crt/aws-c-io/include/aws/io/io.h +3 -0
- data/aws-crt-ffi/crt/aws-c-io/include/aws/io/socket.h +6 -0
- data/aws-crt-ffi/crt/aws-c-io/include/aws/io/stream.h +35 -5
- data/aws-crt-ffi/crt/aws-c-io/include/aws/io/tls_channel_handler.h +211 -15
- data/aws-crt-ffi/crt/aws-c-io/source/channel.c +56 -30
- data/aws-crt-ffi/crt/aws-c-io/source/darwin/secure_transport_tls_channel_handler.c +0 -24
- data/aws-crt-ffi/crt/aws-c-io/source/io.c +9 -0
- data/aws-crt-ffi/crt/aws-c-io/source/{pkcs11.c → pkcs11_lib.c} +162 -22
- data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_private.h +18 -20
- data/aws-crt-ffi/crt/aws-c-io/source/pkcs11_tls_op_handler.c +221 -0
- data/aws-crt-ffi/crt/aws-c-io/source/posix/socket.c +135 -81
- data/aws-crt-ffi/crt/aws-c-io/source/retry_strategy.c +12 -8
- data/aws-crt-ffi/crt/aws-c-io/source/s2n/s2n_tls_channel_handler.c +252 -215
- data/aws-crt-ffi/crt/aws-c-io/source/stream.c +65 -82
- data/aws-crt-ffi/crt/aws-c-io/source/tls_channel_handler.c +188 -57
- data/aws-crt-ffi/crt/aws-c-io/source/windows/iocp/socket.c +271 -256
- data/aws-crt-ffi/crt/aws-c-io/tests/CMakeLists.txt +21 -12
- data/aws-crt-ffi/crt/aws-c-io/tests/channel_test.c +32 -4
- data/aws-crt-ffi/crt/aws-c-io/tests/io_lib_test.c +37 -0
- data/aws-crt-ffi/crt/aws-c-io/tests/pkcs11_test.c +412 -93
- data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.crt +15 -0
- data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.key +5 -0
- data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p12 +0 -0
- data/aws-crt-ffi/crt/aws-c-io/tests/resources/ec_unittests.p8 +5 -0
- data/aws-crt-ffi/crt/aws-c-io/tests/resources/generateCerts.sh +24 -15
- data/aws-crt-ffi/crt/aws-c-io/tests/socket_test.c +72 -1
- data/aws-crt-ffi/crt/s2n/CMakeLists.txt +6 -1
- data/aws-crt-ffi/crt/s2n/bindings/rust/Cargo.toml +1 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/generate/src/main.rs +105 -82
- data/aws-crt-ffi/crt/s2n/bindings/rust/generate.sh +1 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/Cargo.toml +2 -2
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls/src/raw/config.rs +1 -1
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/Cargo.toml +1 -1
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/build.rs +84 -30
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-sys/src/lib.rs +4 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/Cargo.toml +21 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/cert.pem +14 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/certs/key.pem +8 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/client.rs +45 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/examples/server.rs +60 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/src/lib.rs +150 -0
- data/aws-crt-ffi/crt/s2n/bindings/rust/s2n-tls-tokio/tests/handshake.rs +51 -0
- data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.c +98 -77
- data/aws-crt-ffi/crt/s2n/crypto/s2n_drbg.h +10 -7
- data/aws-crt-ffi/crt/s2n/crypto/s2n_openssl.h +2 -0
- data/aws-crt-ffi/crt/s2n/error/s2n_errno.c +1 -1
- data/aws-crt-ffi/crt/s2n/error/s2n_errno.h +1 -0
- data/aws-crt-ffi/crt/s2n/s2n.mk +7 -0
- data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/repository.py +233 -0
- data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup-proof.py +8 -7
- data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/setup.py +17 -18
- data/aws-crt-ffi/crt/s2n/tests/cbmc/templates/scripts/util.py +41 -23
- data/aws-crt-ffi/crt/s2n/tests/fuzz/LD_PRELOAD/global_overrides.c +3 -3
- data/aws-crt-ffi/crt/s2n/tests/integration/s2n_client_endpoint_handshake_test.py +2 -2
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/Makefile +13 -42
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/README.md +6 -1
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/common.py +118 -53
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/configuration.py +108 -88
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/conftest.py +6 -3
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/constants.py +6 -4
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/fixtures.py +21 -12
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/global_flags.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/processes.py +62 -19
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/providers.py +304 -48
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_client_authentication.py +20 -11
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_cross_compatibility.py +41 -17
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_dynamic_record_sizes.py +6 -3
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_early_data.py +105 -48
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_external_psk.py +160 -76
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_fragmentation.py +59 -26
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_happy_path.py +42 -28
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_hello_retry_requests.py +33 -13
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_key_update.py +29 -11
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_ocsp.py +138 -0
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_pq_handshake.py +103 -36
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_session_resumption.py +52 -25
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_signature_algorithms.py +47 -21
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sni_match.py +13 -9
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_sslyze.py +88 -17
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_version_negotiation.py +71 -22
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/test_well_known_endpoints.py +4 -3
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/tox.ini +1 -0
- data/aws-crt-ffi/crt/s2n/tests/integrationv2/utils.py +50 -15
- data/aws-crt-ffi/crt/s2n/tests/litani/CHANGELOG +131 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/CONTRIBUTING.md +16 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/README.md +36 -14
- data/aws-crt-ffi/crt/s2n/tests/litani/THIRD-PARTY +205 -41
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/bin/build-html-doc +7 -7
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/configure +27 -23
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-add-job.scdoc +7 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-dump-run.scdoc +7 -5
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani-transform-jobs.scdoc +248 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/src/man/litani.scdoc +2 -2
- data/aws-crt-ffi/crt/s2n/tests/litani/doc/templates/index.jinja.html +4 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/README +12 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/original-run.sh +52 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/add-root-node/run-all.py +71 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/README +13 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-1.sh +34 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-2.sh +35 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-3.sh +34 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/no-standalone-transform/run-all.py +60 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/README.md +10 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/assumptions.html +42 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/file.dat +7 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/histogram.dat +7 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-1.sh +41 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-2.sh +47 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-3.sh +41 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/run-all.py +34 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib-table.py +40 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.plt +5 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/fib.py +32 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin-output.py +40 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.plt +5 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/scripts/sin.py +30 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/fib-table.jinja.html +45 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/examples/rich-output/templates/sin-output.jinja.html +30 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/add_job.py +55 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/graph.py +2 -2
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani.py +6 -1
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/litani_report.py +18 -21
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/ninja.py +2 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/run_printer.py +26 -7
- data/aws-crt-ffi/crt/s2n/tests/litani/lib/transform_jobs.py +84 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/litani +28 -33
- data/aws-crt-ffi/crt/s2n/tests/litani/script/release +220 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/templates/dashboard.jinja.html +78 -15
- data/aws-crt-ffi/crt/s2n/tests/litani/templates/pipeline.jinja.html +21 -5
- data/aws-crt-ffi/crt/s2n/tests/litani/test/README +15 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/run +56 -33
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/custom_stages.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/cwd.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/dump_run.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/graph_line_break.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/html_node.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/job_id_env.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/multiproc_dump_run.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_pool_serialize_graph.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ignored.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/no_timed_out_timeout_ok.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pipeline_order.py +53 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/pool_serialize_graph.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/single_pool.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_multi_shell.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_subprocess_shell.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ignored.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/timed_out_timeout_ok.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_delete_job.py +54 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_modify_job.py +46 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/transform_no_change_job.py +44 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/e2e/tests/zero_pool.py +1 -0
- data/aws-crt-ffi/crt/s2n/tests/litani/test/run +82 -12
- data/aws-crt-ffi/crt/s2n/tests/s2n_test.h +58 -33
- data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_key_schedule_testlib.c +18 -6
- data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_pq_kat_test_utils.c +4 -4
- data/aws-crt-ffi/crt/s2n/tests/testlib/s2n_testlib.h +2 -0
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_client_hello_retry_test.c +66 -2
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_connection_test.c +1 -1
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_drbg_test.c +34 -14
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_fork_generation_number_test.c +28 -5
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_mem_usage_test.c +6 -0
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_override_openssl_random_test.c +1 -1
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_random_test.c +60 -41
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_self_talk_broken_pipe_test.c +2 -2
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_handshake_early_data_test.c +3 -1
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_hybrid_shared_secret_test.c +9 -1
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_rfc8448_test.c +31 -130
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_key_schedule_test.c +2 -4
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_pq_handshake_test.c +11 -6
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_rfc8448_test.c +19 -21
- data/aws-crt-ffi/crt/s2n/tests/unit/s2n_tls13_secrets_test.c +109 -60
- data/aws-crt-ffi/crt/s2n/tls/s2n_config.c +1 -0
- data/aws-crt-ffi/crt/s2n/tls/s2n_config.h +1 -1
- data/aws-crt-ffi/crt/s2n/tls/s2n_connection.c +29 -24
- data/aws-crt-ffi/crt/s2n/tls/s2n_connection.h +5 -5
- data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_hashes.h +1 -7
- data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_io.c +2 -0
- data/aws-crt-ffi/crt/s2n/tls/s2n_handshake_transcript.c +0 -44
- data/aws-crt-ffi/crt/s2n/tls/s2n_internal.h +0 -1
- data/aws-crt-ffi/crt/s2n/tls/s2n_quic_support.h +1 -1
- data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_key_schedule.c +1 -2
- data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.c +84 -44
- data/aws-crt-ffi/crt/s2n/tls/s2n_tls13_secrets.h +3 -9
- data/aws-crt-ffi/crt/s2n/utils/s2n_blob.h +15 -8
- data/aws-crt-ffi/crt/s2n/utils/s2n_fork_detection.c +2 -6
- data/aws-crt-ffi/crt/s2n/utils/s2n_random.c +9 -9
- data/aws-crt-ffi/src/input_stream.c +32 -15
- data/ext/compile.rb +13 -5
- data/lib/aws-crt/platforms.rb +14 -5
- data/lib/aws-crt/string_blob.rb +3 -3
- metadata +61 -7
- data/aws-crt-ffi/crt/aws-c-auth/source/external/cJSON.c +0 -2987
- data/aws-crt-ffi/crt/aws-c-auth/tests/external/cJSON.c +0 -2986
- data/aws-crt-ffi/crt/aws-c-io/tests/error_test.c +0 -20
@@ -23,6 +23,13 @@
|
|
23
23
|
/*
|
24
24
|
* DER encoded DigestInfo value to be prefixed to the hash, used for RSA signing
|
25
25
|
* See https://tools.ietf.org/html/rfc3447#page-43
|
26
|
+
* (Notes to help understand what's going on here with DER encoding)
|
27
|
+
* 0x30 nn - Sequence of tags, nn bytes, including hash, nn = mm+jj+4 (PKCS11 DigestInfo)
|
28
|
+
* 0x30 mm - Subsequence of tags, mm bytes (ii+4) (PKCS11
|
29
|
+
* 0x06 ii - OID encoding, ii bytes, see X.680 - this identifies the hash algorithm
|
30
|
+
* 0x05 00 - NULL
|
31
|
+
* 0x04 jj - OCTET, nn = mm + jj + 4
|
32
|
+
* Digest (nn - mm - 4 bytes)
|
26
33
|
*/
|
27
34
|
static const uint8_t SHA1_PREFIX_TO_RSA_SIG[] = { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
|
28
35
|
static const uint8_t SHA256_PREFIX_TO_RSA_SIG[] = { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 };
|
@@ -31,28 +38,6 @@ static const uint8_t SHA512_PREFIX_TO_RSA_SIG[] = { 0x30, 0x51, 0x30, 0x0d, 0x06
|
|
31
38
|
static const uint8_t SHA224_PREFIX_TO_RSA_SIG[] = { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c };
|
32
39
|
/* clang-format on */
|
33
40
|
|
34
|
-
const char *aws_tls_hash_algorithm_str(enum aws_tls_hash_algorithm hash) {
|
35
|
-
/* clang-format off */
|
36
|
-
switch (hash) {
|
37
|
-
case (AWS_TLS_HASH_SHA1): return "SHA1";
|
38
|
-
case (AWS_TLS_HASH_SHA224): return "SHA224";
|
39
|
-
case (AWS_TLS_HASH_SHA256): return "SHA256";
|
40
|
-
case (AWS_TLS_HASH_SHA384): return "SHA384";
|
41
|
-
case (AWS_TLS_HASH_SHA512): return "SHA512";
|
42
|
-
default: return "<UNKNOWN HASH ALGORITHM>";
|
43
|
-
}
|
44
|
-
/* clang-format on */
|
45
|
-
}
|
46
|
-
|
47
|
-
const char *aws_tls_signature_algorithm_str(enum aws_tls_signature_algorithm signature) {
|
48
|
-
/* clang-format off */
|
49
|
-
switch (signature) {
|
50
|
-
case (AWS_TLS_SIGNATURE_RSA): return "RSA";
|
51
|
-
default: return "<UNKNOWN SIGNATURE ALGORITHM>";
|
52
|
-
}
|
53
|
-
/* clang-format on */
|
54
|
-
}
|
55
|
-
|
56
41
|
/* Return c-string for PKCS#11 CKR_* contants. */
|
57
42
|
const char *aws_pkcs11_ckr_str(CK_RV rv) {
|
58
43
|
/* clang-format off */
|
@@ -945,6 +930,7 @@ int aws_pkcs11_lib_find_private_key(
|
|
945
930
|
|
946
931
|
switch (key_type) {
|
947
932
|
case CKK_RSA:
|
933
|
+
case CKK_EC:
|
948
934
|
break;
|
949
935
|
default:
|
950
936
|
AWS_LOGF_ERROR(
|
@@ -998,6 +984,7 @@ int aws_pkcs11_lib_decrypt(
|
|
998
984
|
CK_MECHANISM mechanism;
|
999
985
|
AWS_ZERO_STRUCT(mechanism);
|
1000
986
|
|
987
|
+
/* Note, CKK_EC is not expected to enter into this code path */
|
1001
988
|
switch (key_type) {
|
1002
989
|
case CKK_RSA:
|
1003
990
|
mechanism.mechanism = CKM_RSA_PKCS;
|
@@ -1177,6 +1164,149 @@ clean_up:
|
|
1177
1164
|
return success ? AWS_OP_SUCCESS : AWS_OP_ERR;
|
1178
1165
|
}
|
1179
1166
|
|
1167
|
+
/*
|
1168
|
+
* Basic ASN.1 (DER) encoding of header -- sufficient for ECDSA
|
1169
|
+
*/
|
1170
|
+
static int s_asn1_enc_prefix(struct aws_byte_buf *buffer, uint8_t identifier, size_t length) {
|
1171
|
+
if (((identifier & 0x1f) == 0x1f) || (length > 0x7f)) {
|
1172
|
+
AWS_LOGF_ERROR(AWS_LS_IO_PKCS11, "Unable to encode ASN.1 (DER) header 0x%02x %zu", identifier, length);
|
1173
|
+
return aws_raise_error(AWS_ERROR_PKCS11_ENCODING_ERROR);
|
1174
|
+
}
|
1175
|
+
uint8_t head[2];
|
1176
|
+
head[0] = identifier;
|
1177
|
+
head[1] = (uint8_t)length;
|
1178
|
+
if (!aws_byte_buf_write(buffer, head, sizeof(head))) {
|
1179
|
+
AWS_LOGF_ERROR(
|
1180
|
+
AWS_LS_IO_PKCS11, "Insufficient buffer to encode ASN.1 (DER) header 0x%02x %zu", identifier, length);
|
1181
|
+
return aws_raise_error(AWS_ERROR_PKCS11_ENCODING_ERROR);
|
1182
|
+
}
|
1183
|
+
return AWS_OP_SUCCESS;
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
/*
|
1187
|
+
* Basic ASN.1 (DER) encoding of an unsigned big number -- sufficient for ECDSA. Note that this implementation
|
1188
|
+
* may reduce the number of integer bytes down to 1 (removing leading zero bytes), or conversely increase by
|
1189
|
+
* one extra byte to ensure the unsigned integer is unambiguously encoded.
|
1190
|
+
*/
|
1191
|
+
int aws_pkcs11_asn1_enc_ubigint(struct aws_byte_buf *const buffer, struct aws_byte_cursor bigint) {
|
1192
|
+
|
1193
|
+
// trim out all leading zero's
|
1194
|
+
while (bigint.len > 0 && bigint.ptr[0] == 0) {
|
1195
|
+
aws_byte_cursor_advance(&bigint, 1);
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
// If the most significant bit is a '1', prefix with a zero-byte to prevent misinterpreting number as negative.
|
1199
|
+
// If the big integer value was zero, length will be zero, replace with zero-byte using the same approach.
|
1200
|
+
bool add_leading_zero = bigint.len == 0 || (bigint.ptr[0] & 0x80) != 0;
|
1201
|
+
size_t actual_len = bigint.len + (add_leading_zero ? 1 : 0);
|
1202
|
+
|
1203
|
+
// header - indicate integer of given length (including any prefix zero)
|
1204
|
+
bool success = s_asn1_enc_prefix(buffer, 0x02, actual_len) == AWS_OP_SUCCESS;
|
1205
|
+
if (add_leading_zero) {
|
1206
|
+
success = success && aws_byte_buf_write_u8(buffer, 0);
|
1207
|
+
}
|
1208
|
+
// write rest of number
|
1209
|
+
success = success && aws_byte_buf_write_from_whole_cursor(buffer, bigint);
|
1210
|
+
if (success) {
|
1211
|
+
return AWS_OP_SUCCESS;
|
1212
|
+
} else {
|
1213
|
+
AWS_LOGF_ERROR(
|
1214
|
+
AWS_LS_IO_PKCS11, "Insufficient buffer to ASN.1 (DER) encode big integer of length %zu", actual_len);
|
1215
|
+
return aws_raise_error(AWS_ERROR_PKCS11_ENCODING_ERROR);
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
static int s_pkcs11_sign_ecdsa(
|
1220
|
+
struct aws_pkcs11_lib *pkcs11_lib,
|
1221
|
+
CK_SESSION_HANDLE session_handle,
|
1222
|
+
CK_OBJECT_HANDLE key_handle,
|
1223
|
+
struct aws_byte_cursor digest_data,
|
1224
|
+
struct aws_allocator *allocator,
|
1225
|
+
enum aws_tls_signature_algorithm signature_alg,
|
1226
|
+
struct aws_byte_buf *out_signature) {
|
1227
|
+
|
1228
|
+
struct aws_byte_buf part_signature;
|
1229
|
+
struct aws_byte_buf r_part;
|
1230
|
+
struct aws_byte_buf s_part;
|
1231
|
+
AWS_ZERO_STRUCT(part_signature);
|
1232
|
+
AWS_ZERO_STRUCT(r_part);
|
1233
|
+
AWS_ZERO_STRUCT(s_part);
|
1234
|
+
|
1235
|
+
if (signature_alg != AWS_TLS_SIGNATURE_ECDSA) {
|
1236
|
+
AWS_LOGF_ERROR(
|
1237
|
+
AWS_LS_IO_PKCS11,
|
1238
|
+
"id=%p session=%lu: Signature algorithm '%s' is currently unsupported for PKCS#11 EC keys. "
|
1239
|
+
"Supported algorithms are: ECDSA",
|
1240
|
+
(void *)pkcs11_lib,
|
1241
|
+
session_handle,
|
1242
|
+
aws_tls_signature_algorithm_str(signature_alg));
|
1243
|
+
return aws_raise_error(AWS_IO_TLS_SIGNATURE_ALGORITHM_UNSUPPORTED);
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
bool success = false;
|
1247
|
+
|
1248
|
+
/* ECDSA signing consists of DER-encoding of "r" and "s" parameters. C_Sign returns the two
|
1249
|
+
* integers as big numbers in big-endian format, so translation is required.
|
1250
|
+
*/
|
1251
|
+
CK_MECHANISM mechanism = {.mechanism = CKM_ECDSA};
|
1252
|
+
|
1253
|
+
if (s_pkcs11_sign_helper(
|
1254
|
+
pkcs11_lib, session_handle, key_handle, mechanism, digest_data, allocator, &part_signature) !=
|
1255
|
+
AWS_OP_SUCCESS) {
|
1256
|
+
goto error;
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
/* PKCS11 library returns these parameters as two big unsigned integer numbers of exactly the same length. The
|
1260
|
+
* numbers need to be ASN.1/DER encoded (variable length). In addition to the header, space is needed to allow for
|
1261
|
+
* an occasional extra 0x00 prefix byte to ensure integer is encoded and interpreted as unsigned.
|
1262
|
+
*/
|
1263
|
+
if (part_signature.len == 0 || (part_signature.len & 1) != 0) {
|
1264
|
+
/* This should never happen, we would fail anyway, but making it explicit and fail early */
|
1265
|
+
AWS_LOGF_ERROR(
|
1266
|
+
AWS_LS_IO_PKCS11,
|
1267
|
+
"PKCS11 library returned an invalid length, unable to interpret ECDSA signature to encode correctly.");
|
1268
|
+
return aws_raise_error(AWS_ERROR_PKCS11_ENCODING_ERROR);
|
1269
|
+
goto error;
|
1270
|
+
}
|
1271
|
+
size_t num_bytes = part_signature.len / 2;
|
1272
|
+
aws_byte_buf_init(&r_part, allocator, num_bytes + 4);
|
1273
|
+
aws_byte_buf_init(&s_part, allocator, num_bytes + 4);
|
1274
|
+
|
1275
|
+
if (aws_pkcs11_asn1_enc_ubigint(&r_part, aws_byte_cursor_from_array(part_signature.buffer, num_bytes)) !=
|
1276
|
+
AWS_OP_SUCCESS) {
|
1277
|
+
goto error;
|
1278
|
+
}
|
1279
|
+
if (aws_pkcs11_asn1_enc_ubigint(
|
1280
|
+
&s_part, aws_byte_cursor_from_array(part_signature.buffer + num_bytes, num_bytes)) != AWS_OP_SUCCESS) {
|
1281
|
+
goto error;
|
1282
|
+
}
|
1283
|
+
size_t pair_len = r_part.len + s_part.len;
|
1284
|
+
aws_byte_buf_init(out_signature, allocator, pair_len + 2); // inc header
|
1285
|
+
if (s_asn1_enc_prefix(out_signature, 0x30, pair_len) != AWS_OP_SUCCESS) {
|
1286
|
+
goto error;
|
1287
|
+
}
|
1288
|
+
if (!aws_byte_buf_write_from_whole_buffer(out_signature, r_part)) {
|
1289
|
+
AWS_LOGF_ERROR(AWS_LS_IO_PKCS11, "Insufficient buffer to ASN.1 (DER) encode ECDSA signature R-part.");
|
1290
|
+
return aws_raise_error(AWS_ERROR_PKCS11_ENCODING_ERROR);
|
1291
|
+
goto error;
|
1292
|
+
}
|
1293
|
+
if (!aws_byte_buf_write_from_whole_buffer(out_signature, s_part)) {
|
1294
|
+
AWS_LOGF_ERROR(AWS_LS_IO_PKCS11, "Insufficient buffer to ASN.1 (DER) encode ECDSA signature S-part.");
|
1295
|
+
return aws_raise_error(AWS_ERROR_PKCS11_ENCODING_ERROR);
|
1296
|
+
goto error;
|
1297
|
+
}
|
1298
|
+
success = true;
|
1299
|
+
goto clean_up;
|
1300
|
+
|
1301
|
+
error:
|
1302
|
+
aws_byte_buf_clean_up(out_signature);
|
1303
|
+
clean_up:
|
1304
|
+
aws_byte_buf_clean_up(&part_signature);
|
1305
|
+
aws_byte_buf_clean_up(&r_part);
|
1306
|
+
aws_byte_buf_clean_up(&s_part);
|
1307
|
+
return success ? AWS_OP_SUCCESS : AWS_OP_ERR;
|
1308
|
+
}
|
1309
|
+
|
1180
1310
|
int aws_pkcs11_lib_sign(
|
1181
1311
|
struct aws_pkcs11_lib *pkcs11_lib,
|
1182
1312
|
CK_SESSION_HANDLE session_handle,
|
@@ -1202,6 +1332,16 @@ int aws_pkcs11_lib_sign(
|
|
1202
1332
|
digest_alg,
|
1203
1333
|
signature_alg,
|
1204
1334
|
out_signature);
|
1335
|
+
case CKK_ECDSA:
|
1336
|
+
return s_pkcs11_sign_ecdsa(
|
1337
|
+
pkcs11_lib,
|
1338
|
+
session_handle,
|
1339
|
+
key_handle,
|
1340
|
+
digest_data,
|
1341
|
+
allocator,
|
1342
|
+
// not digest_alg -- need to check this
|
1343
|
+
signature_alg,
|
1344
|
+
out_signature);
|
1205
1345
|
default:
|
1206
1346
|
return aws_raise_error(AWS_ERROR_PKCS11_KEY_TYPE_UNSUPPORTED);
|
1207
1347
|
}
|
@@ -5,7 +5,7 @@
|
|
5
5
|
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
6
6
|
* SPDX-License-Identifier: Apache-2.0.
|
7
7
|
*/
|
8
|
-
#include <aws/io/
|
8
|
+
#include <aws/io/tls_channel_handler.h>
|
9
9
|
|
10
10
|
/* These defines must exist before the official PKCS#11 headers are included */
|
11
11
|
#define CK_PTR *
|
@@ -28,23 +28,9 @@
|
|
28
28
|
*/
|
29
29
|
|
30
30
|
struct aws_pkcs11_lib;
|
31
|
+
struct aws_pkcs11_tls_key_handler;
|
31
32
|
struct aws_string;
|
32
33
|
|
33
|
-
enum aws_tls_hash_algorithm {
|
34
|
-
AWS_TLS_HASH_UNKNOWN = -1,
|
35
|
-
AWS_TLS_HASH_SHA1,
|
36
|
-
AWS_TLS_HASH_SHA224,
|
37
|
-
AWS_TLS_HASH_SHA256,
|
38
|
-
AWS_TLS_HASH_SHA384,
|
39
|
-
AWS_TLS_HASH_SHA512,
|
40
|
-
};
|
41
|
-
|
42
|
-
enum aws_tls_signature_algorithm {
|
43
|
-
AWS_TLS_SIGNATURE_UNKNOWN = -1,
|
44
|
-
AWS_TLS_SIGNATURE_RSA,
|
45
|
-
/* TODO: add support for additional algorithms (ECDSA) */
|
46
|
-
};
|
47
|
-
|
48
34
|
AWS_EXTERN_C_BEGIN
|
49
35
|
|
50
36
|
/**
|
@@ -144,16 +130,28 @@ AWS_IO_API
|
|
144
130
|
int aws_get_prefix_to_rsa_sig(enum aws_tls_hash_algorithm digest_alg, struct aws_byte_cursor *out_prefix);
|
145
131
|
|
146
132
|
/**
|
147
|
-
*
|
133
|
+
* ASN.1 DER encode a big unsigned integer. Note that the source integer may be zero padded. It may also have
|
134
|
+
* most significant bit set. The encoded format is canonical and unambiguous - that is, most significant
|
135
|
+
* bit is never set.
|
148
136
|
*/
|
149
137
|
AWS_IO_API
|
150
|
-
|
138
|
+
int aws_pkcs11_asn1_enc_ubigint(struct aws_byte_buf *const buffer, struct aws_byte_cursor bigint);
|
151
139
|
|
152
140
|
/**
|
153
|
-
*
|
141
|
+
* Creates a new PKCS11 TLS operation handler with an associated aws_custom_key_op_handler
|
142
|
+
* with a reference count set to 1.
|
143
|
+
*
|
144
|
+
* The PKCS11 TLS operation handler will automatically be destroyed when the reference count reaches zero
|
145
|
+
* on the aws_custom_key_op_handler.
|
154
146
|
*/
|
155
147
|
AWS_IO_API
|
156
|
-
|
148
|
+
struct aws_custom_key_op_handler *aws_pkcs11_tls_op_handler_new(
|
149
|
+
struct aws_allocator *allocator,
|
150
|
+
struct aws_pkcs11_lib *pkcs11_lib,
|
151
|
+
const struct aws_byte_cursor *user_pin,
|
152
|
+
const struct aws_byte_cursor *match_token_label,
|
153
|
+
const struct aws_byte_cursor *match_private_key_label,
|
154
|
+
const uint64_t *match_slot_id);
|
157
155
|
|
158
156
|
AWS_EXTERN_C_END
|
159
157
|
#endif /* AWS_IO_PKCS11_PRIVATE_H */
|
@@ -0,0 +1,221 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3
|
+
* SPDX-License-Identifier: Apache-2.0.
|
4
|
+
*/
|
5
|
+
#include <aws/io/pkcs11.h>
|
6
|
+
|
7
|
+
#include "pkcs11_private.h"
|
8
|
+
|
9
|
+
#include <aws/common/mutex.h>
|
10
|
+
#include <aws/common/string.h>
|
11
|
+
#include <aws/io/logging.h>
|
12
|
+
|
13
|
+
struct aws_pkcs11_tls_op_handler {
|
14
|
+
/* The custom key operation handler needed for the callbacks */
|
15
|
+
struct aws_custom_key_op_handler base;
|
16
|
+
|
17
|
+
struct aws_allocator *alloc;
|
18
|
+
struct aws_pkcs11_lib *lib;
|
19
|
+
|
20
|
+
/* Use a single PKCS#11 session for all TLS connections on an aws_tls_ctx.
|
21
|
+
* We do this because PKCS#11 tokens may only support a
|
22
|
+
* limited number of sessions (PKCS11-UG-v2.40 section 2.6.7).
|
23
|
+
* If this one shared session turns out to be a severe bottleneck,
|
24
|
+
* we could look into other setups (ex: put session on its own thread,
|
25
|
+
* 1 session per event-loop, 1 session per connection, etc).
|
26
|
+
*
|
27
|
+
* The lock must be held while performing session operations.
|
28
|
+
* Otherwise, it would not be safe for multiple threads to share a
|
29
|
+
* session (PKCS11-UG-v2.40 section 2.6.7). The lock isn't needed for
|
30
|
+
* setup and teardown though, since we ensure nothing parallel is going
|
31
|
+
* on at these times */
|
32
|
+
struct aws_mutex session_lock;
|
33
|
+
CK_SESSION_HANDLE session_handle;
|
34
|
+
CK_OBJECT_HANDLE private_key_handle;
|
35
|
+
CK_KEY_TYPE private_key_type;
|
36
|
+
};
|
37
|
+
|
38
|
+
static void s_aws_custom_key_op_handler_destroy(struct aws_custom_key_op_handler *key_op_handler) {
|
39
|
+
|
40
|
+
struct aws_pkcs11_tls_op_handler *handler = (struct aws_pkcs11_tls_op_handler *)key_op_handler->impl;
|
41
|
+
|
42
|
+
if (handler->session_handle != 0) {
|
43
|
+
aws_pkcs11_lib_close_session(handler->lib, handler->session_handle);
|
44
|
+
}
|
45
|
+
aws_mutex_clean_up(&handler->session_lock);
|
46
|
+
aws_pkcs11_lib_release(handler->lib);
|
47
|
+
|
48
|
+
aws_mem_release(handler->alloc, handler);
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Performs the PKCS11 TLS private key operation. This is called automatically when performing a mutual TLS handshake.
|
53
|
+
*/
|
54
|
+
void s_aws_pkcs11_tls_op_handler_do_operation(
|
55
|
+
struct aws_custom_key_op_handler *handler,
|
56
|
+
struct aws_tls_key_operation *operation) {
|
57
|
+
|
58
|
+
struct aws_pkcs11_tls_op_handler *pkcs11_handler = (struct aws_pkcs11_tls_op_handler *)handler->impl;
|
59
|
+
struct aws_byte_buf output_buf; /* initialized later */
|
60
|
+
AWS_ZERO_STRUCT(output_buf);
|
61
|
+
|
62
|
+
/*********** BEGIN CRITICAL SECTION ***********/
|
63
|
+
aws_mutex_lock(&pkcs11_handler->session_lock);
|
64
|
+
bool success_while_locked = false;
|
65
|
+
|
66
|
+
switch (aws_tls_key_operation_get_type(operation)) {
|
67
|
+
case AWS_TLS_KEY_OPERATION_DECRYPT:
|
68
|
+
if (aws_pkcs11_lib_decrypt(
|
69
|
+
pkcs11_handler->lib,
|
70
|
+
pkcs11_handler->session_handle,
|
71
|
+
pkcs11_handler->private_key_handle,
|
72
|
+
pkcs11_handler->private_key_type,
|
73
|
+
aws_tls_key_operation_get_input(operation),
|
74
|
+
pkcs11_handler->alloc,
|
75
|
+
&output_buf)) {
|
76
|
+
|
77
|
+
goto unlock;
|
78
|
+
}
|
79
|
+
break;
|
80
|
+
|
81
|
+
case AWS_TLS_KEY_OPERATION_SIGN:
|
82
|
+
if (aws_pkcs11_lib_sign(
|
83
|
+
pkcs11_handler->lib,
|
84
|
+
pkcs11_handler->session_handle,
|
85
|
+
pkcs11_handler->private_key_handle,
|
86
|
+
pkcs11_handler->private_key_type,
|
87
|
+
aws_tls_key_operation_get_input(operation),
|
88
|
+
pkcs11_handler->alloc,
|
89
|
+
aws_tls_key_operation_get_digest_algorithm(operation),
|
90
|
+
aws_tls_key_operation_get_signature_algorithm(operation),
|
91
|
+
&output_buf)) {
|
92
|
+
|
93
|
+
goto unlock;
|
94
|
+
}
|
95
|
+
break;
|
96
|
+
|
97
|
+
default:
|
98
|
+
AWS_LOGF_ERROR(
|
99
|
+
AWS_LS_IO_PKCS11,
|
100
|
+
"PKCS11 Handler %p: Unknown TLS key operation with value of %u",
|
101
|
+
(void *)handler,
|
102
|
+
aws_tls_key_operation_get_type(operation));
|
103
|
+
aws_raise_error(AWS_ERROR_INVALID_STATE);
|
104
|
+
goto unlock;
|
105
|
+
}
|
106
|
+
|
107
|
+
success_while_locked = true;
|
108
|
+
unlock:
|
109
|
+
aws_mutex_unlock(&pkcs11_handler->session_lock);
|
110
|
+
/*********** END CRITICAL SECTION ***********/
|
111
|
+
|
112
|
+
if (success_while_locked) {
|
113
|
+
aws_tls_key_operation_complete(operation, aws_byte_cursor_from_buf(&output_buf));
|
114
|
+
} else {
|
115
|
+
aws_tls_key_operation_complete_with_error(operation, aws_last_error());
|
116
|
+
}
|
117
|
+
|
118
|
+
aws_byte_buf_clean_up(&output_buf);
|
119
|
+
}
|
120
|
+
|
121
|
+
static struct aws_custom_key_op_handler_vtable s_aws_custom_key_op_handler_vtable = {
|
122
|
+
.on_key_operation = s_aws_pkcs11_tls_op_handler_do_operation,
|
123
|
+
};
|
124
|
+
|
125
|
+
struct aws_custom_key_op_handler *aws_pkcs11_tls_op_handler_new(
|
126
|
+
struct aws_allocator *allocator,
|
127
|
+
struct aws_pkcs11_lib *pkcs11_lib,
|
128
|
+
const struct aws_byte_cursor *user_pin,
|
129
|
+
const struct aws_byte_cursor *match_token_label,
|
130
|
+
const struct aws_byte_cursor *match_private_key_label,
|
131
|
+
const uint64_t *match_slot_id) {
|
132
|
+
|
133
|
+
bool success = false;
|
134
|
+
|
135
|
+
struct aws_pkcs11_tls_op_handler *pkcs11_handler =
|
136
|
+
aws_mem_calloc(allocator, 1, sizeof(struct aws_pkcs11_tls_op_handler));
|
137
|
+
|
138
|
+
// Optional data
|
139
|
+
struct aws_string *pkcs_user_pin = NULL;
|
140
|
+
struct aws_string *pkcs_token_label = NULL;
|
141
|
+
struct aws_string *pkcs_private_key_object_label = NULL;
|
142
|
+
|
143
|
+
aws_ref_count_init(
|
144
|
+
&pkcs11_handler->base.ref_count,
|
145
|
+
&pkcs11_handler->base,
|
146
|
+
(aws_simple_completion_callback *)s_aws_custom_key_op_handler_destroy);
|
147
|
+
|
148
|
+
pkcs11_handler->base.impl = (void *)pkcs11_handler;
|
149
|
+
pkcs11_handler->base.vtable = &s_aws_custom_key_op_handler_vtable;
|
150
|
+
|
151
|
+
pkcs11_handler->alloc = allocator;
|
152
|
+
|
153
|
+
/* pkcs11_lib is required */
|
154
|
+
if (pkcs11_lib == NULL) {
|
155
|
+
aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
|
156
|
+
AWS_LOGF_ERROR(AWS_LS_IO_PKCS11, "PKCS11 Handler %p new: PKCS11 library is null", (void *)pkcs11_handler);
|
157
|
+
goto done;
|
158
|
+
}
|
159
|
+
pkcs11_handler->lib = aws_pkcs11_lib_acquire(pkcs11_lib); /* cannot fail */
|
160
|
+
aws_mutex_init(&pkcs11_handler->session_lock);
|
161
|
+
|
162
|
+
/* user_pin is optional */
|
163
|
+
if (user_pin->ptr != NULL) {
|
164
|
+
pkcs_user_pin = aws_string_new_from_cursor(allocator, user_pin);
|
165
|
+
}
|
166
|
+
|
167
|
+
/* token_label is optional */
|
168
|
+
if (match_token_label->ptr != NULL) {
|
169
|
+
pkcs_token_label = aws_string_new_from_cursor(allocator, match_token_label);
|
170
|
+
}
|
171
|
+
|
172
|
+
/* private_key_object_label is optional */
|
173
|
+
if (match_private_key_label->ptr != NULL) {
|
174
|
+
pkcs_private_key_object_label = aws_string_new_from_cursor(allocator, match_private_key_label);
|
175
|
+
}
|
176
|
+
|
177
|
+
CK_SLOT_ID slot_id;
|
178
|
+
if (aws_pkcs11_lib_find_slot_with_token(pkcs11_handler->lib, match_slot_id, pkcs_token_label, &slot_id /*out*/)) {
|
179
|
+
goto done;
|
180
|
+
}
|
181
|
+
|
182
|
+
if (aws_pkcs11_lib_open_session(pkcs11_handler->lib, slot_id, &pkcs11_handler->session_handle)) {
|
183
|
+
goto done;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (pkcs_user_pin != NULL) {
|
187
|
+
if (aws_pkcs11_lib_login_user(pkcs11_handler->lib, pkcs11_handler->session_handle, pkcs_user_pin)) {
|
188
|
+
goto done;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
if (aws_pkcs11_lib_find_private_key(
|
193
|
+
pkcs11_handler->lib,
|
194
|
+
pkcs11_handler->session_handle,
|
195
|
+
pkcs_private_key_object_label,
|
196
|
+
&pkcs11_handler->private_key_handle /*out*/,
|
197
|
+
&pkcs11_handler->private_key_type /*out*/)) {
|
198
|
+
goto done;
|
199
|
+
}
|
200
|
+
success = true;
|
201
|
+
|
202
|
+
done:
|
203
|
+
|
204
|
+
/* CLEANUP */
|
205
|
+
if (pkcs_user_pin != NULL) {
|
206
|
+
aws_string_destroy_secure(pkcs_user_pin);
|
207
|
+
}
|
208
|
+
if (pkcs_token_label != NULL) {
|
209
|
+
aws_string_destroy(pkcs_token_label);
|
210
|
+
}
|
211
|
+
if (pkcs_private_key_object_label != NULL) {
|
212
|
+
aws_string_destroy(pkcs_private_key_object_label);
|
213
|
+
}
|
214
|
+
|
215
|
+
if (success) {
|
216
|
+
return &pkcs11_handler->base;
|
217
|
+
} else {
|
218
|
+
aws_custom_key_op_handler_release(&pkcs11_handler->base);
|
219
|
+
return NULL;
|
220
|
+
}
|
221
|
+
}
|