]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/threadTest/testutil.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / clxutils / threadTest / testutil.c
1
2 #include "testutil.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
6
7 const char *sslGetCipherSuiteString(SSLCipherSuite cs)
8 {
9 static char noSuite[40];
10
11 switch(cs) {
12 case SSL_NULL_WITH_NULL_NULL:
13 return "SSL_NULL_WITH_NULL_NULL";
14 case SSL_RSA_WITH_NULL_MD5:
15 return "SSL_RSA_WITH_NULL_MD5";
16 case SSL_RSA_WITH_NULL_SHA:
17 return "SSL_RSA_WITH_NULL_SHA";
18 case SSL_RSA_EXPORT_WITH_RC4_40_MD5:
19 return "SSL_RSA_EXPORT_WITH_RC4_40_MD5";
20 case SSL_RSA_WITH_RC4_128_MD5:
21 return "SSL_RSA_WITH_RC4_128_MD5";
22 case SSL_RSA_WITH_RC4_128_SHA:
23 return "SSL_RSA_WITH_RC4_128_SHA";
24 case SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5:
25 return "SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5";
26 case SSL_RSA_WITH_IDEA_CBC_SHA:
27 return "SSL_RSA_WITH_IDEA_CBC_SHA";
28 case SSL_RSA_EXPORT_WITH_DES40_CBC_SHA:
29 return "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA";
30 case SSL_RSA_WITH_DES_CBC_SHA:
31 return "SSL_RSA_WITH_DES_CBC_SHA";
32 case SSL_RSA_WITH_3DES_EDE_CBC_SHA:
33 return "SSL_RSA_WITH_3DES_EDE_CBC_SHA";
34 case SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA:
35 return "SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA";
36 case SSL_DH_DSS_WITH_DES_CBC_SHA:
37 return "SSL_DH_DSS_WITH_DES_CBC_SHA";
38 case SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA:
39 return "SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA";
40 case SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA:
41 return "SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA";
42 case SSL_DH_RSA_WITH_DES_CBC_SHA:
43 return "SSL_DH_RSA_WITH_DES_CBC_SHA";
44 case SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA:
45 return "SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA";
46 case SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA:
47 return "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA";
48 case SSL_DHE_DSS_WITH_DES_CBC_SHA:
49 return "SSL_DHE_DSS_WITH_DES_CBC_SHA";
50 case SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA:
51 return "SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA";
52 case SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA:
53 return "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA";
54 case SSL_DHE_RSA_WITH_DES_CBC_SHA:
55 return "SSL_DHE_RSA_WITH_DES_CBC_SHA";
56 case SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA:
57 return "SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA";
58 case SSL_DH_anon_EXPORT_WITH_RC4_40_MD5:
59 return "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5";
60 case SSL_DH_anon_WITH_RC4_128_MD5:
61 return "SSL_DH_anon_WITH_RC4_128_MD5";
62 case SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA:
63 return "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA";
64 case SSL_DH_anon_WITH_DES_CBC_SHA:
65 return "SSL_DH_anon_WITH_DES_CBC_SHA";
66 case SSL_DH_anon_WITH_3DES_EDE_CBC_SHA:
67 return "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA";
68 case SSL_FORTEZZA_DMS_WITH_NULL_SHA:
69 return "SSL_FORTEZZA_DMS_WITH_NULL_SHA";
70 case SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA:
71 return "SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA";
72 case SSL_RSA_WITH_RC2_CBC_MD5:
73 return "SSL_RSA_WITH_RC2_CBC_MD5";
74 case SSL_RSA_WITH_IDEA_CBC_MD5:
75 return "SSL_RSA_WITH_IDEA_CBC_MD5";
76 case SSL_RSA_WITH_DES_CBC_MD5:
77 return "SSL_RSA_WITH_DES_CBC_MD5";
78 case SSL_RSA_WITH_3DES_EDE_CBC_MD5:
79 return "SSL_RSA_WITH_3DES_EDE_CBC_MD5";
80 case SSL_NO_SUCH_CIPHERSUITE:
81 return "SSL_NO_SUCH_CIPHERSUITE";
82 default:
83 sprintf(noSuite, "Unknown (%d)", (unsigned)cs);
84 return noSuite;
85 }
86 }
87
88 /*
89 * Given a SSLProtocolVersion - typically from SSLGetProtocolVersion -
90 * return a string representation.
91 */
92 const char *sslGetProtocolVersionString(SSLProtocol prot)
93 {
94 static char noProt[20];
95
96 switch(prot) {
97 case kSSLProtocolUnknown:
98 return "kSSLProtocolUnknown";
99 case kSSLProtocol2:
100 return "kSSLProtocol2";
101 case kSSLProtocol3:
102 return "kSSLProtocol3";
103 case kSSLProtocol3Only:
104 return "kSSLProtocol3Only";
105 default:
106 sprintf(noProt, "Unknown (%d)", (unsigned)prot);
107 return noProt;
108 }
109 }
110
111 /*
112 * Return string representation of SecureTransport-related OSStatus.
113 */
114 const char *sslGetSSLErrString(OSStatus err)
115 {
116 static char noErrStr[20];
117
118 switch(err) {
119 case noErr:
120 return "noErr";
121 case memFullErr:
122 return "memFullErr";
123 case unimpErr:
124 return "unimpErr";
125 case errSSLProtocol:
126 return "errSSLProtocol";
127 case errSSLNegotiation:
128 return "errSSLNegotiation";
129 case errSSLFatalAlert:
130 return "errSSLFatalAlert";
131 case errSSLWouldBlock:
132 return "errSSLWouldBlock";
133 case ioErr:
134 return "ioErr";
135 case errSSLSessionNotFound:
136 return "errSSLSessionNotFound";
137 case errSSLClosedGraceful:
138 return "errSSLClosedGraceful";
139 case errSSLClosedAbort:
140 return "errSSLClosedAbort";
141 case errSSLXCertChainInvalid:
142 return "errSSLXCertChainInvalid";
143 case errSSLBadCert:
144 return "errSSLBadCert";
145 case errSSLCrypto:
146 return "errSSLCrypto";
147 case errSSLInternal:
148 return "errSSLInternal";
149 case errSSLModuleAttach:
150 return "errSSLModuleAttach";
151 case errSSLUnknownRootCert:
152 return "errSSLUnknownRootCert";
153 case errSSLNoRootCert:
154 return "errSSLNoRootCert";
155 case errSSLCertExpired:
156 return "errSSLCertExpired";
157 case errSSLCertNotYetValid:
158 return "errSSLCertNotYetValid";
159 case badReqErr:
160 return "badReqErr";
161 case errSSLClosedNoNotify:
162 return "errSSLClosedNoNotify";
163 default:
164 sprintf(noErrStr, "Unknown (%d)", (unsigned)err);
165 return noErrStr;
166 }
167 }
168
169 void printSslErrStr(
170 const char *op,
171 OSStatus err)
172 {
173 printf("*** %s: %s\n", op, sslGetSSLErrString(err));
174 }
175