2 * nisccSimpleClient.cpp - just do one SSL client session expecting
3 * errSSLPeerCertUnknown and ClientCertRejected
6 #include <Security/SecureTransport.h>
7 #include <Security/Security.h>
8 #include <Security/SecBasePriv.h>
9 #include <clAppUtils/sslAppUtils.h>
10 #include <clAppUtils/ioSock.h>
11 #include <clAppUtils/sslThreading.h>
12 #include <security_cdsa_utils/cuFileIo.h>
13 #include <security_cdsa_utils/cuCdsaUtils.h>
14 #include <security_cdsa_utils/cuPrintCert.h>
15 #include <security_utilities/threading.h>
16 #include <security_utilities/devrandom.h>
18 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
25 #include <sys/param.h>
27 /* skip certs larger than this - ST can't fragment protocol msgs (yet) */
28 #define MAX_CERT_SIZE 16000
30 static void usage(char **argv
)
32 printf("Usage: %s hostname port keychain [q(uiet)]\n", argv
[0]);
36 #define IGNORE_SIGPIPE 1
43 #endif /* IGNORE_SIGPIPE */
45 SslAppTestParams clientDefaults
=
47 NULL
, // hostName - user-provided
48 true, // skipHostNameCHeck
49 0, // port - user-provided
50 NULL
, NULL
, // RingBuffers
53 NULL
, // acceptedProts - not used in this test
54 NULL
, // myCerts - user-provided
55 NULL
, // password - same as myCerts
56 false, // idIsTrustedRoot
57 true, // disableCertVerify - SPECIAL FOR THIS TEST
58 NULL
, // anchorFile - not needed - right?
59 false, // replaceAnchors
61 false, // resumeEnable
66 errSSLPeerCertUnknown
, // expectRtn
67 kTLSProtocol1
, // expectVersion
68 kSSLClientCertRejected
,
70 false, // quiet - user-provided
78 SSL_NULL_WITH_NULL_NULL
,
84 static void testStartBanner(
89 printf("Starting %s; args: ", testName
);
90 for(int i
=1; i
<argc
; i
++) {
91 printf("%s ", argv
[i
]);
96 /* this normally comes from libcsputils.a, which we don't link against */
99 char *cssmErrToStr(CSSM_RETURN err
);
102 char *cssmErrToStr(CSSM_RETURN err
)
104 string errStr
= cssmErrorString(err
);
105 return const_cast<char *>(errStr
.c_str());
109 int main(int argc
, char **argv
)
120 clientDefaults
.hostName
= argv
[1];
121 clientDefaults
.password
= argv
[1];
122 clientDefaults
.port
= atoi(argv
[2]);
123 clientDefaults
.myCertKcName
= argv
[3];
126 for(int arg
=4; arg
<argc
; arg
++) {
130 clientDefaults
.quiet
= true;
138 signal(SIGPIPE
, sigpipe
);
141 if(!clientDefaults
.quiet
) {
142 testStartBanner("nisccSimpleClient", argc
, argv
);
144 ourRtn
= sslAppClient(&clientDefaults
);
146 /* accept a number of returns - even success! */
147 if((ourRtn
!= errSSLPeerCertUnknown
) &&
148 (ourRtn
!= errSSLPeerUnknownCA
) &&
149 (ourRtn
!= errSSLPeerRecordOverflow
) &&
151 printf("***Unexpected error return (%s)\n",
152 sslGetSSLErrString(ourRtn
));
155 if(ourRtn
== noErr
) {
156 errCount
+= sslVerifyClientCertState("client",
158 clientDefaults
.certState
);
161 errCount
+= sslVerifyClientCertState("client",
162 clientDefaults
.expectCertState
,
163 clientDefaults
.certState
);
166 if(!clientDefaults
.quiet
) {
168 printf("===== %s test PASSED =====\n", argv
[0]);
172 printf("****FAIL: sslAppClient detected %d errors\n", errCount
);