Commit 3221022fc9f10a3dd28a46e333485cfe3597c5c4
Committed by
Jay Berkenbilt
1 parent
32245ca3
fix WindowsCryptProvider fixes #432
Showing
1 changed file
with
3 additions
and
48 deletions
libqpdf/SecureRandomDataProvider.cc
| ... | ... | @@ -42,60 +42,15 @@ class WindowsCryptProvider |
| 42 | 42 | public: |
| 43 | 43 | WindowsCryptProvider() |
| 44 | 44 | { |
| 45 | - if (!CryptAcquireContext(&crypt_prov, | |
| 46 | - "Container", | |
| 45 | + if (!CryptAcquireContextW(&crypt_prov, | |
| 46 | + NULL, | |
| 47 | 47 | NULL, |
| 48 | 48 | PROV_RSA_FULL, |
| 49 | - CRYPT_MACHINE_KEYSET)) | |
| 49 | + CRYPT_VERIFYCONTEXT)) | |
| 50 | 50 | { |
| 51 | -#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | |
| 52 | - defined(__clang__)) | |
| 53 | -# pragma GCC diagnostic push | |
| 54 | -# pragma GCC diagnostic ignored "-Wold-style-cast" | |
| 55 | -# pragma GCC diagnostic ignored "-Wsign-compare" | |
| 56 | -# pragma GCC diagnostic ignored "-Wsign-conversion" | |
| 57 | -#endif | |
| 58 | - if (GetLastError() == NTE_BAD_KEYSET) | |
| 59 | - { | |
| 60 | - if (! CryptAcquireContext(&crypt_prov, | |
| 61 | - "Container", | |
| 62 | - NULL, | |
| 63 | - PROV_RSA_FULL, | |
| 64 | - CRYPT_NEWKEYSET|CRYPT_MACHINE_KEYSET)) | |
| 65 | - { | |
| 66 | - throw std::runtime_error( | |
| 67 | - "unable to acquire crypt context with new keyset: " + | |
| 68 | - getErrorMessage()); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - else if (GetLastError() == NTE_EXISTS) | |
| 72 | - { | |
| 73 | - throw std::runtime_error( | |
| 74 | - "unable to acquire crypt context; the key container" | |
| 75 | - " already exists, but you are attempting to create it." | |
| 76 | - " If a previous attempt to open the key failed with" | |
| 77 | - " NTE_BAD_KEYSET, it implies that access to the key" | |
| 78 | - " container is denied. Error: " + getErrorMessage()); | |
| 79 | - } | |
| 80 | - else if (GetLastError() == NTE_KEYSET_NOT_DEF) | |
| 81 | - { | |
| 82 | - throw std::runtime_error( | |
| 83 | - "unable to acquire crypt context; the Crypto Service" | |
| 84 | - " Provider (CSP) may not be set up correctly. Use of" | |
| 85 | - " Regsvr32.exe on CSP DLLs (Rsabase.dll or Rsaenh.dll)" | |
| 86 | - " may fix the problem, depending on the provider being" | |
| 87 | - " used. Error: " + getErrorMessage()); | |
| 88 | - } | |
| 89 | - else | |
| 90 | - { | |
| 91 | 51 | throw std::runtime_error( |
| 92 | 52 | "unable to acquire crypt context: " + |
| 93 | 53 | getErrorMessage()); |
| 94 | - } | |
| 95 | -#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \ | |
| 96 | - defined(__clang__)) | |
| 97 | -# pragma GCC diagnostic pop | |
| 98 | -#endif | |
| 99 | 54 | } |
| 100 | 55 | } |
| 101 | 56 | ~WindowsCryptProvider() | ... | ... |