2 * Copyright (c) 2006-2008,2010 Apple Inc. All Rights Reserved.
5 #ifndef _SSLS_APP_UTILS_H_
6 #define _SSLS_APP_UTILS_H_ 1
8 #include <Security/SecBase.h>
9 #include <Security/SecureTransport.h>
10 #include <Security/SecureTransportPriv.h>
11 #include <CoreFoundation/CFArray.h>
13 #include <Security/SecCertificate.h>
19 /* disable some Panther-only features */
20 #define JAGUAR_BUILD 0
22 const char *sslGetCipherSuiteString(SSLCipherSuite cs
);
23 const char *sslGetProtocolVersionString(SSLProtocol prot
);
24 const char *sslGetSSLErrString(OSStatus err
);
25 void printSslErrStr(const char *op
, OSStatus err
);
26 const char *sslGetClientCertStateString(SSLClientCertificateState state
);
27 const char *sslGetClientAuthTypeString(SSLClientAuthenticationType authType
);
29 CFArrayRef
getSslCerts(
30 const char *kcName
, // may be NULL, i.e., use default
32 bool completeCertChain
,
33 const char *anchorFile
, // optional trusted anchor
34 SecKeychainRef
*pKcRef
); // RETURNED
35 OSStatus
sslCompleteCertChain(
36 SecIdentityRef identity
,
37 SecCertificateRef trustedAnchor
, // optional additional trusted anchor
38 bool includeRoot
, // include the root in outArray
39 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL
40 CFArrayRef
*outArray
); // created and RETURNED
41 CFArrayRef
sslKcRefToCertArray(
44 bool completeCertChain
,
45 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL policy to complete
46 const char *trustedAnchorFile
);
48 OSStatus
addTrustedSecCert(
50 SecCertificateRef secCert
,
52 OSStatus
sslReadAnchor(
53 const char *anchorFile
,
54 SecCertificateRef
*certRef
);
55 OSStatus
sslAddTrustedRoot(
57 const char *anchorFile
,
61 * Assume incoming identity contains a root (e.g., created by
62 * certtool) and add that cert to ST's trusted anchors. This
63 * enables ST's verify of the incoming chain to succeed without
64 * a kludgy "AllowAnyRoot" specification.
66 OSStatus
addIdentityAsTrustedRoot(
68 CFArrayRef identArray
);
70 OSStatus
sslAddTrustedRoots(
72 SecKeychainRef keychain
,
75 void sslOutputDot(void);
78 * Lists of SSLCipherSuites used in sslSetCipherRestrictions.
80 extern const SSLCipherSuite suites40
[];
81 extern const SSLCipherSuite suitesDES
[];
82 extern const SSLCipherSuite suitesDES40
[];
83 extern const SSLCipherSuite suites3DES
[];
84 extern const SSLCipherSuite suitesRC4
[];
85 extern const SSLCipherSuite suitesRC4_40
[];
86 extern const SSLCipherSuite suitesRC2
[];
87 extern const SSLCipherSuite suitesAES128
[];
88 extern const SSLCipherSuite suitesAES256
[];
89 extern const SSLCipherSuite suitesDH
[];
90 extern const SSLCipherSuite suitesDHAnon
[];
91 extern const SSLCipherSuite suitesDH_RSA
[];
92 extern const SSLCipherSuite suitesDH_DSS
[];
93 extern const SSLCipherSuite suites_SHA1
[];
94 extern const SSLCipherSuite suites_MD5
[];
95 extern const SSLCipherSuite suites_ECDHE
[];
96 extern const SSLCipherSuite suites_ECDH
[];
99 * Given an SSLContextRef and an array of SSLCipherSuites, terminated by
100 * SSL_NO_SUCH_CIPHERSUITE, select those SSLCipherSuites which the library
101 * supports and do a SSLSetEnabledCiphers() specifying those.
103 OSStatus
sslSetEnabledCiphers(
105 const SSLCipherSuite
*ciphers
);
108 * Specify restricted sets of cipherspecs and protocols.
110 OSStatus
sslSetCipherRestrictions(
112 char cipherRestrict
);
115 OSStatus
sslSetProtocols(
117 const char *acceptedProts
,
118 SSLProtocol tryVersion
); // only used if acceptedProts NULL
122 const char *whichSide
, // "client" or "server"
125 int sslVerifyProtVers(
126 const char *whichSide
, // "client" or "server"
127 SSLProtocol expectProt
,
128 SSLProtocol gotProt
);
129 int sslVerifyClientCertState(
130 const char *whichSide
, // "client" or "server"
131 SSLClientCertificateState expectState
,
132 SSLClientCertificateState gotState
);
134 const char *whichSide
, // "client" or "server"
135 SSLCipherSuite expectCipher
,
136 SSLCipherSuite gotCipher
);
140 * Wrapper for sslIdentPicker, with optional trusted anchor specified as a filename.
142 OSStatus
sslIdentityPicker(
143 SecKeychainRef kcRef
, // NULL means use default list
144 const char *trustedAnchor
, // optional additional trusted anchor
145 bool includeRoot
, // true --> root is appended to outArray
146 // false --> root not included
147 // const CSSM_OID *vfyPolicy, // optional - if NULL, use SSL
148 CFArrayRef
*outArray
); // created and RETURNED
150 void sslKeychainPath(
152 char *kcPath
); // allocd by caller, MAXPATHLEN
154 /* Verify presence of required file. Returns nonzero if not found. */
155 int sslCheckFile(const char *path
);
157 /* Stringify a SSL_ECDSA_NamedCurve */
158 extern const char *sslCurveString(
159 SSL_ECDSA_NamedCurve namedCurve
);
161 SecKeyRef
create_private_key_from_der(bool ecdsa
, const unsigned char *pkey_der
, size_t pkey_der_len
);
162 CFArrayRef
chain_from_der(bool ecdsa
, const unsigned char *pkey_der
, size_t pkey_der_len
, const unsigned char *cert_der
, size_t cert_der_len
);
168 #endif /* _SSLS_APP_UTILS_H_ */