underscore case all the things

This commit is contained in:
Brendan Forster 2017-04-29 19:28:42 +10:00
parent 5534181ebd
commit 1ccc2afb03

View file

@ -16,22 +16,22 @@ namespace certificate_trust {
// store for the current user. // store for the current user.
// //
// This requires prompting the user to confirm they trust the certificate. // This requires prompting the user to confirm they trust the certificate.
BOOL AddToTrustedRootStore(const PCCERT_CONTEXT certContext, BOOL AddToTrustedRootStore(const PCCERT_CONTEXT cert_context,
const scoped_refptr<net::X509Certificate>& cert) { const scoped_refptr<net::X509Certificate>& cert) {
auto rootCertStore = CertOpenStore( auto root_cert_store = 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 (root_cert_store == NULL) {
return false; return false;
} }
auto result = CertAddCertificateContextToStore( auto result = CertAddCertificateContextToStore(
rootCertStore, root_cert_store,
certContext, cert_context,
CERT_STORE_ADD_REPLACE_EXISTING, CERT_STORE_ADD_REPLACE_EXISTING,
NULL); NULL);
@ -41,23 +41,23 @@ BOOL AddToTrustedRootStore(const PCCERT_CONTEXT certContext,
cert_db->NotifyObserversCertDBChanged(cert.get()); cert_db->NotifyObserversCertDBChanged(cert.get());
} }
CertCloseStore(rootCertStore, CERT_CLOSE_STORE_FORCE_FLAG); CertCloseStore(root_cert_store, CERT_CLOSE_STORE_FORCE_FLAG);
return result; return result;
} }
CERT_CHAIN_PARA GetCertificateChainParameters() { CERT_CHAIN_PARA GetCertificateChainParameters() {
CERT_ENHKEY_USAGE enhkeyUsage; CERT_ENHKEY_USAGE enhkey_usage;
enhkeyUsage.cUsageIdentifier = 0; enhkey_usage.cUsageIdentifier = 0;
enhkeyUsage.rgpszUsageIdentifier = NULL; enhkey_usage.rgpszUsageIdentifier = NULL;
CERT_USAGE_MATCH CertUsage; CERT_USAGE_MATCH cert_usage;
// ensure the rules are applied to the entire chain // ensure the rules are applied to the entire chain
CertUsage.dwType = USAGE_MATCH_TYPE_AND; cert_usage.dwType = USAGE_MATCH_TYPE_AND;
CertUsage.Usage = enhkeyUsage; cert_usage.Usage = enhkey_usage;
CERT_CHAIN_PARA params = { sizeof(CERT_CHAIN_PARA) }; CERT_CHAIN_PARA params = { sizeof(CERT_CHAIN_PARA) };
params.RequestedUsage = CertUsage; params.RequestedUsage = cert_usage;
return params; return params;
} }
@ -66,34 +66,30 @@ 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 chain_context;
auto pCertContext = cert->CreateOSCertChainForCert(); auto cert_context = cert->CreateOSCertChainForCert();
auto params = GetCertificateChainParameters(); auto params = GetCertificateChainParameters();
if (CertGetCertificateChain(NULL, if (CertGetCertificateChain(NULL,
pCertContext, cert_context,
NULL, NULL,
NULL, NULL,
&params, &params,
NULL, NULL,
NULL, NULL,
&chainContext)) { &chain_context)) {
switch (chainContext->TrustStatus.dwErrorStatus) { auto error_status = chain_context->TrustStatus.dwErrorStatus;
case CERT_TRUST_IS_SELF_SIGNED: if (error_status == CERT_TRUST_IS_SELF_SIGNED) {
AddToTrustedRootStore(pCertContext, cert); // this is the only scenario we're interested in supporting for now
break; AddToTrustedRootStore(cert_context, cert);
default:
// we can't handle other scenarios, giving up
break;
} }
CertFreeCertificateChain(chainContext); CertFreeCertificateChain(chain_context);
} }
CertFreeCertificateContext(pCertContext); CertFreeCertificateContext(cert_context);
callback.Run(); callback.Run();
} }