Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LibAWSCRT to v0.2 #20

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AWSCRT"
uuid = "df31ea59-17a4-4ebd-9d69-4f45266dc2c7"
version = "0.1.5"
version = "0.1.6"

[deps]
AWSCRT_jll = "01db5350-6ea1-5d9a-9a47-8a31a394cb9c"
Expand All @@ -12,11 +12,11 @@ LibAWSCRT = "df7458b6-5204-493f-a0e7-404b4eb72fac"

[compat]
AWSCRT_jll = "0.1"
CEnum = "0.4"
CEnum = "0.5"
CountDownLatches = "2"
ForeignCallbacks = "0.1"
JSON = "0.21"
LibAWSCRT = "0.1"
LibAWSCRT = "0.2"
julia = "1.9"

[extras]
Expand Down
37 changes: 25 additions & 12 deletions src/AWSIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ mutable struct ClientTLSContext
ptr::Ptr{aws_tls_ctx}
end

const NULL_AWS_TLS_CTX_OPTIONS = aws_tls_ctx_options(
C_NULL,
AWS_IO_TLS_VER_SYS_DEFAULTS,
AWS_IO_TLS_CIPHER_PREF_SYSTEM_DEFAULT,
aws_byte_buf(0, C_NULL, 0, C_NULL),
C_NULL,
C_NULL,
aws_byte_buf(0, C_NULL, 0, C_NULL),
aws_byte_buf(0, C_NULL, 0, C_NULL),
0,
false,
C_NULL,
C_NULL,
)

"""
ClientTLSContext(options::TLSContextOptions)

Expand All @@ -303,31 +318,29 @@ Arguments:
- `options (TLSContextOptions)`: Configuration options.
"""
function ClientTLSContext(options::TLSContextOptions)
tls_ctx_opt = Ref(aws_tls_ctx_options(ntuple(_ -> UInt8(0), 200)))
tls_ctx_opt = Ref(NULL_AWS_TLS_CTX_OPTIONS)
GC.@preserve tls_ctx_opt begin
tls_ctx_opt_ptr = Base.unsafe_convert(Ptr{aws_tls_ctx_options}, tls_ctx_opt)

# TODO pkcs11
# TODO pkcs12
# TODO windows cert store
if options.cert_data !== nothing
# mTLS with certificate and private key
cert = Ref(aws_byte_cursor_from_c_str(options.cert_data))
key = Ref(aws_byte_cursor_from_c_str(options.pk_data))
if aws_tls_ctx_options_init_client_mtls(tls_ctx_opt_ptr, _AWSCRT_ALLOCATOR[], cert, key) != AWS_OP_SUCCESS
if aws_tls_ctx_options_init_client_mtls(tls_ctx_opt, _AWSCRT_ALLOCATOR[], cert, key) != AWS_OP_SUCCESS
error("Failed to create client TLS context. $(aws_err_string())")
end
else
# no mTLS
aws_tls_ctx_options_init_default_client(tls_ctx_opt_ptr, _AWSCRT_ALLOCATOR[])
aws_tls_ctx_options_init_default_client(tls_ctx_opt, _AWSCRT_ALLOCATOR[])
end

tls_ctx_opt_ptr.minimum_tls_version = options.min_tls_version
tls_ctx_opt[].minimum_tls_version = options.min_tls_version

try
if options.ca_dirpath !== nothing || options.ca_filepath !== nothing
if aws_tls_ctx_options_override_default_trust_store_from_path(
tls_ctx_opt_ptr,
tls_ctx_opt,
options.ca_dirpath === nothing ? C_NULL : options.ca_dirpath,
options.ca_filepath === nothing ? C_NULL : options.ca_filepath,
) != AWS_OP_SUCCESS
Expand All @@ -337,21 +350,21 @@ function ClientTLSContext(options::TLSContextOptions)

if options.ca_data !== nothing
ca = Ref(aws_byte_cursor_from_c_str(options.ca_data))
if aws_tls_ctx_options_override_default_trust_store(tls_ctx_opt_ptr, ca) != AWS_OP_SUCCESS
if aws_tls_ctx_options_override_default_trust_store(tls_ctx_opt, ca) != AWS_OP_SUCCESS
error("Failed to override trust store. $(aws_err_string())")
end
end

if options.alpn_list !== nothing
alpn_list_string = join(options.alpn_list, ';')
if aws_tls_ctx_options_set_alpn_list(tls_ctx_opt_ptr, alpn_list_string) != AWS_OP_SUCCESS
if aws_tls_ctx_options_set_alpn_list(tls_ctx_opt, alpn_list_string) != AWS_OP_SUCCESS
error("Failed to set ALPN list. $(aws_err_string())")
end
end

tls_ctx_opt_ptr.verify_peer = options.verify_peer
tls_ctx_opt[].verify_peer = options.verify_peer

tls_ctx = aws_tls_client_ctx_new(_AWSCRT_ALLOCATOR[], tls_ctx_opt_ptr)
tls_ctx = aws_tls_client_ctx_new(_AWSCRT_ALLOCATOR[], tls_ctx_opt)
if tls_ctx == C_NULL
error("Failed to create TLS context. $(aws_err_string())")
end
Expand All @@ -361,7 +374,7 @@ function ClientTLSContext(options::TLSContextOptions)
aws_tls_ctx_release(x.ptr)
end
catch
aws_tls_ctx_options_clean_up(tls_ctx_opt_ptr)
aws_tls_ctx_options_clean_up(tls_ctx_opt)
rethrow()
end
end
Expand Down
Loading