| 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/ui/login/login_prompt.h" | 5 #include "chrome/browser/ui/login/login_prompt.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 14 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 15 #include "chrome/browser/prerender/prerender_contents.h" | 15 #include "chrome/browser/prerender/prerender_contents.h" |
| 16 #include "chrome/browser/ssl/ssl_error_info.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
| 17 #include "chrome/browser/ui/login/login_interstitial_delegate.h" | 18 #include "chrome/browser/ui/login/login_interstitial_delegate.h" |
| 18 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 19 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
| 19 #include "components/password_manager/core/browser/password_manager.h" | 20 #include "components/password_manager/core/browser/password_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/cert_store.h" |
| 23 #include "content/public/browser/navigation_controller.h" |
| 24 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
| 22 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/resource_dispatcher_host.h" | 29 #include "content/public/browser/resource_dispatcher_host.h" |
| 25 #include "content/public/browser/resource_request_info.h" | 30 #include "content/public/browser/resource_request_info.h" |
| 31 #include "content/public/browser/signed_certificate_timestamp_store.h" |
| 26 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/browser/web_contents_delegate.h" |
| 34 #include "content/public/common/security_style.h" |
| 35 #include "content/public/common/signed_certificate_timestamp_id_and_status.h" |
| 36 #include "content/public/common/ssl_status.h" |
| 27 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 28 #include "net/base/auth.h" | 38 #include "net/base/auth.h" |
| 29 #include "net/base/load_flags.h" | 39 #include "net/base/load_flags.h" |
| 30 #include "net/base/net_util.h" | 40 #include "net/base/net_util.h" |
| 31 #include "net/http/http_transaction_factory.h" | 41 #include "net/http/http_transaction_factory.h" |
| 42 #include "net/ssl/ssl_info.h" |
| 32 #include "net/url_request/url_request.h" | 43 #include "net/url_request/url_request.h" |
| 33 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/gfx/text_elider.h" | 46 #include "ui/gfx/text_elider.h" |
| 36 | 47 |
| 37 using autofill::PasswordForm; | 48 using autofill::PasswordForm; |
| 38 using content::BrowserThread; | 49 using content::BrowserThread; |
| 39 using content::NavigationController; | 50 using content::NavigationController; |
| 40 using content::RenderViewHost; | 51 using content::RenderViewHost; |
| 41 using content::RenderViewHostDelegate; | 52 using content::RenderViewHostDelegate; |
| 42 using content::ResourceDispatcherHost; | 53 using content::ResourceDispatcherHost; |
| 43 using content::ResourceRequestInfo; | 54 using content::ResourceRequestInfo; |
| 44 using content::WebContents; | 55 using content::WebContents; |
| 45 | 56 |
| 46 class LoginHandlerImpl; | 57 class LoginHandlerImpl; |
| 47 | 58 |
| 59 namespace { |
| 60 // TODO(meacer): This is the same as |
| 61 // ResourceLoader::StoreSignedCertificateTimestamps. Can't include |
| 62 // resource_loader.h so it's copied here. Remove duplication. |
| 63 void StoreSignedCertificateTimestamps( |
| 64 const net::SignedCertificateTimestampAndStatusList& sct_list, |
| 65 int process_id, |
| 66 content::SignedCertificateTimestampIDStatusList* sct_ids) { |
| 67 content::SignedCertificateTimestampStore* sct_store( |
| 68 content::SignedCertificateTimestampStore::GetInstance()); |
| 69 |
| 70 for (net::SignedCertificateTimestampAndStatusList::const_iterator iter = |
| 71 sct_list.begin(); iter != sct_list.end(); ++iter) { |
| 72 const int sct_id(sct_store->Store(iter->sct, process_id)); |
| 73 sct_ids->push_back( |
| 74 content::SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); |
| 75 } |
| 76 } |
| 77 |
| 78 } // namespace |
| 79 |
| 48 // Helper to remove the ref from an net::URLRequest to the LoginHandler. | 80 // Helper to remove the ref from an net::URLRequest to the LoginHandler. |
| 49 // Should only be called from the IO thread, since it accesses an | 81 // Should only be called from the IO thread, since it accesses an |
| 50 // net::URLRequest. | 82 // net::URLRequest. |
| 51 void ResetLoginHandlerForRequest(net::URLRequest* request) { | 83 void ResetLoginHandlerForRequest(net::URLRequest* request) { |
| 52 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request); | 84 ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(request); |
| 53 } | 85 } |
| 54 | 86 |
| 55 // Get the signon_realm under which this auth info should be stored. | 87 // Get the signon_realm under which this auth info should be stored. |
| 56 // | 88 // |
| 57 // The format of the signon_realm for proxy auth is: | 89 // The format of the signon_realm for proxy auth is: |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 request_url.scheme() + "://" + auth_info->challenger.ToString()); | 514 request_url.scheme() + "://" + auth_info->challenger.ToString()); |
| 483 base::string16 explanation = elided_realm.empty() ? | 515 base::string16 explanation = elided_realm.empty() ? |
| 484 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | 516 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, |
| 485 host_and_port) : | 517 host_and_port) : |
| 486 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, | 518 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, |
| 487 host_and_port, | 519 host_and_port, |
| 488 elided_realm); | 520 elided_realm); |
| 489 handler->BuildViewForPasswordManager(password_manager, explanation); | 521 handler->BuildViewForPasswordManager(password_manager, explanation); |
| 490 } | 522 } |
| 491 | 523 |
| 524 // static |
| 525 void LoginHandler::UpdateSSLState(content::NavigationEntry* entry, |
| 526 content::WebContents* web_contents, |
| 527 const net::SSLInfo& ssl_info) { |
| 528 // Login prompts are displayed before the provisional navigation entry |
| 529 // is committed so SSL information isn't yet set. Override it here. |
| 530 content::SSLStatus original_ssl_status = entry->GetSSL(); // Copy. |
| 531 |
| 532 if (entry->GetSSL().security_style != content::SECURITY_STYLE_UNKNOWN) |
| 533 return; |
| 534 entry->GetSSL().cert_status = ssl_info.cert_status; |
| 535 entry->GetSSL().security_bits = ssl_info.security_bits; |
| 536 entry->GetSSL().connection_status = ssl_info.connection_status; |
| 537 |
| 538 int render_process_host_id = web_contents->GetRenderProcessHost()->GetID(); |
| 539 // Storing an existing cert does nothing and just returns the existing id. |
| 540 int cert_id = content::CertStore::GetInstance()->StoreCert( |
| 541 ssl_info.cert.get(), render_process_host_id); |
| 542 DCHECK(cert_id); |
| 543 entry->GetSSL().cert_id = cert_id; |
| 544 |
| 545 content::SignedCertificateTimestampIDStatusList |
| 546 signed_certificate_timestamp_ids; |
| 547 StoreSignedCertificateTimestamps( |
| 548 ssl_info.signed_certificate_timestamps, |
| 549 render_process_host_id, |
| 550 &signed_certificate_timestamp_ids); |
| 551 entry->GetSSL().signed_certificate_timestamp_ids = |
| 552 signed_certificate_timestamp_ids; |
| 553 |
| 554 // The rest is a subset of the logic from SSLPolicy::UpdateEntry. |
| 555 // Since login prompts display before the page is shown, there is no need to |
| 556 // check for mixed content. In any case, the SSL information will be fully |
| 557 // updated once the navigation is committed. |
| 558 // TODO(meacer): Reuse the code from ssl_policy.cc here. Can't link against |
| 559 // it from ui code. |
| 560 entry->GetSSL().security_style = |
| 561 entry->GetURL().SchemeIsSecure() ? |
| 562 content::SECURITY_STYLE_AUTHENTICATED : |
| 563 content::SECURITY_STYLE_UNAUTHENTICATED; |
| 564 // An HTTPS response may not have a certificate for some reason. When that |
| 565 // happens, use the unauthenticated (HTTP) rather than the authentication |
| 566 // broken security style so that we can detect this error condition. |
| 567 if (!entry->GetSSL().cert_id) { |
| 568 entry->GetSSL().security_style = content::SECURITY_STYLE_UNAUTHENTICATED; |
| 569 return; |
| 570 } |
| 571 if (net::IsCertStatusError(entry->GetSSL().cert_status)) { |
| 572 // Minor errors don't lower the security style to |
| 573 // SECURITY_STYLE_AUTHENTICATION_BROKEN. |
| 574 if (!net::IsCertStatusMinorError(entry->GetSSL().cert_status)) { |
| 575 entry->GetSSL().security_style = |
| 576 content::SECURITY_STYLE_AUTHENTICATION_BROKEN; |
| 577 } |
| 578 } |
| 579 if (!entry->GetSSL().Equals(original_ssl_status)) |
| 580 web_contents->GetDelegate()->VisibleSSLStateChanged(web_contents); |
| 581 } |
| 582 |
| 492 // This callback is run on the UI thread and creates a constrained window with | 583 // This callback is run on the UI thread and creates a constrained window with |
| 493 // a LoginView to prompt the user. If the prompt is triggered because of | 584 // a LoginView to prompt the user. If the prompt is triggered because of |
| 494 // a cross origin navigation in the main frame, a blank interstitial is first | 585 // a cross origin navigation in the main frame, a blank interstitial is first |
| 495 // created which in turn creates the LoginView. Otherwise, a LoginView is | 586 // created which in turn creates the LoginView. Otherwise, a LoginView is |
| 496 // directly in this callback. In both cases, the response will be sent to | 587 // directly in this callback. In both cases, the response will be sent to |
| 497 // LoginHandler, which then routes it to the net::URLRequest on the I/O thread. | 588 // LoginHandler, which then routes it to the net::URLRequest on the I/O thread. |
| 498 void LoginDialogCallback(const GURL& request_url, | 589 void LoginDialogCallback(const GURL& request_url, |
| 499 net::AuthChallengeInfo* auth_info, | 590 net::AuthChallengeInfo* auth_info, |
| 500 LoginHandler* handler, | 591 LoginHandler* handler, |
| 501 bool is_main_frame) { | 592 bool is_main_frame, |
| 593 const net::SSLInfo& ssl_info) { |
| 502 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 594 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 503 WebContents* parent_contents = handler->GetWebContentsForLogin(); | 595 WebContents* parent_contents = handler->GetWebContentsForLogin(); |
| 504 if (!parent_contents || handler->WasAuthHandled()) { | 596 if (!parent_contents || handler->WasAuthHandled()) { |
| 505 // The request may have been cancelled, or it may be for a renderer | 597 // The request may have been cancelled, or it may be for a renderer |
| 506 // not hosted by a tab (e.g. an extension). Cancel just in case | 598 // not hosted by a tab (e.g. an extension). Cancel just in case |
| 507 // (cancelling twice is a no-op). | 599 // (cancelling twice is a no-op). |
| 508 handler->CancelAuth(); | 600 handler->CancelAuth(); |
| 509 return; | 601 return; |
| 510 } | 602 } |
| 603 if (is_main_frame) { |
| 604 // Update SSL state for all main frame navigations. For cross origin |
| 605 // navigations, LoginInterstitialDelegate creates a new navigation entry |
| 606 // and updates the SSL state itself. |
| 607 NavigationController* controller = &parent_contents->GetController(); |
| 608 content::NavigationEntry* entry = controller->GetVisibleEntry(); |
| 609 LoginHandler::UpdateSSLState(entry, parent_contents, ssl_info); |
| 610 } |
| 511 | 611 |
| 512 if (is_main_frame && | 612 if (is_main_frame && |
| 513 parent_contents->GetVisibleURL().GetOrigin() != request_url.GetOrigin()) { | 613 parent_contents->GetVisibleURL().GetOrigin() != request_url.GetOrigin()) { |
| 514 // Show a blank interstitial for main-frame, cross origin requests | 614 // Show a blank interstitial for main-frame, cross origin requests |
| 515 // so that the correct URL is shown in the omnibox. | 615 // so that the correct URL is shown in the omnibox. |
| 516 base::Closure callback = base::Bind(&ShowLoginPrompt, | 616 base::Closure callback = base::Bind(&ShowLoginPrompt, |
| 517 request_url, | 617 request_url, |
| 518 make_scoped_refptr(auth_info), | 618 make_scoped_refptr(auth_info), |
| 519 make_scoped_refptr(handler)); | 619 make_scoped_refptr(handler)); |
| 620 |
| 520 // This is owned by the interstitial it creates. | 621 // This is owned by the interstitial it creates. |
| 521 new LoginInterstitialDelegate(parent_contents, | 622 new LoginInterstitialDelegate(parent_contents, |
| 522 request_url, | 623 request_url, |
| 523 callback); | 624 callback, |
| 625 ssl_info); |
| 524 } else { | 626 } else { |
| 525 ShowLoginPrompt(request_url, | 627 ShowLoginPrompt(request_url, |
| 526 auth_info, | 628 auth_info, |
| 527 handler); | 629 handler); |
| 528 } | 630 } |
| 529 } | 631 } |
| 530 | 632 |
| 531 // ---------------------------------------------------------------------------- | 633 // ---------------------------------------------------------------------------- |
| 532 // Public API | 634 // Public API |
| 533 | 635 |
| 534 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 636 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 535 net::URLRequest* request) { | 637 net::URLRequest* request) { |
| 536 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 638 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
| 537 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 639 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 640 const net::SSLInfo& ssl_info = request->response_info().ssl_info; |
| 538 BrowserThread::PostTask( | 641 BrowserThread::PostTask( |
| 539 BrowserThread::UI, FROM_HERE, | 642 BrowserThread::UI, FROM_HERE, |
| 540 base::Bind(&LoginDialogCallback, request->url(), | 643 base::Bind(&LoginDialogCallback, request->url(), |
| 541 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 644 make_scoped_refptr(auth_info), make_scoped_refptr(handler), |
| 542 is_main_frame)); | 645 is_main_frame, |
| 646 ssl_info)); |
| 543 return handler; | 647 return handler; |
| 544 } | 648 } |
| OLD | NEW |