| OLD | NEW |
| 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 "chrome/browser/ssl_client_certificate_selector.h" | 5 #include "chrome/browser/ssl_client_certificate_selector.h" |
| 6 | 6 |
| 7 #import <SecurityInterface/SFChooseIdentityPanel.h> | 7 #import <SecurityInterface/SFChooseIdentityPanel.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #import "base/memory/scoped_nsobject.h" | 13 #import "base/memory/scoped_nsobject.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/ssl/ssl_client_auth_observer.h" | 17 #include "chrome/browser/ssl/ssl_client_auth_observer.h" |
| 18 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" | 18 #import "chrome/browser/ui/cocoa/constrained_window_mac.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 22 #include "net/base/ssl_cert_request_info.h" | 22 #include "net/base/ssl_cert_request_info.h" |
| 23 #include "net/base/x509_certificate.h" | 23 #include "net/base/x509_certificate.h" |
| 24 #include "net/base/x509_util_mac.h" | 24 #include "net/base/x509_util_mac.h" |
| 25 #include "ui/base/l10n/l10n_util_mac.h" | 25 #include "ui/base/l10n/l10n_util_mac.h" |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 | 28 |
| 29 @interface SFChooseIdentityPanel (SystemPrivate) | 29 @interface SFChooseIdentityPanel (SystemPrivate) |
| 30 // A system-private interface that dismisses a panel whose sheet was started by | 30 // A system-private interface that dismisses a panel whose sheet was started by |
| 31 // beginSheetForWindow:modalDelegate:didEndSelector:contextInfo:identities:messa
ge: | 31 // -beginSheetForWindow:modalDelegate:didEndSelector:contextInfo:identities:mess
age: |
| 32 // as though the user clicked the button identified by returnCode. Verified | 32 // as though the user clicked the button identified by returnCode. Verified |
| 33 // present in 10.5, 10.6, and 10.7. | 33 // present in 10.5, 10.6, and 10.7. |
| 34 - (void)_dismissWithCode:(NSInteger)code; | 34 - (void)_dismissWithCode:(NSInteger)code; |
| 35 @end | 35 @end |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 class NotificationProxy; | 38 class NotificationProxy; |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 @interface SSLClientCertificateSelectorCocoa : NSObject { | 41 @interface SSLClientCertificateSelectorCocoa : NSObject { |
| 42 @private | 42 @private |
| 43 // The list of identities offered to the user. | 43 // The list of identities offered to the user. |
| 44 scoped_nsobject<NSMutableArray> identities_; | 44 scoped_nsobject<NSMutableArray> identities_; |
| 45 // The corresponding list of certificates. | 45 // The corresponding list of certificates. |
| 46 std::vector<scoped_refptr<net::X509Certificate> > certificates_; | 46 std::vector<scoped_refptr<net::X509Certificate> > certificates_; |
| 47 // The currently open dialog. | 47 // The currently open dialog. |
| 48 ConstrainedWindow* window_; | 48 ConstrainedWindow* window_; |
| 49 // A C++ object to proxy SSLClientAuthObserver notifications to us. | 49 // A C++ object to proxy SSLClientAuthObserver notifications to us. |
| 50 scoped_ptr<NotificationProxy> observer_; | 50 scoped_ptr<NotificationProxy> observer_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 - (id)initWithObserver:(const net::HttpNetworkSession*)networkSession | 53 - (id)initWithObserver:(const net::HttpNetworkSession*)networkSession |
| 54 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo | 54 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo |
| 55 callback:(const base::Callback<void(net::X509Certificate*)>&)callback; | 55 callback:(const base::Callback<void(net::X509Certificate*)>&)callback; |
| 56 - (void)onNotification; | 56 - (void)onNotification; |
| 57 - (void)displayDialog:(TabContentsWrapper*)wrapper; | 57 - (void)displayDialog:(TabContents*)tabContents; |
| 58 @end | 58 @end |
| 59 | 59 |
| 60 namespace { | 60 namespace { |
| 61 | 61 |
| 62 class ConstrainedSFChooseIdentityPanel | 62 class ConstrainedSFChooseIdentityPanel |
| 63 : public ConstrainedWindowMacDelegateSystemSheet { | 63 : public ConstrainedWindowMacDelegateSystemSheet { |
| 64 public: | 64 public: |
| 65 ConstrainedSFChooseIdentityPanel(SFChooseIdentityPanel* panel, | 65 ConstrainedSFChooseIdentityPanel(SFChooseIdentityPanel* panel, |
| 66 id delegate, SEL didEndSelector, | 66 id delegate, SEL didEndSelector, |
| 67 NSArray* identities, NSString* message) | 67 NSArray* identities, NSString* message) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 SSLClientCertificateSelectorCocoa* controller_; | 129 SSLClientCertificateSelectorCocoa* controller_; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 namespace browser { | 134 namespace browser { |
| 135 | 135 |
| 136 void ShowSSLClientCertificateSelector( | 136 void ShowSSLClientCertificateSelector( |
| 137 TabContentsWrapper* wrapper, | 137 TabContents* tabContents, |
| 138 const net::HttpNetworkSession* network_session, | 138 const net::HttpNetworkSession* network_session, |
| 139 net::SSLCertRequestInfo* cert_request_info, | 139 net::SSLCertRequestInfo* cert_request_info, |
| 140 const base::Callback<void(net::X509Certificate*)>& callback) { | 140 const base::Callback<void(net::X509Certificate*)>& callback) { |
| 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 142 SSLClientCertificateSelectorCocoa* selector = | 142 SSLClientCertificateSelectorCocoa* selector = |
| 143 [[[SSLClientCertificateSelectorCocoa alloc] | 143 [[[SSLClientCertificateSelectorCocoa alloc] |
| 144 initWithObserver:network_session | 144 initWithObserver:network_session |
| 145 certRequestInfo:cert_request_info | 145 certRequestInfo:cert_request_info |
| 146 callback:callback] autorelease]; | 146 callback:callback] autorelease]; |
| 147 [selector displayDialog:wrapper]; | 147 [selector displayDialog:tabContents]; |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace browser | 150 } // namespace browser |
| 151 | 151 |
| 152 @implementation SSLClientCertificateSelectorCocoa | 152 @implementation SSLClientCertificateSelectorCocoa |
| 153 | 153 |
| 154 - (id)initWithObserver:(const net::HttpNetworkSession*)networkSession | 154 - (id)initWithObserver:(const net::HttpNetworkSession*)networkSession |
| 155 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo | 155 certRequestInfo:(net::SSLCertRequestInfo*)certRequestInfo |
| 156 callback:(const base::Callback<void(net::X509Certificate*)>&)callback { | 156 callback:(const base::Callback<void(net::X509Certificate*)>&)callback { |
| 157 DCHECK(networkSession); | 157 DCHECK(networkSession); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 184 observer_->CertificateSelected(cert); | 184 observer_->CertificateSelected(cert); |
| 185 // Close the constrained window. | 185 // Close the constrained window. |
| 186 DCHECK(window_); | 186 DCHECK(window_); |
| 187 window_->CloseConstrainedWindow(); | 187 window_->CloseConstrainedWindow(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 - (void)onNotification { | 190 - (void)onNotification { |
| 191 window_->CloseConstrainedWindow(); | 191 window_->CloseConstrainedWindow(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 - (void)displayDialog:(TabContentsWrapper*)wrapper { | 194 - (void)displayDialog:(TabContents*)tabContents { |
| 195 DCHECK(!window_); | 195 DCHECK(!window_); |
| 196 // Create an array of CFIdentityRefs for the certificates: | 196 // Create an array of CFIdentityRefs for the certificates: |
| 197 size_t numCerts = observer_->cert_request_info()->client_certs.size(); | 197 size_t numCerts = observer_->cert_request_info()->client_certs.size(); |
| 198 identities_.reset([[NSMutableArray alloc] initWithCapacity:numCerts]); | 198 identities_.reset([[NSMutableArray alloc] initWithCapacity:numCerts]); |
| 199 for (size_t i = 0; i < numCerts; ++i) { | 199 for (size_t i = 0; i < numCerts; ++i) { |
| 200 SecCertificateRef cert; | 200 SecCertificateRef cert; |
| 201 cert = observer_->cert_request_info()->client_certs[i]->os_cert_handle(); | 201 cert = observer_->cert_request_info()->client_certs[i]->os_cert_handle(); |
| 202 SecIdentityRef identity; | 202 SecIdentityRef identity; |
| 203 if (SecIdentityCreateWithCertificate(NULL, cert, &identity) == noErr) { | 203 if (SecIdentityCreateWithCertificate(NULL, cert, &identity) == noErr) { |
| 204 [identities_ addObject:(id)identity]; | 204 [identities_ addObject:(id)identity]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 218 [panel setInformativeText:message]; | 218 [panel setInformativeText:message]; |
| 219 [panel setDefaultButtonTitle:l10n_util::GetNSString(IDS_OK)]; | 219 [panel setDefaultButtonTitle:l10n_util::GetNSString(IDS_OK)]; |
| 220 [panel setAlternateButtonTitle:l10n_util::GetNSString(IDS_CANCEL)]; | 220 [panel setAlternateButtonTitle:l10n_util::GetNSString(IDS_CANCEL)]; |
| 221 SecPolicyRef sslPolicy; | 221 SecPolicyRef sslPolicy; |
| 222 if (net::x509_util::CreateSSLClientPolicy(&sslPolicy) == noErr) { | 222 if (net::x509_util::CreateSSLClientPolicy(&sslPolicy) == noErr) { |
| 223 [panel setPolicies:(id)sslPolicy]; | 223 [panel setPolicies:(id)sslPolicy]; |
| 224 CFRelease(sslPolicy); | 224 CFRelease(sslPolicy); |
| 225 } | 225 } |
| 226 | 226 |
| 227 window_ = new ConstrainedWindowMac( | 227 window_ = new ConstrainedWindowMac( |
| 228 wrapper, | 228 tabContents, |
| 229 new ConstrainedSFChooseIdentityPanel( | 229 new ConstrainedSFChooseIdentityPanel( |
| 230 panel, self, | 230 panel, self, |
| 231 @selector(sheetDidEnd:returnCode:context:), | 231 @selector(sheetDidEnd:returnCode:context:), |
| 232 identities_, title)); | 232 identities_, title)); |
| 233 observer_->StartObserving(); | 233 observer_->StartObserving(); |
| 234 // Note: SFChooseIdentityPanel does not take a reference to itself while the | 234 // Note: SFChooseIdentityPanel does not take a reference to itself while the |
| 235 // sheet is open. ConstrainedSFChooseIdentityPanel will release ownership | 235 // sheet is open. ConstrainedSFChooseIdentityPanel will release ownership |
| 236 // on destruction. | 236 // on destruction. |
| 237 } | 237 } |
| 238 | 238 |
| 239 @end | 239 @end |
| OLD | NEW |