diff options
author | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 22:55:27 +0000 |
---|---|---|
committer | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-07 22:55:27 +0000 |
commit | 8ae178b1da02c2ab5104060a711c305cb826221d (patch) | |
tree | ad8f723b09064d68239d6db01bf0c7532831137d /chrome/browser/cocoa/certificate_viewer.mm | |
parent | 4fe95a617e494a2e279d9d623816f3e3b7aed944 (diff) | |
download | chromium_src-8ae178b1da02c2ab5104060a711c305cb826221d.zip chromium_src-8ae178b1da02c2ab5104060a711c305cb826221d.tar.gz chromium_src-8ae178b1da02c2ab5104060a711c305cb826221d.tar.bz2 |
Refactor certificate viewer code behind ShowCertificateViewer
This abstracts away the platform-specific certificate viewer behind a common
function call.
R=wtc,mattm
BUG=none
TEST=Viewing the certificate information on an SSL session continues to work
Review URL: http://codereview.chromium.org/2815024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/certificate_viewer.mm')
-rw-r--r-- | chrome/browser/cocoa/certificate_viewer.mm | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/certificate_viewer.mm b/chrome/browser/cocoa/certificate_viewer.mm new file mode 100644 index 0000000..ed29ef4 --- /dev/null +++ b/chrome/browser/cocoa/certificate_viewer.mm @@ -0,0 +1,45 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/certificate_viewer.h" + +#include <Security/Security.h> +#include <SecurityInterface/SFCertificatePanel.h> + +#include <vector> + +#include "base/logging.h" +#include "base/scoped_cftyperef.h" +#include "net/base/x509_certificate.h" + +void ShowCertificateViewer(gfx::NativeWindow parent, + net::X509Certificate* cert) { + SecCertificateRef cert_mac = cert->os_cert_handle(); + if (!cert_mac) + return; + + scoped_cftyperef<CFMutableArrayRef> certificates( + CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); + if (!certificates.get()) { + NOTREACHED(); + return; + } + CFArrayAppendValue(certificates, cert_mac); + + // Server certificate must be first in the array; subsequent certificates + // in the chain can be in any order. + const std::vector<SecCertificateRef>& ca_certs = + cert->GetIntermediateCertificates(); + for (size_t i = 0; i < ca_certs.size(); ++i) + CFArrayAppendValue(certificates, ca_certs[i]); + + [[[SFCertificatePanel alloc] init] + beginSheetForWindow:parent + modalDelegate:nil + didEndSelector:NULL + contextInfo:NULL + certificates:reinterpret_cast<NSArray*>(certificates.get()) + showGroup:YES]; + // The SFCertificatePanel releases itself when the sheet is dismissed. +} |