OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "chrome/browser/ui/certificate_viewer_mac.h" | |
6 | |
7 #include "base/mac/foundation_util.h" | |
8 #include "base/mac/scoped_cftyperef.h" | |
9 #import "base/mac/scoped_nsobject.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 #include "net/cert/x509_certificate.h" | |
12 #include "net/cert/x509_util_mac.h" | |
13 | |
14 @implementation SSLCertificateViewerMac { | |
15 // The corresponding list of certificates. | |
16 base::scoped_nsobject<NSArray> certificates_; | |
17 base::scoped_nsobject<SFCertificatePanel> panel_; | |
18 } | |
19 | |
20 - (id)initWithCertificate:(net::X509Certificate*)certificate { | |
21 if ((self = [super init])) { | |
22 base::ScopedCFTypeRef<CFArrayRef> cert_chain( | |
Robert Sesek
2016/08/24 18:42:41
naming: certChain
Patti Lor
2016/08/25 08:25:12
Done.
| |
23 certificate->CreateOSCertChainForCert()); | |
24 NSArray* certificates = base::mac::CFToNSCast(cert_chain.get()); | |
25 certificates_.reset([certificates retain]); | |
26 } | |
27 return self; | |
28 } | |
29 | |
30 - (void)sheetDidEnd:(NSWindow*)parent | |
31 returnCode:(NSInteger)returnCode | |
32 context:(void*)context { | |
33 NOTREACHED(); // Subclasses must implement this. | |
34 } | |
35 | |
36 - (void)displayForWebContents:(content::WebContents*)webContents { | |
37 // Explicitly disable revocation checking, regardless of user preferences | |
38 // or system settings. The behaviour of SFCertificatePanel is to call | |
39 // SecTrustEvaluate on the certificate(s) supplied, effectively | |
40 // duplicating the behaviour of net::X509Certificate::Verify(). However, | |
41 // 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 | |
43 // revocation checking, the stall is limited to the time taken for path | |
44 // building and verification, which should be minimized due to the path | |
45 // being provided in |certificates|. This does not affect normal | |
46 // revocation checking from happening, which is controlled by | |
47 // net::X509Certificate::Verify() and user preferences, but will prevent | |
48 // the certificate viewer UI from displaying which certificate is revoked. | |
49 // This is acceptable, as certificate revocation will still be shown in | |
50 // the page info bubble if a certificate in the chain is actually revoked. | |
51 base::ScopedCFTypeRef<CFMutableArrayRef> policies( | |
52 CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); | |
53 if (!policies.get()) { | |
54 NOTREACHED(); | |
55 return; | |
56 } | |
57 // Add a basic X.509 policy, in order to match the behaviour of | |
58 // SFCertificatePanel when no policies are specified. | |
59 SecPolicyRef basic_policy = NULL; | |
Robert Sesek
2016/08/24 18:42:41
naming: basicPolicy
Patti Lor
2016/08/25 08:25:12
Done.
| |
60 OSStatus status = net::x509_util::CreateBasicX509Policy(&basic_policy); | |
61 if (status != noErr) { | |
62 NOTREACHED(); | |
63 return; | |
64 } | |
65 CFArrayAppendValue(policies, basic_policy); | |
66 CFRelease(basic_policy); | |
67 | |
68 status = net::x509_util::CreateRevocationPolicies(false, false, policies); | |
69 if (status != noErr) { | |
70 NOTREACHED(); | |
71 return; | |
72 } | |
73 | |
74 panel_.reset([[SFCertificatePanel alloc] init]); | |
75 [panel_ setPolicies:(id)policies.get()]; | |
Robert Sesek
2016/08/24 18:42:41
CFToNSCast again?
Patti Lor
2016/08/25 08:25:12
Done.
| |
76 } | |
77 | |
78 - (void)showCertificateSheet:(NSWindow*)window { | |
79 [panel_ beginSheetForWindow:window | |
80 modalDelegate:self | |
81 didEndSelector:@selector(sheetDidEnd:returnCode:context:) | |
82 contextInfo:NULL | |
83 certificates:certificates_ | |
84 showGroup:YES]; | |
85 } | |
86 | |
87 - (void)closeCertificateSheet { | |
88 // Closing the sheet using -[NSApp endSheet:] doesn't work so use the private | |
89 // method. | |
90 [panel_ _dismissWithCode:NSFileHandlingPanelCancelButton]; | |
91 certificates_.reset(); | |
92 } | |
93 | |
94 - (void)releaseSheetWindow { | |
95 panel_.reset(); | |
96 } | |
97 | |
98 - (NSWindow*)certificatePanel { | |
99 return panel_; | |
100 } | |
101 | |
102 @end | |
OLD | NEW |