crypt32: Implement CryptEncryptMessage.

This commit is contained in:
Alexander Morozov 2010-12-08 14:51:42 +03:00 committed by Alexandre Julliard
parent 2a2020d997
commit 02ab124cd2
2 changed files with 55 additions and 18 deletions

View File

@ -536,8 +536,61 @@ BOOL WINAPI CryptEncryptMessage(PCRYPT_ENCRYPT_MESSAGE_PARA pEncryptPara,
const BYTE *pbToBeEncrypted, DWORD cbToBeEncrypted, BYTE *pbEncryptedBlob,
DWORD *pcbEncryptedBlob)
{
FIXME("(%p, %d, %p, %p, %d, %p, %p): stub\n", pEncryptPara, cRecipientCert,
BOOL ret = TRUE;
DWORD i;
PCERT_INFO *certInfo = NULL;
CMSG_ENVELOPED_ENCODE_INFO envelopedInfo;
HCRYPTMSG msg = 0;
TRACE("(%p, %d, %p, %p, %d, %p, %p)\n", pEncryptPara, cRecipientCert,
rgpRecipientCert, pbToBeEncrypted, cbToBeEncrypted, pbEncryptedBlob,
pcbEncryptedBlob);
if (pEncryptPara->cbSize != sizeof(CRYPT_ENCRYPT_MESSAGE_PARA) ||
GET_CMSG_ENCODING_TYPE(pEncryptPara->dwMsgEncodingType) !=
PKCS_7_ASN_ENCODING)
{
*pcbEncryptedBlob = 0;
SetLastError(E_INVALIDARG);
return FALSE;
}
memset(&envelopedInfo, 0, sizeof(envelopedInfo));
envelopedInfo.cbSize = sizeof(envelopedInfo);
envelopedInfo.hCryptProv = pEncryptPara->hCryptProv;
envelopedInfo.ContentEncryptionAlgorithm =
pEncryptPara->ContentEncryptionAlgorithm;
envelopedInfo.pvEncryptionAuxInfo = pEncryptPara->pvEncryptionAuxInfo;
if (cRecipientCert)
{
certInfo = CryptMemAlloc(sizeof(PCERT_INFO) * cRecipientCert);
if (certInfo)
{
for (i = 0; i < cRecipientCert; ++i)
certInfo[i] = rgpRecipientCert[i]->pCertInfo;
envelopedInfo.cRecipients = cRecipientCert;
envelopedInfo.rgpRecipientCert = certInfo;
}
else
ret = FALSE;
}
if (ret)
msg = CryptMsgOpenToEncode(pEncryptPara->dwMsgEncodingType, 0,
CMSG_ENVELOPED, &envelopedInfo, NULL, NULL);
if (msg)
{
ret = CryptMsgUpdate(msg, pbToBeEncrypted, cbToBeEncrypted, TRUE);
if (ret)
ret = CryptMsgGetParam(msg, CMSG_CONTENT_PARAM, 0, pbEncryptedBlob,
pcbEncryptedBlob);
CryptMsgClose(msg);
}
else
ret = FALSE;
CryptMemFree(certInfo);
if (!ret) *pcbEncryptedBlob = 0;
return ret;
}

View File

@ -1225,10 +1225,8 @@ static void test_encrypt_message(void)
encryptedBlobSize = 255;
ret = CryptEncryptMessage(&para, 0, NULL, NULL, 0, NULL,
&encryptedBlobSize);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
todo_wine
ok(!encryptedBlobSize, "unexpected size %d\n", encryptedBlobSize);
para.cbSize = sizeof(para);
para.dwMsgEncodingType = X509_ASN_ENCODING;
@ -1236,23 +1234,19 @@ static void test_encrypt_message(void)
encryptedBlobSize = 255;
ret = CryptEncryptMessage(&para, 0, NULL, NULL, 0, NULL,
&encryptedBlobSize);
todo_wine
ok(!ret && GetLastError() == E_INVALIDARG,
"expected E_INVALIDARG, got %08x\n", GetLastError());
todo_wine
ok(!encryptedBlobSize, "unexpected size %d\n", encryptedBlobSize);
para.dwMsgEncodingType = PKCS_7_ASN_ENCODING;
SetLastError(0xdeadbeef);
encryptedBlobSize = 255;
ret = CryptEncryptMessage(&para, 0, NULL, NULL, 0, NULL,
&encryptedBlobSize);
todo_wine
ok(!ret &&
(GetLastError() == CRYPT_E_UNKNOWN_ALGO ||
GetLastError() == E_INVALIDARG), /* Win9x */
"expected CRYPT_E_UNKNOWN_ALGO or E_INVALIDARG, got %08x\n",
GetLastError());
todo_wine
ok(!encryptedBlobSize, "unexpected size %d\n", encryptedBlobSize);
para.hCryptProv = hCryptProv;
@ -1262,7 +1256,6 @@ static void test_encrypt_message(void)
encryptedBlobSize = 0;
ret = CryptEncryptMessage(&para, 0, NULL, NULL, 0, NULL,
&encryptedBlobSize);
todo_wine
ok(ret ||
broken(!ret) /* Win9x */,
"CryptEncryptMessage failed: %08x\n", GetLastError());
@ -1274,9 +1267,7 @@ static void test_encrypt_message(void)
SetLastError(0xdeadbeef);
ret = CryptEncryptMessage(&para, 0, NULL, NULL, 0, encryptedBlob,
&encryptedBlobSize);
todo_wine
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
todo_wine
ok(encryptedBlobSize == sizeof(encryptedMessage),
"unexpected size of encrypted blob %d\n", encryptedBlobSize);
ok(!memcmp(encryptedBlob, encryptedMessage, encryptedBlobSize),
@ -1289,7 +1280,6 @@ static void test_encrypt_message(void)
encryptedBlobSize = 0;
ret = CryptEncryptMessage(&para, 2, certs, NULL, 0, NULL,
&encryptedBlobSize);
todo_wine
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
if (ret)
{
@ -1299,7 +1289,6 @@ static void test_encrypt_message(void)
SetLastError(0xdeadbeef);
ret = CryptEncryptMessage(&para, 2, certs, NULL, 0, encryptedBlob,
&encryptedBlobSize);
todo_wine
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
CryptMemFree(encryptedBlob);
}
@ -1309,7 +1298,6 @@ static void test_encrypt_message(void)
encryptedBlobSize = 0;
ret = CryptEncryptMessage(&para, 0, NULL, blob, sizeof(blob), NULL,
&encryptedBlobSize);
todo_wine
ok(ret ||
broken(!ret) /* Win9x */,
"CryptEncryptMessage failed: %08x\n", GetLastError());
@ -1321,13 +1309,11 @@ static void test_encrypt_message(void)
SetLastError(0xdeadbeef);
ret = CryptEncryptMessage(&para, 0, NULL, blob, sizeof(blob),
encryptedBlob, &encryptedBlobSize);
todo_wine
ok(ret ||
broken(!ret && GetLastError() == NTE_PERM), /* some NT4 */
"CryptEncryptMessage failed: %08x\n", GetLastError());
if (ret)
{
todo_wine
ok(encryptedBlobSize == 55,
"unexpected size of encrypted blob %d\n", encryptedBlobSize);
}
@ -1339,7 +1325,6 @@ static void test_encrypt_message(void)
encryptedBlobSize = 0;
ret = CryptEncryptMessage(&para, 2, certs, blob, sizeof(blob), NULL,
&encryptedBlobSize);
todo_wine
ok(ret, "CryptEncryptMessage failed: %08x\n", GetLastError());
if (ret)
{
@ -1349,7 +1334,6 @@ static void test_encrypt_message(void)
SetLastError(0xdeadbeef);
ret = CryptEncryptMessage(&para, 2, certs, blob, sizeof(blob),
encryptedBlob, &encryptedBlobSize);
todo_wine
ok(ret ||
broken(!ret), /* some Win95 and some NT4 */
"CryptEncryptMessage failed: %08x\n", GetLastError());