2 * Copyright (c) 2006-2008,2010-2012,2014 Apple Inc. All Rights Reserved.
5 #ifndef _SSLS_APP_UTILS_H_
6 #define _SSLS_APP_UTILS_H_ 1
8 #include <Security/SecureTransport.h>
9 #include <Security/SecureTransportPriv.h>
10 #include <CoreFoundation/CFArray.h>
12 #include <Security/SecCertificate.h>
14 #include <TargetConditionals.h>
17 typedef void *SecKeychainRef
;
24 const char *sslGetCipherSuiteString(SSLCipherSuite cs
);
25 const char *sslGetProtocolVersionString(SSLProtocol prot
);
26 const char *sslGetSSLErrString(OSStatus err
);
27 void printSslErrStr(const char *op
, OSStatus err
);
28 const char *sslGetClientCertStateString(SSLClientCertificateState state
);
29 const char *sslGetClientAuthTypeString(SSLClientAuthenticationType authType
);
31 CFArrayRef
getSslCerts(
32 const char *kcName
, // may be NULL, i.e., use default
34 bool completeCertChain
,
35 const char *anchorFile
, // optional trusted anchor
36 SecKeychainRef
*pKcRef
); // RETURNED
37 OSStatus
sslCompleteCertChain(
38 SecIdentityRef identity
,
39 SecCertificateRef trustedAnchor
, // optional additional trusted anchor
40 bool includeRoot
, // include the root in outArray
41 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL
42 CFArrayRef
*outArray
); // created and RETURNED
43 CFArrayRef
sslKcRefToCertArray(
46 bool completeCertChain
,
47 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL policy to complete
48 const char *trustedAnchorFile
);
50 OSStatus
addTrustedSecCert(
52 SecCertificateRef secCert
,
54 OSStatus
sslReadAnchor(
55 const char *anchorFile
,
56 SecCertificateRef
*certRef
);
57 OSStatus
sslAddTrustedRoot(
59 const char *anchorFile
,
63 * Assume incoming identity contains a root (e.g., created by
64 * certtool) and add that cert to ST's trusted anchors. This
65 * enables ST's verify of the incoming chain to succeed without
66 * a kludgy "AllowAnyRoot" specification.
68 OSStatus
addIdentityAsTrustedRoot(
70 CFArrayRef identArray
);
72 OSStatus
sslAddTrustedRoots(
74 SecKeychainRef keychain
,
80 * Lists of SSLCipherSuites used in sslSetCipherRestrictions.
82 extern const SSLCipherSuite suites40
[];
83 extern const SSLCipherSuite suitesDES
[];
84 extern const SSLCipherSuite suitesDES40
[];
85 extern const SSLCipherSuite suites3DES
[];
86 extern const SSLCipherSuite suitesRC4
[];
87 extern const SSLCipherSuite suitesRC4_40
[];
88 extern const SSLCipherSuite suitesRC2
[];
89 extern const SSLCipherSuite suitesAES128
[];
90 extern const SSLCipherSuite suitesAES256
[];
91 extern const SSLCipherSuite suitesDH
[];
92 extern const SSLCipherSuite suitesDHAnon
[];
93 extern const SSLCipherSuite suitesDH_RSA
[];
94 extern const SSLCipherSuite suitesDH_DSS
[];
95 extern const SSLCipherSuite suites_SHA1
[];
96 extern const SSLCipherSuite suites_MD5
[];
97 extern const SSLCipherSuite suites_ECDHE
[];
98 extern const SSLCipherSuite suites_ECDH
[];
101 * Given an SSLContextRef and an array of SSLCipherSuites, terminated by
102 * SSL_NO_SUCH_CIPHERSUITE, select those SSLCipherSuites which the library
103 * supports and do a SSLSetEnabledCiphers() specifying those.
105 OSStatus
sslSetEnabledCiphers(
107 const SSLCipherSuite
*ciphers
);
110 * Specify restricted sets of cipherspecs and protocols.
112 OSStatus
sslSetCipherRestrictions(
114 char cipherRestrict
);
117 OSStatus
sslSetProtocols(
119 const char *acceptedProts
,
120 SSLProtocol tryVersion
); // only used if acceptedProts NULL
124 const char *whichSide
, // "client" or "server"
127 int sslVerifyProtVers(
128 const char *whichSide
, // "client" or "server"
129 SSLProtocol expectProt
,
130 SSLProtocol gotProt
);
131 int sslVerifyClientCertState(
132 const char *whichSide
, // "client" or "server"
133 SSLClientCertificateState expectState
,
134 SSLClientCertificateState gotState
);
136 const char *whichSide
, // "client" or "server"
137 SSLCipherSuite expectCipher
,
138 SSLCipherSuite gotCipher
);
142 * Wrapper for sslIdentPicker, with optional trusted anchor specified as a filename.
144 OSStatus
sslIdentityPicker(
145 SecKeychainRef kcRef
, // NULL means use default list
146 const char *trustedAnchor
, // optional additional trusted anchor
147 bool includeRoot
, // true --> root is appended to outArray
148 // false --> root not included
149 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL
150 CFArrayRef
*outArray
); // created and RETURNED
152 void sslKeychainPath(
154 char *kcPath
); // allocd by caller, MAXPATHLEN
156 /* Verify presence of required file. Returns nonzero if not found. */
157 int sslCheckFile(const char *path
);
159 /* Stringify a SSL_ECDSA_NamedCurve */
160 extern const char *sslCurveString(
161 SSL_ECDSA_NamedCurve namedCurve
);
167 #endif /* _SSLS_APP_UTILS_H_ */