Juan Lang : crypt32: Support reading a serialized store object from memory in CryptQueryObject.

Alexandre Julliard julliard at winehq.org
Tue Nov 3 15:37:19 CST 2009


Module: wine
Branch: master
Commit: 9928e2e1c534ac5e9fafeb03140c354743c09d82
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9928e2e1c534ac5e9fafeb03140c354743c09d82

Author: Juan Lang <juan.lang at gmail.com>
Date:   Thu Oct 29 16:48:52 2009 -0700

crypt32: Support reading a serialized store object from memory in CryptQueryObject.

---

 dlls/crypt32/crypt32_private.h |    6 ++++
 dlls/crypt32/object.c          |   55 +++++++++++++++++++++++++++++++++------
 dlls/crypt32/serialize.c       |   31 ++++++++++++++++++++++
 3 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h
index 5e5b540..8c5b13b 100644
--- a/dlls/crypt32/crypt32_private.h
+++ b/dlls/crypt32/crypt32_private.h
@@ -282,6 +282,12 @@ const void *CRYPT_ReadSerializedElement(const BYTE *pbElement,
  */
 BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store);
 
+/* Reads contexts serialized in the blob into the memory store.  Returns FALSE
+ * if the file is not of the expected format.
+ */
+BOOL CRYPT_ReadSerializedStoreFromBlob(const CRYPT_DATA_BLOB *blob,
+ HCERTSTORE store);
+
 /* Fixes up the pointers in info, where info is assumed to be a
  * CRYPT_KEY_PROV_INFO, followed by its container name, provider name, and any
  * provider parameters, in a contiguous buffer, but where info's pointers are
diff --git a/dlls/crypt32/object.c b/dlls/crypt32/object.c
index f505b7d..c337784 100644
--- a/dlls/crypt32/object.c
+++ b/dlls/crypt32/object.c
@@ -283,20 +283,13 @@ end:
     return ret;
 }
 
-static BOOL CRYPT_QuerySerializedStoreObject(DWORD dwObjectType,
- const void *pvObject, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
+static BOOL CRYPT_QuerySerializedStoreFromFile(LPCWSTR fileName,
+ DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
  HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
 {
-    LPCWSTR fileName = pvObject;
     HANDLE file;
     BOOL ret = FALSE;
 
-    if (dwObjectType != CERT_QUERY_OBJECT_FILE)
-    {
-        FIXME("unimplemented for non-file type %d\n", dwObjectType);
-        SetLastError(E_INVALIDARG); /* FIXME: is this the correct error? */
-        return FALSE;
-    }
     TRACE("%s\n", debugstr_w(fileName));
     file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
      OPEN_EXISTING, 0, NULL);
@@ -322,6 +315,50 @@ static BOOL CRYPT_QuerySerializedStoreObject(DWORD dwObjectType,
     return ret;
 }
 
+static BOOL CRYPT_QuerySerializedStoreFromBlob(const CRYPT_DATA_BLOB *blob,
+ DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
+ HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
+{
+    HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
+     CERT_STORE_CREATE_NEW_FLAG, NULL);
+    BOOL ret;
+
+    TRACE("(%d, %p)\n", blob->cbData, blob->pbData);
+
+    ret = CRYPT_ReadSerializedStoreFromBlob(blob, store);
+    if (ret)
+    {
+        if (pdwMsgAndCertEncodingType)
+            *pdwMsgAndCertEncodingType = X509_ASN_ENCODING;
+        if (pdwContentType)
+            *pdwContentType = CERT_QUERY_CONTENT_SERIALIZED_STORE;
+        if (phCertStore)
+            *phCertStore = CertDuplicateStore(store);
+    }
+    CertCloseStore(store, 0);
+    TRACE("returning %d\n", ret);
+    return ret;
+}
+
+static BOOL CRYPT_QuerySerializedStoreObject(DWORD dwObjectType,
+ const void *pvObject, DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType,
+ HCERTSTORE *phCertStore, HCRYPTMSG *phMsg)
+{
+    switch (dwObjectType)
+    {
+    case CERT_QUERY_OBJECT_FILE:
+        return CRYPT_QuerySerializedStoreFromFile(pvObject,
+         pdwMsgAndCertEncodingType, pdwContentType, phCertStore, phMsg);
+    case CERT_QUERY_OBJECT_BLOB:
+        return CRYPT_QuerySerializedStoreFromBlob(pvObject,
+         pdwMsgAndCertEncodingType, pdwContentType, phCertStore, phMsg);
+    default:
+        FIXME("unimplemented for type %d\n", dwObjectType);
+        SetLastError(E_INVALIDARG); /* FIXME: is this the correct error? */
+        return FALSE;
+    }
+}
+
 static BOOL CRYPT_QuerySignedMessage(const CRYPT_DATA_BLOB *blob,
  DWORD *pdwMsgAndCertEncodingType, DWORD *pdwContentType, HCRYPTMSG *phMsg)
 {
diff --git a/dlls/crypt32/serialize.c b/dlls/crypt32/serialize.c
index 45a3e25..b502110 100644
--- a/dlls/crypt32/serialize.c
+++ b/dlls/crypt32/serialize.c
@@ -534,6 +534,37 @@ BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
     return CRYPT_ReadSerializedStore(file, read_file_wrapper, store);
 }
 
+struct BlobReader
+{
+    const CRYPT_DATA_BLOB *blob;
+    DWORD current;
+};
+
+static BOOL read_blob_wrapper(void *handle, void *buffer, DWORD bytesToRead,
+ DWORD *bytesRead)
+{
+    struct BlobReader *reader = handle;
+    BOOL ret;
+
+    if (reader->current < reader->blob->cbData)
+    {
+        *bytesRead = min(bytesToRead, reader->blob->cbData - reader->current);
+        memcpy(buffer, reader->blob->pbData + reader->current, *bytesRead);
+        ret = TRUE;
+    }
+    else
+        ret = FALSE;
+    return ret;
+}
+
+BOOL CRYPT_ReadSerializedStoreFromBlob(const CRYPT_DATA_BLOB *blob,
+ HCERTSTORE store)
+{
+    struct BlobReader reader = { blob, 0 };
+
+    return CRYPT_ReadSerializedStore(&reader, read_blob_wrapper, store);
+}
+
 static BOOL WINAPI CRYPT_SerializeCertNoHash(PCCERT_CONTEXT pCertContext,
  DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
 {




More information about the wine-cvs mailing list