2017-04-06 01:01:58 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/ui/certificate_trust.h"
|
|
|
|
|
2017-04-20 11:12:32 +00:00
|
|
|
#include <wincrypt.h>
|
2017-04-21 02:23:50 +00:00
|
|
|
#include <windows.h>
|
2017-04-06 01:01:58 +00:00
|
|
|
|
|
|
|
namespace certificate_trust {
|
|
|
|
|
2017-04-06 01:09:58 +00:00
|
|
|
void ShowCertificateTrust(atom::NativeWindow* parent_window,
|
|
|
|
const scoped_refptr<net::X509Certificate>& cert,
|
|
|
|
const std::string& message,
|
|
|
|
const ShowTrustCallback& callback) {
|
2017-04-20 11:12:32 +00:00
|
|
|
BOOL result = false;
|
|
|
|
HCERTSTORE hCertStore = NULL;
|
|
|
|
PCCERT_CONTEXT pCertContext = cert->CreateOSCertChainForCert();
|
|
|
|
|
|
|
|
// opening the Trusted Root Certificate store for the current user
|
2017-04-21 02:17:01 +00:00
|
|
|
hCertStore = CertOpenStore(
|
|
|
|
CERT_STORE_PROV_SYSTEM,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
CERT_SYSTEM_STORE_CURRENT_USER,
|
|
|
|
L"Root");
|
2017-04-20 11:12:32 +00:00
|
|
|
|
|
|
|
// NOTE: this is a blocking call which displays a prompt to the user to
|
|
|
|
// confirm they trust this certificate
|
2017-04-21 02:17:01 +00:00
|
|
|
result = CertAddCertificateContextToStore(
|
|
|
|
hCertStore,
|
|
|
|
pCertContext,
|
|
|
|
CERT_STORE_ADD_REPLACE_EXISTING,
|
|
|
|
NULL);
|
2017-04-20 11:12:32 +00:00
|
|
|
|
|
|
|
// close certificate store
|
|
|
|
CertCloseStore(hCertStore, CERT_CLOSE_STORE_FORCE_FLAG);
|
|
|
|
|
|
|
|
// free certificate
|
|
|
|
CertFreeCertificateContext(pCertContext);
|
|
|
|
|
|
|
|
&callback;
|
2017-04-06 01:09:58 +00:00
|
|
|
}
|
2017-04-06 01:01:58 +00:00
|
|
|
|
|
|
|
} // namespace certificate_trust
|