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

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

Issue 2373533003: Mac: Use SecPolicyCreateSSL instead of CreatePolicy(&CSSMOID_APPLE_TP_SSL, ...) (Closed)
Patch Set: review changes 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) {
63 base::ScopedCFTypeRef<CFStringRef> hostname_cfstring;
66 if (!hostname.empty()) { 64 if (!hostname.empty()) {
67 CSSM_APPLE_TP_SSL_OPTIONS tp_ssl_options; 65 hostname_cfstring.reset(base::SysUTF8ToCFStringRef(hostname));
68 memset(&tp_ssl_options, 0, sizeof(tp_ssl_options)); 66 if (!hostname_cfstring)
69 tp_ssl_options.Version = CSSM_APPLE_TP_SSL_OPTS_VERSION; 67 return errSecNoPolicyModule;
70 tp_ssl_options.ServerName = hostname.data();
71 tp_ssl_options.ServerNameLen = hostname.size();
72
73 return CreatePolicy(&CSSMOID_APPLE_TP_SSL, &tp_ssl_options,
74 sizeof(tp_ssl_options), policy);
75 } 68 }
76 69
77 return CreatePolicy(&CSSMOID_APPLE_TP_SSL, nullptr, 0U, policy); 70 *policy = SecPolicyCreateSSL(true /* server */, hostname_cfstring.get());
71 return *policy ? noErr : errSecNoPolicyModule;
78 } 72 }
79 73
80 OSStatus CreateBasicX509Policy(SecPolicyRef* policy) { 74 OSStatus CreateBasicX509Policy(SecPolicyRef* policy) {
81 return CreatePolicy(&CSSMOID_APPLE_X509_BASIC, NULL, 0, policy); 75 *policy = SecPolicyCreateBasicX509();
76 return *policy ? noErr : errSecNoPolicyModule;
82 } 77 }
83 78
84 OSStatus CreateRevocationPolicies(bool enable_revocation_checking, 79 OSStatus CreateRevocationPolicies(bool enable_revocation_checking,
85 bool enable_ev_checking, 80 bool enable_ev_checking,
86 CFMutableArrayRef policies) { 81 CFMutableArrayRef policies) {
87 OSStatus status = noErr; 82 OSStatus status = noErr;
88 83
89 // In order to bypass the system revocation checking settings, the 84 // In order to bypass the system revocation checking settings, the
90 // SecTrustRef must have at least one revocation policy associated with it. 85 // SecTrustRef must have at least one revocation policy associated with it.
91 // 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
234 CSSM_CL_CertAbortQuery(cl_handle_, results_handle); 229 CSSM_CL_CertAbortQuery(cl_handle_, results_handle);
235 field->Reset(cl_handle_, oid, field_ptr); 230 field->Reset(cl_handle_, oid, field_ptr);
236 return CSSM_OK; 231 return CSSM_OK;
237 } 232 }
238 233
239 } // namespace x509_util 234 } // namespace x509_util
240 235
241 #pragma clang diagnostic pop // "-Wdeprecated-declarations" 236 #pragma clang diagnostic pop // "-Wdeprecated-declarations"
242 237
243 } // 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