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

Side by Side Diff: chrome/browser/gtk/ssl_client_certificate_selector.cc

Issue 5686002: NSS: PKCS 11 password prompt. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "app/gtk_signal.h" 12 #include "app/gtk_signal.h"
13 #include "app/l10n_util.h" 13 #include "app/l10n_util.h"
14 #include "base/i18n/time_formatting.h" 14 #include "base/i18n/time_formatting.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/nss_util.h" 16 #include "base/nss_util.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/certificate_viewer.h" 18 #include "chrome/browser/certificate_viewer.h"
19 #include "chrome/browser/gtk/constrained_window_gtk.h" 19 #include "chrome/browser/gtk/constrained_window_gtk.h"
20 #include "chrome/browser/gtk/gtk_util.h" 20 #include "chrome/browser/gtk/gtk_util.h"
21 #include "chrome/browser/gtk/owned_widget_gtk.h" 21 #include "chrome/browser/gtk/owned_widget_gtk.h"
22 #include "chrome/browser/ssl/ssl_client_auth_handler.h" 22 #include "chrome/browser/ssl/ssl_client_auth_handler.h"
23 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
24 #include "chrome/browser/ui/pk11_password_dialog.h"
24 #include "chrome/common/net/x509_certificate_model.h" 25 #include "chrome/common/net/x509_certificate_model.h"
25 #include "gfx/native_widget_types.h" 26 #include "gfx/native_widget_types.h"
26 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
27 #include "net/base/x509_certificate.h" 28 #include "net/base/x509_certificate.h"
28 29
29 namespace { 30 namespace {
30 31
31 enum { 32 enum {
32 RESPONSE_SHOW_CERT_INFO = 1, 33 RESPONSE_SHOW_CERT_INFO = 1,
33 }; 34 };
(...skipping 19 matching lines...) Expand all
53 void PopulateCerts(); 54 void PopulateCerts();
54 55
55 net::X509Certificate* GetSelectedCert(); 56 net::X509Certificate* GetSelectedCert();
56 57
57 static std::string FormatComboBoxText( 58 static std::string FormatComboBoxText(
58 net::X509Certificate::OSCertHandle cert, 59 net::X509Certificate::OSCertHandle cert,
59 const std::string& nickname); 60 const std::string& nickname);
60 static std::string FormatDetailsText( 61 static std::string FormatDetailsText(
61 net::X509Certificate::OSCertHandle cert); 62 net::X509Certificate::OSCertHandle cert);
62 63
64 // Callback after unlocking certificate slot.
65 void Unlocked();
66
63 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnComboBoxChanged); 67 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnComboBoxChanged);
64 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnViewClicked); 68 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnViewClicked);
65 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnCancelClicked); 69 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnCancelClicked);
66 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnOkClicked); 70 CHROMEGTK_CALLBACK_0(SSLClientCertificateSelector, void, OnOkClicked);
67 CHROMEGTK_CALLBACK_1(SSLClientCertificateSelector, void, OnPromptShown, 71 CHROMEGTK_CALLBACK_1(SSLClientCertificateSelector, void, OnPromptShown,
68 GtkWidget*); 72 GtkWidget*);
69 73
70 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_; 74 scoped_refptr<net::SSLCertRequestInfo> cert_request_info_;
71 75
72 std::vector<std::string> details_strings_; 76 std::vector<std::string> details_strings_;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return rv; 243 return rv;
240 } 244 }
241 245
242 // static 246 // static
243 std::string SSLClientCertificateSelector::FormatDetailsText( 247 std::string SSLClientCertificateSelector::FormatDetailsText(
244 net::X509Certificate::OSCertHandle cert) { 248 net::X509Certificate::OSCertHandle cert) {
245 std::string rv; 249 std::string rv;
246 250
247 rv += l10n_util::GetStringFUTF8( 251 rv += l10n_util::GetStringFUTF8(
248 IDS_CERT_SUBJECTNAME_FORMAT, 252 IDS_CERT_SUBJECTNAME_FORMAT,
249 UTF8ToUTF16(x509_certificate_model::GetSubjectName(cert)));; 253 UTF8ToUTF16(x509_certificate_model::GetSubjectName(cert)));
250 254
251 rv += "\n "; 255 rv += "\n ";
252 rv += l10n_util::GetStringFUTF8( 256 rv += l10n_util::GetStringFUTF8(
253 IDS_CERT_SERIAL_NUMBER_FORMAT, 257 IDS_CERT_SERIAL_NUMBER_FORMAT,
254 UTF8ToUTF16( 258 UTF8ToUTF16(
255 x509_certificate_model::GetSerialNumberHexified(cert, ""))); 259 x509_certificate_model::GetSerialNumberHexified(cert, "")));
256 260
257 base::Time issued, expires; 261 base::Time issued, expires;
258 if (x509_certificate_model::GetTimes(cert, &issued, &expires)) { 262 if (x509_certificate_model::GetTimes(cert, &issued, &expires)) {
259 string16 issued_str = WideToUTF16( 263 string16 issued_str = WideToUTF16(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 300
297 string16 token(UTF8ToUTF16(x509_certificate_model::GetTokenName(cert))); 301 string16 token(UTF8ToUTF16(x509_certificate_model::GetTokenName(cert)));
298 if (!token.empty()) { 302 if (!token.empty()) {
299 rv += '\n'; 303 rv += '\n';
300 rv += l10n_util::GetStringFUTF8(IDS_CERT_TOKEN_FORMAT, token); 304 rv += l10n_util::GetStringFUTF8(IDS_CERT_TOKEN_FORMAT, token);
301 } 305 }
302 306
303 return rv; 307 return rv;
304 } 308 }
305 309
310 void SSLClientCertificateSelector::Unlocked() {
311 net::X509Certificate* cert = GetSelectedCert();
wtc 2010/12/15 20:54:36 Can |cert| be passed to this method as a parameter
mattm 2011/01/12 01:22:07 Could be done, but UnlockSlotIfNecessary and Unloc
312 delegate_->CertificateSelected(cert);
313 delegate_ = NULL;
314 DCHECK(window_);
315 window_->CloseConstrainedWindow();
316 }
317
306 void SSLClientCertificateSelector::OnComboBoxChanged(GtkWidget* combo_box) { 318 void SSLClientCertificateSelector::OnComboBoxChanged(GtkWidget* combo_box) {
307 int selected = gtk_combo_box_get_active( 319 int selected = gtk_combo_box_get_active(
308 GTK_COMBO_BOX(cert_combo_box_)); 320 GTK_COMBO_BOX(cert_combo_box_));
309 if (selected < 0) 321 if (selected < 0)
310 return; 322 return;
311 gtk_text_buffer_set_text(cert_details_buffer_, 323 gtk_text_buffer_set_text(cert_details_buffer_,
312 details_strings_[selected].c_str(), 324 details_strings_[selected].c_str(),
313 details_strings_[selected].size()); 325 details_strings_[selected].size());
314 } 326 }
315 327
316 void SSLClientCertificateSelector::OnViewClicked(GtkWidget* button) { 328 void SSLClientCertificateSelector::OnViewClicked(GtkWidget* button) {
317 net::X509Certificate* cert = GetSelectedCert(); 329 net::X509Certificate* cert = GetSelectedCert();
318 if (cert) { 330 if (cert) {
319 GtkWidget* toplevel = gtk_widget_get_toplevel(root_widget_.get()); 331 GtkWidget* toplevel = gtk_widget_get_toplevel(root_widget_.get());
320 ShowCertificateViewer(GTK_WINDOW(toplevel), cert); 332 ShowCertificateViewer(GTK_WINDOW(toplevel), cert);
321 } 333 }
322 } 334 }
323 335
324 void SSLClientCertificateSelector::OnCancelClicked(GtkWidget* button) { 336 void SSLClientCertificateSelector::OnCancelClicked(GtkWidget* button) {
325 delegate_->CertificateSelected(NULL); 337 delegate_->CertificateSelected(NULL);
326 delegate_ = NULL; 338 delegate_ = NULL;
327 DCHECK(window_); 339 DCHECK(window_);
328 window_->CloseConstrainedWindow(); 340 window_->CloseConstrainedWindow();
329 } 341 }
330 342
331 void SSLClientCertificateSelector::OnOkClicked(GtkWidget* button) { 343 void SSLClientCertificateSelector::OnOkClicked(GtkWidget* button) {
332 net::X509Certificate* cert = GetSelectedCert(); 344 net::X509Certificate* cert = GetSelectedCert();
333 delegate_->CertificateSelected(cert); 345
334 delegate_ = NULL; 346 browser::UnlockCertSlotIfNecessary(
335 DCHECK(window_); 347 cert,
336 window_->CloseConstrainedWindow(); 348 browser::kPK11PasswordClientAuth,
349 cert_request_info_->host_and_port, // TODO(mattm): strip port part?
wtc 2010/12/15 20:54:36 The port part is important.
mattm 2011/01/12 01:22:07 Done.
350 NewCallback(this, &SSLClientCertificateSelector::Unlocked));
337 } 351 }
338 352
339 void SSLClientCertificateSelector::OnPromptShown(GtkWidget* widget, 353 void SSLClientCertificateSelector::OnPromptShown(GtkWidget* widget,
340 GtkWidget* previous_toplevel) { 354 GtkWidget* previous_toplevel) {
341 if (!root_widget_.get() || 355 if (!root_widget_.get() ||
342 !GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(root_widget_.get()))) 356 !GTK_WIDGET_TOPLEVEL(gtk_widget_get_toplevel(root_widget_.get())))
343 return; 357 return;
344 GTK_WIDGET_SET_FLAGS(select_button_, GTK_CAN_DEFAULT); 358 GTK_WIDGET_SET_FLAGS(select_button_, GTK_CAN_DEFAULT);
345 gtk_widget_grab_default(select_button_); 359 gtk_widget_grab_default(select_button_);
346 gtk_widget_grab_focus(select_button_); 360 gtk_widget_grab_focus(select_button_);
347 } 361 }
348 362
349 } // namespace 363 } // namespace
350 364
351 /////////////////////////////////////////////////////////////////////////////// 365 ///////////////////////////////////////////////////////////////////////////////
352 // SSLClientAuthHandler platform specific implementation: 366 // SSLClientAuthHandler platform specific implementation:
353 367
354 namespace browser { 368 namespace browser {
355 369
356 void ShowSSLClientCertificateSelector( 370 void ShowSSLClientCertificateSelector(
357 TabContents* parent, 371 TabContents* parent,
358 net::SSLCertRequestInfo* cert_request_info, 372 net::SSLCertRequestInfo* cert_request_info,
359 SSLClientAuthHandler* delegate) { 373 SSLClientAuthHandler* delegate) {
360 (new SSLClientCertificateSelector(parent, 374 (new SSLClientCertificateSelector(parent,
361 cert_request_info, 375 cert_request_info,
362 delegate))->Show(); 376 delegate))->Show();
363 } 377 }
364 378
365 } // namespace browser 379 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698