Author: akhaldi
Date: Sun Jul 19 13:13:36 2015
New Revision: 68426
URL: 
http://svn.reactos.org/svn/reactos?rev=68426&view=rev
Log:
[CRYPT32] Sync with Wine Staging 1.7.47. CORE-9924
Modified:
    trunk/reactos/dll/win32/crypt32/crypt32_private.h
    trunk/reactos/dll/win32/crypt32/decode.c
    trunk/reactos/media/doc/README.WINE
Modified: trunk/reactos/dll/win32/crypt32/crypt32_private.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/crypt32/crypt32_…
==============================================================================
--- trunk/reactos/dll/win32/crypt32/crypt32_private.h   [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/crypt32/crypt32_private.h   [iso-8859-1] Sun Jul 19 13:13:36
2015
@@ -459,7 +459,7 @@
 void ContextPropertyList_Free(CONTEXT_PROPERTY_LIST *list) DECLSPEC_HIDDEN;
-extern WINECRYPT_CERTSTORE empty_store;
+extern WINECRYPT_CERTSTORE empty_store DECLSPEC_HIDDEN;
 void init_empty_store(void) DECLSPEC_HIDDEN;
 /**
Modified: trunk/reactos/dll/win32/crypt32/decode.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/crypt32/decode.c…
==============================================================================
--- trunk/reactos/dll/win32/crypt32/decode.c    [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/crypt32/decode.c    [iso-8859-1] Sun Jul 19 13:13:36 2015
@@ -3919,6 +3919,147 @@
     return ret;
 }
+#define RSA2_MAGIC 0x32415352
+
+struct DECODED_RSA_PRIV_KEY
+{
+    DWORD              version;
+    DWORD              pubexp;
+    CRYPT_INTEGER_BLOB modulus;
+    CRYPT_INTEGER_BLOB privexp;
+    CRYPT_INTEGER_BLOB prime1;
+    CRYPT_INTEGER_BLOB prime2;
+    CRYPT_INTEGER_BLOB exponent1;
+    CRYPT_INTEGER_BLOB exponent2;
+    CRYPT_INTEGER_BLOB coefficient;
+};
+
+static BOOL WINAPI CRYPT_AsnDecodeRsaPrivKey(DWORD dwCertEncodingType,
+ LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
+ PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
+{
+    BOOL ret;
+    DWORD halflen;
+
+    __TRY
+    {
+        struct AsnDecodeSequenceItem items[] = {
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, version),
+           CRYPT_AsnDecodeIntInternal, sizeof(DWORD), FALSE, FALSE, 0, 0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, modulus),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, modulus.pbData),
+           0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, pubexp),
+           CRYPT_AsnDecodeIntInternal, sizeof(DWORD), FALSE, FALSE, 0, 0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, privexp),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, privexp.pbData),
+           0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, prime1),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, prime1.pbData),
+           0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, prime2),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, prime2.pbData),
+           0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, exponent1),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, exponent1.pbData),
+           0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, exponent2),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, exponent2.pbData),
+           0 },
+         { ASN_INTEGER, offsetof(struct DECODED_RSA_PRIV_KEY, coefficient),
+           CRYPT_AsnDecodeUnsignedIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
+           FALSE, TRUE, offsetof(struct DECODED_RSA_PRIV_KEY, coefficient.pbData),
+           0 },
+        };
+        struct DECODED_RSA_PRIV_KEY *decodedKey = NULL;
+        DWORD size = 0;
+
+        ret = CRYPT_AsnDecodeSequence(items, sizeof(items) / sizeof(items[0]),
+         pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, &decodedKey,
+         &size, NULL, NULL);
+        if (ret)
+        {
+            halflen = decodedKey->modulus.cbData / 2;
+            if ((decodedKey->modulus.cbData != halflen * 2) ||
+                (decodedKey->prime1.cbData != halflen) ||
+                (decodedKey->prime2.cbData != halflen) ||
+                (decodedKey->exponent1.cbData != halflen) ||
+                (decodedKey->exponent2.cbData != halflen) ||
+                (decodedKey->coefficient.cbData != halflen) ||
+                (decodedKey->privexp.cbData != halflen * 2))
+            {
+                ret = FALSE;
+                SetLastError(CRYPT_E_BAD_ENCODE);
+            }
+
+            if (ret)
+            {
+                DWORD bytesNeeded = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) +
+                 (halflen * 9);
+
+                if (!pvStructInfo)
+                {
+                    *pcbStructInfo = bytesNeeded;
+                    ret = TRUE;
+                }
+                else if ((ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara,
+                 pvStructInfo, pcbStructInfo, bytesNeeded)))
+                {
+                    BLOBHEADER *hdr;
+                    RSAPUBKEY *rsaPubKey;
+                    BYTE *vardata;
+
+                    if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
+                        pvStructInfo = *(BYTE **)pvStructInfo;
+
+                    hdr = pvStructInfo;
+                    hdr->bType = PRIVATEKEYBLOB;
+                    hdr->bVersion = CUR_BLOB_VERSION;
+                    hdr->reserved = 0;
+                    hdr->aiKeyAlg = CALG_RSA_KEYX;
+
+                    rsaPubKey = (RSAPUBKEY *)((BYTE *)pvStructInfo +
+                     sizeof(BLOBHEADER));
+                    rsaPubKey->magic = RSA2_MAGIC;
+                    rsaPubKey->pubexp = decodedKey->pubexp;
+                    rsaPubKey->bitlen = halflen * 16;
+
+                    vardata = (BYTE*)(rsaPubKey + 1);
+                    memcpy(vardata,
+                     decodedKey->modulus.pbData, halflen * 2);
+                    memcpy(vardata + halflen * 2,
+                     decodedKey->prime1.pbData, halflen);
+                    memcpy(vardata + halflen * 3,
+                     decodedKey->prime2.pbData, halflen);
+                    memcpy(vardata + halflen * 4,
+                     decodedKey->exponent1.pbData, halflen);
+                    memcpy(vardata + halflen * 5,
+                     decodedKey->exponent2.pbData, halflen);
+                    memcpy(vardata + halflen * 6,
+                     decodedKey->coefficient.pbData, halflen);
+                    memcpy(vardata + halflen * 7,
+                     decodedKey->privexp.pbData, halflen * 2);
+                }
+            }
+
+            LocalFree(decodedKey);
+        }
+    }
+    __EXCEPT_PAGE_FAULT
+    {
+        SetLastError(STATUS_ACCESS_VIOLATION);
+        ret = FALSE;
+    }
+    __ENDTRY
+    return ret;
+}
+
 static BOOL CRYPT_AsnDecodeOctetsInternal(const BYTE *pbEncoded,
  DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo,
  DWORD *pcbDecoded)
@@ -5485,6 +5626,9 @@
        offsetof(CMSG_CMS_SIGNER_INFO, AuthAttrs),
        CRYPT_AsnDecodePKCSAttributesInternal, sizeof(CRYPT_ATTRIBUTES),
        TRUE, TRUE, offsetof(CMSG_CMS_SIGNER_INFO, AuthAttrs.rgAttr), 0 },
+     /* FIXME: Tests show that CertOpenStore accepts such certificates, but
+      * how exactly should they be interpreted? */
+     { ASN_CONSTRUCTOR | ASN_UNIVERSAL | 0x11, 0, NULL, 0, TRUE, FALSE, 0, 0 },
      { ASN_SEQUENCEOF, offsetof(CMSG_CMS_SIGNER_INFO, HashEncryptionAlgorithm),
        CRYPT_AsnDecodeAlgorithmId, sizeof(CRYPT_ALGORITHM_IDENTIFIER),
        FALSE, TRUE, offsetof(CMSG_CMS_SIGNER_INFO,
@@ -5599,8 +5743,8 @@
        offsetof(CRYPT_SIGNED_INFO, rgSignerInfo), 0 },
     };
-    TRACE("%p, %d, %08x, %p, %p, %d\n", pbEncoded, cbEncoded, dwFlags,
-     pDecodePara, signedInfo, *pcbSignedInfo);
+    TRACE("%p, %d, %08x, %p, %p, %p\n", pbEncoded, cbEncoded, dwFlags,
+     pDecodePara, signedInfo, pcbSignedInfo);
     ret = CRYPT_AsnDecodeSequence(items, sizeof(items) / sizeof(items[0]),
      pbEncoded, cbEncoded, dwFlags, pDecodePara, signedInfo, pcbSignedInfo,
@@ -5717,8 +5861,8 @@
        offsetof(CRYPT_ENVELOPED_DATA, encryptedContentInfo.contentType), 0 },
     };
-    TRACE("%p, %d, %08x, %p, %p, %d\n", pbEncoded, cbEncoded, dwFlags,
-     pDecodePara, envelopedData, *pcbEnvelopedData);
+    TRACE("%p, %d, %08x, %p, %p, %p\n", pbEncoded, cbEncoded, dwFlags,
+     pDecodePara, envelopedData, pcbEnvelopedData);
     ret = CRYPT_AsnDecodeSequence(items, sizeof(items) / sizeof(items[0]),
      pbEncoded, cbEncoded, dwFlags, pDecodePara, envelopedData,
@@ -5780,6 +5924,9 @@
             break;
         case LOWORD(RSA_CSP_PUBLICKEYBLOB):
             decodeFunc = CRYPT_AsnDecodeRsaPubKey;
+            break;
+        case LOWORD(PKCS_RSA_PRIVATE_KEY):
+            decodeFunc = CRYPT_AsnDecodeRsaPrivKey;
             break;
         case LOWORD(X509_UNICODE_NAME):
             decodeFunc = CRYPT_AsnDecodeUnicodeName;
Modified: trunk/reactos/media/doc/README.WINE
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/media/doc/README.WINE?rev=…
==============================================================================
--- trunk/reactos/media/doc/README.WINE [iso-8859-1] (original)
+++ trunk/reactos/media/doc/README.WINE [iso-8859-1] Sun Jul 19 13:13:36 2015
@@ -59,7 +59,7 @@
 reactos/dll/win32/comdlg32            # Synced to WineStaging-1.7.37
 reactos/dll/win32/compstui            # Synced to WineStaging-1.7.37
 reactos/dll/win32/credui              # Synced to WineStaging-1.7.37
-reactos/dll/win32/crypt32             # Synced to WineStaging-1.7.37
+reactos/dll/win32/crypt32             # Synced to WineStaging-1.7.47
 reactos/dll/win32/cryptdlg            # Synced to WineStaging-1.7.37
 reactos/dll/win32/cryptdll            # Synced to WineStaging-1.7.37
 reactos/dll/win32/cryptnet            # Synced to WineStaging-1.7.37