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

Apple Network Framework SecItem #668

Open
wants to merge 174 commits into
base: nw_socket
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
92e2bf3
initial secitem implementation for iOS
sbSteveK Aug 21, 2024
cad8639
nw_parameters_create_custom_ip not available on iOS
sbSteveK Aug 21, 2024
e0a5f59
add Network Socket related TLS error codes
sbSteveK Sep 3, 2024
ac6390e
work in progress setting up identity for use during nw connection
sbSteveK Sep 3, 2024
8b47db8
Merge branch 'nw_socket' into nw_secitem
sbSteveK Sep 3, 2024
1246540
setting setup_run to true has to occur before submitting result to pr…
sbSteveK Sep 3, 2024
c97a0f1
Checkpoint before PKCS12
sbSteveK Sep 5, 2024
82f399b
add pkcs12 import
sbSteveK Sep 9, 2024
fd81c00
use mutable dictionaries
sbSteveK Sep 9, 2024
d09df65
pass error as pointer
sbSteveK Sep 9, 2024
1edfe43
root_ca and verification block
sbSteveK Sep 17, 2024
4aa7590
merge with latest nw_socket changes
sbSteveK Sep 18, 2024
4b8b2a4
remove TLS slot creation for iOS as it's handled internally by nw_con…
sbSteveK Sep 18, 2024
6984b79
clarity related name changes
sbSteveK Sep 18, 2024
8ba6827
merge with changes to nw_socket_2
sbSteveK Sep 19, 2024
de92f24
pass host name and tls ctx to nw_connection parameter initialization
sbSteveK Sep 20, 2024
32f4af5
unify root ca handling for macOS and iOS
sbSteveK Sep 20, 2024
df152fa
minor cleanup of darwin_pki_utils.c
sbSteveK Sep 20, 2024
cd84db5
private header for dispatch queue and use of dispatch queue in verifi…
sbSteveK Sep 23, 2024
3341c7c
group TLS errors
sbSteveK Sep 23, 2024
c6aa207
remove unecessary wrappers around CFRelease
sbSteveK Sep 23, 2024
6beed13
remove CFRelease wrapping cont.
sbSteveK Sep 23, 2024
2ad7f1d
remove some platform specific build items
sbSteveK Sep 23, 2024
dc506e7
move secure_transport_ctx to private header
sbSteveK Sep 23, 2024
1745e21
remove unecessary include
sbSteveK Sep 23, 2024
8557fba
clarify comments
sbSteveK Sep 23, 2024
bfd662e
remove print statements
sbSteveK Sep 23, 2024
d4959a6
check if nw_socket is open before trying to cancel/close
sbSteveK Sep 24, 2024
c8e2a5e
state change handler expansion
sbSteveK Sep 24, 2024
29d5b06
Merge branch 'nw_socket_2' into nw_secitem
sbSteveK Sep 24, 2024
739140e
check if closed and reorder socket close
sbSteveK Sep 24, 2024
fad7e91
Merge branch 'nw_socket_2' into nw_secitem
sbSteveK Sep 24, 2024
beec73d
dispatch_queue.h
sbSteveK Sep 24, 2024
a4be446
merge nw_socket_2
sbSteveK Sep 24, 2024
8945b5f
merge with nw_socket
sbSteveK Sep 24, 2024
8b3fad0
merge with nw_socket
sbSteveK Sep 24, 2024
63311b8
Merge branch 'nw_socket' into nw_secitem
sbSteveK Sep 24, 2024
da24afd
Merge branch 'nw_socket' into nw_secitem
sbSteveK Sep 24, 2024
fb8c0aa
Merge branch 'nw_socket' into nw_secitem
sbSteveK Sep 24, 2024
1ff2443
clang format
sbSteveK Sep 24, 2024
76d7368
better comments and clearer action branching
sbSteveK Sep 24, 2024
aefa022
save copy of host_name to the nw_socket on connect
sbSteveK Sep 26, 2024
06ff298
use of aws_secitem_options
sbSteveK Sep 26, 2024
c6adea9
updated tls options retreival at nw_socket connect
sbSteveK Sep 26, 2024
2bcc063
set min tls version
sbSteveK Sep 26, 2024
19e6055
comment cleanup
sbSteveK Sep 26, 2024
9acfc22
rename parameters and catch some potential mem leaks
sbSteveK Sep 27, 2024
fcbc2b6
handle default and invalid TLS protocol version
sbSteveK Sep 27, 2024
16d498d
expand commenting
sbSteveK Sep 27, 2024
b047d2c
seitem_options handling improved
sbSteveK Sep 27, 2024
eec1b39
handle default value that shouldn't be hit
sbSteveK Sep 27, 2024
a58111a
space
sbSteveK Sep 30, 2024
3353ec6
rename set secitem options argument for clarity
sbSteveK Oct 1, 2024
209be07
missed a spot
sbSteveK Oct 1, 2024
ced9f88
const the secitem options and improve logging
sbSteveK Oct 2, 2024
bdcbf39
s_schedule_next_read should not return anything
sbSteveK Oct 2, 2024
b9e5411
forgot ;
sbSteveK Oct 2, 2024
2f5d2ce
use define AWS_USE_SECITEM instead of AWS_OS_IOS
sbSteveK Oct 2, 2024
c3a6bd6
some aspects should still do an ios check
sbSteveK Oct 2, 2024
b7e75a9
change the ifdef to AWS_USE_DISPATCH_QUEUE in dispatch_queue.h
sbSteveK Oct 2, 2024
849d009
ifdef checks for AWS_USE_DISPATCH_QUEUE
sbSteveK Oct 3, 2024
a3a7a6c
forward declare aws_tls_connection_options
sbSteveK Oct 3, 2024
c9c6600
split out the ifndefs
sbSteveK Oct 3, 2024
6113acf
if -> ifdef
sbSteveK Oct 3, 2024
99e1ed0
if -> ifdef
sbSteveK Oct 3, 2024
f75ffc4
merge with latest nw_socket
sbSteveK Oct 3, 2024
968edde
apply platform check where applicable
sbSteveK Oct 3, 2024
e102c32
all apple builds need secure_transport_ctx
sbSteveK Oct 4, 2024
cde0b76
aws-c-io platform.h should include aws-c-common platform.h to setup OS
sbSteveK Oct 4, 2024
4363d64
fix unused error
sbSteveK Oct 4, 2024
3caac5e
remove platform.h and rename dispatch_queue.h
sbSteveK Oct 4, 2024
f165dfe
merge with latest nw_socket
sbSteveK Oct 4, 2024
02deb47
aws_socket_connect fix in tests
sbSteveK Oct 4, 2024
01e4356
missed a connect
sbSteveK Oct 4, 2024
9082d44
clang format
sbSteveK Oct 4, 2024
93c8a72
clang
sbSteveK Oct 4, 2024
c6656e9
fix windows/iocp definition s_socket_connect
sbSteveK Oct 4, 2024
d895738
wrap double defined socket functions in an ifdef check
sbSteveK Oct 4, 2024
95a7a8a
rearranging
sbSteveK Oct 7, 2024
8d353f1
merge with nw_socket
sbSteveK Oct 7, 2024
83c43de
remove deprecated kSecTrustResultConfirm to string
sbSteveK Oct 7, 2024
ad15ad2
remove support for deprecated tls versions
sbSteveK Oct 7, 2024
64cff09
unused metadata (void)
sbSteveK Oct 7, 2024
ef0f550
SecIdentityRef to sec_identity_t in secure_transport_ctx
sbSteveK Oct 7, 2024
7ca4fbc
remove unused parameter from s_setup_socket_params
sbSteveK Oct 7, 2024
4572550
remove unused socket variable
sbSteveK Oct 7, 2024
2861462
replace deprecated verify block function
sbSteveK Oct 7, 2024
ca52061
error used before initialized
sbSteveK Oct 7, 2024
10032ad
try dispatch queue with secitem
sbSteveK Oct 7, 2024
e7cd42e
use the correct matrix for macos job
sbSteveK Oct 8, 2024
c859bde
merge with nw_socket_udp changes
sbSteveK Oct 15, 2024
efde266
event_loop handling in nw_socket
sbSteveK Oct 15, 2024
c9ddf44
fix test
sbSteveK Oct 15, 2024
ade496f
fix wrong name in AWS_PRECONDITION func check
sbSteveK Oct 16, 2024
4f17063
add checks for nw_parameters and return errors if missing
sbSteveK Oct 16, 2024
b68abcf
handle missing tls_options
sbSteveK Oct 16, 2024
521294c
setup proper parameters for a local socket
sbSteveK Oct 16, 2024
79e28bb
add Secitem option to build
sbSteveK Oct 17, 2024
f064f21
merge with latest nw_socket
sbSteveK Oct 17, 2024
c0ea8ec
endif
sbSteveK Oct 17, 2024
c153294
missing function from merge
sbSteveK Oct 17, 2024
2e681df
merge changes
sbSteveK Oct 17, 2024
f2fd4cd
try including aws_apple_network_framework despite not ifndef dispatch
sbSteveK Oct 17, 2024
9bde1ae
try to turn on secitem testing
sbSteveK Oct 17, 2024
303bb92
super clarify AWS_USE_SECITEM
sbSteveK Oct 17, 2024
af0b484
separate out secitem CI job
sbSteveK Oct 17, 2024
618ec16
Fix CMakeLists for secitem
sbSteveK Oct 17, 2024
ecf722b
CMakeLists.txt revision
sbSteveK Oct 17, 2024
d001e8e
test
sbSteveK Oct 17, 2024
aeb4cb7
CMakeLists changes
sbSteveK Oct 18, 2024
c6c03ec
fully separate out secitem in cmakelists
sbSteveK Oct 18, 2024
12e4669
add separated cmake-extra
sbSteveK Oct 18, 2024
27dae96
temp have TLS errors all return a singular error
sbSteveK Oct 18, 2024
622fc7c
cleaner passing of tls related pointers and initial tls_result handli…
sbSteveK Oct 24, 2024
3d8d019
zero struct properly
sbSteveK Oct 24, 2024
fab363d
restore granular TLS errors and include an error check for TLS errors
sbSteveK Oct 24, 2024
c9c072a
store and serve tls error hotfix
sbSteveK Oct 24, 2024
63bb48b
add errSSLPeerProtocolVersion error case as TLS negotiation error
sbSteveK Oct 24, 2024
8ffbc9e
rename nw_socket tasks and fix peer_verification skip
sbSteveK Oct 25, 2024
cff20a6
try removing test that Secitem doesn't support
sbSteveK Oct 25, 2024
54fd3ff
rename socket timeout cancellation task
sbSteveK Oct 25, 2024
f93cb36
remove tests for SECITEM that require an appbundle and entitlements
sbSteveK Oct 25, 2024
d4c3a2c
more descriptive verification error reporting
sbSteveK Oct 25, 2024
a43174e
actually set min tls version to 1.1 in test
sbSteveK Oct 25, 2024
c0be01e
fix setting of proper requested tls version on tests
sbSteveK Oct 25, 2024
e0af474
revert tls version tests
sbSteveK Oct 28, 2024
9c096a5
missed a TLS revert
sbSteveK Oct 28, 2024
187b704
another missed revert
sbSteveK Oct 28, 2024
2b9a972
WIP checkpoint
sbSteveK Oct 28, 2024
81288f5
Merge branch 'nw_socket' into nw_secitem
sbSteveK Oct 28, 2024
fc93da9
comment out unused test func
sbSteveK Oct 28, 2024
1398249
match server and client setup complete callback logic
sbSteveK Oct 28, 2024
851273d
pkcs8 not supported on iOS
sbSteveK Oct 29, 2024
ecc4417
misspelling
sbSteveK Oct 29, 2024
03f67bc
logic on setup_completed related to secitem/tls separation
sbSteveK Oct 31, 2024
c519e19
set protocol server name in parameters
sbSteveK Oct 31, 2024
9df47da
temp pass as successful socket slot only
sbSteveK Oct 31, 2024
a81b09b
reorganize handling of secitem setup completed
sbSteveK Oct 31, 2024
3de0e84
add alpn protocols to parameters
sbSteveK Nov 1, 2024
a1226e9
add to socket vtable to allow access to protocol and server_name
sbSteveK Nov 4, 2024
8e735cf
missed a ;
sbSteveK Nov 4, 2024
5ae660d
set new vtable functions in non secitem sockets to null
sbSteveK Nov 4, 2024
c6869e4
log errors when secitem functions are called on non-secitem sockets
sbSteveK Nov 4, 2024
36e5c73
trigger negotiation result using secitem
sbSteveK Nov 4, 2024
1ff72ae
check for NULL before releasing verification CF objects
sbSteveK Nov 4, 2024
b586a9e
remove unused callback from nw_socket and add null terminator to prot…
sbSteveK Nov 4, 2024
5030dee
move around some declarations
sbSteveK Nov 4, 2024
7cf8376
secitem allows import of cert/key
sbSteveK Nov 4, 2024
4e45818
another test that requires entitlements
sbSteveK Nov 4, 2024
df15054
split out the tls block of parameters
sbSteveK Nov 5, 2024
649d554
s_setup_tls_options needs to be wrapped in ifdef Secitem
sbSteveK Nov 5, 2024
b3b6645
simplify parameters logic
sbSteveK Nov 5, 2024
b7882f9
SecItem does not use tls channel statistics
sbSteveK Nov 5, 2024
e875822
allow passing of an event loop into a server listener bind
sbSteveK Nov 5, 2024
8674aa7
forgot iocp socket_bind
sbSteveK Nov 5, 2024
1efece0
missed it
sbSteveK Nov 5, 2024
e66a9a6
cleanup and test fix for windows
sbSteveK Nov 5, 2024
6836232
restore s2n in cmakelists
sbSteveK Nov 6, 2024
b4c9306
aws_apple_network_framework.h should only be used with Apple OS
sbSteveK Nov 6, 2024
79ba389
documentation
sbSteveK Nov 6, 2024
32ea35d
more documentation and logic simplification
sbSteveK Nov 7, 2024
0ba007b
cleanup
sbSteveK Nov 7, 2024
565de94
simplify tls error_code reporting in channel bootstrap
sbSteveK Nov 7, 2024
b7b96ca
documentation and reorder
sbSteveK Nov 7, 2024
31eab1e
documentation and cleanup
sbSteveK Nov 8, 2024
bf4680a
unify tls options from context
sbSteveK Nov 8, 2024
bd6d2da
remove unecessary check
sbSteveK Nov 8, 2024
5e95bbb
wrap secitem function execution within a block to maintin min macOS v…
sbSteveK Nov 8, 2024
41923c1
initial merge with latest nw_socket
sbSteveK Nov 13, 2024
14a79cc
definition misspelling
sbSteveK Nov 13, 2024
8daedcb
merge with latest nw_socket
sbSteveK Dec 4, 2024
aa21e8b
include private socket header for secure_transport_tls_channel_handler.c
sbSteveK Dec 4, 2024
5c211f1
handle duplicate functions related to darwin
sbSteveK Dec 4, 2024
fd147d1
wrong define label
sbSteveK Dec 4, 2024
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ jobs:
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=${{ matrix.eventloop }}

macos-secitem:
runs-on: macos-14 # latest
steps:
- name: Build ${{ env.PACKAGE_NAME }} + consumers
run: |
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')"
chmod a+x builder
./builder build -p ${{ env.PACKAGE_NAME }} --cmake-extra=-DAWS_USE_APPLE_NETWORK_FRAMEWORK=ON --cmake-extra=-DAWS_USE_SECITEM=ON

macos-x64:
runs-on: macos-14-large # latest
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ elseif (APPLE)
list(APPEND EVENT_LOOP_DEFINES "DISPATCH_QUEUE")
endif ()

# Enable KQUEUE on MacOS
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Enable KQUEUE on MacOS only if AWS_USE_SECITEM is not declared. SecItem requires Dispatch Queue.
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT DEFINED AWS_USE_SECITEM)
list(APPEND EVENT_LOOP_DEFINES "KQUEUE")
endif()

Expand Down Expand Up @@ -198,6 +198,10 @@ foreach(EVENT_LOOP_DEFINE IN LISTS EVENT_LOOP_DEFINES)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_ENABLE_${EVENT_LOOP_DEFINE}")
endforeach()

if (AWS_USE_SECITEM)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DAWS_USE_SECITEM")
endif()

if (BYO_CRYPTO)
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DBYO_CRYPTO")
endif()
Expand Down
1 change: 1 addition & 0 deletions include/aws/io/channel_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ struct aws_server_socket_channel_bootstrap_options {
aws_server_bootstrap_on_accept_channel_shutdown_fn *shutdown_callback;
aws_server_bootstrap_on_server_listener_destroy_fn *destroy_callback;
bool enable_read_back_pressure;
struct aws_event_loop *requested_event_loop;
void *user_data;
};

Expand Down
36 changes: 25 additions & 11 deletions include/aws/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ enum aws_io_errors {
AWS_IO_CHANNEL_READ_WOULD_EXCEED_WINDOW,
AWS_IO_EVENT_LOOP_ALREADY_ASSIGNED,
AWS_IO_EVENT_LOOP_SHUTDOWN,
AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
AWS_IO_TLS_ERROR_WRITE_FAILURE,
AWS_IO_TLS_ERROR_ALERT_RECEIVED,
AWS_IO_TLS_CTX_ERROR,
AWS_IO_TLS_VERSION_UNSUPPORTED,
AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
AWS_IO_MISSING_ALPN_MESSAGE,
AWS_IO_UNHANDLED_ALPN_PROTOCOL_MESSAGE,
AWS_IO_FILE_VALIDATION_FAILURE,
Expand Down Expand Up @@ -140,12 +133,35 @@ enum aws_io_errors {
DEPRECATED_AWS_IO_INVALID_FILE_HANDLE,
AWS_IO_SHARED_LIBRARY_LOAD_FAILURE,
AWS_IO_SHARED_LIBRARY_FIND_SYMBOL_FAILURE,
AWS_IO_TLS_NEGOTIATION_TIMEOUT,
AWS_IO_TLS_ALERT_NOT_GRACEFUL,
AWS_IO_MAX_RETRIES_EXCEEDED,
AWS_IO_RETRY_PERMISSION_DENIED,

AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE,
AWS_IO_TLS_ERROR_NOT_NEGOTIATED,
AWS_IO_TLS_ERROR_WRITE_FAILURE,
AWS_IO_TLS_ERROR_ALERT_RECEIVED,
AWS_IO_TLS_CTX_ERROR,
AWS_IO_TLS_VERSION_UNSUPPORTED,
AWS_IO_TLS_CIPHER_PREF_UNSUPPORTED,
AWS_IO_TLS_NEGOTIATION_TIMEOUT,
AWS_IO_TLS_ALERT_NOT_GRACEFUL,
AWS_IO_TLS_DIGEST_ALGORITHM_UNSUPPORTED,
AWS_IO_TLS_SIGNATURE_ALGORITHM_UNSUPPORTED,
AWS_IO_TLS_ERROR_READ_FAILURE,
AWS_IO_TLS_UNKNOWN_ROOT_CERTIFICATE,
AWS_IO_TLS_NO_ROOT_CERTIFICATE_FOUND,
AWS_IO_TLS_CERTIFICATE_EXPIRED,
AWS_IO_TLS_CERTIFICATE_NOT_YET_VALID,
AWS_IO_TLS_BAD_CERTIFICATE,
AWS_IO_TLS_PEER_CERTIFICATE_EXPIRED,
AWS_IO_TLS_BAD_PEER_CERTIFICATE,
AWS_IO_TLS_PEER_CERTIFICATE_REVOKED,
AWS_IO_TLS_PEER_CERTIFICATE_UNKNOWN,
AWS_IO_TLS_INTERNAL_ERROR,
AWS_IO_TLS_CLOSED_GRACEFUL,
AWS_IO_TLS_CLOSED_ABORT,
AWS_IO_TLS_INVALID_CERTIFICATE_CHAIN,
AWS_IO_TLS_HOST_NAME_MISSMATCH,

AWS_ERROR_PKCS11_VERSION_UNSUPPORTED,
AWS_ERROR_PKCS11_TOKEN_NOT_FOUND,
Expand Down Expand Up @@ -258,8 +274,6 @@ enum aws_io_errors {
AWS_IO_STREAM_SEEK_UNSUPPORTED,
AWS_IO_STREAM_GET_LENGTH_UNSUPPORTED,

AWS_IO_TLS_ERROR_READ_FAILURE,

AWS_ERROR_PEM_MALFORMED,

AWS_IO_ERROR_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_IO_PACKAGE_ID),
Expand Down
36 changes: 25 additions & 11 deletions include/aws/io/private/pki_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#ifdef AWS_OS_APPLE
/* It's ok to include external headers because this is a PRIVATE header file */
# include <CoreFoundation/CFArray.h>
# include <Security/Security.h>
#endif /* AWS_OS_APPLE */

struct aws_secitem_options;
struct aws_string;

AWS_EXTERN_C_BEGIN
Expand All @@ -29,7 +31,6 @@ AWS_IO_API const char *aws_determine_default_pki_dir(void);
AWS_IO_API const char *aws_determine_default_pki_ca_file(void);

#ifdef AWS_OS_APPLE
# if !defined(AWS_OS_IOS)
/**
* Imports a PEM armored PKCS#7 public/private key pair
* into identity for use with SecurityFramework.
Expand All @@ -41,7 +42,6 @@ int aws_import_public_and_private_keys_to_identity(
const struct aws_byte_cursor *private_key,
CFArrayRef *identity,
const struct aws_string *keychain_path);
# endif /* AWS_OS_IOS */

/**
* Imports a PKCS#12 file into identity for use with
Expand All @@ -54,24 +54,38 @@ int aws_import_pkcs12_to_identity(
CFArrayRef *identity);

/**
* Loads PRM armored PKCS#7 certificates into certs
* for use with custom CA.
* Imports a PEM armored PKCS#7 public/private key pair
* into protected data keychain for use with Apple Network Framework.
* Currently only implemented for iOS.
*/
int aws_import_trusted_certificates(
int aws_secitem_import_cert_and_key(
struct aws_allocator *alloc,
CFAllocatorRef cf_alloc,
const struct aws_byte_cursor *certificates_blob,
CFArrayRef *certs);
const struct aws_byte_cursor *public_cert_chain,
const struct aws_byte_cursor *private_key,
sec_identity_t *secitem_identity,
const struct aws_secitem_options *secitem_options);

/**
* Releases identity (the output of the aws_import_* functions).
* Imports a PKCS#12 file into protected data keychain for use with
* Apple Network Framework.
* Currently only implemented for iOS.
*/
void aws_release_identity(CFArrayRef identity);
int aws_secitem_import_pkcs12(
CFAllocatorRef cf_alloc,
const struct aws_byte_cursor *pkcs12_cursor,
const struct aws_byte_cursor *password,
sec_identity_t *out_identity);

/**
* releases the output of aws_import_trusted_certificates.
* Loads PRM armored PKCS#7 certificates into certs
* for use with custom CA.
*/
void aws_release_certificates(CFArrayRef certs);
int aws_import_trusted_certificates(
struct aws_allocator *alloc,
CFAllocatorRef cf_alloc,
const struct aws_byte_cursor *certificates_blob,
CFArrayRef *certs);

#endif /* AWS_OS_APPLE */

Expand Down
12 changes: 11 additions & 1 deletion include/aws/io/private/socket_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ int aws_socket_init_apple_nw_socket(
struct aws_allocator *alloc,
const struct aws_socket_options *options);

struct aws_byte_cursor;
struct aws_string;

struct aws_socket_vtable {
void (*socket_cleanup_fn)(struct aws_socket *socket);
int (*socket_connect_fn)(
struct aws_socket *socket,
const struct aws_socket_endpoint *remote_endpoint,
struct aws_event_loop *event_loop,
aws_socket_on_connection_result_fn *on_connection_result,
aws_socket_retrieve_tls_options_fn *retrieve_tls_options,
void *user_data);
int (*socket_bind_fn)(
struct aws_socket *socket,
const struct aws_socket_endpoint *local_endpoint,
aws_socket_retrieve_tls_options_fn *retrieve_tls_options,
void *user_data);
int (*socket_bind_fn)(struct aws_socket *socket, const struct aws_socket_endpoint *local_endpoint);
int (*socket_listen_fn)(struct aws_socket *socket, int backlog_size);
int (*socket_start_accept_fn)(
struct aws_socket *socket,
Expand All @@ -67,6 +75,8 @@ struct aws_socket_vtable {
void *user_data);
int (*socket_get_error_fn)(struct aws_socket *socket);
bool (*socket_is_open_fn)(struct aws_socket *socket);
struct aws_byte_buf (*socket_get_protocol_fn)(const struct aws_socket *socket);
struct aws_string *(*socket_get_server_name_fn)(const struct aws_socket *socket);
};

#endif // AWS_IO_SOCKET_IMPL_H
13 changes: 13 additions & 0 deletions include/aws/io/private/tls_channel_handler_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ enum aws_tls_handler_read_state {
AWS_TLS_HANDLER_READ_SHUT_DOWN_COMPLETE,
};

/* Apple Network socket connections when using secitem handles both the TCP and TLS
* handshakes with a singular completion state change/callback.
* Various TLS related elements must be accessible during the socket creation
* and listener binding to fit within the framework around TCP, TLS, and ALPN.
* This struct is used as a container that can retrieve the necessary elements when
* they are needed. */
struct tls_connection_context {
struct aws_string *host_name;
struct aws_string *alpn_list;
struct aws_tls_ctx *tls_ctx;
struct aws_event_loop *event_loop;
};

AWS_EXTERN_C_BEGIN

AWS_IO_API void aws_tls_channel_handler_shared_init(
Expand Down
22 changes: 19 additions & 3 deletions include/aws/io/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct aws_socket_options {

struct aws_socket;
struct aws_event_loop;
struct tls_connection_context;

/**
* Called in client mode when an outgoing connection has succeeded or an error has occurred.
Expand All @@ -91,6 +92,16 @@ struct aws_event_loop;
*/
typedef void(aws_socket_on_connection_result_fn)(struct aws_socket *socket, int error_code, void *user_data);

struct aws_tls_connection_options;

/**
* Called to retrieve TLS related options during socket creation/initialization and socket listener binding.
* Typically the TLS handshake occurs after a socket connection is established but Apple Network Framework requires
* the setup of TLS related parameters at creation of the connection as its internal framework
* handles both the socket connection and the TLS handshake.
*/
typedef void(aws_socket_retrieve_tls_options_fn)(struct tls_connection_context *context, void *user_data);

/**
* Called by a listening socket when either an incoming connection has been received or an error occurred.
*
Expand Down Expand Up @@ -158,8 +169,8 @@ struct aws_socket {
void *impl;
};

struct aws_byte_buf;
struct aws_byte_cursor;
// struct aws_byte_buf;
// struct aws_byte_cursor;

AWS_EXTERN_C_BEGIN

Expand Down Expand Up @@ -203,14 +214,19 @@ AWS_IO_API int aws_socket_connect(
const struct aws_socket_endpoint *remote_endpoint,
struct aws_event_loop *event_loop,
aws_socket_on_connection_result_fn *on_connection_result,
aws_socket_retrieve_tls_options_fn *retrieve_tls_options,
void *user_data);

/**
* Binds the socket to a local address. In UDP mode, the socket is ready for `aws_socket_read()` operations. In
* connection oriented modes, you still must call `aws_socket_listen()` and `aws_socket_start_accept()` before using the
* socket. local_endpoint is copied.
*/
AWS_IO_API int aws_socket_bind(struct aws_socket *socket, const struct aws_socket_endpoint *local_endpoint);
AWS_IO_API int aws_socket_bind(
struct aws_socket *socket,
const struct aws_socket_endpoint *local_endpoint,
aws_socket_retrieve_tls_options_fn *retrieve_tls_options,
void *user_data);

/**
* Get the local address which the socket is bound to.
Expand Down
Loading
Loading