2 * Copyright (c) 2006-2008,2010-2012 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>
18 typedef struct OpaqueSecKeychainRef
*SecKeychainRef
;
20 const char *sslGetCipherSuiteString(SSLCipherSuite cs
);
21 const char *sslGetProtocolVersionString(SSLProtocol prot
);
22 const char *sslGetSSLErrString(OSStatus err
);
23 void printSslErrStr(const char *op
, OSStatus err
);
24 const char *sslGetClientCertStateString(SSLClientCertificateState state
);
25 const char *sslGetClientAuthTypeString(SSLClientAuthenticationType authType
);
27 CFArrayRef
getSslCerts(
28 const char *kcName
, // may be NULL, i.e., use default
30 bool completeCertChain
,
31 const char *anchorFile
, // optional trusted anchor
32 SecKeychainRef
*pKcRef
); // RETURNED
33 OSStatus
sslCompleteCertChain(
34 SecIdentityRef identity
,
35 SecCertificateRef trustedAnchor
, // optional additional trusted anchor
36 bool includeRoot
, // include the root in outArray
37 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL
38 CFArrayRef
*outArray
); // created and RETURNED
39 CFArrayRef
sslKcRefToCertArray(
42 bool completeCertChain
,
43 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL policy to complete
44 const char *trustedAnchorFile
);
46 OSStatus
addTrustedSecCert(
48 SecCertificateRef secCert
,
50 OSStatus
sslReadAnchor(
51 const char *anchorFile
,
52 SecCertificateRef
*certRef
);
53 OSStatus
sslAddTrustedRoot(
55 const char *anchorFile
,
59 * Assume incoming identity contains a root (e.g., created by
60 * certtool) and add that cert to ST's trusted anchors. This
61 * enables ST's verify of the incoming chain to succeed without
62 * a kludgy "AllowAnyRoot" specification.
64 OSStatus
addIdentityAsTrustedRoot(
66 CFArrayRef identArray
);
68 OSStatus
sslAddTrustedRoots(
70 SecKeychainRef keychain
,
76 * Lists of SSLCipherSuites used in sslSetCipherRestrictions.
78 extern const SSLCipherSuite suites40
[];
79 extern const SSLCipherSuite suitesDES
[];
80 extern const SSLCipherSuite suitesDES40
[];
81 extern const SSLCipherSuite suites3DES
[];
82 extern const SSLCipherSuite suitesRC4
[];
83 extern const SSLCipherSuite suitesRC4_40
[];
84 extern const SSLCipherSuite suitesRC2
[];
85 extern const SSLCipherSuite suitesAES128
[];
86 extern const SSLCipherSuite suitesAES256
[];
87 extern const SSLCipherSuite suitesDH
[];
88 extern const SSLCipherSuite suitesDHAnon
[];
89 extern const SSLCipherSuite suitesDH_RSA
[];
90 extern const SSLCipherSuite suitesDH_DSS
[];
91 extern const SSLCipherSuite suites_SHA1
[];
92 extern const SSLCipherSuite suites_MD5
[];
93 extern const SSLCipherSuite suites_ECDHE
[];
94 extern const SSLCipherSuite suites_ECDH
[];
97 * Given an SSLContextRef and an array of SSLCipherSuites, terminated by
98 * SSL_NO_SUCH_CIPHERSUITE, select those SSLCipherSuites which the library
99 * supports and do a SSLSetEnabledCiphers() specifying those.
101 OSStatus
sslSetEnabledCiphers(
103 const SSLCipherSuite
*ciphers
);
106 * Specify restricted sets of cipherspecs and protocols.
108 OSStatus
sslSetCipherRestrictions(
110 char cipherRestrict
);
113 OSStatus
sslSetProtocols(
115 const char *acceptedProts
,
116 SSLProtocol tryVersion
); // only used if acceptedProts NULL
120 const char *whichSide
, // "client" or "server"
123 int sslVerifyProtVers(
124 const char *whichSide
, // "client" or "server"
125 SSLProtocol expectProt
,
126 SSLProtocol gotProt
);
127 int sslVerifyClientCertState(
128 const char *whichSide
, // "client" or "server"
129 SSLClientCertificateState expectState
,
130 SSLClientCertificateState gotState
);
132 const char *whichSide
, // "client" or "server"
133 SSLCipherSuite expectCipher
,
134 SSLCipherSuite gotCipher
);
138 * Wrapper for sslIdentPicker, with optional trusted anchor specified as a filename.
140 OSStatus
sslIdentityPicker(
141 SecKeychainRef kcRef
, // NULL means use default list
142 const char *trustedAnchor
, // optional additional trusted anchor
143 bool includeRoot
, // true --> root is appended to outArray
144 // false --> root not included
145 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL
146 CFArrayRef
*outArray
); // created and RETURNED
148 void sslKeychainPath(
150 char *kcPath
); // allocd by caller, MAXPATHLEN
152 /* Verify presence of required file. Returns nonzero if not found. */
153 int sslCheckFile(const char *path
);
155 /* Stringify a SSL_ECDSA_NamedCurve */
156 extern const char *sslCurveString(
157 SSL_ECDSA_NamedCurve namedCurve
);
163 #endif /* _SSLS_APP_UTILS_H_ */