mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-02 20:08:24 +00:00
fix WindowsCryptProvider fixes #432
This commit is contained in:
parent
32245ca339
commit
3221022fc9
@ -42,60 +42,15 @@ class WindowsCryptProvider
|
|||||||
public:
|
public:
|
||||||
WindowsCryptProvider()
|
WindowsCryptProvider()
|
||||||
{
|
{
|
||||||
if (!CryptAcquireContext(&crypt_prov,
|
if (!CryptAcquireContextW(&crypt_prov,
|
||||||
"Container",
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
PROV_RSA_FULL,
|
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(
|
throw std::runtime_error(
|
||||||
"unable to acquire crypt context: " +
|
"unable to acquire crypt context: " +
|
||||||
getErrorMessage());
|
getErrorMessage());
|
||||||
}
|
|
||||||
#if ((defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || \
|
|
||||||
defined(__clang__))
|
|
||||||
# pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
~WindowsCryptProvider()
|
~WindowsCryptProvider()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user