| // Copyright 2012 The Goma 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 "openssl_engine_helper.h" |
| |
| #include <windows.h> |
| |
| #include <string> |
| |
| #include "certs_resource.h" |
| #include "glog/logging.h" |
| |
| using std::string; |
| |
| namespace { |
| |
| bool LoadTrustedRootCertsInResource(string* certs) { |
| // Since we use the current process resource, HMODULE can be nullptr. |
| HRSRC resource_info = FindResource(nullptr, MAKEINTRESOURCE(ROOT_CA_NAME), |
| RT_RCDATA); |
| if (resource_info == nullptr) { |
| LOG_SYSRESULT(GetLastError()); |
| LOG(ERROR) << "Cannot find the root certificate resource."; |
| return false; |
| } |
| HGLOBAL resource_handle = LoadResource(nullptr, resource_info); |
| if (resource_handle == nullptr) { |
| LOG_SYSRESULT(GetLastError()); |
| LOG(ERROR) << "Cannot load the root certificate resource."; |
| return false; |
| } |
| LPVOID resource = LockResource(resource_handle); |
| if (resource == nullptr) { |
| LOG_SYSRESULT(GetLastError()); |
| LOG(ERROR) << "Cannot obtain pointer to the root certificate resource."; |
| return false; |
| } |
| const DWORD resource_size = SizeofResource(nullptr, resource_info); |
| if (resource_size == 0) { |
| LOG_SYSRESULT(GetLastError()); |
| LOG(ERROR) << "Cannot get size of root certificate resource."; |
| return false; |
| } |
| |
| certs->assign(static_cast<const char*>(resource), resource_size); |
| return true; |
| } |
| |
| } // anonymous namespace. |
| |
| namespace devtools_goma { |
| |
| bool GetTrustedRootCerts(string* certs) { |
| return LoadTrustedRootCertsInResource(certs); |
| } |
| |
| } // namespace devtools_goma |