tighten up indenting
This commit is contained in:
parent
50af70a0e8
commit
5151107c28
1 changed files with 78 additions and 84 deletions
|
@ -12,131 +12,125 @@
|
||||||
|
|
||||||
namespace certificate_trust {
|
namespace certificate_trust {
|
||||||
|
|
||||||
BOOL AddCertificateAndRefresh(
|
BOOL AddCertificate(const HCERTSTORE certStore,
|
||||||
const HCERTSTORE certStore,
|
const PCCERT_CONTEXT certContext,
|
||||||
const PCCERT_CONTEXT certContext,
|
const scoped_refptr<net::X509Certificate>& cert) {
|
||||||
const scoped_refptr<net::X509Certificate>& cert) {
|
auto result = CertAddCertificateContextToStore(
|
||||||
auto result = CertAddCertificateContextToStore(
|
certStore,
|
||||||
certStore,
|
certContext,
|
||||||
certContext,
|
CERT_STORE_ADD_REPLACE_EXISTING,
|
||||||
CERT_STORE_ADD_REPLACE_EXISTING,
|
NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
auto cert_db = net::CertDatabase::GetInstance();
|
// force Chromium to reload it's database for this certificate
|
||||||
// Force Chromium to reload the certificate since it might be trusted
|
auto cert_db = net::CertDatabase::GetInstance();
|
||||||
// now.
|
cert_db->NotifyObserversCertDBChanged(cert.get());
|
||||||
cert_db->NotifyObserversCertDBChanged(cert.get());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add the provided certificate to the Trusted Root Certificate Authorities
|
||||||
// Add the provided certificate to the Trusted Root
|
// store for the current user.
|
||||||
// Certificate Authorities store for the current user.
|
|
||||||
//
|
//
|
||||||
// This requires prompting the user to confirm they
|
// This requires prompting the user to confirm they trust the certificate.
|
||||||
// trust the certificate.
|
|
||||||
BOOL AddToTrustedRootStore(const PCCERT_CONTEXT certContext,
|
BOOL AddToTrustedRootStore(const PCCERT_CONTEXT certContext,
|
||||||
const scoped_refptr<net::X509Certificate>& cert) {
|
const scoped_refptr<net::X509Certificate>& cert) {
|
||||||
auto rootCertStore = CertOpenStore(
|
auto rootCertStore = CertOpenStore(
|
||||||
CERT_STORE_PROV_SYSTEM,
|
CERT_STORE_PROV_SYSTEM,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
CERT_SYSTEM_STORE_CURRENT_USER,
|
CERT_SYSTEM_STORE_CURRENT_USER,
|
||||||
L"Root");
|
L"Root");
|
||||||
|
|
||||||
if (rootCertStore == NULL) {
|
if (rootCertStore == NULL) {
|
||||||
// could not resolve the certificate store, giving up
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto result = AddCertificateAndRefresh(rootCertStore, certContext, cert);
|
auto result = AddCertificate(rootCertStore, certContext, cert);
|
||||||
|
|
||||||
CertCloseStore(rootCertStore, CERT_CLOSE_STORE_FORCE_FLAG);
|
CertCloseStore(rootCertStore, CERT_CLOSE_STORE_FORCE_FLAG);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the provided certificate to the Personal
|
// Add the provided certificate to the Personal
|
||||||
// certificate store for the current user.
|
// certificate store for the current user.
|
||||||
BOOL AddToPersonalStore(const PCCERT_CONTEXT certContext,
|
BOOL AddToPersonalStore(const PCCERT_CONTEXT certContext,
|
||||||
const scoped_refptr<net::X509Certificate>& cert) {
|
const scoped_refptr<net::X509Certificate>& cert) {
|
||||||
auto userCertStore = CertOpenStore(
|
auto userCertStore = CertOpenStore(
|
||||||
CERT_STORE_PROV_SYSTEM,
|
CERT_STORE_PROV_SYSTEM,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
CERT_SYSTEM_STORE_CURRENT_USER,
|
CERT_SYSTEM_STORE_CURRENT_USER,
|
||||||
L"My");
|
L"My");
|
||||||
|
|
||||||
if (userCertStore == NULL) {
|
if (userCertStore == NULL) {
|
||||||
// could not resolve the certificate store, giving up
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto result = AddCertificateAndRefresh(userCertStore, certContext, cert);
|
auto result = AddCertificate(userCertStore, certContext, cert);
|
||||||
|
|
||||||
CertCloseStore(userCertStore, CERT_CLOSE_STORE_FORCE_FLAG);
|
CertCloseStore(userCertStore, CERT_CLOSE_STORE_FORCE_FLAG);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CERT_CHAIN_PARA GetCertificateChainParameters() {
|
CERT_CHAIN_PARA GetCertificateChainParameters() {
|
||||||
CERT_ENHKEY_USAGE enhkeyUsage;
|
CERT_ENHKEY_USAGE enhkeyUsage;
|
||||||
enhkeyUsage.cUsageIdentifier = 0;
|
enhkeyUsage.cUsageIdentifier = 0;
|
||||||
enhkeyUsage.rgpszUsageIdentifier = NULL;
|
enhkeyUsage.rgpszUsageIdentifier = NULL;
|
||||||
|
|
||||||
CERT_USAGE_MATCH CertUsage;
|
CERT_USAGE_MATCH CertUsage;
|
||||||
// ensure the rules are applied to the entire chain
|
// ensure the rules are applied to the entire chain
|
||||||
CertUsage.dwType = USAGE_MATCH_TYPE_AND;
|
CertUsage.dwType = USAGE_MATCH_TYPE_AND;
|
||||||
CertUsage.Usage = enhkeyUsage;
|
CertUsage.Usage = enhkeyUsage;
|
||||||
|
|
||||||
CERT_CHAIN_PARA params = { sizeof(CERT_CHAIN_PARA) };
|
CERT_CHAIN_PARA params = { sizeof(CERT_CHAIN_PARA) };
|
||||||
params.RequestedUsage = CertUsage;
|
params.RequestedUsage = CertUsage;
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowCertificateTrust(atom::NativeWindow* parent_window,
|
void ShowCertificateTrust(atom::NativeWindow* parent_window,
|
||||||
const scoped_refptr<net::X509Certificate>& cert,
|
const scoped_refptr<net::X509Certificate>& cert,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const ShowTrustCallback& callback) {
|
const ShowTrustCallback& callback) {
|
||||||
PCCERT_CHAIN_CONTEXT chainContext;
|
PCCERT_CHAIN_CONTEXT chainContext;
|
||||||
|
|
||||||
auto pCertContext = cert->CreateOSCertChainForCert();
|
auto pCertContext = cert->CreateOSCertChainForCert();
|
||||||
|
|
||||||
auto params = GetCertificateChainParameters();
|
auto params = GetCertificateChainParameters();
|
||||||
|
|
||||||
if (CertGetCertificateChain(NULL,
|
if (CertGetCertificateChain(NULL,
|
||||||
pCertContext,
|
pCertContext,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
¶ms,
|
¶ms,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&chainContext)) {
|
&chainContext)) {
|
||||||
switch (chainContext->TrustStatus.dwErrorStatus) {
|
switch (chainContext->TrustStatus.dwErrorStatus) {
|
||||||
case CERT_TRUST_NO_ERROR:
|
case CERT_TRUST_NO_ERROR:
|
||||||
AddToPersonalStore(pCertContext, cert);
|
AddToPersonalStore(pCertContext, cert);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CERT_TRUST_IS_UNTRUSTED_ROOT:
|
case CERT_TRUST_IS_UNTRUSTED_ROOT:
|
||||||
case CERT_TRUST_IS_SELF_SIGNED:
|
case CERT_TRUST_IS_SELF_SIGNED:
|
||||||
AddToTrustedRootStore(pCertContext, cert);
|
AddToTrustedRootStore(pCertContext, cert);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// we can't handle other scenarios, giving up
|
// we can't handle other scenarios, giving up
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
CertFreeCertificateChain(chainContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CertFreeCertificateContext(pCertContext);
|
CertFreeCertificateChain(chainContext);
|
||||||
|
}
|
||||||
|
|
||||||
callback.Run();
|
CertFreeCertificateContext(pCertContext);
|
||||||
|
|
||||||
|
callback.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace certificate_trust
|
} // namespace certificate_trust
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue