Skip to content

New build option to allow reuse of the windows crypt provider handle … #8706

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dgarske
Copy link
Contributor

@dgarske dgarske commented Apr 23, 2025

Description

New build option to allow reuse of the windows crypt provider handle (WIN_REUSE_CRYPT_HANDLE). Documentation from Windows suggests using the same handle from different threads in the same process is safe when CRYPT_VERIFYCONTEXT is used.

Fixes ZD 19754

Testing

Tested on Windows 10 with Visual Studio 2022 with and without WIN_REUSE_CRYPT_HANDLE.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@dgarske dgarske self-assigned this Apr 23, 2025
@dgarske
Copy link
Contributor Author

dgarske commented Apr 24, 2025

Retest this please: "Found unhandled org.jenkinsci.plugins.workflow.support.steps.AgentOfflineException exception:"

@@ -2741,14 +2745,26 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
}
#endif /* HAVE_INTEL_RDSEED */

#ifdef WIN_REUSE_CRYPT_HANDLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OS_Seed already contains ProviderHandle, wouldn't it be enough not to release it with CryptReleaseContext and init only when not initialised? This will avoid global static

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be multiple OS_Seed provider handles and without a global static there would be no way to properly cleanup handles.

@@ -2711,6 +2711,10 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)

#elif defined(USE_WINDOWS_API)

#ifdef WIN_REUSE_CRYPT_HANDLE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is safe optimisation, can it be enabled unconditionally without build option? If it is not and users must make choice what are consequences here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@redbaron , in order to consider making this default I'll have to do some more testing with multiple threads to confirm there aren't any issues.

CRYPT_VERIFYCONTEXT))
return WINCRYPT_E;
}
os->handle = gHandle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if WIN_REUSE_CRYPT_HANDLE is enabled os->handle seems to be unused and can be removed from OS_Seed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping for compatibility (structure needs a member)

@@ -2741,14 +2745,26 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
}
#endif /* HAVE_INTEL_RDSEED */

#ifdef WIN_REUSE_CRYPT_HANDLE
if (gHandle == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is wc_GenerateSeed supposed to be thread safe? if it is, then this check is not safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @redbaron , no this is not thread-safe and it will need fixed before this can be considered. It was already pointed out by a few other wolfSSL engineers.

@dgarske dgarske assigned dgarske and unassigned wolfSSL-Bot Apr 28, 2025
@dgarske dgarske requested a review from redbaron May 6, 2025 17:39
…ws crypt provider handle. Seeding happens on any new RNG or after `WC_RESEED_INTERVAL`. If using threads make sure wolfSSL_Init() or wolfCrypt_Init() is called before spinning up threads. ZD 19754. Fixed minor implicit cast warnings in internal.c. Add missing `hpke.c` to wolfssl VS project.
@dgarske
Copy link
Contributor Author

dgarske commented May 6, 2025

Retest this please: "Found unhandled org.jenkinsci.plugins.workflow.support.steps.AgentOfflineException exception:"

@dgarske dgarske assigned SparkiDev and unassigned dgarske May 6, 2025
@dgarske dgarske requested review from SparkiDev and removed request for redbaron May 6, 2025 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants