| OLD | NEW |
| 1 // Copyright (c) 2010 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <cryptuiapi.h> | 8 #include <cryptuiapi.h> |
| 9 #pragma comment(lib, "cryptui.lib") | 9 #pragma comment(lib, "cryptui.lib") |
| 10 | 10 |
| 11 #include "base/logging.h" |
| 11 #include "net/base/x509_certificate.h" | 12 #include "net/base/x509_certificate.h" |
| 12 | 13 |
| 13 void ShowCertificateViewer(gfx::NativeWindow parent, | 14 void ShowCertificateViewer(gfx::NativeWindow parent, |
| 14 net::X509Certificate* cert) { | 15 net::X509Certificate* cert) { |
| 16 // Create a new cert context and store containing just the certificate |
| 17 // and its intermediate certificates. |
| 18 PCCERT_CONTEXT cert_list = cert->CreateOSCertChainForCert(); |
| 19 CHECK(cert_list); |
| 20 |
| 15 CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 }; | 21 CRYPTUI_VIEWCERTIFICATE_STRUCT view_info = { 0 }; |
| 16 view_info.dwSize = sizeof(view_info); | 22 view_info.dwSize = sizeof(view_info); |
| 17 // We set our parent to the tab window. This makes the cert dialog created | 23 // We set our parent to the tab window. This makes the cert dialog created |
| 18 // in CryptUIDlgViewCertificate modal to the browser. | 24 // in CryptUIDlgViewCertificate modal to the browser. |
| 19 view_info.hwndParent = parent; | 25 view_info.hwndParent = parent; |
| 20 view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | | 26 view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | |
| 21 CRYPTUI_DISABLE_ADDTOSTORE; | 27 CRYPTUI_DISABLE_ADDTOSTORE; |
| 22 view_info.pCertContext = cert->os_cert_handle(); | 28 view_info.pCertContext = cert_list; |
| 23 // Search the cert store that 'cert' is in when building the cert chain. | 29 HCERTSTORE cert_store = cert_list->hCertStore; |
| 24 HCERTSTORE cert_store = view_info.pCertContext->hCertStore; | |
| 25 view_info.cStores = 1; | 30 view_info.cStores = 1; |
| 26 view_info.rghStores = &cert_store; | 31 view_info.rghStores = &cert_store; |
| 27 BOOL properties_changed; | 32 BOOL properties_changed; |
| 28 | 33 |
| 29 // This next call blocks but keeps processing windows messages, making it | 34 // This next call blocks but keeps processing windows messages, making it |
| 30 // modal to the browser window. | 35 // modal to the browser window. |
| 31 BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed); | 36 BOOL rv = ::CryptUIDlgViewCertificate(&view_info, &properties_changed); |
| 37 |
| 38 CertFreeCertificateContext(cert_list); |
| 32 } | 39 } |
| OLD | NEW |