Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: net/cert/x509_util_mac.cc

Issue 2388503002: Mac: Use SecPolicyCreateSSL instead of CreatePolicy(&CSSMOID_APPLE_TP_SSL, ...) (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cert/x509_util_mac.h" 5 #include "net/cert/x509_util_mac.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/strings/sys_string_conversions.h"
9 #include "third_party/apple_apsl/cssmapplePriv.h" 11 #include "third_party/apple_apsl/cssmapplePriv.h"
10 12
11 namespace net { 13 namespace net {
12 14
13 // CSSM functions are deprecated as of OSX 10.7, but have no replacement. 15 // CSSM functions are deprecated as of OSX 10.7, but have no replacement.
14 // https://bugs.chromium.org/p/chromium/issues/detail?id=590914#c1 16 // https://bugs.chromium.org/p/chromium/issues/detail?id=590914#c1
15 #pragma clang diagnostic push 17 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 18 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
17 19
18 namespace x509_util { 20 namespace x509_util {
(...skipping 26 matching lines...) Expand all
45 return err; 47 return err;
46 } 48 }
47 } 49 }
48 return noErr; 50 return noErr;
49 } 51 }
50 52
51 } // namespace 53 } // namespace
52 54
53 55
54 OSStatus CreateSSLClientPolicy(SecPolicyRef* policy) { 56 OSStatus CreateSSLClientPolicy(SecPolicyRef* policy) {
55 CSSM_APPLE_TP_SSL_OPTIONS tp_ssl_options; 57 *policy = SecPolicyCreateSSL(false /* server */, nullptr);
56 memset(&tp_ssl_options, 0, sizeof(tp_ssl_options)); 58 return *policy ? noErr : errSecNoPolicyModule;
57 tp_ssl_options.Version = CSSM_APPLE_TP_SSL_OPTS_VERSION;
58 tp_ssl_options.Flags |= CSSM_APPLE_TP_SSL_CLIENT;
59
60 return CreatePolicy(&CSSMOID_APPLE_TP_SSL, &tp_ssl_options,
61 sizeof(tp_ssl_options), policy);
62 } 59 }
63 60
64 OSStatus CreateSSLServerPolicy(const std::string& hostname, 61 OSStatus CreateSSLServerPolicy(const std::string& hostname,
65 SecPolicyRef* policy) { 62 SecPolicyRef* policy) {
66 CSSM_APPLE_TP_SSL_OPTIONS tp_ssl_options; 63 base::ScopedCFTypeRef<CFStringRef> hostname_cfstring;
67 memset(&tp_ssl_options, 0, sizeof(tp_ssl_options));
68 tp_ssl_options.Version = CSSM_APPLE_TP_SSL_OPTS_VERSION;
69 if (!hostname.empty()) { 64 if (!hostname.empty()) {
70 tp_ssl_options.ServerName = hostname.data(); 65 hostname_cfstring.reset(base::SysUTF8ToCFStringRef(hostname));
71 tp_ssl_options.ServerNameLen = hostname.size(); 66 if (!hostname_cfstring)
67 return errSecNoPolicyModule;
72 } 68 }
73 69
74 return CreatePolicy(&CSSMOID_APPLE_TP_SSL, &tp_ssl_options, 70 *policy = SecPolicyCreateSSL(true /* server */, hostname_cfstring.get());
75 sizeof(tp_ssl_options), policy); 71 return *policy ? noErr : errSecNoPolicyModule;
76 } 72 }
77 73
78 OSStatus CreateBasicX509Policy(SecPolicyRef* policy) { 74 OSStatus CreateBasicX509Policy(SecPolicyRef* policy) {
79 return CreatePolicy(&CSSMOID_APPLE_X509_BASIC, NULL, 0, policy); 75 *policy = SecPolicyCreateBasicX509();
76 return *policy ? noErr : errSecNoPolicyModule;
80 } 77 }
81 78
82 OSStatus CreateRevocationPolicies(bool enable_revocation_checking, 79 OSStatus CreateRevocationPolicies(bool enable_revocation_checking,
83 bool enable_ev_checking, 80 bool enable_ev_checking,
84 CFMutableArrayRef policies) { 81 CFMutableArrayRef policies) {
85 OSStatus status = noErr; 82 OSStatus status = noErr;
86 83
87 // In order to bypass the system revocation checking settings, the 84 // In order to bypass the system revocation checking settings, the
88 // SecTrustRef must have at least one revocation policy associated with it. 85 // SecTrustRef must have at least one revocation policy associated with it.
89 // Since it is not known prior to verification whether the Apple TP will 86 // Since it is not known prior to verification whether the Apple TP will
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 CSSM_CL_CertAbortQuery(cl_handle_, results_handle); 229 CSSM_CL_CertAbortQuery(cl_handle_, results_handle);
233 field->Reset(cl_handle_, oid, field_ptr); 230 field->Reset(cl_handle_, oid, field_ptr);
234 return CSSM_OK; 231 return CSSM_OK;
235 } 232 }
236 233
237 } // namespace x509_util 234 } // namespace x509_util
238 235
239 #pragma clang diagnostic pop // "-Wdeprecated-declarations" 236 #pragma clang diagnostic pop // "-Wdeprecated-declarations"
240 237
241 } // namespace net 238 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698