crypt32(6/9): Implement getting some parameters from a decoded signed message

Juan Lang juan.lang at gmail.com
Fri Jul 27 13:02:18 CDT 2007


--Juan
-------------- next part --------------
From 6be9e67f8c5ed2a7f1394ab9896f380032ecb617 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Fri, 27 Jul 2007 10:57:50 -0700
Subject: [PATCH] Implement getting some parameters from a decoded signed message
---
 dlls/crypt32/msg.c       |   88 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/tests/msg.c |   12 ------
 2 files changed, 88 insertions(+), 12 deletions(-)

diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index 042b1ef..bca4040 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -1559,6 +1559,90 @@ static BOOL CDecodeHashMsg_GetParam(CDec
     return ret;
 }
 
+static BOOL CDecodeSignedMsg_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_SIGNER_COUNT_PARAM:
+        if (msg->u.signedInfo)
+            ret = CRYPT_CopyParam(pvData, pcbData,
+             &msg->u.signedInfo->cSignerInfo, sizeof(DWORD));
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_CERT_COUNT_PARAM:
+        if (msg->u.signedInfo)
+            ret = CRYPT_CopyParam(pvData, pcbData,
+             &msg->u.signedInfo->cCertEncoded, sizeof(DWORD));
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_CERT_PARAM:
+        if (msg->u.signedInfo)
+        {
+            if (dwIndex >= msg->u.signedInfo->cCertEncoded)
+                SetLastError(CRYPT_E_INVALID_INDEX);
+            else
+                ret = CRYPT_CopyParam(pvData, pcbData,
+                 msg->u.signedInfo->rgCertEncoded[dwIndex].pbData,
+                 msg->u.signedInfo->rgCertEncoded[dwIndex].cbData);
+        }
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_CRL_COUNT_PARAM:
+        if (msg->u.signedInfo)
+            ret = CRYPT_CopyParam(pvData, pcbData,
+             &msg->u.signedInfo->cCrlEncoded, sizeof(DWORD));
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_CRL_PARAM:
+        if (msg->u.signedInfo)
+        {
+            if (dwIndex >= msg->u.signedInfo->cCrlEncoded)
+                SetLastError(CRYPT_E_INVALID_INDEX);
+            else
+                ret = CRYPT_CopyParam(pvData, pcbData,
+                 msg->u.signedInfo->rgCrlEncoded[dwIndex].pbData,
+                 msg->u.signedInfo->rgCrlEncoded[dwIndex].cbData);
+        }
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_ATTR_CERT_COUNT_PARAM:
+        if (msg->u.signedInfo)
+            ret = CRYPT_CopyParam(pvData, pcbData,
+             &msg->u.signedInfo->cAttrCertEncoded, sizeof(DWORD));
+        else
+            SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+        break;
+    case CMSG_ATTR_CERT_PARAM:
+        if (msg->u.signedInfo)
+        {
+            if (dwIndex >= msg->u.signedInfo->cAttrCertEncoded)
+                SetLastError(CRYPT_E_INVALID_INDEX);
+            else
+                ret = CRYPT_CopyParam(pvData, pcbData,
+                 msg->u.signedInfo->rgAttrCertEncoded[dwIndex].pbData,
+                 msg->u.signedInfo->rgAttrCertEncoded[dwIndex].cbData);
+        }
+        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 CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
  DWORD dwIndex, void *pvData, DWORD *pcbData)
 {
@@ -1571,6 +1655,10 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
         ret = CDecodeHashMsg_GetParam(msg, dwParamType, dwIndex, pvData,
          pcbData);
         break;
+    case CMSG_SIGNED:
+        ret = CDecodeSignedMsg_GetParam(msg, dwParamType, dwIndex, pvData,
+         pcbData);
+        break;
     default:
         switch (dwParamType)
         {
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index b7f9393..85a9d62 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -1961,26 +1961,18 @@ static void test_decode_msg_get_param(vo
     size = sizeof(value);
     value = 2112;
     ret = CryptMsgGetParam(msg, CMSG_SIGNER_COUNT_PARAM, 0, &value, &size);
-    todo_wine {
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
     ok(value == 1, "Expected 1 signer, got %d\n", value);
-    }
     /* index is ignored when getting signer count */
     ret = CryptMsgGetParam(msg, CMSG_SIGNER_COUNT_PARAM, 1, &value, &size);
-    todo_wine {
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
     ok(value == 1, "Expected 1 signer, got %d\n", value);
-    }
     ret = CryptMsgGetParam(msg, CMSG_CERT_COUNT_PARAM, 0, &value, &size);
-    todo_wine {
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
     ok(value == 0, "Expected 0 certs, got %d\n", value);
-    }
     ret = CryptMsgGetParam(msg, CMSG_CRL_COUNT_PARAM, 0, &value, &size);
-    todo_wine {
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
     ok(value == 0, "Expected 0 CRLs, got %d\n", value);
-    }
     CryptMsgClose(msg);
     msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, CMSG_SIGNED, 0, NULL,
      NULL);
@@ -1988,17 +1980,13 @@ static void test_decode_msg_get_param(vo
      sizeof(signedWithCertAndCrlBareContent), TRUE);
     ok(ret, "CryptMsgUpdate failed: %08x\n", GetLastError());
     ret = CryptMsgGetParam(msg, CMSG_CERT_COUNT_PARAM, 0, &value, &size);
-    todo_wine {
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
     ok(value == 1, "Expected 1 cert, got %d\n", value);
     check_param("cert", msg, CMSG_CERT_PARAM, cert, sizeof(cert));
-    }
     ret = CryptMsgGetParam(msg, CMSG_CRL_COUNT_PARAM, 0, &value, &size);
-    todo_wine {
     ok(ret, "CryptMsgGetParam failed: %08x\n", GetLastError());
     ok(value == 1, "Expected 1 CRL, got %d\n", value);
     check_param("crl", msg, CMSG_CRL_PARAM, crl, sizeof(crl));
-    }
     CryptMsgClose(msg);
 }
 
-- 
1.4.1


More information about the wine-patches mailing list