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 3 // found in the LICENSE file. 4 5 #include "content/browser/certificate_viewer.h" 6 7 #include <Security/Security.h> 8 #include <SecurityInterface/SFCertificatePanel.h> 9 10 #include <vector> 11 12 #include "base/logging.h" 13 #include "base/mac/scoped_cftyperef.h" 14 #include "net/base/x509_certificate.h" 15 16 void ShowCertificateViewer(gfx::NativeWindow parent, 17 net::X509Certificate* cert) { 18 SecCertificateRef cert_mac = cert->os_cert_handle(); 19 if (!cert_mac) 20 return; 21 22 base::mac::ScopedCFTypeRef<CFMutableArrayRef> certificates( 23 CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); 24 if (!certificates.get()) { 25 NOTREACHED(); 26 return; 27 } 28 CFArrayAppendValue(certificates, cert_mac); 29 30 // Server certificate must be first in the array; subsequent certificates 31 // in the chain can be in any order. 32 const std::vector<SecCertificateRef>& ca_certs = 33 cert->GetIntermediateCertificates(); 34 for (size_t i = 0; i < ca_certs.size(); ++i) 35 CFArrayAppendValue(certificates, ca_certs[i]); 36 37 [[[SFCertificatePanel alloc] init] 38 beginSheetForWindow:parent 39 modalDelegate:nil 40 didEndSelector:NULL 41 contextInfo:NULL 42 certificates:reinterpret_cast<NSArray*>(certificates.get()) 43 showGroup:YES]; 44 // The SFCertificatePanel releases itself when the sheet is dismissed. 45 } 46