Skip to content
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

schannel: when importing PFX, disable key persistence #9460

Closed
wants to merge 5 commits into from

Conversation

DHowett
Copy link
Contributor

@DHowett DHowett commented Sep 9, 2022

By default, the PFXImportCertStore API persists the key in the user's
key store (as though the certificate was being imported for permanent,
ongoing use.)

The documentation specifies that keys that are not to be persisted
should be imported with the flag PKCS12_NO_PERSIST_KEY.
NOTE: this flag is only supported on versions of Windows newer than XP
and Server 2003.

--

This is take 2 of the original fix. It extends the lifetime of the
client certificate store to that of the credential handle. The original
fix which landed in 70d010d and was later reverted in aec8d30 failed to
work properly because it did not do that.

Minor changes were made to the schannel credential context to support
closing the client certificate store handle at the end of an SSL session.

Supersedes #9363
Closes #9300

DHowett and others added 2 commits September 8, 2022 08:51
By default, the PFXImportCertStore API persists the key in the user's
key store (as though the certificate was being imported for permanent,
ongoing use.)

The documentation specifies that keys that are not to be persisted
should be imported with the flag `PKCS12_NO_PERSIST_KEY`.
NOTE: this flag is only supported on versions of Windows newer than XP
and Server 2003.

Closes curl#9300
…ection

Since we are no longer storing the key in permanent storage, we need to
keep the handle to the cert store that we produced in client cert
loading and close it only when we're done with all SSL transactions.
@DHowett
Copy link
Contributor Author

DHowett commented Sep 9, 2022

This was tested for use in libcurl by the original reporter, who verified it as of #9300 (comment).

@DHowett DHowett marked this pull request as draft September 9, 2022 18:17
@vszakats vszakats added the Windows Windows-specific label Sep 10, 2022
@DHowett DHowett marked this pull request as ready for review September 10, 2022 19:42
@DHowett
Copy link
Contributor Author

DHowett commented Sep 10, 2022

The tests pass locally at the top of my branch (04c11a4), and it seems like these specific build runs (mingw64, WinIDN) are failing in a few other pull requests. I marked the pull request as draft until I could validate the tests, so I'm going to mark it as ready for review now.

lib/vtls/schannel.c Show resolved Hide resolved
jay pushed a commit to jay/curl that referenced this pull request Sep 14, 2022
By default, the PFXImportCertStore API persists the key in the user's
key store (as though the certificate was being imported for permanent,
ongoing use.)

The documentation specifies that keys that are not to be persisted
should be imported with the flag `PKCS12_NO_PERSIST_KEY`.
NOTE: this flag is only supported on versions of Windows newer than XP
and Server 2003.

---

This is take 2 of the original fix. It extends the lifetime of the
client certificate store to that of the credential handle. The original
fix which landed in 70d010d and was later reverted in aec8d30 failed to
work properly because it did not do that.

Fixes curl#9300
Closes curl#9460
@DHowett
Copy link
Contributor Author

DHowett commented Sep 15, 2022

Pushed an update. I've taken your updated commit message into the PR body for tracking purposes. Thanks for the review!

@bagder bagder requested a review from jay September 22, 2022 13:03
wincrypt defines symbols we test for such as CryptStringToBinary,
therefore it must always be included beforehand. prior to this
change it was not included for mingw.
@jay
Copy link
Member

jay commented Sep 28, 2022

I've pushed a change to your branch to always include wincrypt, since now there is a test to see if CryptStringToBinary is defined, which is defined by wincrypt if it is defined. Assuming the CI has no problems I will review again but otherwise this looks ready.

@DHowett
Copy link
Contributor Author

DHowett commented Sep 28, 2022

Thanks! That makes sense.

Surprising number of OpenSSL and WolfSSL failures in CI. Are those already known/baselined?

@jay
Copy link
Member

jay commented Sep 29, 2022

The 3 CI failures I see are unrelated. The BoringSSL failure might be an actual problem, though unrelated, and the other two look like random failures that occasionally happen due to resource constraints.

@DHowett
Copy link
Contributor Author

DHowett commented Oct 11, 2022

unrelated ... might be an actual problem

Ah, makes sense.

Is there anything I need to do to get this over the finish line for the coming release? 😄

Thanks!

@bagder
Copy link
Member

bagder commented Oct 11, 2022

@jay any remaining nits or can we merge?

@jay jay closed this in 1027d52 Oct 11, 2022
@jay
Copy link
Member

jay commented Oct 11, 2022

Thanks!

obonaventure pushed a commit to mptcp-apps/curl that referenced this pull request Oct 12, 2022
By default, the PFXImportCertStore API persists the key in the user's
key store (as though the certificate was being imported for permanent,
ongoing use.)

The documentation specifies that keys that are not to be persisted
should be imported with the flag PKCS12_NO_PERSIST_KEY.
NOTE: this flag is only supported on versions of Windows newer than XP
and Server 2003.

--

This is take 2 of the original fix. It extends the lifetime of the
client certificate store to that of the credential handle. The original
fix which landed in 70d010d and was later reverted in aec8d30 failed to
work properly because it did not do that.

Minor changes were made to the schannel credential context to support
closing the client certificate store handle at the end of an SSL session.

--

Reported-by: ShadowZzj@users.noreply.github.com

Fixes curl#9300
Supersedes curl#9363
Closes curl#9460
jquepi pushed a commit to jquepi/curl.1.555 that referenced this pull request Oct 24, 2022
By default, the PFXImportCertStore API persists the key in the user's
key store (as though the certificate was being imported for permanent,
ongoing use.)

The documentation specifies that keys that are not to be persisted
should be imported with the flag PKCS12_NO_PERSIST_KEY.
NOTE: this flag is only supported on versions of Windows newer than XP
and Server 2003.

--

This is take 2 of the original fix. It extends the lifetime of the
client certificate store to that of the credential handle. The original
fix which landed in 70d010d and was later reverted in aec8d30 failed to
work properly because it did not do that.

Minor changes were made to the schannel credential context to support
closing the client certificate store handle at the end of an SSL session.

--

Reported-by: ShadowZzj@users.noreply.github.com

Fixes curl/curl#9300
Supersedes curl/curl#9363
Closes curl/curl#9460
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Windows Windows-specific
Development

Successfully merging this pull request may close these issues.

RSA key file leak in C:\ProgramData\Microsoft\Crypto\RSA\S-1-5-18
4 participants