OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/certificate_viewer.h" | 5 #include "chrome/browser/certificate_viewer.h" |
6 | 6 |
7 #include <Security/Security.h> | 7 #include <Security/Security.h> |
8 #include <SecurityInterface/SFCertificatePanel.h> | 8 #include <SecurityInterface/SFCertificatePanel.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/mac/mac_util.h" |
wtc
2011/10/04 00:26:34
I believe we can include "base/mac/foundation_util
| |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "net/base/x509_certificate.h" | 14 #include "net/base/x509_certificate.h" |
15 | 15 |
16 void ShowCertificateViewer(gfx::NativeWindow parent, | 16 void ShowCertificateViewer(gfx::NativeWindow parent, |
17 net::X509Certificate* cert) { | 17 net::X509Certificate* cert) { |
18 SecCertificateRef cert_mac = cert->os_cert_handle(); | 18 base::mac::ScopedCFTypeRef<CFArrayRef> cert_list( |
19 if (!cert_mac) | 19 cert->CreateOSCertListHandle()); |
20 return; | 20 NSArray* certificates = base::mac::CFToNSCast(cert_list.get()); |
21 | |
22 base::mac::ScopedCFTypeRef<CFMutableArrayRef> certificates( | |
23 CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); | |
24 if (!certificates.get()) { | |
25 NOTREACHED(); | |
26 return; | |
27 } | |
28 CFArrayAppendValue(certificates, cert_mac); | |
29 | |
30 // Server certificate must be first in the array; subsequent certificates | |
31 // in the chain can be in any order. | |
32 const std::vector<SecCertificateRef>& ca_certs = | |
33 cert->GetIntermediateCertificates(); | |
34 for (size_t i = 0; i < ca_certs.size(); ++i) | |
35 CFArrayAppendValue(certificates, ca_certs[i]); | |
36 | 21 |
37 // Explicitly disable revocation checking, regardless of user preferences | 22 // Explicitly disable revocation checking, regardless of user preferences |
38 // or system settings. The behaviour of SFCertificatePanel is to call | 23 // or system settings. The behaviour of SFCertificatePanel is to call |
39 // SecTrustEvaluate on the certificate(s) supplied, effectively | 24 // SecTrustEvaluate on the certificate(s) supplied, effectively |
40 // duplicating the behaviour of net::X509Certificate::Verify(). However, | 25 // duplicating the behaviour of net::X509Certificate::Verify(). However, |
41 // this call stalls the UI if revocation checking is enabled in the | 26 // this call stalls the UI if revocation checking is enabled in the |
42 // Keychain preferences or if the cert may be an EV cert. By disabling | 27 // Keychain preferences or if the cert may be an EV cert. By disabling |
43 // revocation checking, the stall is limited to the time taken for path | 28 // revocation checking, the stall is limited to the time taken for path |
44 // building and verification, which should be minimized due to the path | 29 // building and verification, which should be minimized due to the path |
45 // being provided in |certificates|. This does not affect normal | 30 // being provided in |certificates|. This does not affect normal |
(...skipping 24 matching lines...) Expand all Loading... | |
70 NOTREACHED(); | 55 NOTREACHED(); |
71 return; | 56 return; |
72 } | 57 } |
73 | 58 |
74 SFCertificatePanel* panel = [[SFCertificatePanel alloc] init]; | 59 SFCertificatePanel* panel = [[SFCertificatePanel alloc] init]; |
75 [panel setPolicies:(id)policies.get()]; | 60 [panel setPolicies:(id)policies.get()]; |
76 [panel beginSheetForWindow:parent | 61 [panel beginSheetForWindow:parent |
77 modalDelegate:nil | 62 modalDelegate:nil |
78 didEndSelector:NULL | 63 didEndSelector:NULL |
79 contextInfo:NULL | 64 contextInfo:NULL |
80 certificates:reinterpret_cast<NSArray*>(certificates.get()) | 65 certificates:certificates |
81 showGroup:YES]; | 66 showGroup:YES]; |
82 // The SFCertificatePanel releases itself when the sheet is dismissed. | 67 // The SFCertificatePanel releases itself when the sheet is dismissed. |
83 } | 68 } |
OLD | NEW |