aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/SecureRandomDataProvider.cc
diff options
context:
space:
mode:
authoroltolm <oleg.tolmatcev@gmail.com>2020-04-21 20:07:43 +0200
committerJay Berkenbilt <jberkenbilt@users.noreply.github.com>2020-10-17 01:56:33 +0200
commit3221022fc9f10a3dd28a46e333485cfe3597c5c4 (patch)
tree230515ea25ab32528597d6fab6694254bfc9ca36 /libqpdf/SecureRandomDataProvider.cc
parent32245ca33947557fc850cdecc50d496713eaf8bc (diff)
downloadqpdf-3221022fc9f10a3dd28a46e333485cfe3597c5c4.tar.zst
fix WindowsCryptProvider fixes #432
Diffstat (limited to 'libqpdf/SecureRandomDataProvider.cc')
-rw-r--r--libqpdf/SecureRandomDataProvider.cc51
1 files changed, 3 insertions, 48 deletions
diff --git a/libqpdf/SecureRandomDataProvider.cc b/libqpdf/SecureRandomDataProvider.cc
index fe2c93f9..87839dc6 100644
--- a/libqpdf/SecureRandomDataProvider.cc
+++ b/libqpdf/SecureRandomDataProvider.cc
@@ -42,60 +42,15 @@ class WindowsCryptProvider
public:
WindowsCryptProvider()
{
- if (!CryptAcquireContext(&crypt_prov,
- "Container",
+ if (!CryptAcquireContextW(&crypt_prov,
+ NULL,
NULL,
PROV_RSA_FULL,
- CRYPT_MACHINE_KEYSET))
+ CRYPT_VERIFYCONTEXT))
{
-#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wold-style-cast"
-# pragma GCC diagnostic ignored "-Wsign-compare"
-# pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
- if (GetLastError() == NTE_BAD_KEYSET)
- {
- if (! CryptAcquireContext(&crypt_prov,
- "Container",
- NULL,
- PROV_RSA_FULL,
- CRYPT_NEWKEYSET|CRYPT_MACHINE_KEYSET))
- {
- throw std::runtime_error(
- "unable to acquire crypt context with new keyset: " +
- getErrorMessage());
- }
- }
- else if (GetLastError() == NTE_EXISTS)
- {
- throw std::runtime_error(
- "unable to acquire crypt context; the key container"
- " already exists, but you are attempting to create it."
- " If a previous attempt to open the key failed with"
- " NTE_BAD_KEYSET, it implies that access to the key"
- " container is denied. Error: " + getErrorMessage());
- }
- else if (GetLastError() == NTE_KEYSET_NOT_DEF)
- {
- throw std::runtime_error(
- "unable to acquire crypt context; the Crypto Service"
- " Provider (CSP) may not be set up correctly. Use of"
- " Regsvr32.exe on CSP DLLs (Rsabase.dll or Rsaenh.dll)"
- " may fix the problem, depending on the provider being"
- " used. Error: " + getErrorMessage());
- }
- else
- {
throw std::runtime_error(
"unable to acquire crypt context: " +
getErrorMessage());
- }
-#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
- defined(__clang__))
-# pragma GCC diagnostic pop
-#endif
}
}
~WindowsCryptProvider()