2 * Copyright (c) 2006-2007,2013 Apple Inc. All Rights Reserved.
4 * sslThreading.h - support for two-threaded SSL client/server tests.
7 #ifndef _SSL_THREADING_H_
8 #define _SSL_THREADING_H_ 1
10 #include <Security/SecureTransport.h>
11 #include <Security/Security.h>
17 /* "Don't bother verifying" values */
18 #define SSL_PROTOCOL_IGNORE ((SSLProtocol)0x123456)
19 #define SSL_CLIENT_CERT_IGNORE ((SSLClientCertificateState)0x234567)
20 #define SSL_CIPHER_IGNORE ((SSLCipherSuite)0x345678)
23 * Test params passed to both sslClient() and sslServer()
27 /* client side only */
29 bool skipHostNameCheck
;
33 SSLProtocol tryVersion
; // only used if acceptedProts
35 const char *acceptedProts
;
36 const char *myCertKcName
; // required for server,
37 // optional for client
38 const char *password
; // optional, to unlock keychain
39 bool idIsTrustedRoot
; // cert in KC is trusted root
40 bool disableCertVerify
;
41 const char *anchorFile
; // to add/replace anchors
43 SSLAuthenticate authenticate
;
45 const SSLCipherSuite
*ciphers
; // optional array of allowed ciphers,
46 // terminated with SSL_NO_SUCH_CIPHERSUITE
48 const unsigned char *dhParams
; // optional Diffie-Hellman params
51 /* expected results */
53 SSLProtocol expectVersion
;
54 SSLClientCertificateState expectCertState
;
55 SSLCipherSuite expectCipher
;
65 * -- main thread inits and sets serverRady false
66 * -- main thread starts up server thread
67 * -- server thread inits and sets of a socket for listening
68 * -- serrver thread sets serverReady true and does pthread_cond_broadcast
70 pthread_mutex_t pthreadMutex
;
71 pthread_cond_t pthreadCond
;
74 * To ensure error abort is what we expect instead of just "
75 * peer closed their socket", server avoids closing down the
76 * socket until client sets this flag. It's just polled, no
77 * locking. Setting the serverAbort flag skips this
78 * step to facilitate testing cases where server explicitly
79 * drops connection (e.g. in response to an unacceptable
86 * Returned and also verified by sslRunSession().
87 * Conditions in which expected value NOT verified are listed
88 * in following comments.
90 * NegCipher is only verified if (ortn == errSecSuccess).
92 SSLProtocol negVersion
; // SSL_PROTOCOL_IGNORE
93 SSLCipherSuite negCipher
; // SSL_CIPHER_IGNORE
94 SSLClientCertificateState certState
; // SSL_CLIENT_CERT_IGNORE
95 OSStatus ortn
; // always checked
99 /* client and server in sslClient.cpp and sslServe.cpp */
100 OSStatus
sslAppClient(
101 SslAppTestParams
*params
);
102 OSStatus
sslAppServe(
103 SslAppTestParams
*params
);
106 * Run one session, with the server in a separate thread.
107 * On entry, serverParams->port is the port we attempt to run on;
108 * the server thread may overwrite that with a different port if it's
109 * unable to open the port we specify. Whatever is left in
110 * serverParams->port is what's used for the client side.
113 SslAppTestParams
*serverParams
,
114 SslAppTestParams
*clientParams
,
115 const char *testDesc
);
118 char *whichSide
, // "client" or "server"
119 SslAppTestParams
*params
);
123 * Macros which do the repetetive setup/run work
125 #define SSL_THR_SETUP(serverParams, clientParams, clientDefaults, serverDefault) \
127 unsigned short serverPort; \
128 serverPort = serverParams.port + 1; \
129 clientParams = clientDefaults; \
130 serverParams = serverDefaults; \
131 serverParams.port = serverPort; \
134 #define SSL_THR_RUN(serverParams, clientParams, desc, ourRtn) \
136 thisRtn = sslRunSession(&serverParams, &clientParams, desc); \
139 if(testError(clientParams.quiet)) { \
145 #define SSL_THR_RUN_NUM(serverParams, clientParams, desc, ourRtn, testNum) \
147 thisRtn = sslRunSession(&serverParams, &clientParams, desc);\
150 printf("***Error on test %u\n", testNum); \
151 if(testError(clientParams.quiet)) { \
157 #define THREADING_DEBUG 0
160 #define sslThrDebug(side, end) \
161 printf("^^^%s thread %p %s\n", side, pthread_self(), end)
162 #else /* THREADING_DEBUG */
163 #define sslThrDebug(side, end)
164 #endif /* THREADING_DEBUG */
169 #endif /* _SSL_THREADING_H_ */