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
@@ -4,6 +4,56 @@
|
|
4
4
|
use std::path::{Path, PathBuf};
|
5
5
|
|
6
6
|
fn main() {
|
7
|
+
let external = External::default();
|
8
|
+
if external.is_enabled() {
|
9
|
+
external.link();
|
10
|
+
} else {
|
11
|
+
build_vendored();
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
fn env<N: AsRef<str>>(name: N) -> String {
|
16
|
+
option_env(name).expect("missing env var")
|
17
|
+
}
|
18
|
+
|
19
|
+
fn option_env<N: AsRef<str>>(name: N) -> Option<String> {
|
20
|
+
let name = name.as_ref();
|
21
|
+
eprintln!("cargo:rerun-if-env-changed={}", name);
|
22
|
+
std::env::var(name).ok()
|
23
|
+
}
|
24
|
+
|
25
|
+
struct FeatureDetector<'a> {
|
26
|
+
out_dir: &'a std::path::Path,
|
27
|
+
}
|
28
|
+
|
29
|
+
impl<'a> FeatureDetector<'a> {
|
30
|
+
pub fn new(out_dir: &'a Path) -> Self {
|
31
|
+
Self { out_dir }
|
32
|
+
}
|
33
|
+
|
34
|
+
pub fn supports(&self, name: &str) -> bool {
|
35
|
+
let out = self.out_dir.join("features").join(name);
|
36
|
+
let out = out.to_str().unwrap();
|
37
|
+
|
38
|
+
cc::Build::new()
|
39
|
+
.file(
|
40
|
+
std::path::Path::new("lib/tests/features")
|
41
|
+
.join(name)
|
42
|
+
.with_extension("c"),
|
43
|
+
)
|
44
|
+
// don't print anything
|
45
|
+
.cargo_metadata(false)
|
46
|
+
// make sure it doesn't warn
|
47
|
+
.warnings(true)
|
48
|
+
.debug(false)
|
49
|
+
// set the archiver to the `true` program, since we don't actually link anything
|
50
|
+
.archiver("true")
|
51
|
+
.try_compile(out)
|
52
|
+
.is_ok()
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
fn build_vendored() {
|
7
57
|
let mut build = cc::Build::new();
|
8
58
|
|
9
59
|
let pq = option_env("CARGO_FEATURE_PQ").is_some();
|
@@ -85,43 +135,47 @@ fn main() {
|
|
85
135
|
println!("cargo:include={}", include_dir.display());
|
86
136
|
}
|
87
137
|
|
88
|
-
|
89
|
-
|
138
|
+
struct External {
|
139
|
+
lib_dir: Option<PathBuf>,
|
140
|
+
include_dir: Option<PathBuf>,
|
90
141
|
}
|
91
142
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
std::env::var(name).ok()
|
96
|
-
}
|
143
|
+
impl Default for External {
|
144
|
+
fn default() -> Self {
|
145
|
+
let dir = option_env("S2N_TLS_DIR").map(PathBuf::from);
|
97
146
|
|
98
|
-
|
99
|
-
|
147
|
+
let lib_dir = option_env("S2N_TLS_LIB_DIR")
|
148
|
+
.map(PathBuf::from)
|
149
|
+
.or_else(|| dir.as_ref().map(|d| d.join("lib")));
|
150
|
+
|
151
|
+
let include_dir = option_env("S2N_TLS_INCLUDE_DIR")
|
152
|
+
.map(PathBuf::from)
|
153
|
+
.or_else(|| dir.as_ref().map(|d| d.join("include")));
|
154
|
+
|
155
|
+
Self {
|
156
|
+
lib_dir,
|
157
|
+
include_dir,
|
158
|
+
}
|
159
|
+
}
|
100
160
|
}
|
101
161
|
|
102
|
-
impl
|
103
|
-
|
104
|
-
|
162
|
+
impl External {
|
163
|
+
fn is_enabled(&self) -> bool {
|
164
|
+
self.lib_dir.is_some()
|
105
165
|
}
|
106
166
|
|
107
|
-
|
108
|
-
|
109
|
-
|
167
|
+
fn link(&self) {
|
168
|
+
println!(
|
169
|
+
"cargo:rustc-link-search={}",
|
170
|
+
self.lib_dir.as_ref().unwrap().display()
|
171
|
+
);
|
172
|
+
println!("cargo:rustc-link-lib=s2n");
|
110
173
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
// don't print anything
|
118
|
-
.cargo_metadata(false)
|
119
|
-
// make sure it doesn't warn
|
120
|
-
.warnings(true)
|
121
|
-
.debug(false)
|
122
|
-
// set the archiver to the `true` program, since we don't actually link anything
|
123
|
-
.archiver("true")
|
124
|
-
.try_compile(out)
|
125
|
-
.is_ok()
|
174
|
+
// tell rust we're linking with libcrypto
|
175
|
+
println!("cargo:rustc-link-lib=crypto");
|
176
|
+
|
177
|
+
if let Some(include_dir) = self.include_dir.as_ref() {
|
178
|
+
println!("cargo:include={}", include_dir.display());
|
179
|
+
}
|
126
180
|
}
|
127
181
|
}
|
@@ -1,17 +1,20 @@
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
3
3
|
|
4
|
+
#[rustfmt::skip]
|
4
5
|
mod api;
|
5
6
|
|
6
7
|
pub use api::*;
|
7
8
|
|
8
9
|
#[cfg(feature = "quic")]
|
10
|
+
#[rustfmt::skip]
|
9
11
|
mod quic;
|
10
12
|
|
11
13
|
#[cfg(feature = "quic")]
|
12
14
|
pub use quic::*;
|
13
15
|
|
14
16
|
#[cfg(feature = "internal")]
|
17
|
+
#[rustfmt::skip]
|
15
18
|
mod internal;
|
16
19
|
|
17
20
|
#[cfg(feature = "internal")]
|
@@ -37,4 +40,5 @@ pub mod s2n_tls_version {
|
|
37
40
|
}
|
38
41
|
|
39
42
|
#[cfg(test)]
|
43
|
+
#[rustfmt::skip]
|
40
44
|
mod tests;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
[package]
|
2
|
+
name = "s2n-tls-tokio"
|
3
|
+
description = "An implementation of TLS streams for Tokio built on top of s2n-tls"
|
4
|
+
version = "0.0.1"
|
5
|
+
authors = ["AWS s2n"]
|
6
|
+
edition = "2018"
|
7
|
+
repository = "https://github.com/aws/s2n-tls"
|
8
|
+
license = "Apache-2.0"
|
9
|
+
|
10
|
+
[features]
|
11
|
+
default = []
|
12
|
+
|
13
|
+
[dependencies]
|
14
|
+
errno = { version = "0.2" }
|
15
|
+
libc = { version = "0.2" }
|
16
|
+
s2n-tls = { version = "0.0", path = "../s2n-tls" }
|
17
|
+
tokio = { version = "1", features = ["net"] }
|
18
|
+
|
19
|
+
[dev-dependencies]
|
20
|
+
clap = { version = "3.1", features = ["derive"] }
|
21
|
+
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread"] }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIICLDCCAdGgAwIBAgIUPYYEnK24qDzz59IIDcNLc4P2H5swCgYIKoZIzj0EAwIw
|
3
|
+
XzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAldBMRAwDgYDVQQHDAdTZWF0dGxlMQ8w
|
4
|
+
DQYDVQQKDAZBbWF6b24xDDAKBgNVBAsMA3MybjESMBAGA1UEAwwJbG9jYWxob3N0
|
5
|
+
MCAXDTIwMTIwNDA3NDg1NloYDzIxMjAxMTEwMDc0ODU2WjBfMQswCQYDVQQGEwJV
|
6
|
+
UzELMAkGA1UECAwCV0ExEDAOBgNVBAcMB1NlYXR0bGUxDzANBgNVBAoMBkFtYXpv
|
7
|
+
bjEMMAoGA1UECwwDczJuMRIwEAYDVQQDDAlsb2NhbGhvc3QwWTATBgcqhkjOPQIB
|
8
|
+
BggqhkjOPQMBBwNCAARhONnk1k68YnnabiHzf3AvlWwN93SOvdq6v1Grl3YEiGM1
|
9
|
+
W8WFH7O4cxb+otlVlhhbPzaox4EVthLExJZumx8go2kwZzAdBgNVHQ4EFgQU0ip8
|
10
|
+
rN6YlbtCUIueCOqfh3/J3KMwHwYDVR0jBBgwFoAU0ip8rN6YlbtCUIueCOqfh3/J
|
11
|
+
3KMwDwYDVR0TAQH/BAUwAwEB/zAUBgNVHREEDTALggkxMjcuMC4wLjEwCgYIKoZI
|
12
|
+
zj0EAwIDSQAwRgIhAJwlrxN5SDi2dC17ZPgajqZ8BZyOsNFE+gsobhMBUGN0AiEA
|
13
|
+
6KFJgyPGBNdQqaczkNyBcutPGqEubuah5Me6faN4qqU=
|
14
|
+
-----END CERTIFICATE-----
|
@@ -0,0 +1,8 @@
|
|
1
|
+
-----BEGIN EC PARAMETERS-----
|
2
|
+
BggqhkjOPQMBBw==
|
3
|
+
-----END EC PARAMETERS-----
|
4
|
+
-----BEGIN EC PRIVATE KEY-----
|
5
|
+
MHcCAQEEIK4AEDQja7MDATqWWu4T0+iMFdSZH4y4+nuVzDX5ao8KoAoGCCqGSM49
|
6
|
+
AwEHoUQDQgAEYTjZ5NZOvGJ52m4h839wL5VsDfd0jr3aur9Rq5d2BIhjNVvFhR+z
|
7
|
+
uHMW/qLZVZYYWz82qMeBFbYSxMSWbpsfIA==
|
8
|
+
-----END EC PRIVATE KEY-----
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
use clap::Parser;
|
5
|
+
use s2n_tls::raw::{config::Config, security::DEFAULT_TLS13};
|
6
|
+
use s2n_tls_tokio::TlsConnector;
|
7
|
+
use std::{error::Error, fs};
|
8
|
+
use tokio::net::TcpStream;
|
9
|
+
|
10
|
+
/// NOTE: this certificate is to be used for demonstration purposes only!
|
11
|
+
const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/certs/cert.pem");
|
12
|
+
|
13
|
+
#[derive(Parser, Debug)]
|
14
|
+
struct Args {
|
15
|
+
#[clap(short, long, default_value_t = String::from(DEFAULT_CERT))]
|
16
|
+
trust: String,
|
17
|
+
addr: String,
|
18
|
+
}
|
19
|
+
|
20
|
+
async fn run_client(trust_pem: &[u8], addr: &str) -> Result<(), Box<dyn Error>> {
|
21
|
+
// Set up the configuration for new connections.
|
22
|
+
// Minimally you will need a trust store.
|
23
|
+
let mut config = Config::builder();
|
24
|
+
config.set_security_policy(&DEFAULT_TLS13)?;
|
25
|
+
config.trust_pem(trust_pem)?;
|
26
|
+
|
27
|
+
// Create the TlsConnector based on the configuration.
|
28
|
+
let client = TlsConnector::new(config.build()?);
|
29
|
+
|
30
|
+
// Connect to the server.
|
31
|
+
let stream = TcpStream::connect(addr).await?;
|
32
|
+
client.connect("localhost", stream).await?;
|
33
|
+
|
34
|
+
// TODO: echo
|
35
|
+
|
36
|
+
Ok(())
|
37
|
+
}
|
38
|
+
|
39
|
+
#[tokio::main]
|
40
|
+
async fn main() -> Result<(), Box<dyn Error>> {
|
41
|
+
let args = Args::parse();
|
42
|
+
let trust_pem = fs::read(args.trust)?;
|
43
|
+
run_client(&trust_pem, &args.addr).await?;
|
44
|
+
Ok(())
|
45
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
use clap::Parser;
|
5
|
+
use s2n_tls::raw::{config::Config, security::DEFAULT_TLS13};
|
6
|
+
use s2n_tls_tokio::TlsAcceptor;
|
7
|
+
use std::{error::Error, fs};
|
8
|
+
use tokio::net::TcpListener;
|
9
|
+
|
10
|
+
/// NOTE: this certificate and key are to be used for demonstration purposes only!
|
11
|
+
const DEFAULT_CERT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/certs/cert.pem");
|
12
|
+
const DEFAULT_KEY: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/certs/key.pem");
|
13
|
+
|
14
|
+
#[derive(Parser, Debug)]
|
15
|
+
struct Args {
|
16
|
+
#[clap(short, long, requires = "key", default_value_t = String::from(DEFAULT_CERT))]
|
17
|
+
cert: String,
|
18
|
+
#[clap(short, long, requires = "cert", default_value_t = String::from(DEFAULT_KEY))]
|
19
|
+
key: String,
|
20
|
+
#[clap(short, long, default_value_t = String::from("127.0.0.1:0"))]
|
21
|
+
addr: String,
|
22
|
+
}
|
23
|
+
|
24
|
+
async fn run_server(cert_pem: &[u8], key_pem: &[u8], addr: &str) -> Result<(), Box<dyn Error>> {
|
25
|
+
// Set up the configuration for new connections.
|
26
|
+
// Minimally you will need a certificate and private key.
|
27
|
+
let mut config = Config::builder();
|
28
|
+
config.set_security_policy(&DEFAULT_TLS13)?;
|
29
|
+
config.load_pem(cert_pem, key_pem)?;
|
30
|
+
|
31
|
+
// Create the TlsAcceptor based on the configuration.
|
32
|
+
let server = TlsAcceptor::new(config.build()?);
|
33
|
+
|
34
|
+
// Bind to an address and listen for connections.
|
35
|
+
// ":0" can be used to automatically assign a port.
|
36
|
+
let listener = TcpListener::bind(&addr).await?;
|
37
|
+
let addr = listener
|
38
|
+
.local_addr()
|
39
|
+
.map(|x| x.to_string())
|
40
|
+
.unwrap_or_else(|_| "UNKNOWN".to_owned());
|
41
|
+
println!("Listening on {}", addr);
|
42
|
+
|
43
|
+
loop {
|
44
|
+
// Wait for a client to connect.
|
45
|
+
let (stream, peer_addr) = listener.accept().await?;
|
46
|
+
println!("Connection from {:?}", peer_addr);
|
47
|
+
server.accept(stream).await?;
|
48
|
+
|
49
|
+
// TODO: echo
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
#[tokio::main]
|
54
|
+
async fn main() -> Result<(), Box<dyn Error>> {
|
55
|
+
let args = Args::parse();
|
56
|
+
let cert_pem = fs::read(args.cert)?;
|
57
|
+
let key_pem = fs::read(args.key)?;
|
58
|
+
run_server(&cert_pem, &key_pem, &args.addr).await?;
|
59
|
+
Ok(())
|
60
|
+
}
|
@@ -0,0 +1,150 @@
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
use errno::{set_errno, Errno};
|
5
|
+
use s2n_tls::raw::{
|
6
|
+
config::Config,
|
7
|
+
connection::Connection,
|
8
|
+
error::Error,
|
9
|
+
ffi::{s2n_mode, s2n_status_code},
|
10
|
+
};
|
11
|
+
use std::{
|
12
|
+
future::Future,
|
13
|
+
os::raw::{c_int, c_void},
|
14
|
+
pin::Pin,
|
15
|
+
task::{Context, Poll},
|
16
|
+
};
|
17
|
+
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
18
|
+
|
19
|
+
pub struct TlsAcceptor {
|
20
|
+
config: Config,
|
21
|
+
}
|
22
|
+
|
23
|
+
impl TlsAcceptor {
|
24
|
+
pub fn new(config: Config) -> Self {
|
25
|
+
TlsAcceptor { config }
|
26
|
+
}
|
27
|
+
|
28
|
+
pub async fn accept<S>(&self, stream: S) -> Result<TlsStream<S>, Error>
|
29
|
+
where
|
30
|
+
S: AsyncRead + AsyncWrite + Unpin,
|
31
|
+
{
|
32
|
+
TlsStream::open(self.config.clone(), s2n_mode::SERVER, stream).await
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
pub struct TlsConnector {
|
37
|
+
config: Config,
|
38
|
+
}
|
39
|
+
|
40
|
+
impl TlsConnector {
|
41
|
+
pub fn new(config: Config) -> Self {
|
42
|
+
TlsConnector { config }
|
43
|
+
}
|
44
|
+
|
45
|
+
pub async fn connect<S>(&self, _domain: &str, stream: S) -> Result<TlsStream<S>, Error>
|
46
|
+
where
|
47
|
+
S: AsyncRead + AsyncWrite + Unpin,
|
48
|
+
{
|
49
|
+
TlsStream::open(self.config.clone(), s2n_mode::CLIENT, stream).await
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
struct TlsHandshake<'a, S> {
|
54
|
+
tls: &'a mut TlsStream<S>,
|
55
|
+
}
|
56
|
+
|
57
|
+
impl<S> Future for TlsHandshake<'_, S>
|
58
|
+
where
|
59
|
+
S: AsyncRead + AsyncWrite + Unpin,
|
60
|
+
{
|
61
|
+
type Output = Result<(), Error>;
|
62
|
+
|
63
|
+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
64
|
+
self.tls.with_io(|mut context| {
|
65
|
+
context.conn.set_waker(Some(cx.waker()))?;
|
66
|
+
context.conn.negotiate().map(|r| r.map(|_| ()))
|
67
|
+
})
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
pub struct TlsStream<S> {
|
72
|
+
conn: Connection,
|
73
|
+
stream: S,
|
74
|
+
}
|
75
|
+
|
76
|
+
impl<S> TlsStream<S>
|
77
|
+
where
|
78
|
+
S: AsyncRead + AsyncWrite + Unpin,
|
79
|
+
{
|
80
|
+
async fn open(config: Config, mode: s2n_mode::Type, stream: S) -> Result<Self, Error> {
|
81
|
+
let mut conn = Connection::new(mode);
|
82
|
+
conn.set_config(config)?;
|
83
|
+
|
84
|
+
let mut tls = TlsStream { conn, stream };
|
85
|
+
TlsHandshake { tls: &mut tls }.await?;
|
86
|
+
Ok(tls)
|
87
|
+
}
|
88
|
+
|
89
|
+
fn with_io<F>(&mut self, action: F) -> Poll<Result<(), Error>>
|
90
|
+
where
|
91
|
+
F: FnOnce(Pin<&mut Self>) -> Poll<Result<(), Error>>,
|
92
|
+
{
|
93
|
+
// Setting contexts on a connection is considered unsafe
|
94
|
+
// because the raw pointers provide no lifetime or memory guarantees.
|
95
|
+
// We protect against this by pinning the stream during the action
|
96
|
+
// and clearing the context afterwards.
|
97
|
+
unsafe {
|
98
|
+
let context = self as *mut Self as *mut c_void;
|
99
|
+
|
100
|
+
self.conn.set_receive_callback(Some(Self::recv_io_cb))?;
|
101
|
+
self.conn.set_send_callback(Some(Self::send_io_cb))?;
|
102
|
+
self.conn.set_receive_context(context)?;
|
103
|
+
self.conn.set_send_context(context)?;
|
104
|
+
|
105
|
+
let result = action(Pin::new(self));
|
106
|
+
|
107
|
+
self.conn.set_receive_callback(None)?;
|
108
|
+
self.conn.set_send_callback(None)?;
|
109
|
+
self.conn.set_receive_context(std::ptr::null_mut())?;
|
110
|
+
self.conn.set_send_context(std::ptr::null_mut())?;
|
111
|
+
result
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
fn poll_io<F>(ctx: *mut c_void, action: F) -> c_int
|
116
|
+
where
|
117
|
+
F: FnOnce(Pin<&mut S>, &mut Context) -> Poll<Result<usize, std::io::Error>>,
|
118
|
+
{
|
119
|
+
debug_assert_ne!(ctx, std::ptr::null_mut());
|
120
|
+
let tls = unsafe { &mut *(ctx as *mut Self) };
|
121
|
+
|
122
|
+
let mut async_context = Context::from_waker(tls.conn.waker().unwrap());
|
123
|
+
let stream = Pin::new(&mut tls.stream);
|
124
|
+
|
125
|
+
match action(stream, &mut async_context) {
|
126
|
+
Poll::Ready(Ok(len)) => len as c_int,
|
127
|
+
Poll::Pending => {
|
128
|
+
set_errno(Errno(libc::EWOULDBLOCK));
|
129
|
+
s2n_status_code::FAILURE
|
130
|
+
}
|
131
|
+
_ => s2n_status_code::FAILURE,
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
unsafe extern "C" fn recv_io_cb(ctx: *mut c_void, buf: *mut u8, len: u32) -> c_int {
|
136
|
+
Self::poll_io(ctx, |stream, async_context| {
|
137
|
+
let mut dest = ReadBuf::new(std::slice::from_raw_parts_mut(buf, len as usize));
|
138
|
+
stream
|
139
|
+
.poll_read(async_context, &mut dest)
|
140
|
+
.map_ok(|_| dest.filled().len())
|
141
|
+
})
|
142
|
+
}
|
143
|
+
|
144
|
+
unsafe extern "C" fn send_io_cb(ctx: *mut c_void, buf: *const u8, len: u32) -> c_int {
|
145
|
+
Self::poll_io(ctx, |stream, async_context| {
|
146
|
+
let src = std::slice::from_raw_parts(buf, len as usize);
|
147
|
+
stream.poll_write(async_context, src)
|
148
|
+
})
|
149
|
+
}
|
150
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
use s2n_tls::raw::{config::Config, error::Error, security::DEFAULT_TLS13};
|
5
|
+
use s2n_tls_tokio::{TlsAcceptor, TlsConnector};
|
6
|
+
use tokio::net::{TcpListener, TcpStream};
|
7
|
+
|
8
|
+
/// NOTE: this certificate and key are used for testing purposes only!
|
9
|
+
pub static CERT_PEM: &[u8] = include_bytes!(concat!(
|
10
|
+
env!("CARGO_MANIFEST_DIR"),
|
11
|
+
"/examples/certs/cert.pem"
|
12
|
+
));
|
13
|
+
pub static KEY_PEM: &[u8] = include_bytes!(concat!(
|
14
|
+
env!("CARGO_MANIFEST_DIR"),
|
15
|
+
"/examples/certs/key.pem"
|
16
|
+
));
|
17
|
+
|
18
|
+
async fn run_client(stream: TcpStream) -> Result<(), Error> {
|
19
|
+
let mut config = Config::builder();
|
20
|
+
config.set_security_policy(&DEFAULT_TLS13)?;
|
21
|
+
config.trust_pem(CERT_PEM)?;
|
22
|
+
unsafe {
|
23
|
+
config.disable_x509_verification()?;
|
24
|
+
}
|
25
|
+
|
26
|
+
let client = TlsConnector::new(config.build()?);
|
27
|
+
client.connect("localhost", stream).await?;
|
28
|
+
Ok(())
|
29
|
+
}
|
30
|
+
|
31
|
+
async fn run_server(stream: TcpStream) -> Result<(), Error> {
|
32
|
+
let mut config = Config::builder();
|
33
|
+
config.set_security_policy(&DEFAULT_TLS13)?;
|
34
|
+
config.load_pem(CERT_PEM, KEY_PEM)?;
|
35
|
+
|
36
|
+
let server = TlsAcceptor::new(config.build()?);
|
37
|
+
server.accept(stream).await?;
|
38
|
+
Ok(())
|
39
|
+
}
|
40
|
+
|
41
|
+
#[tokio::test]
|
42
|
+
async fn handshake_basic() -> Result<(), Error> {
|
43
|
+
let localhost = "127.0.0.1".to_owned();
|
44
|
+
let listener = TcpListener::bind(format!("{}:0", localhost)).await.unwrap();
|
45
|
+
let addr = listener.local_addr().unwrap();
|
46
|
+
let client_stream = TcpStream::connect(&addr).await.unwrap();
|
47
|
+
let (server_stream, _) = listener.accept().await.unwrap();
|
48
|
+
|
49
|
+
tokio::try_join!(run_client(client_stream), run_server(server_stream))?;
|
50
|
+
Ok(())
|
51
|
+
}
|