mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Pass SSL certificate information to CefRequestHandler::OnCertificateError via a new CefSSLInfo interface (issue #1530).
- cefclient: Improve error message text and use a data: URI instead of LoadString for loading error messages (issue #579). - Add functions in cef_url.h for base64 and URI encoding/decoding (issue #579). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/2272@2029 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "libcef/browser/printing/printing_message_filter.h"
|
||||
#include "libcef/browser/resource_dispatcher_host_delegate.h"
|
||||
#include "libcef/browser/speech_recognition_manager_delegate.h"
|
||||
#include "libcef/browser/ssl_info_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/browser/web_plugin_impl.h"
|
||||
#include "libcef/common/cef_switches.h"
|
||||
@@ -774,13 +775,15 @@ void CefContentBrowserClient::AllowCertificateError(
|
||||
if (!handler.get())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefSSLInfo> cef_ssl_info = new CefSSLInfoImpl(ssl_info);
|
||||
|
||||
CefRefPtr<CefAllowCertificateErrorCallbackImpl> callbackImpl;
|
||||
if (overridable && !strict_enforcement)
|
||||
callbackImpl = new CefAllowCertificateErrorCallbackImpl(callback);
|
||||
|
||||
bool proceed = handler->OnCertificateError(
|
||||
static_cast<cef_errorcode_t>(cert_error), request_url.spec(),
|
||||
callbackImpl.get());
|
||||
browser.get(), static_cast<cef_errorcode_t>(cert_error),
|
||||
request_url.spec(), cef_ssl_info, callbackImpl.get());
|
||||
if (!proceed && callbackImpl.get())
|
||||
callbackImpl->Disconnect();
|
||||
|
||||
|
66
libcef/browser/ssl_cert_principal_impl.cc
Normal file
66
libcef/browser/ssl_cert_principal_impl.cc
Normal file
@@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2015 The Chromium Embedded Framework 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 "libcef/browser/ssl_cert_principal_impl.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void TransferVector(const std::vector<std::string>& source,
|
||||
std::vector<CefString>& target) {
|
||||
if (!target.empty())
|
||||
target.clear();
|
||||
|
||||
if (!source.empty()) {
|
||||
std::vector<std::string>::const_iterator it = source.begin();
|
||||
for (; it != source.end(); ++it)
|
||||
target.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
CefSSLCertPrincipalImpl::CefSSLCertPrincipalImpl(
|
||||
const net::CertPrincipal& value)
|
||||
: value_(value) {
|
||||
}
|
||||
|
||||
CefString CefSSLCertPrincipalImpl::GetDisplayName() {
|
||||
return value_.GetDisplayName();
|
||||
}
|
||||
|
||||
CefString CefSSLCertPrincipalImpl::GetCommonName() {
|
||||
return value_.common_name;
|
||||
}
|
||||
|
||||
CefString CefSSLCertPrincipalImpl::GetLocalityName() {
|
||||
return value_.locality_name;
|
||||
}
|
||||
|
||||
CefString CefSSLCertPrincipalImpl::GetStateOrProvinceName() {
|
||||
return value_.state_or_province_name;
|
||||
}
|
||||
|
||||
CefString CefSSLCertPrincipalImpl::GetCountryName() {
|
||||
return value_.country_name;
|
||||
}
|
||||
|
||||
void CefSSLCertPrincipalImpl::GetStreetAddresses(
|
||||
std::vector<CefString>& addresses) {
|
||||
TransferVector(value_.street_addresses, addresses);
|
||||
}
|
||||
|
||||
void CefSSLCertPrincipalImpl::GetOrganizationNames(
|
||||
std::vector<CefString>& names) {
|
||||
TransferVector(value_.organization_names, names);
|
||||
}
|
||||
|
||||
void CefSSLCertPrincipalImpl::GetOrganizationUnitNames(
|
||||
std::vector<CefString>& names) {
|
||||
TransferVector(value_.organization_unit_names, names);
|
||||
}
|
||||
|
||||
void CefSSLCertPrincipalImpl::GetDomainComponents(
|
||||
std::vector<CefString>& components) {
|
||||
TransferVector(value_.domain_components, components);
|
||||
}
|
36
libcef/browser/ssl_cert_principal_impl.h
Normal file
36
libcef/browser/ssl_cert_principal_impl.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_SSL_CERT_PRINCIPAL_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_SSL_CERT_PRINCIPAL_IMPL_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_ssl_info.h"
|
||||
|
||||
#include "net/cert/x509_cert_types.h"
|
||||
|
||||
// CefSSLCertPrincipal implementation
|
||||
class CefSSLCertPrincipalImpl : public CefSSLCertPrincipal {
|
||||
public:
|
||||
explicit CefSSLCertPrincipalImpl(const net::CertPrincipal& value);
|
||||
|
||||
// CefSSLCertPrincipal methods.
|
||||
CefString GetDisplayName() override;
|
||||
CefString GetCommonName() override;
|
||||
CefString GetLocalityName() override;
|
||||
CefString GetStateOrProvinceName() override;
|
||||
CefString GetCountryName() override;
|
||||
void GetStreetAddresses(std::vector<CefString>& addresses) override;
|
||||
void GetOrganizationNames(std::vector<CefString>& names) override;
|
||||
void GetOrganizationUnitNames(std::vector<CefString>& names) override;
|
||||
void GetDomainComponents(std::vector<CefString>& components) override;
|
||||
|
||||
private:
|
||||
net::CertPrincipal value_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefSSLCertPrincipalImpl);
|
||||
DISALLOW_COPY_AND_ASSIGN(CefSSLCertPrincipalImpl);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_SSL_CERT_PRINCIPAL_IMPL_H_
|
70
libcef/browser/ssl_info_impl.cc
Normal file
70
libcef/browser/ssl_info_impl.cc
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) 2015 The Chromium Embedded Framework 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 "libcef/browser/ssl_info_impl.h"
|
||||
#include "libcef/browser/ssl_cert_principal_impl.h"
|
||||
#include "libcef/common/time_util.h"
|
||||
|
||||
#include "net/cert/x509_certificate.h"
|
||||
|
||||
CefSSLInfoImpl::CefSSLInfoImpl(const net::SSLInfo& value) {
|
||||
if (value.cert.get()) {
|
||||
subject_ = new CefSSLCertPrincipalImpl(value.cert->subject());
|
||||
issuer_ = new CefSSLCertPrincipalImpl(value.cert->issuer());
|
||||
|
||||
const std::string& serial_number = value.cert->serial_number();
|
||||
serial_number_ = CefBinaryValue::Create(serial_number.c_str(),
|
||||
serial_number.size());
|
||||
|
||||
const base::Time& valid_start = value.cert->valid_start();
|
||||
if (!valid_start.is_null())
|
||||
cef_time_from_basetime(valid_start, valid_start_);
|
||||
|
||||
const base::Time& valid_expiry = value.cert->valid_expiry();
|
||||
if (!valid_expiry.is_null())
|
||||
cef_time_from_basetime(valid_expiry, valid_expiry_);
|
||||
|
||||
net::X509Certificate::OSCertHandle os_handle = value.cert->os_cert_handle();
|
||||
if (os_handle) {
|
||||
std::string encoded;
|
||||
if (value.cert->GetDEREncoded(os_handle, &encoded)) {
|
||||
der_encoded_ = CefBinaryValue::Create(encoded.c_str(),
|
||||
encoded.size());
|
||||
}
|
||||
encoded.clear();
|
||||
if (value.cert->GetPEMEncoded(os_handle, &encoded)) {
|
||||
pem_encoded_ = CefBinaryValue::Create(encoded.c_str(),
|
||||
encoded.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefSSLCertPrincipal> CefSSLInfoImpl::GetSubject() {
|
||||
return subject_;
|
||||
}
|
||||
|
||||
CefRefPtr<CefSSLCertPrincipal> CefSSLInfoImpl::GetIssuer() {
|
||||
return issuer_;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBinaryValue> CefSSLInfoImpl::GetSerialNumber() {
|
||||
return serial_number_;
|
||||
}
|
||||
|
||||
CefTime CefSSLInfoImpl::GetValidStart() {
|
||||
return valid_start_;
|
||||
}
|
||||
|
||||
CefTime CefSSLInfoImpl::GetValidExpiry() {
|
||||
return valid_expiry_;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBinaryValue> CefSSLInfoImpl::GetDEREncoded() {
|
||||
return der_encoded_;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBinaryValue> CefSSLInfoImpl::GetPEMEncoded() {
|
||||
return pem_encoded_;
|
||||
}
|
40
libcef/browser/ssl_info_impl.h
Normal file
40
libcef/browser/ssl_info_impl.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef CEF_LIBCEF_BROWSER_SSL_INFO_IMPL_H_
|
||||
#define CEF_LIBCEF_BROWSER_SSL_INFO_IMPL_H_
|
||||
#pragma once
|
||||
|
||||
#include "include/cef_ssl_info.h"
|
||||
|
||||
#include "net/ssl/ssl_info.h"
|
||||
|
||||
// CefSSLInfo implementation
|
||||
class CefSSLInfoImpl : public CefSSLInfo {
|
||||
public:
|
||||
explicit CefSSLInfoImpl(const net::SSLInfo& value);
|
||||
|
||||
// CefSSLInfo methods.
|
||||
CefRefPtr<CefSSLCertPrincipal> GetSubject() override;
|
||||
CefRefPtr<CefSSLCertPrincipal> GetIssuer() override;
|
||||
CefRefPtr<CefBinaryValue> GetSerialNumber() override;
|
||||
CefTime GetValidStart() override;
|
||||
CefTime GetValidExpiry() override;
|
||||
CefRefPtr<CefBinaryValue> GetDEREncoded() override;
|
||||
CefRefPtr<CefBinaryValue> GetPEMEncoded() override;
|
||||
|
||||
private:
|
||||
CefRefPtr<CefSSLCertPrincipal> subject_;
|
||||
CefRefPtr<CefSSLCertPrincipal> issuer_;
|
||||
CefRefPtr<CefBinaryValue> serial_number_;
|
||||
CefTime valid_start_;
|
||||
CefTime valid_expiry_;
|
||||
CefRefPtr<CefBinaryValue> der_encoded_;
|
||||
CefRefPtr<CefBinaryValue> pem_encoded_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefSSLInfoImpl);
|
||||
DISALLOW_COPY_AND_ASSIGN(CefSSLInfoImpl);
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_SSL_INFO_IMPL_H_
|
@@ -4,6 +4,9 @@
|
||||
|
||||
#include <sstream>
|
||||
#include "include/cef_url.h"
|
||||
|
||||
#include "base/base64.h"
|
||||
#include "net/base/escape.h"
|
||||
#include "net/base/mime_util.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
@@ -85,3 +88,39 @@ void CefGetExtensionsForMimeType(const CefString& mime_type,
|
||||
extensions.push_back(*it);
|
||||
}
|
||||
|
||||
CefString CefBase64Encode(const void* data, size_t data_size) {
|
||||
if (data_size == 0)
|
||||
return CefString();
|
||||
|
||||
base::StringPiece input;
|
||||
input.set(static_cast<const char*>(data), data_size);
|
||||
std::string output;
|
||||
base::Base64Encode(input, &output);
|
||||
return output;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBinaryValue> CefBase64Decode(const CefString& data) {
|
||||
if (data.size() == 0)
|
||||
return NULL;
|
||||
|
||||
const std::string& input = data;
|
||||
std::string output;
|
||||
if (base::Base64Decode(input, &output))
|
||||
return CefBinaryValue::Create(output.data(), output.size());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefString CefURIEncode(const CefString& text, bool use_plus) {
|
||||
return net::EscapeQueryParamValue(text, use_plus);
|
||||
}
|
||||
|
||||
CefString CefURIDecode(const CefString& text,
|
||||
bool convert_to_utf8,
|
||||
cef_uri_unescape_rule_t unescape_rule) {
|
||||
const net::UnescapeRule::Type type =
|
||||
static_cast<net::UnescapeRule::Type>(unescape_rule);
|
||||
if (convert_to_utf8)
|
||||
return net::UnescapeAndDecodeUTF8URLComponent(text.ToString(), type);
|
||||
else
|
||||
return net::UnescapeURLComponent(text.ToString(), type);
|
||||
}
|
||||
|
Reference in New Issue
Block a user