1 #ifndef _SSLS_APP_UTILS_H_
2 #define _SSLS_APP_UTILS_H_ 1
4 #include <Security/SecureTransport.h>
5 #include <Security/SecureTransportPriv.h>
6 #include <Security/Security.h>
7 #include <security_utilities/threading.h>
13 /* disable some Panther-only features */
14 #define JAGUAR_BUILD 0
16 const char *sslGetCipherSuiteString(SSLCipherSuite cs
);
17 const char *sslGetProtocolVersionString(SSLProtocol prot
);
18 const char *sslGetSSLErrString(OSStatus err
);
19 void printSslErrStr(const char *op
, OSStatus err
);
20 const char *sslGetClientCertStateString(SSLClientCertificateState state
);
21 const char *sslGetClientAuthTypeString(SSLClientAuthenticationType authType
);
23 CFArrayRef
getSslCerts(
24 const char *kcName
, // may be NULL, i.e., use default
25 CSSM_BOOL encryptOnly
,
26 CSSM_BOOL completeCertChain
,
27 const char *anchorFile
, // optional trusted anchor
28 SecKeychainRef
*pKcRef
); // RETURNED
29 OSStatus
sslCompleteCertChain(
30 SecIdentityRef identity
,
31 SecCertificateRef trustedAnchor
, // optional additional trusted anchor
32 bool includeRoot
, // include the root in outArray
33 const CSSM_OID
*vfyPolicy
, // optional - if NULL, use SSL
34 CFArrayRef
*outArray
); // created and RETURNED
35 CFArrayRef
sslKcRefToCertArray(
37 CSSM_BOOL encryptOnly
,
38 CSSM_BOOL completeCertChain
,
39 const CSSM_OID
*vfyPolicy
, // optional - if NULL, use SSL policy to complete
40 const char *trustedAnchorFile
);
42 OSStatus
addTrustedSecCert(
44 SecCertificateRef secCert
,
45 CSSM_BOOL replaceAnchors
);
46 OSStatus
sslReadAnchor(
47 const char *anchorFile
,
48 SecCertificateRef
*certRef
);
49 OSStatus
sslAddTrustedRoot(
51 const char *anchorFile
,
52 CSSM_BOOL replaceAnchors
);
55 * Assume incoming identity contains a root (e.g., created by
56 * certtool) and add that cert to ST's trusted anchors. This
57 * enables ST's verify of the incoming chain to succeed without
58 * a kludgy "AllowAnyRoot" specification.
60 OSStatus
addIdentityAsTrustedRoot(
62 CFArrayRef identArray
);
64 OSStatus
sslAddTrustedRoots(
66 SecKeychainRef keychain
,
72 * Lists of SSLCipherSuites used in sslSetCipherRestrictions.
74 extern const SSLCipherSuite suites40
[];
75 extern const SSLCipherSuite suitesDES
[];
76 extern const SSLCipherSuite suitesDES40
[];
77 extern const SSLCipherSuite suites3DES
[];
78 extern const SSLCipherSuite suitesRC4
[];
79 extern const SSLCipherSuite suitesRC4_40
[];
80 extern const SSLCipherSuite suitesRC2
[];
81 extern const SSLCipherSuite suitesAES128
[];
82 extern const SSLCipherSuite suitesAES256
[];
83 extern const SSLCipherSuite suitesDH
[];
84 extern const SSLCipherSuite suitesDHAnon
[];
85 extern const SSLCipherSuite suitesDH_RSA
[];
86 extern const SSLCipherSuite suitesDH_DSS
[];
87 extern const SSLCipherSuite suites_SHA1
[];
88 extern const SSLCipherSuite suites_MD5
[];
89 extern const SSLCipherSuite suites_ECDHE
[];
90 extern const SSLCipherSuite suites_ECDH
[];
93 * Given an SSLContextRef and an array of SSLCipherSuites, terminated by
94 * SSL_NO_SUCH_CIPHERSUITE, select those SSLCipherSuites which the library
95 * supports and do a SSLSetEnabledCiphers() specifying those.
97 OSStatus
sslSetEnabledCiphers(
99 const SSLCipherSuite
*ciphers
);
102 * Specify restricted sets of cipherspecs and protocols.
104 OSStatus
sslSetCipherRestrictions(
106 char cipherRestrict
);
109 OSStatus
sslSetProtocols(
111 const char *acceptedProts
,
112 SSLProtocol tryVersion
); // only used if acceptedProts NULL
116 const char *whichSide
, // "client" or "server"
119 int sslVerifyProtVers(
120 const char *whichSide
, // "client" or "server"
121 SSLProtocol expectProt
,
122 SSLProtocol gotProt
);
123 int sslVerifyClientCertState(
124 const char *whichSide
, // "client" or "server"
125 SSLClientCertificateState expectState
,
126 SSLClientCertificateState gotState
);
128 const char *whichSide
, // "client" or "server"
129 SSLCipherSuite expectCipher
,
130 SSLCipherSuite gotCipher
);
134 * Wrapper for sslIdentPicker, with optional trusted anchor specified as a filename.
136 OSStatus
sslIdentityPicker(
137 SecKeychainRef kcRef
, // NULL means use default list
138 const char *trustedAnchor
, // optional additional trusted anchor
139 bool includeRoot
, // true --> root is appended to outArray
140 // false --> root not included
141 const CSSM_OID
*vfyPolicy
, // optional - if NULL, use SSL
142 CFArrayRef
*outArray
); // created and RETURNED
144 void sslKeychainPath(
146 char *kcPath
); // allocd by caller, MAXPATHLEN
148 /* Verify presence of required file. Returns nonzero if not found. */
149 int sslCheckFile(const char *path
);
151 /* Stringify a SSL_ECDSA_NamedCurve */
152 extern const char *sslCurveString(
153 SSL_ECDSA_NamedCurve namedCurve
);
159 #endif /* _SSLS_APP_UTILS_H_ */