2 * sslThreading.h - support for two-threaded SSL client/server tests.
5 #ifndef _SSL_THREADING_H_
6 #define _SSL_THREADING_H_ 1
8 #include <Security/SecureTransport.h>
9 #include <Security/Security.h>
10 #include <clAppUtils/ringBufferIo.h>
16 /* "Don't bother verifying" values */
17 #define SSL_PROTOCOL_IGNORE ((SSLProtocol)0x123456)
18 #define SSL_CLIENT_CERT_IGNORE ((SSLClientCertificateState)0x234567)
19 #define SSL_CIPHER_IGNORE ((SSLCipherSuite)0x345678)
22 * Test params passed to both sslClient() and sslServer()
26 /* client side only */
28 bool skipHostNameCheck
;
32 RingBuffer
*serverToClientRing
;
33 RingBuffer
*clientToServerRing
;
35 bool noProtSpec
; // if true, don't set protocol in either
37 SSLProtocol tryVersion
; // only used if acceptedProts
39 const char *acceptedProts
;
40 const char *myCertKcName
; // required for server,
41 // optional for client
42 const char *password
; // optional, to unlock keychain
43 bool idIsTrustedRoot
; // cert in KC is trusted root
44 bool disableCertVerify
;
45 const char *anchorFile
; // to add/replace anchors
47 SSLAuthenticate authenticate
;
49 const SSLCipherSuite
*ciphers
; // optional array of allowed ciphers,
50 // terminated with SSL_NO_SUCH_CIPHERSUITE
52 const unsigned char *dhParams
; // optional Diffie-Hellman params
55 /* expected results */
57 SSLProtocol expectVersion
;
58 SSLClientCertificateState expectCertState
;
59 SSLCipherSuite expectCipher
;
69 * -- main thread inits and sets serverReady false
70 * -- main thread starts up server thread
71 * -- server thread inits and sets up a socket for listening
72 * -- server thread sets serverReady true and does pthread_cond_broadcast
74 pthread_mutex_t pthreadMutex
;
75 pthread_cond_t pthreadCond
;
79 * To ensure error abort is what we expect instead of just
80 * "peer closed their socket", server avoids closing down the
81 * socket until client sets this flag. It's just polled, no
82 * locking. Setting the serverAbort flag skips this
83 * step to facilitate testing cases where server explicitly
84 * drops connection (e.g. in response to an unacceptable
91 * Returned and also verified by sslRunSession().
92 * Conditions in which expected value NOT verified are listed
93 * in following comments.
95 * NegCipher is only verified if (ortn == noErr).
97 SSLProtocol negVersion
; // SSL_PROTOCOL_IGNORE
98 SSLCipherSuite negCipher
; // SSL_CIPHER_IGNORE
99 SSLClientCertificateState certState
; // SSL_CLIENT_CERT_IGNORE
100 OSStatus ortn
; // always checked
104 /* client and server in sslClient.cpp and sslServe.cpp */
105 OSStatus
sslAppClient(
106 SslAppTestParams
*params
);
107 OSStatus
sslAppServe(
108 SslAppTestParams
*params
);
111 * Run one session, with the server in a separate thread.
112 * On entry, serverParams->port is the port we attempt to run on;
113 * the server thread may overwrite that with a different port if it's
114 * unable to open the port we specify. Whatever is left in
115 * serverParams->port is what's used for the client side.
118 SslAppTestParams
*serverParams
,
119 SslAppTestParams
*clientParams
,
120 const char *testDesc
);
123 const char *whichSide
, // "client" or "server"
124 SslAppTestParams
*params
);
128 * Macros which do the repetetive setup/run work
130 #define SSL_THR_SETUP(serverParams, clientParams, clientDefaults, serverDefault) \
132 unsigned short serverPort; \
133 serverPort = serverParams.port + 1; \
134 clientParams = clientDefaults; \
135 serverParams = serverDefaults; \
136 serverParams.port = serverPort; \
139 #define SSL_THR_RUN(serverParams, clientParams, desc, ourRtn) \
141 thisRtn = sslRunSession(&serverParams, &clientParams, desc); \
144 if(testError(clientParams.quiet)) { \
150 #define SSL_THR_RUN_NUM(serverParams, clientParams, desc, ourRtn, testNum) \
152 thisRtn = sslRunSession(&serverParams, &clientParams, desc);\
155 printf("***Error on test %u\n", testNum); \
156 if(testError(clientParams.quiet)) { \
162 #define THREADING_DEBUG 0
165 #define sslThrDebug(side, end) \
166 printf("^^^%s thread %p %s\n", side, pthread_self(), end)
167 #else /* THREADING_DEBUG */
168 #define sslThrDebug(side, end)
169 #endif /* THREADING_DEBUG */
174 #endif /* _SSL_THREADING_H_ */