I want to connect to a server with PSK-TLS without the use of certificates, but when it attempts to send the client key exchange after saying hello to the openssl server it fails with 'bad record / mac' from the server side which the guys at OpenSSL say is an issue with the encryption on the client side. This is my code:
nw_parameters_configure_protocol_block_t configure_tls = ^(nw_protocol_options_t tls_options) {
sec_protocol_options_t sec_options = nw_tls_copy_sec_protocol_options(tls_options);
dispatch_data_t psk = dispatch_data_create("abc123", 6, nil, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
dispatch_data_t client_id = dispatch_data_create("test", 4, nil, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
sec_protocol_options_set_min_tls_protocol_version(sec_options, tls_protocol_version_TLSv12);
sec_protocol_options_set_tls_max_version(sec_options, tls_protocol_version_TLSv12);
sec_protocol_options_add_tls_ciphersuite(sec_options, (SSLCipherSuite)TLS_PSK_WITH_AES_256_GCM_SHA384);
sec_protocol_options_set_tls_ocsp_enabled(sec_options, false);
sec_protocol_options_set_tls_sct_enabled(sec_options, false);
sec_protocol_options_set_peer_authentication_required(sec_options, true);
sec_protocol_options_set_tls_renegotiation_enabled(sec_options, true);
sec_protocol_options_set_tls_tickets_enabled(sec_options, true);
sec_protocol_options_set_tls_resumption_enabled(sec_options, true);
sec_protocol_options_add_pre_shared_key(sec_options, psk, client_id);
};
nw_parameters_t parameters = nw_parameters_create_secure_tcp(configure_tls, NW_PARAMETERS_DEFAULT_CONFIGURATION);
nw_endpoint_t endpoint = nw_endpoint_create_host("192.168.0.29", "8888");
nw_connection_t connection = nw_connection_create(endpoint, parameters);
nw_connection_set_state_changed_handler(connection, ^(nw_connection_state_t state, nw_error_t error) {
switch (state) {
case nw_connection_state_waiting:
NSLog(@"waiting");
break;
case nw_connection_state_failed:
NSLog(@"failed");
break;
case nw_connection_state_ready:
NSLog(@"connection is ready");
break;
case nw_connection_state_cancelled:
NSLog(@"connection is cancelled");
break;
default:
NSLog(@"other");
break;
}
});
nw_connection_set_queue(connection, dispatch_get_main_queue());
nw_connection_start(connection);
I'm using the OpenSSL server to establish the connection with the command:
openssl3 s_server -tls1_2 -accept 8888 -nocert -psk abc123 -psk_identity test -cipher PSK-AES128-GCM-SHA384
I've tested the connection works using:
openssl3 s_client -tls1_2 -connect localhost:8888 -psk abc123 -psk_identity test -cipher PSK-AES128-GCM-SHA384
But for some reason it always fails when trying to do the iOS network.framework equivilant. I've tried with a number of ciphersuites that use PSK too so it doesn't seem to be that it is because of i.e. a deprecated ciphersuite.