From d11ddebc763bbccb5b07f952085fdb5d342f5ec7 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Mon, 23 Jul 2007 17:33:09 -0700 Subject: [PATCH] crypt32: Add a partial stub for updating a signed encoded message. --- dlls/crypt32/msg.c | 42 ++++++++++++++++++++++++++++++++++++---- dlls/crypt32/tests/msg.c | 7 ------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c index 08b3ce8499e..c134e68e370 100644 --- a/dlls/crypt32/msg.c +++ b/dlls/crypt32/msg.c @@ -592,12 +592,15 @@ static BOOL CRYPT_IsValidSigner(CMSG_SIGNER_ENCODE_INFO_WITH_CMS *signer) typedef struct _CSignedEncodeMsg { - CryptMsgBase base; + CryptMsgBase base; + CRYPT_DATA_BLOB data; } CSignedEncodeMsg; static void CSignedEncodeMsg_Close(HCRYPTMSG hCryptMsg) { - FIXME("(%p)\n", hCryptMsg); + CSignedEncodeMsg *msg = (CSignedEncodeMsg *)hCryptMsg; + + CryptMemFree(msg->data.pbData); } static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, @@ -611,8 +614,37 @@ static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, static BOOL CSignedEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal) { - FIXME("(%p, %p, %d, %d)\n", hCryptMsg, pbData, cbData, fFinal); - return FALSE; + CSignedEncodeMsg *msg = (CSignedEncodeMsg *)hCryptMsg; + BOOL ret = FALSE; + + if (msg->base.streamed || (msg->base.open_flags & CMSG_DETACHED_FLAG)) + { + FIXME("streamed / detached update unimplemented\n"); + ret = TRUE; + } + else + { + if (!fFinal) + SetLastError(CRYPT_E_MSG_ERROR); + else + { + if (cbData) + { + msg->data.pbData = CryptMemAlloc(cbData); + if (msg->data.pbData) + { + memcpy(msg->data.pbData, pbData, cbData); + msg->data.cbData = cbData; + ret = TRUE; + } + } + else + ret = TRUE; + if (ret) + FIXME("non-streamed final update: partial stub\n"); + } + } + return ret; } static HCRYPTMSG CSignedEncodeMsg_Open(DWORD dwFlags, @@ -644,6 +676,8 @@ static HCRYPTMSG CSignedEncodeMsg_Open(DWORD dwFlags, CryptMsgBase_Init((CryptMsgBase *)msg, dwFlags, pStreamInfo, CSignedEncodeMsg_Close, CSignedEncodeMsg_GetParam, CSignedEncodeMsg_Update); + msg->data.cbData = 0; + msg->data.pbData = NULL; } return msg; } diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c index 8ef97e82874..94864c142f9 100644 --- a/dlls/crypt32/tests/msg.c +++ b/dlls/crypt32/tests/msg.c @@ -1112,11 +1112,9 @@ static void test_signed_msg_update(void) ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError()); /* CMSG_SIGNED allows non-final updates. */ ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); /* CMSG_SIGNED also allows non-final updates with no data. */ ret = CryptMsgUpdate(msg, NULL, 0, FALSE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); /* The final update requires a private key in the hCryptProv, in order to * generate the signature. @@ -1143,17 +1141,14 @@ static void test_signed_msg_update(void) ok(msg != NULL, "CryptMsgOpenToEncode failed: %x\n", GetLastError()); /* CMSG_SIGNED allows non-final updates. */ ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), FALSE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); /* CMSG_SIGNED also allows non-final updates with no data. */ ret = CryptMsgUpdate(msg, NULL, 0, FALSE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); /* Now that the private key exists, the final update can succeed (even * with no data.) */ ret = CryptMsgUpdate(msg, NULL, 0, TRUE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); /* But no updates are allowed after the final update. */ SetLastError(0xdeadbeef); @@ -1282,7 +1277,6 @@ static void test_signed_msg_encoding(void) check_param("detached signed empty content", msg, CMSG_CONTENT_PARAM, signedEmptyContent, sizeof(signedEmptyContent)); ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); todo_wine check_param("detached signed hash", msg, CMSG_COMPUTED_HASH_PARAM, @@ -1312,7 +1306,6 @@ static void test_signed_msg_encoding(void) check_param("signed empty content", msg, CMSG_CONTENT_PARAM, signedEmptyContent, sizeof(signedEmptyContent)); ret = CryptMsgUpdate(msg, msgData, sizeof(msgData), TRUE); - todo_wine ok(ret, "CryptMsgUpdate failed: %x\n", GetLastError()); todo_wine check_param("signed bare content", msg, CMSG_BARE_CONTENT_PARAM,