[3/3] crypt32: Implement getting content and some parameters from a decoded enveloped message.

Alexander Morozov amorozov at etersoft.ru
Wed Dec 15 09:07:15 CST 2010


-------------- next part --------------
From 035e6502739787608b4f7f3fe648b19d9cac56f4 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov at etersoft.ru>
Date: Wed, 15 Dec 2010 17:51:37 +0300
Subject: [PATCH 3/3] crypt32: Implement getting content and some parameters from a decoded enveloped message.

---
 dlls/crypt32/msg.c       |   87 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/tests/msg.c |   15 --------
 2 files changed, 87 insertions(+), 15 deletions(-)

diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index d85d2a0..b083d26 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -2881,6 +2881,89 @@ static BOOL CRYPT_CopySignerCertInfo(void *pvData, DWORD *pcbData,
     return ret;
 }
 
+static BOOL CRYPT_CopyRecipientInfo(void *pvData, DWORD *pcbData,
+ const CERT_ISSUER_SERIAL_NUMBER *in)
+{
+    DWORD size = sizeof(CERT_INFO);
+    BOOL ret;
+
+    TRACE("(%p, %d, %p)\n", pvData, pvData ? *pcbData : 0, in);
+
+    size += in->SerialNumber.cbData;
+    size += in->Issuer.cbData;
+    if (!pvData)
+    {
+        *pcbData = size;
+        ret = TRUE;
+    }
+    else if (*pcbData < size)
+    {
+        *pcbData = size;
+        SetLastError(ERROR_MORE_DATA);
+        ret = FALSE;
+    }
+    else
+    {
+        LPBYTE nextData = (BYTE *)pvData + sizeof(CERT_INFO);
+        CERT_INFO *out = pvData;
+
+        CRYPT_CopyBlob(&out->SerialNumber, &in->SerialNumber, &nextData);
+        CRYPT_CopyBlob(&out->Issuer, &in->Issuer, &nextData);
+        ret = TRUE;
+    }
+    TRACE("returning %d\n", ret);
+    return ret;
+}
+
+static BOOL CDecodeEnvelopedMsg_GetParam(CDecodeMsg *msg, DWORD dwParamType,
+ DWORD dwIndex, void *pvData, DWORD *pcbData)
+{
+    BOOL ret = FALSE;
+
+    switch (dwParamType)
+    {
+    case CMSG_TYPE_PARAM:
+        ret = CRYPT_CopyParam(pvData, pcbData, &msg->type, sizeof(msg->type));
+        break;
+    case CMSG_CONTENT_PARAM:
+        if (msg->u.enveloped_data.data)
+            ret = CRYPT_CopyParam(pvData, pcbData,
+             msg->u.enveloped_data.content.pbData,
+             msg->u.enveloped_data.content.cbData);
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_RECIPIENT_COUNT_PARAM:
+        if (msg->u.enveloped_data.data)
+            ret = CRYPT_CopyParam(pvData, pcbData,
+             &msg->u.enveloped_data.data->cRecipientInfo, sizeof(DWORD));
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_RECIPIENT_INFO_PARAM:
+        if (msg->u.enveloped_data.data)
+        {
+            if (dwIndex < msg->u.enveloped_data.data->cRecipientInfo)
+            {
+                PCMSG_KEY_TRANS_RECIPIENT_INFO recipientInfo =
+                 &msg->u.enveloped_data.data->rgRecipientInfo[dwIndex];
+
+                ret = CRYPT_CopyRecipientInfo(pvData, pcbData,
+                 &recipientInfo->RecipientId.u.IssuerSerialNumber);
+            }
+            else
+                SetLastError(CRYPT_E_INVALID_INDEX);
+        }
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    default:
+        FIXME("unimplemented for %d\n", dwParamType);
+        SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+    }
+    return ret;
+}
+
 static BOOL CDecodeSignedMsg_GetParam(CDecodeMsg *msg, DWORD dwParamType,
  DWORD dwIndex, void *pvData, DWORD *pcbData)
 {
@@ -3073,6 +3156,10 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
         ret = CDecodeHashMsg_GetParam(msg, dwParamType, dwIndex, pvData,
          pcbData);
         break;
+    case CMSG_ENVELOPED:
+        ret = CDecodeEnvelopedMsg_GetParam(msg, dwParamType, dwIndex, pvData,
+         pcbData);
+        break;
     case CMSG_SIGNED:
         ret = CDecodeSignedMsg_GetParam(msg, dwParamType, dwIndex, pvData,
          pcbData);
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index 20ad5c9..77b468c 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -3057,7 +3057,6 @@ static void test_decode_msg_get_param(void)
      NULL);
     CryptMsgUpdate(msg, envelopedEmptyBareContent,
      sizeof(envelopedEmptyBareContent), TRUE);
-    todo_wine
     check_param("enveloped empty bare content", msg, CMSG_CONTENT_PARAM, NULL,
      0);
     CryptMsgClose(msg);
@@ -3065,7 +3064,6 @@ static void test_decode_msg_get_param(void)
     msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, 0, 0, NULL, NULL);
     CryptMsgUpdate(msg, envelopedEmptyContent, sizeof(envelopedEmptyContent),
      TRUE);
-    todo_wine
     check_param("enveloped empty content", msg, CMSG_CONTENT_PARAM, NULL, 0);
     CryptMsgClose(msg);
 
@@ -3080,7 +3078,6 @@ static void test_decode_msg_get_param(void)
 
     msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, 0, 0, NULL, NULL);
     CryptMsgUpdate(msg, envelopedMessage, sizeof(envelopedMessage), TRUE);
-    todo_wine
     check_param("enveloped message before decrypting", msg, CMSG_CONTENT_PARAM,
      envelopedMessage + sizeof(envelopedMessage) - 4, 4);
     if (key)
@@ -3094,7 +3091,6 @@ static void test_decode_msg_get_param(void)
         ret = CryptMsgControl(msg, 0, CMSG_CTRL_DECRYPT, &decryptPara);
         ok(!ret && GetLastError() == CRYPT_E_ALREADY_DECRYPTED,
          "expected CRYPT_E_ALREADY_DECRYPTED, got %08x\n", GetLastError());
-        todo_wine
         check_param("enveloped message", msg, CMSG_CONTENT_PARAM, msgData,
          sizeof(msgData));
     }
@@ -3106,7 +3102,6 @@ static void test_decode_msg_get_param(void)
      NULL);
     CryptMsgUpdate(msg, envelopedBareMessage, sizeof(envelopedBareMessage),
      TRUE);
-    todo_wine
     check_param("enveloped bare message before decrypting", msg,
      CMSG_CONTENT_PARAM, envelopedBareMessage +
      sizeof(envelopedBareMessage) - 4, 4);
@@ -3116,7 +3111,6 @@ static void test_decode_msg_get_param(void)
         SetLastError(0xdeadbeef);
         ret = CryptMsgControl(msg, 0, CMSG_CTRL_DECRYPT, &decryptPara);
         ok(ret, "CryptMsgControl failed: %08x\n", GetLastError());
-        todo_wine
         check_param("enveloped bare message", msg, CMSG_CONTENT_PARAM, msgData,
          sizeof(msgData));
     }
@@ -3132,21 +3126,17 @@ static void test_decode_msg_get_param(void)
     CryptMsgUpdate(msg, envelopedMessageWith3Recps,
      sizeof(envelopedMessageWith3Recps), TRUE);
     value = 3;
-    todo_wine
     check_param("recipient count", msg, CMSG_RECIPIENT_COUNT_PARAM,
      (const BYTE *)&value, sizeof(value));
     size = 0;
     SetLastError(0xdeadbeef);
     ret = CryptMsgGetParam(msg, CMSG_RECIPIENT_INFO_PARAM, 3, NULL, &size);
-    todo_wine
     ok(!ret && GetLastError() == CRYPT_E_INVALID_INDEX,
      "expected CRYPT_E_INVALID_INDEX, got %08x\n", GetLastError());
     size = 0;
     SetLastError(0xdeadbeef);
     ret = CryptMsgGetParam(msg, CMSG_RECIPIENT_INFO_PARAM, 2, NULL, &size);
-    todo_wine
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
-    todo_wine
     ok(size >= 142, "unexpected size: %u\n", size);
     if (ret)
         buf = CryptMemAlloc(size);
@@ -3158,18 +3148,13 @@ static void test_decode_msg_get_param(void)
 
         SetLastError(0xdeadbeef);
         ret = CryptMsgGetParam(msg, CMSG_RECIPIENT_INFO_PARAM, 2, buf, &size);
-        todo_wine
         ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
-        todo_wine
         ok(certInfo->SerialNumber.cbData == sizeof(serialNumber),
          "unexpected serial number size: %u\n", certInfo->SerialNumber.cbData);
-        todo_wine
         ok(!memcmp(certInfo->SerialNumber.pbData, serialNumber,
          sizeof(serialNumber)), "unexpected serial number\n");
-        todo_wine
         ok(certInfo->Issuer.cbData == sizeof(issuer),
          "unexpected issuer size: %u\n", certInfo->Issuer.cbData);
-        todo_wine
         ok(!memcmp(certInfo->Issuer.pbData, issuer, sizeof(issuer)),
          "unexpected issuer\n");
         CryptMemFree(buf);
-- 
1.7.3.2



More information about the wine-patches mailing list