1 #include <AssertMacros.h>
2 #import "STLegacyTests.h"
9 #include <CoreFoundation/CoreFoundation.h>
11 #include <Security/SecureTransportPriv.h> /* SSLSetOption */
12 #include <Security/SecureTransport.h>
13 #include <Security/SecPolicy.h>
14 #include <Security/SecTrust.h>
15 #include <Security/SecIdentity.h>
16 #include <Security/SecIdentityPriv.h>
17 #include <Security/SecCertificatePriv.h>
18 #include <Security/SecKeyPriv.h>
19 #include <Security/SecItem.h>
20 #include <Security/SecRandom.h>
22 #include <utilities/array_size.h>
23 #include <utilities/SecCFRelease.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
29 #include <mach/mach_time.h>
31 #include <tls_ciphersuites.h>
34 #include <Security/SecRSAKey.h>
37 #include "ssl-utils.h"
39 #pragma clang diagnostic push
40 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
45 @implementation STLegacyTests (ciphers)
47 static const SSLCipherSuite SupportedCipherSuites[] = {
49 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
50 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
51 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
52 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
53 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
54 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
55 TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
57 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
58 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
59 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
60 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
61 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
62 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
63 TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
65 TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
66 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
67 TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
68 TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
69 TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
70 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
71 SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
73 TLS_RSA_WITH_AES_256_GCM_SHA384,
74 TLS_RSA_WITH_AES_128_GCM_SHA256,
75 TLS_RSA_WITH_AES_256_CBC_SHA256,
76 TLS_RSA_WITH_AES_128_CBC_SHA256,
77 TLS_RSA_WITH_AES_256_CBC_SHA,
78 TLS_RSA_WITH_AES_128_CBC_SHA,
79 SSL_RSA_WITH_3DES_EDE_CBC_SHA,
81 /* Unsafe ciphersuites */
83 TLS_DH_anon_WITH_AES_256_GCM_SHA384,
84 TLS_DH_anon_WITH_AES_128_GCM_SHA256,
85 TLS_DH_anon_WITH_AES_128_CBC_SHA256,
86 TLS_DH_anon_WITH_AES_256_CBC_SHA256,
87 TLS_DH_anon_WITH_AES_128_CBC_SHA,
88 TLS_DH_anon_WITH_AES_256_CBC_SHA,
89 SSL_DH_anon_WITH_3DES_EDE_CBC_SHA,
91 TLS_ECDH_anon_WITH_NULL_SHA,
92 TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA,
93 TLS_ECDH_anon_WITH_AES_128_CBC_SHA,
94 TLS_ECDH_anon_WITH_AES_256_CBC_SHA,
96 TLS_ECDHE_ECDSA_WITH_NULL_SHA,
97 TLS_ECDHE_RSA_WITH_NULL_SHA,
99 TLS_PSK_WITH_AES_256_CBC_SHA384,
100 TLS_PSK_WITH_AES_128_CBC_SHA256,
101 TLS_PSK_WITH_AES_256_CBC_SHA,
102 TLS_PSK_WITH_AES_128_CBC_SHA,
103 TLS_PSK_WITH_3DES_EDE_CBC_SHA,
104 TLS_PSK_WITH_NULL_SHA384,
105 TLS_PSK_WITH_NULL_SHA256,
106 TLS_PSK_WITH_NULL_SHA,
108 TLS_RSA_WITH_NULL_SHA256,
109 SSL_RSA_WITH_NULL_SHA,
110 SSL_RSA_WITH_NULL_MD5
114 static const unsigned SupportedCipherSuitesCount = sizeof(SupportedCipherSuites)/sizeof(SupportedCipherSuites[0]);
117 static int protos[]={kTLSProtocol1, kTLSProtocol11, kTLSProtocol12, kDTLSProtocol1 };
118 static int nprotos = sizeof(protos)/sizeof(protos[0]);
121 static unsigned char dh_param_1024_bytes[] = {
122 0x30, 0x81, 0x87, 0x02, 0x81, 0x81, 0x00, 0xf2, 0x56, 0xb9, 0x41, 0x74,
123 0x8c, 0x54, 0x22, 0xad, 0x94, 0x2b, 0xed, 0x83, 0xb9, 0xa0, 0x2f, 0x40,
124 0xce, 0xf8, 0xec, 0x96, 0xed, 0xcd, 0x8e, 0xfc, 0xf8, 0xdd, 0x06, 0x15,
125 0xbc, 0x68, 0x0d, 0x0e, 0x2c, 0xef, 0x00, 0x71, 0x28, 0x3d, 0x27, 0x6d,
126 0x5e, 0x42, 0x8c, 0xbd, 0x0f, 0x07, 0x23, 0x9d, 0x07, 0x8e, 0x52, 0x47,
127 0xa2, 0x5d, 0xf8, 0xd9, 0x9a, 0x7b, 0xb4, 0xab, 0xd2, 0xa3, 0x39, 0xe9,
128 0x2c, 0x3b, 0x9b, 0xaa, 0xbe, 0x4e, 0x01, 0x36, 0x16, 0xc2, 0x9e, 0x7b,
129 0x38, 0x78, 0x82, 0xd0, 0xed, 0x8e, 0x1e, 0xce, 0xa6, 0x23, 0x95, 0xae,
130 0x31, 0x66, 0x58, 0x60, 0x44, 0xdf, 0x1f, 0x9c, 0x68, 0xbf, 0x8b, 0xf1,
131 0xb4, 0xa8, 0xe7, 0xb2, 0x43, 0x8b, 0xa9, 0x3d, 0xa1, 0xb7, 0x1a, 0x11,
132 0xcf, 0xf4, 0x5e, 0xf7, 0x08, 0xf6, 0x84, 0x1c, 0xd7, 0xfa, 0x40, 0x10,
133 0xdc, 0x64, 0x83, 0x02, 0x01, 0x02
135 static unsigned char *dh_param_der = dh_param_1024_bytes;
136 static unsigned int dh_param_der_len = sizeof(dh_param_1024_bytes);
141 bool is_session_resume;
145 SSLAuthenticate client_side_auth;
149 CFArrayRef peer_certs;
151 uint64_t time; // output
154 #if SECTRANS_VERBOSE_DEBUG
155 static void hexdump(const uint8_t *bytes, size_t len) {
157 printf("socket write(%p, %lu)\n", bytes, len);
158 for (ix = 0; ix < len; ++ix) {
161 printf("%02X ", bytes[ix]);
166 #define hexdump(bytes, len)
169 static OSStatus SocketWrite(SSLConnectionRef conn, const void *data, size_t *length)
171 size_t len = *length;
172 uint8_t *ptr = (uint8_t *)data;
178 ret = write((int)conn, ptr, len);
179 } while ((ret < 0) && (errno == EAGAIN || errno == EINTR));
188 *length = *length - len;
189 return errSecSuccess;
192 static OSStatus SocketRead(SSLConnectionRef conn, void *data, size_t *length)
194 size_t len = *length;
195 uint8_t *ptr = (uint8_t *)data;
200 ret = read((int)conn, ptr, len);
201 } while ((ret < 0) && (errno == EINPROGRESS || errno == EAGAIN || errno == EINTR));
206 printf("read error(%d): ret=%zd, errno=%d\n", (int)conn, ret, errno);
211 *length = *length - len;
212 return errSecSuccess;
215 static unsigned char dn[] = {
216 0x30, 0x5e, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
217 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a,
218 0x13, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x63, 0x2e,
219 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x1d, 0x41,
220 0x70, 0x70, 0x6c, 0x65, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69,
221 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f,
222 0x72, 0x69, 0x74, 0x79, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04,
223 0x03, 0x13, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74
225 static unsigned int dn_len = 96;
227 static SSLContextRef make_ssl_ref(bool server, SSLAuthenticate client_side_auth, bool dh_anonymous,
228 bool dtls, int sock, CFArrayRef certs, SSLProtocol proto)
230 SSLContextRef ctx = SSLCreateContext(kCFAllocatorDefault,
231 server ? kSSLServerSide : kSSLClientSide,
232 dtls ? kSSLDatagramType : kSSLStreamType);
237 require_noerr(SSLSetMaxDatagramRecordSize(ctx, 400), out);
238 require_noerr(SSLGetMaxDatagramRecordSize(ctx, &mtu), out);
240 require_noerr(SSLSetProtocolVersionMax(ctx, proto), out);
242 require_noerr(SSLSetIOFuncs(ctx,
243 (SSLReadFunc)SocketRead, (SSLWriteFunc)SocketWrite), out);
244 require_noerr(SSLSetConnection(ctx, (SSLConnectionRef)(intptr_t)sock), out);
245 static const char *peer_domain_name = "localhost";
246 require_noerr(SSLSetPeerDomainName(ctx, peer_domain_name,
247 strlen(peer_domain_name)), out);
249 require_noerr(SSLSetMinimumDHGroupSize(ctx, 512), out);
253 require_noerr(SSLSetCertificate(ctx, certs), out);
255 if ((client_side_auth != kNeverAuthenticate) && server) {
256 SSLAuthenticate auth;
257 require_noerr(SSLSetClientSideAuthenticate(ctx, client_side_auth), out);
258 require_noerr(SSLGetClientSideAuthenticate(ctx, &auth), out);
259 require(auth == client_side_auth, out);
260 require_noerr(SSLAddDistinguishedName(ctx, dn, dn_len), out);
262 if ((client_side_auth != kNeverAuthenticate) && !server) { /* enable break from SSLHandshake */
263 require_noerr(SSLSetSessionOption(ctx,
264 kSSLSessionOptionBreakOnCertRequested, true), out);
268 /* Set this option, even if doing anonDH or PSK - it should NOT break out in those case */
269 require_noerr(SSLSetSessionOption(ctx, kSSLSessionOptionBreakOnServerAuth, true), out);
272 require_noerr(SSLSetDiffieHellmanParams(ctx,
273 dh_param_der, dh_param_der_len), out);
275 else /* if client */ {
286 static bool check_peer_cert(SSLContextRef ctx, const ssl_test_handle *ssl, SecTrustRef *trust)
288 CFMutableArrayRef peer_cert_array = NULL;
289 CFMutableArrayRef orig_peer_cert_array = NULL;
291 /* verify peer cert chain */
292 require_noerr(SSLCopyPeerTrust(ctx, trust), out);
293 require_noerr(SSLGetPeerSecTrust(ctx, trust), out);
294 SecTrustResultType trust_result = 0;
295 /* this won't verify without setting up a trusted anchor */
296 require_noerr(SecTrustEvaluate(*trust, &trust_result), out);
298 CFIndex n_certs = SecTrustGetCertificateCount(*trust);
300 peer_cert_array = CFArrayCreateMutable(NULL, n_certs, &kCFTypeArrayCallBacks);
301 orig_peer_cert_array = CFArrayCreateMutableCopy(NULL, n_certs, ssl->peer_certs);
303 CFArrayInsertValueAtIndex(peer_cert_array, 0,
304 SecTrustGetCertificateAtIndex(*trust, n_certs));
307 SecIdentityRef ident = (SecIdentityRef)CFArrayGetValueAtIndex(orig_peer_cert_array, 0);
308 SecCertificateRef peer_cert = NULL;
309 require_noerr(SecIdentityCopyCertificate(ident, &peer_cert), out);
310 CFArraySetValueAtIndex(orig_peer_cert_array, 0, peer_cert);
311 CFRelease(peer_cert);
313 require(CFEqual(orig_peer_cert_array, peer_cert_array), out);
314 CFReleaseNull(orig_peer_cert_array);
315 CFReleaseNull(peer_cert_array);
319 CFReleaseNull(orig_peer_cert_array);
320 CFReleaseNull(peer_cert_array);
325 #include <mach/mach_time.h>
327 #define perf_start() uint64_t _perf_time = mach_absolute_time();
328 #define perf_scale_factor() ({struct mach_timebase_info info; mach_timebase_info(&info); ((double)info.numer) / (1000000.0 * info.denom);})
329 #define perf_time() ((mach_absolute_time() - _perf_time) * perf_scale_factor())
331 static void test_get_client_server_random(SSLContextRef ctx, const void *arg, void *secret, size_t *secretLen)
336 static void *securetransport_ssl_thread(void *arg)
339 ssl_test_handle * ssl = (ssl_test_handle *)arg;
340 SSLContextRef ctx = ssl->st;
341 SecTrustRef trust = NULL;
342 bool got_server_auth = false, got_client_cert_req = false;
343 SSLSessionState ssl_state;
344 char random[SSL_CLIENT_SRVR_RAND_SIZE*2];
345 size_t randomSize = SSL_CLIENT_SRVR_RAND_SIZE*2;
350 pthread_setname_np(ssl->is_server ? "server thread" : "client thread");
352 require_noerr(ortn = SSLGetSessionState(ctx, &ssl_state), out);
353 require_action(ssl_state == kSSLIdle, out, ortn = -1);
356 ortn = SSLHandshake(ctx);
357 require_noerr(SSLGetSessionState(ctx, &ssl_state), out);
358 require_noerr(SSLInternalSetMasterSecretFunction(ctx, test_get_client_server_random, NULL), out);
359 require_noerr(SSLInternalClientRandom(ctx, random, &randomSize), out);
361 randomSize = SSL_CLIENT_SRVR_RAND_SIZE;
362 require_noerr(SSLInternalServerRandom(ctx, random+offset, &randomSize), out);
363 if (ortn == errSSLPeerAuthCompleted) {
364 require_action(ssl_state == kSSLHandshake, out, ortn = -1);
365 require_string(!got_server_auth, out, "second server auth");
366 require_string(!ssl->dh_anonymous, out, "server auth with anon cipher");
367 // Note: Previously, the implementation always returned errSSLPeerAuthCompleted before
368 // errSSLClientCertRequested. Due to OCSP stappling implementation, this is no longer guaranteed.
369 // This behavior change should not be an issue, but it's possible that some applications will
370 // have issue with this new behavior. If we do find out that this is causing an issue, then
371 // the following require statement should be re-enabled, and the implementation changed
372 // to implement the former behavior.
373 //require_string(!got_client_cert_req, out, "got client cert req before server auth");
374 got_server_auth = true;
375 require_string(!trust, out, "Got errSSLServerAuthCompleted twice?");
376 require_string(check_peer_cert(ctx, ssl, &trust), out, "Certificate check failed");
377 } else if (ortn == errSSLClientCertRequested) {
378 require_action(ssl_state == kSSLHandshake, out, ortn = -1);
379 require_string(!got_client_cert_req, out, "second client cert req");
380 // Note: see Note above.
381 //require_string(got_server_auth, out, "didn't get server auth first");
382 got_client_cert_req = true;
384 /* set client cert */
385 require_string(!ssl->is_server, out, "errSSLClientCertRequested while running server");
386 require_string(!ssl->dh_anonymous, out, "errSSLClientCertRequested while running anon DH");
388 CFArrayRef DNs = NULL;
389 require_noerr(SSLCopyDistinguishedNames (ctx, &DNs), out);
393 require_string(ssl->client_side_auth != kNeverAuthenticate, out, "errSSLClientCertRequested in run not testing that");
394 if(ssl->client_side_auth == kAlwaysAuthenticate) { // Only set a client cert in mode 1.
395 require_noerr(SSLSetCertificate(ctx, ssl->certs), out);
397 } else if (ortn == errSSLWouldBlock) {
398 require_action(ssl_state == kSSLHandshake, out, ortn = -1);
400 } while (ortn == errSSLWouldBlock
401 || ortn == errSSLServerAuthCompleted
402 || ortn == errSSLClientCertRequested);
403 require_noerr_action_quiet(ortn, out,
404 fprintf(stderr, "Fell out of SSLHandshake with error: %d (%s)\n", (int)ortn, ssl->is_server ? "server" : "client"));
406 require_action(ssl_state == kSSLConnected, out, ortn = -1);
408 if (!ssl->is_server && !ssl->dh_anonymous && !ssl->is_session_resume) {
409 require_string(got_server_auth, out, "never got server auth");
410 if (ssl->client_side_auth != kNeverAuthenticate)
411 require_string(got_client_cert_req, out, "never got client cert req");
414 if (!ssl->is_server && !ssl->dh_anonymous && ssl->is_session_resume) {
415 require_string(!got_server_auth, out, "got server auth during resumption??");
416 require_string(check_peer_cert(ctx, ssl, &trust), out, "Certificate check failed (resumption case)");
419 SSLCipherSuite cipherSuite;
420 require_noerr_quiet(ortn = SSLGetNegotiatedCipher(ctx, &cipherSuite), out);
421 KeyExchangeMethod kem = sslCipherSuiteGetKeyExchangeMethod(cipherSuite);
422 if (kem == SSL_ECDHE_ECDSA || kem == SSL_ECDHE_RSA) {
423 SSL_ECDSA_NamedCurve namedCurve;
424 require_noerr_quiet(ortn = SSLGetNegotiatedCurve(ctx, &namedCurve), out);
428 SSLGetDatagramWriteSize(ctx, &sz);
431 Boolean sessionWasResumed = false;
432 uint8_t session_id_data[MAX_SESSION_ID_LENGTH];
433 size_t session_id_length = sizeof(session_id_data);
434 require_noerr_quiet(ortn = SSLGetResumableSessionInfo(ctx, &sessionWasResumed, session_id_data, &session_id_length), out);
435 require_action(ssl->dh_anonymous || (ssl->is_session_resume == sessionWasResumed), out, ortn = -1);
437 #define BUFSIZE (8*1024)
438 unsigned char ibuf[BUFSIZE], obuf[BUFSIZE];
440 for (int i = 0; i < 10; i++) {
442 if (ssl->is_server) {
443 memset(obuf, i, BUFSIZE);
444 require_noerr(ortn = SSLWrite(ctx, obuf, BUFSIZE, &len), out);
445 require_action(len == BUFSIZE, out, ortn = -1);
447 require_noerr(ortn = SSLWrite(ctx, obuf, 0, &len), out);
448 require_action(len == 0, out, ortn = -1);
452 while (len < BUFSIZE) {
454 ortn = SSLRead(ctx, ibuf+len, BUFSIZE-len, &l);
458 require_noerr(ortn, out);
459 require_action(len == BUFSIZE, out, ortn = -1);
461 if (ssl->is_server) {
462 require_noerr(memcmp(ibuf, obuf, BUFSIZE), out);
464 require_noerr(ortn = SSLWrite(ctx, ibuf, BUFSIZE, &len), out);
465 require_action(len == BUFSIZE, out, ortn = -1);
472 if (trust) CFRelease(trust);
475 ssl->time = perf_time();
477 pthread_exit((void *)(intptr_t)ortn);
483 static ssl_test_handle *
484 ssl_test_handle_create(uint32_t session_id, bool resume, bool server, SSLAuthenticate client_side_auth, bool dh_anonymous, bool dtls,
485 int comm, CFArrayRef certs, CFArrayRef peer_certs, SSLProtocol proto)
487 ssl_test_handle *handle = calloc(1, sizeof(ssl_test_handle));
489 handle->session_id = session_id;
490 handle->is_session_resume = resume;
491 handle->is_server = server;
492 handle->is_dtls = dtls;
493 handle->client_side_auth = client_side_auth;
494 handle->dh_anonymous = dh_anonymous;
496 handle->certs = certs;
497 handle->peer_certs = peer_certs;
498 handle->proto = proto;
499 handle->st = make_ssl_ref(server, client_side_auth, dh_anonymous, dtls, comm, certs, proto);
506 pthread_t client_thread, server_thread;
508 CFArrayRef server_rsa_certs = server_chain();
509 CFArrayRef server_ec_certs = server_ec_chain();
510 CFArrayRef client_certs = trusted_client_chain();
511 XCTAssert(server_rsa_certs != NULL);
512 XCTAssert(server_ec_certs != NULL);
513 XCTAssert(client_certs != NULL);
518 for (p = 0; p < nprotos; p++)
519 for (k = 0; k < 3; k++) /* client side auth mode:
520 0 (kSSLNeverAuthenticate): server doesn't request ,
521 1 (kSSLAlwaysAuthenticate): server request, client provide,
522 2 (kSSLTryAuthenticate): server request, client does not provide */
525 for (i = 0; i < SupportedCipherSuitesCount; i++) {
526 for (l = 0; l < 2; l++) { /* resumption or not */
527 uint16_t cs = (uint16_t)(SupportedCipherSuites[i]);
528 KeyExchangeMethod kem = sslCipherSuiteGetKeyExchangeMethod(cs);
529 SSL_CipherAlgorithm cipher = sslCipherSuiteGetSymmetricCipherAlgorithm(cs);
530 tls_protocol_version min_version = sslCipherSuiteGetMinSupportedTLSVersion(cs);
532 CFArrayRef server_certs;
534 if (kem == SSL_ECDHE_ECDSA) {
535 server_certs = server_ec_certs;
537 server_certs = server_rsa_certs;
542 bool dtls = (protos[p] == kDTLSProtocol1);
543 bool server_ok = ((kem != SSL_ECDH_ECDSA) && (kem != SSL_ECDH_RSA) && (kem != SSL_ECDH_anon));
544 bool dh_anonymous = ((kem == SSL_DH_anon) || (kem == TLS_PSK));
549 version_ok = cipher != SSL_CipherAlgorithmRC4_128 && (min_version != tls_protocol_version_TLS_1_2);
552 version_ok = (min_version == tls_protocol_version_SSL_3);
556 version_ok = (min_version != tls_protocol_version_TLS_1_2);
566 if (!server_ok) continue;
567 if (!version_ok) continue;
570 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sp)) {
573 fcntl(sp[0], F_SETNOSIGPIPE, 1);
574 fcntl(sp[1], F_SETNOSIGPIPE, 1);
576 ssl_test_handle *server, *client;
577 size_t num_supported_ciphers = 0;
578 SSLCipherSuite *supported_ciphers = NULL;
580 SSLAuthenticate client_side_auth = k;
582 uint32_t session_id = (p<<24) | (k<<16) | (i+1);
583 server = ssl_test_handle_create(session_id, (l == 1), true /*server*/,
584 client_side_auth, dh_anonymous, dtls,
585 sp[0], server_certs, client_certs, protos[p]);
586 client = ssl_test_handle_create(session_id, (l == 1), false /*client*/,
587 client_side_auth, dh_anonymous, dtls,
588 sp[1], client_certs, server_certs, protos[p]);
590 XCTAssertEqual(errSecSuccess, SSLSetPeerID(server->st, &session_id, sizeof(session_id)));
591 XCTAssertEqual(errSecSuccess, SSLSetPeerID(client->st, &session_id, sizeof(session_id)));
593 /* set single cipher on client, default ciphers on server */
594 num_supported_ciphers = 0;
595 XCTAssertEqual(errSecSuccess, SSLSetEnabledCiphers(client->st, &(SupportedCipherSuites[i]), 1));
596 XCTAssertEqual(errSecSuccess, SSLGetNumberSupportedCiphers(server->st, &num_supported_ciphers));
597 XCTAssert(supported_ciphers=malloc(num_supported_ciphers*sizeof(SSLCipherSuite)));
598 XCTAssertEqual(errSecSuccess, SSLGetSupportedCiphers(server->st, supported_ciphers, &num_supported_ciphers));
599 XCTAssertEqual(errSecSuccess, SSLSetEnabledCiphers(server->st, supported_ciphers, num_supported_ciphers));
601 XCTAssertEqual(errSecSuccess, SSLSetPSKSharedSecret(client->st, "123456789", 9));
602 XCTAssertEqual(errSecSuccess, SSLSetPSKSharedSecret(server->st, "123456789", 9));
604 pthread_create(&client_thread, NULL, securetransport_ssl_thread, client);
605 pthread_create(&server_thread, NULL, securetransport_ssl_thread, server);
607 intptr_t server_err, client_err;
608 pthread_join(client_thread, (void*)&client_err);
609 pthread_join(server_thread, (void*)&server_err);
610 const char *cipher_name = ciphersuite_name(SupportedCipherSuites[i]);
611 #if SECTRANS_VERBOSE_DEBUG
612 // If you want to print an approximate time for each handshake.
613 printf("%4llu - %40s CSA:%d RESUME:%d PROTO:0x%04x\n",
616 server->client_side_auth,
620 XCTAssert(!server_err && !client_err,
621 "%40s CSA:%d RESUME:%d PROTO:0x%04x",
623 server->client_side_auth,
627 free(supported_ciphers);
634 CFReleaseNull(client_certs);
635 CFReleaseNull(server_ec_certs);
636 CFReleaseNull(server_rsa_certs);
641 #pragma clang diagnostic pop
644 TODO: count errSSLWouldBlock
645 TODO: skip tests that don't matter: client_auth and anonymous dh
646 TODO: we seem to only be negotiating tls - force a round of sslv3
647 TODO: allow secure transport to also defer client side auth to client
648 TODO: make sure anonymous dh is never selected if not expicitly enabled
649 TODO: make sure DHE is not available if not explicitly enabled and no parameters
651 TODO: resumable sessions