[MSTSC] Fix BSOD when we can't acquire context from CryptoAPI. CORE-13263 #resolve
authorPeter Hater <7element@mail.bg>
Thu, 18 May 2017 08:47:30 +0000 (08:47 +0000)
committerPeter Hater <7element@mail.bg>
Thu, 18 May 2017 08:47:30 +0000 (08:47 +0000)
svn path=/trunk/; revision=74577

reactos/base/applications/mstsc/ssl_calls.c

index af9a78a..d02a50b 100644 (file)
@@ -59,11 +59,23 @@ rdssl_rc4_info_create(void)
         return NULL;
     }
     ret = CryptAcquireContext(&info->hCryptProv,
-                              NULL,
+                              L"MSTSC",
                               MS_ENHANCED_PROV,
                               PROV_RSA_FULL,
                               0);
     if (!ret)
+    {
+        dwErr = GetLastError();
+        if (dwErr == NTE_BAD_KEYSET)
+        {
+            ret = CryptAcquireContext(&info->hCryptProv,
+                                      L"MSTSC",
+                                      MS_ENHANCED_PROV,
+                                      PROV_RSA_FULL,
+                                      CRYPT_NEWKEYSET);
+        }
+    }
+    if (!ret)
     {
         dwErr = GetLastError();
         error("CryptAcquireContext failed with %lx\n", dwErr);
@@ -214,11 +226,23 @@ rdssl_hash_info_create(ALG_ID id)
         return NULL;
     }
     ret = CryptAcquireContext(&info->hCryptProv,
-                              NULL,
+                              L"MSTSC",
                               MS_ENHANCED_PROV,
                               PROV_RSA_FULL,
                               0);
     if (!ret)
+    {
+        dwErr = GetLastError();
+        if (dwErr == NTE_BAD_KEYSET)
+        {
+            ret = CryptAcquireContext(&info->hCryptProv,
+                                      L"MSTSC",
+                                      MS_ENHANCED_PROV,
+                                      PROV_RSA_FULL,
+                                      CRYPT_NEWKEYSET);
+        }
+    }
+    if (!ret)
     {
         dwErr = GetLastError();
         g_free(info);
@@ -451,11 +475,23 @@ rdssl_hmac_md5(char* key, int keylen, char* data, int len, char* output)
         return;
     }
     ret = CryptAcquireContext(&hCryptProv,
-                              NULL,
+                              L"MSTSC",
                               MS_ENHANCED_PROV,
                               PROV_RSA_FULL,
                               0);
     if (!ret)
+    {
+        dwErr = GetLastError();
+        if (dwErr == NTE_BAD_KEYSET)
+        {
+            ret = CryptAcquireContext(&hCryptProv,
+                                      L"MSTSC",
+                                      MS_ENHANCED_PROV,
+                                      PROV_RSA_FULL,
+                                      CRYPT_NEWKEYSET);
+        }
+    }
+    if (!ret)
     {
         dwErr = GetLastError();
         g_free(blob);
@@ -1566,9 +1602,13 @@ rdssl_sign_ok(char* e_data, int e_len, char* n_data, int n_len,
     {
         return 1;
     }
+    md5 = rdssl_md5_info_create();
+    if (!md5)
+    {
+        return 1;
+    }
     key = (char*)xmalloc(176);
     md5_final = (char*)xmalloc(64);
-    md5 = rdssl_md5_info_create();
     // copy the test key
     memcpy(key, testkey, 176);
     // replace e and n