Hello, I'm developing an SDK that will allow iOS devices (iOS 13+) to connect to AWS IoT Core using Native C. The endpoint requires a mutual TLS handshake to connect. I have been able to successfully import a Certificate and Private Key into the keychain and generate a SecIdentityRef that combines the cert/key pair which I believe is necessary to establish a TCP TLS nw_connection.
I've searched around and while I can find the individual pieces related to creating a TLS connection, I can't seem to find any that show how things go together.
The goal would be to use
nw_connection_create(endpoint, parameters);
to establish a TLS connection.
This is currently how I am creating the parameters for this connection. transport_ctx->secitem_identity is where the SecIdentityRef is kept.
nw_parameters_create_secure_tcp(
// nw_parameters_configure_protocol_block_t for configure_tls
^(nw_protocol_options_t tls_options) {
sec_protocol_options_t sec_options = nw_tls_copy_sec_protocol_options(tls_options);
// Set the minimum TLS version to TLS 1.2
sec_protocol_options_set_min_tls_protocol_version(sec_options, tls_protocol_version_TLSv12);
// Set the maximum TLS version to TLS 1.3
sec_protocol_options_set_max_tls_protocol_version(sec_options, tls_protocol_version_TLSv13);
sec_protocol_options_set_local_identity(sec_options, transport_ctx->secitem_identity);
},
// nw_parameters_configure_protocol_block_t for configure_tcp
// This is also manually set with a code block but not relevant to this q.
NW_PARAMETERS_DEFAULT_CONFIGURATION);
My question is whether or not I'm even on the right track with attempting to use these functions to setup the TLS options associated with the parameters? The sec_protocol_options_set_local_identity appears to be listed under "Security legacy reference" in the apple dev docs: https://developer.apple.com/documentation/security/sec_protocol_options_set_local_identity(::)?language=objc And the surrounding documentation related to using TLS with a network connection feels sparse at best.
Follow up question is whether there is any documentation or reading material available for setting up TLS with a TCP socket connection. I'd love to not have to take up time asking these questions if there's somewhere I can just learn it.
Thanks!
Thanks for the C conversion!
Note that you didn’t include the receive
function, but that’s OK because I could reproduce the crash without it (-:
The issue is with this line:
sec_protocol_options_set_local_identity(sec_options, ident);
It needs to be this:
sec_identity_t secIdent = sec_identity_create(ident);
sec_protocol_options_set_local_identity(sec_options, secIdent);
SecIdentityRef
and sec_identity_t
are different things.
Oh, and just FYI, the static analyser complains about you leaking copyResult
and the temporary CFString
that you create from name
. Both of these are easy to fix, but you may not need to fix them because they’re in clientIdentityNamed
, which is just scaffolding.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"