-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: do not persist the keys loaded from PKCS#12 on Windows #14645
Conversation
Instead of getting the handle with `CryptAcquireCertificatePrivateKey`, we get it from a property of the certificate context.
@@ -121,9 +112,7 @@ StatusOr<UniqueCertStore> OpenP12File(std::string const& source) { | |||
StatusOr<UniqueCertContext> GetCertificate(HCERTSTORE certstore, | |||
std::string const& source) { | |||
// Get the certificate from the store. | |||
PCCERT_CONTEXT cert_raw = CertFindCertificateInStore( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CertFindCertificateInStore
supports searching with more complex criteria. We just want the first/only certificate in the store, and therefore can use the simpler CertEnumCertificatesInStore
.
/gcbrun |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14645 +/- ##
==========================================
- Coverage 93.59% 90.91% -2.68%
==========================================
Files 2316 1755 -561
Lines 207122 133091 -74031
==========================================
- Hits 193849 121004 -72845
+ Misses 13273 12087 -1186 ☔ View full report in Codecov by Sentry. |
Thanks @teo-tsirpanis for the help on Windows! |
As part of investigating #14349, I noticed that the
PFXImportCertStore
function persists the keys on disk by default. This PR fixes that by passing thePKCS12_NO_PERSIST_KEY
flag, and geting a preallocatedHCRYPTPROV
to get the certificate's key.Validated locally by running
_build/Default/google/cloud/storage/oauth2_service_account_credentials_test.exe --gtest_filter=ServiceAccountCredentialsTest.ParseSimpleP12 --gtest_repeat=-1
and letting the test run hundreds of times. I'm not sure if this will fix the occasional CI failures, but this looks like an improvement to me.This change is