ReactOS 0.4.17-dev-444-g71ee754
msg.c
Go to the documentation of this file.
1/*
2 * Copyright 2007 Juan Lang
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19#include <stdarg.h>
20
21#include "windef.h"
22#include "winbase.h"
23#include "wincrypt.h"
24#include "snmp.h"
25#ifdef __REACTOS__
26#include <winternl.h>
27#endif
28
29#include "wine/debug.h"
30#include "wine/exception.h"
31#include "crypt32_private.h"
32
34
35/* Called when a message's ref count reaches zero. Free any message-specific
36 * data here.
37 */
39
40typedef BOOL (*CryptMsgGetParamFunc)(HCRYPTMSG hCryptMsg, DWORD dwParamType,
41 DWORD dwIndex, void *pvData, DWORD *pcbData);
42
43typedef BOOL (*CryptMsgUpdateFunc)(HCRYPTMSG hCryptMsg, const BYTE *pbData,
44 DWORD cbData, BOOL fFinal);
45
47 DWORD dwCtrlType, const void *pvCtrlPara);
48
50{
51 DWORD sz;
52
53 *data = NULL;
54 sz = sizeof(*size);
55 if (!CryptGetHashParam(hash, HP_HASHSIZE, (BYTE *)size, &sz, 0)) return FALSE;
56 if (!(*data = CryptMemAlloc(*size)))
57 {
58 ERR("No memory.\n");
59 return FALSE;
60 }
61 if (CryptGetHashParam(hash, HP_HASHVAL, *data, size, 0)) return TRUE;
63 *data = NULL;
64 return FALSE;
65}
66
68 DWORD dwCtrlType, const void *pvCtrlPara)
69{
70 TRACE("(%p, %08lx, %ld, %p)\n", hCryptMsg, dwFlags, dwCtrlType, pvCtrlPara);
72 return FALSE;
73}
74
75typedef enum _CryptMsgState {
81
82typedef struct _CryptMsgBase
83{
94
99{
100 msg->ref = 1;
101 msg->open_flags = dwFlags;
102 if (pStreamInfo)
103 {
104 msg->streamed = TRUE;
105 msg->stream_info = *pStreamInfo;
106 }
107 else
108 {
109 msg->streamed = FALSE;
110 memset(&msg->stream_info, 0, sizeof(msg->stream_info));
111 }
112 msg->close = close;
113 msg->get_param = get_param;
114 msg->update = update;
115 msg->control = control;
116 msg->state = MsgStateInit;
117}
118
119typedef struct _CDataEncodeMsg
120{
125
126static const BYTE empty_data_content[] = { 0x04,0x00 };
127
128static void CDataEncodeMsg_Close(HCRYPTMSG hCryptMsg)
129{
130 CDataEncodeMsg *msg = hCryptMsg;
131
132 if (msg->bare_content != empty_data_content)
133 LocalFree(msg->bare_content);
134}
135
136static BOOL WINAPI CRYPT_EncodeContentLength(DWORD dwCertEncodingType,
137 LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
138 PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
139{
140 DWORD dataLen = *(DWORD *)pvStructInfo;
141 DWORD lenBytes;
142 BOOL ret = TRUE;
143
144 /* Trick: report bytes needed based on total message length, even though
145 * the message isn't available yet. The caller will use the length
146 * reported here to encode its length.
147 */
148 CRYPT_EncodeLen(dataLen, NULL, &lenBytes);
149 if (!pbEncoded)
150 *pcbEncoded = 1 + lenBytes + dataLen;
151 else
152 {
153 if ((ret = CRYPT_EncodeEnsureSpace(dwFlags, pEncodePara, pbEncoded,
154 pcbEncoded, 1 + lenBytes)))
155 {
157 pbEncoded = *(BYTE **)pbEncoded;
158 *pbEncoded++ = ASN_OCTETSTRING;
159 CRYPT_EncodeLen(dataLen, pbEncoded,
160 &lenBytes);
161 }
162 }
163 return ret;
164}
165
168{
169 BOOL ret;
170
171 if (msg->base.streamed && msg->base.stream_info.cbContent == 0xffffffff)
172 {
173 static const BYTE headerValue[] = { 0x30,0x80,0x06,0x09,0x2a,0x86,0x48,
174 0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x80,0x24,0x80 };
175
176 header->pbData = LocalAlloc(0, sizeof(headerValue));
177 if (header->pbData)
178 {
179 header->cbData = sizeof(headerValue);
180 memcpy(header->pbData, headerValue, sizeof(headerValue));
181 ret = TRUE;
182 }
183 else
184 ret = FALSE;
185 }
186 else
187 {
188 struct AsnConstructedItem constructed = { 0,
189 &msg->base.stream_info.cbContent, CRYPT_EncodeContentLength };
190 struct AsnEncodeSequenceItem items[2] = {
192 { &constructed, CRYPT_AsnEncodeConstructed, 0 },
193 };
194
197 (LPBYTE)&header->pbData, &header->cbData);
198 if (ret)
199 {
200 /* Trick: subtract the content length from the reported length,
201 * as the actual content hasn't come yet.
202 */
203 header->cbData -= msg->base.stream_info.cbContent;
204 }
205 }
206 return ret;
207}
208
209static BOOL CDataEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
210 DWORD cbData, BOOL fFinal)
211{
212 CDataEncodeMsg *msg = hCryptMsg;
213 BOOL ret = FALSE;
214
215 if (msg->base.state == MsgStateFinalized)
217 else if (msg->base.streamed)
218 {
219 __TRY
220 {
221 if (msg->base.state != MsgStateUpdated)
222 {
224
226 if (ret)
227 {
228 ret = msg->base.stream_info.pfnStreamOutput(
229 msg->base.stream_info.pvArg, header.pbData, header.cbData,
230 FALSE);
231 LocalFree(header.pbData);
232 }
233 }
234 /* Curiously, every indefinite-length streamed update appears to
235 * get its own tag and length, regardless of fFinal.
236 */
237 if (msg->base.stream_info.cbContent == 0xffffffff)
238 {
239 BYTE *header;
240 DWORD headerLen;
241
244 &headerLen);
245 if (ret)
246 {
247 ret = msg->base.stream_info.pfnStreamOutput(
248 msg->base.stream_info.pvArg, header, headerLen,
249 FALSE);
251 }
252 }
253 if (!fFinal)
254 {
255 ret = msg->base.stream_info.pfnStreamOutput(
256 msg->base.stream_info.pvArg, (BYTE *)pbData, cbData,
257 FALSE);
258 msg->base.state = MsgStateUpdated;
259 }
260 else
261 {
262 msg->base.state = MsgStateFinalized;
263 if (msg->base.stream_info.cbContent == 0xffffffff)
264 {
265 BYTE indefinite_trailer[6] = { 0 };
266
267 ret = msg->base.stream_info.pfnStreamOutput(
268 msg->base.stream_info.pvArg, (BYTE *)pbData, cbData,
269 FALSE);
270 if (ret)
271 ret = msg->base.stream_info.pfnStreamOutput(
272 msg->base.stream_info.pvArg, indefinite_trailer,
273 sizeof(indefinite_trailer), TRUE);
274 }
275 else
276 ret = msg->base.stream_info.pfnStreamOutput(
277 msg->base.stream_info.pvArg, (BYTE *)pbData, cbData, TRUE);
278 }
279 }
281 {
283 ret = FALSE;
284 }
285 __ENDTRY;
286 }
287 else
288 {
289 if (!fFinal)
290 {
291 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
293 else
295 }
296 else
297 {
298 CRYPT_DATA_BLOB blob = { cbData, (LPBYTE)pbData };
299
300 msg->base.state = MsgStateFinalized;
301 /* non-streamed data messages don't allow non-final updates,
302 * don't bother checking whether data already exist, they can't.
303 */
305 &blob, CRYPT_ENCODE_ALLOC_FLAG, NULL, &msg->bare_content,
306 &msg->bare_content_len);
307 }
308 }
309 return ret;
310}
311
312static BOOL CRYPT_CopyParam(void *pvData, DWORD *pcbData, const void *src,
313 DWORD len)
314{
315 BOOL ret = TRUE;
316
317 if (!pvData)
318 *pcbData = len;
319 else if (*pcbData < len)
320 {
321 *pcbData = len;
323 ret = FALSE;
324 }
325 else
326 {
327 *pcbData = len;
328 memcpy(pvData, src, len);
329 }
330 return ret;
331}
332
333static BOOL CDataEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
334 DWORD dwIndex, void *pvData, DWORD *pcbData)
335{
336 CDataEncodeMsg *msg = hCryptMsg;
337 BOOL ret = FALSE;
338
339 switch (dwParamType)
340 {
342 if (msg->base.streamed)
344 else
345 {
347 char rsa_data[] = "1.2.840.113549.1.7.1";
348
349 info.pszObjId = rsa_data;
350 info.Content.cbData = msg->bare_content_len;
351 info.Content.pbData = msg->bare_content;
353 pvData, pcbData);
354 }
355 break;
357 if (msg->base.streamed)
359 else
360 ret = CRYPT_CopyParam(pvData, pcbData, msg->bare_content,
361 msg->bare_content_len);
362 break;
363 default:
365 }
366 return ret;
367}
368
369static HCRYPTMSG CDataEncodeMsg_Open(DWORD dwFlags, const void *pvMsgEncodeInfo,
370 LPSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
371{
373
374 if (pvMsgEncodeInfo)
375 {
377 return NULL;
378 }
380 if (msg)
381 {
382 CryptMsgBase_Init((CryptMsgBase *)msg, dwFlags, pStreamInfo,
385 msg->bare_content_len = sizeof(empty_data_content);
386 msg->bare_content = (LPBYTE)empty_data_content;
387 }
388 return msg;
389}
390
391typedef struct _CHashEncodeMsg
392{
398
399static void CHashEncodeMsg_Close(HCRYPTMSG hCryptMsg)
400{
401 CHashEncodeMsg *msg = hCryptMsg;
402
403 CryptMemFree(msg->data.pbData);
404 CryptDestroyHash(msg->hash);
405 if (msg->base.open_flags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG)
406 CryptReleaseContext(msg->prov, 0);
407}
408
410 DWORD *pcbData)
411{
412 BOOL ret;
413 ALG_ID algID;
414 DWORD size = sizeof(algID);
415
416 ret = CryptGetHashParam(msg->hash, HP_ALGID, (BYTE *)&algID, &size, 0);
417 if (ret)
418 {
419 CRYPT_DIGESTED_DATA digestedData = { 0 };
420 char oid_rsa_data[] = szOID_RSA_data;
421
423 digestedData.DigestAlgorithm.pszObjId = (LPSTR)CertAlgIdToOID(algID);
424 /* FIXME: what about digestedData.DigestAlgorithm.Parameters? */
425 /* Quirk: OID is only encoded messages if an update has happened */
426 if (msg->base.state != MsgStateInit)
427 digestedData.ContentInfo.pszObjId = oid_rsa_data;
428 if (!(msg->base.open_flags & CMSG_DETACHED_FLAG) && msg->data.cbData)
429 {
430 ret = CRYPT_AsnEncodeOctets(0, NULL, &msg->data,
432 (LPBYTE)&digestedData.ContentInfo.Content.pbData,
433 &digestedData.ContentInfo.Content.cbData);
434 }
435 if (msg->base.state == MsgStateFinalized)
436 ret = extract_hash(msg->hash, &digestedData.hash.pbData, &digestedData.hash.cbData);
437 if (ret)
439 pcbData);
440 CryptMemFree(digestedData.hash.pbData);
441 LocalFree(digestedData.ContentInfo.Content.pbData);
442 }
443 return ret;
444}
445
446static BOOL CHashEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
447 DWORD dwIndex, void *pvData, DWORD *pcbData)
448{
449 CHashEncodeMsg *msg = hCryptMsg;
450 BOOL ret = FALSE;
451
452 TRACE("(%p, %ld, %ld, %p, %p)\n", hCryptMsg, dwParamType, dwIndex,
453 pvData, pcbData);
454
455 switch (dwParamType)
456 {
458 if (msg->base.streamed)
460 else
462 break;
464 {
466
468 &info.Content.cbData);
469 if (ret)
470 {
471 info.Content.pbData = CryptMemAlloc(info.Content.cbData);
472 if (info.Content.pbData)
473 {
475 info.Content.pbData, &info.Content.cbData);
476 if (ret)
477 {
478 char oid_rsa_hashed[] = szOID_RSA_hashedData;
479
480 info.pszObjId = oid_rsa_hashed;
483 }
484 CryptMemFree(info.Content.pbData);
485 }
486 else
487 ret = FALSE;
488 }
489 break;
490 }
493 break;
495 if (msg->base.state != MsgStateFinalized)
497 else
498 {
500
501 /* Since the data are always encoded as octets, the version is
502 * always 0 (see rfc3852, section 7)
503 */
505 }
506 break;
507 default:
509 }
510 return ret;
511}
512
513static BOOL CHashEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
514 DWORD cbData, BOOL fFinal)
515{
516 CHashEncodeMsg *msg = hCryptMsg;
517 BOOL ret = FALSE;
518
519 TRACE("(%p, %p, %ld, %d)\n", hCryptMsg, pbData, cbData, fFinal);
520
521 if (msg->base.state == MsgStateFinalized)
523 else if (msg->base.streamed || (msg->base.open_flags & CMSG_DETACHED_FLAG))
524 {
525 /* Doesn't do much, as stream output is never called, and you
526 * can't get the content.
527 */
528 ret = CryptHashData(msg->hash, pbData, cbData, 0);
529 msg->base.state = fFinal ? MsgStateFinalized : MsgStateUpdated;
530 }
531 else
532 {
533 if (!fFinal)
535 else
536 {
537 ret = CryptHashData(msg->hash, pbData, cbData, 0);
538 if (ret)
539 {
540 msg->data.pbData = CryptMemAlloc(cbData);
541 if (msg->data.pbData)
542 {
543 memcpy(msg->data.pbData + msg->data.cbData, pbData, cbData);
544 msg->data.cbData += cbData;
545 }
546 else
547 ret = FALSE;
548 }
549 msg->base.state = MsgStateFinalized;
550 }
551 }
552 return ret;
553}
554
555static HCRYPTMSG CHashEncodeMsg_Open(DWORD dwFlags, const void *pvMsgEncodeInfo,
556 LPSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
557{
559 const CMSG_HASHED_ENCODE_INFO *info = pvMsgEncodeInfo;
560 HCRYPTPROV prov;
561 ALG_ID algID;
562
563 if (info->cbSize != sizeof(CMSG_HASHED_ENCODE_INFO))
564 {
566 return NULL;
567 }
568 if (!(algID = CertOIDToAlgId(info->HashAlgorithm.pszObjId)))
569 {
571 return NULL;
572 }
573 if (info->hCryptProv)
574 prov = info->hCryptProv;
575 else
576 {
577 prov = I_CryptGetDefaultCryptProv(algID);
578 if (!prov)
579 {
581 return NULL;
582 }
583 dwFlags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
584 }
586 if (msg)
587 {
588 CryptMsgBase_Init((CryptMsgBase *)msg, dwFlags, pStreamInfo,
591 msg->prov = prov;
592 msg->data.cbData = 0;
593 msg->data.pbData = NULL;
594 if (!CryptCreateHash(prov, algID, 0, 0, &msg->hash))
595 {
597 msg = NULL;
598 }
599 }
600 return msg;
601}
602
604{
619
621{
632
634{
635 if (signer->cbSize != sizeof(CMSG_SIGNER_ENCODE_INFO) &&
636 signer->cbSize != sizeof(CMSG_SIGNER_ENCODE_INFO_WITH_CMS))
637 {
639 return FALSE;
640 }
641 if (signer->cbSize == sizeof(CMSG_SIGNER_ENCODE_INFO))
642 {
643 if (!signer->pCertInfo->SerialNumber.cbData)
644 {
646 return FALSE;
647 }
648 if (!signer->pCertInfo->Issuer.cbData)
649 {
651 return FALSE;
652 }
653 }
654 else if (signer->cbSize == sizeof(CMSG_SIGNER_ENCODE_INFO_WITH_CMS))
655 {
656 switch (signer->SignerId.dwIdChoice)
657 {
658 case 0:
659 if (!signer->pCertInfo->SerialNumber.cbData)
660 {
662 return FALSE;
663 }
664 if (!signer->pCertInfo->Issuer.cbData)
665 {
667 return FALSE;
668 }
669 break;
672 {
674 return FALSE;
675 }
677 {
679 return FALSE;
680 }
681 break;
683 if (!signer->SignerId.KeyId.cbData)
684 {
686 return FALSE;
687 }
688 break;
689 default:
691 }
693 {
694 FIXME("CMSG_SIGNER_ENCODE_INFO with CMS fields unsupported\n");
695 return FALSE;
696 }
697 }
698 if (!signer->hCryptProv)
699 {
701 return FALSE;
702 }
704 {
706 return FALSE;
707 }
708 return TRUE;
709}
710
712{
713 BOOL ret = TRUE;
714
715 out->cbData = in->cbData;
716 if (out->cbData)
717 {
718 out->pbData = CryptMemAlloc(out->cbData);
719 if (out->pbData)
720 memcpy(out->pbData, in->pbData, out->cbData);
721 else
722 ret = FALSE;
723 }
724 else
725 out->pbData = NULL;
726 return ret;
727}
728
730 PCRYPT_DATA_BLOB *outPBlobs, DWORD cBlobs, const CRYPT_DATA_BLOB *pBlobs)
731{
732 BOOL ret = TRUE;
733
734 *outCBlobs = cBlobs;
735 if (cBlobs)
736 {
737 *outPBlobs = CryptMemAlloc(cBlobs * sizeof(CRYPT_DATA_BLOB));
738 if (*outPBlobs)
739 {
740 DWORD i;
741
742 memset(*outPBlobs, 0, cBlobs * sizeof(CRYPT_DATA_BLOB));
743 for (i = 0; ret && i < cBlobs; i++)
744 ret = CRYPT_ConstructBlob(&(*outPBlobs)[i], &pBlobs[i]);
745 }
746 else
747 ret = FALSE;
748 }
749 return ret;
750}
751
753{
754 DWORD i;
755
756 for (i = 0; i < cBlobs; i++)
757 CryptMemFree(blobs[i].pbData);
758 CryptMemFree(blobs);
759}
760
762 const CRYPT_ATTRIBUTE *in)
763{
764 BOOL ret;
765
766 out->pszObjId = CryptMemAlloc(strlen(in->pszObjId) + 1);
767 if (out->pszObjId)
768 {
769 strcpy(out->pszObjId, in->pszObjId);
770 ret = CRYPT_ConstructBlobArray(&out->cValue, &out->rgValue,
771 in->cValue, in->rgValue);
772 }
773 else
774 ret = FALSE;
775 return ret;
776}
777
779 const CRYPT_ATTRIBUTES *in)
780{
781 BOOL ret = TRUE;
782
783 out->cAttr = in->cAttr;
784 if (out->cAttr)
785 {
786 out->rgAttr = CryptMemAlloc(out->cAttr * sizeof(CRYPT_ATTRIBUTE));
787 if (out->rgAttr)
788 {
789 DWORD i;
790
791 memset(out->rgAttr, 0, out->cAttr * sizeof(CRYPT_ATTRIBUTE));
792 for (i = 0; ret && i < out->cAttr; i++)
793 ret = CRYPT_ConstructAttribute(&out->rgAttr[i], &in->rgAttr[i]);
794 }
795 else
796 ret = FALSE;
797 }
798 else
799 out->rgAttr = NULL;
800 return ret;
801}
802
803/* Constructs a CMSG_CMS_SIGNER_INFO from a CMSG_SIGNER_ENCODE_INFO_WITH_CMS. */
806{
807 BOOL ret;
808
809 if (in->cbSize == sizeof(CMSG_SIGNER_ENCODE_INFO))
810 {
811 info->dwVersion = CMSG_SIGNER_INFO_V1;
812 ret = CRYPT_ConstructBlob(&info->SignerId.IssuerSerialNumber.Issuer,
813 &in->pCertInfo->Issuer);
814 if (ret)
816 &info->SignerId.IssuerSerialNumber.SerialNumber,
817 &in->pCertInfo->SerialNumber);
818 info->SignerId.dwIdChoice = CERT_ID_ISSUER_SERIAL_NUMBER;
819 info->HashEncryptionAlgorithm.pszObjId =
820 in->pCertInfo->SubjectPublicKeyInfo.Algorithm.pszObjId;
821 if (ret)
822 ret = CRYPT_ConstructBlob(&info->HashEncryptionAlgorithm.Parameters,
823 &in->pCertInfo->SubjectPublicKeyInfo.Algorithm.Parameters);
824 }
825 else
826 {
827 const CRYPT_ALGORITHM_IDENTIFIER *pEncrAlg;
828
829 /* Implicitly in->cbSize == sizeof(CMSG_SIGNER_ENCODE_INFO_WITH_CMS).
830 * See CRYPT_IsValidSigner.
831 */
832 if (!in->SignerId.dwIdChoice)
833 {
834 info->dwVersion = CMSG_SIGNER_INFO_V1;
835 ret = CRYPT_ConstructBlob(&info->SignerId.IssuerSerialNumber.Issuer,
836 &in->pCertInfo->Issuer);
837 if (ret)
839 &info->SignerId.IssuerSerialNumber.SerialNumber,
840 &in->pCertInfo->SerialNumber);
841 info->SignerId.dwIdChoice = CERT_ID_ISSUER_SERIAL_NUMBER;
842 }
843 else if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
844 {
845 info->dwVersion = CMSG_SIGNER_INFO_V1;
846 info->SignerId.dwIdChoice = CERT_ID_ISSUER_SERIAL_NUMBER;
847 ret = CRYPT_ConstructBlob(&info->SignerId.IssuerSerialNumber.Issuer,
848 &in->SignerId.IssuerSerialNumber.Issuer);
849 if (ret)
851 &info->SignerId.IssuerSerialNumber.SerialNumber,
852 &in->SignerId.IssuerSerialNumber.SerialNumber);
853 }
854 else
855 {
856 /* Implicitly dwIdChoice == CERT_ID_KEY_IDENTIFIER */
857 info->dwVersion = CMSG_SIGNER_INFO_V3;
858 info->SignerId.dwIdChoice = CERT_ID_KEY_IDENTIFIER;
859 ret = CRYPT_ConstructBlob(&info->SignerId.KeyId,
860 &in->SignerId.KeyId);
861 }
862 pEncrAlg = in->HashEncryptionAlgorithm.pszObjId ?
863 &in->HashEncryptionAlgorithm :
864 &in->pCertInfo->SubjectPublicKeyInfo.Algorithm;
865 info->HashEncryptionAlgorithm.pszObjId = pEncrAlg->pszObjId;
866 if (ret)
867 ret = CRYPT_ConstructBlob(&info->HashEncryptionAlgorithm.Parameters,
868 &pEncrAlg->Parameters);
869 }
870 /* Assumption: algorithm IDs will point to static strings, not
871 * stack-based ones, so copying the pointer values is safe.
872 */
873 info->HashAlgorithm.pszObjId = in->HashAlgorithm.pszObjId;
874 if (ret)
875 ret = CRYPT_ConstructBlob(&info->HashAlgorithm.Parameters,
876 &in->HashAlgorithm.Parameters);
877 if (ret)
878 ret = CRYPT_ConstructAttributes(&info->AuthAttrs,
879 (CRYPT_ATTRIBUTES *)&in->cAuthAttr);
880 if (ret)
881 ret = CRYPT_ConstructAttributes(&info->UnauthAttrs,
882 (CRYPT_ATTRIBUTES *)&in->cUnauthAttr);
883 return ret;
884}
885
887{
888 DWORD i, j;
889
890 if (info->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
891 {
892 CryptMemFree(info->SignerId.IssuerSerialNumber.Issuer.pbData);
893 CryptMemFree(info->SignerId.IssuerSerialNumber.SerialNumber.pbData);
894 }
895 else
896 CryptMemFree(info->SignerId.KeyId.pbData);
897 CryptMemFree(info->HashAlgorithm.Parameters.pbData);
898 CryptMemFree(info->HashEncryptionAlgorithm.Parameters.pbData);
899 CryptMemFree(info->EncryptedHash.pbData);
900 for (i = 0; i < info->AuthAttrs.cAttr; i++)
901 {
902 for (j = 0; j < info->AuthAttrs.rgAttr[i].cValue; j++)
903 CryptMemFree(info->AuthAttrs.rgAttr[i].rgValue[j].pbData);
904 CryptMemFree(info->AuthAttrs.rgAttr[i].rgValue);
905 CryptMemFree(info->AuthAttrs.rgAttr[i].pszObjId);
906 }
907 CryptMemFree(info->AuthAttrs.rgAttr);
908 for (i = 0; i < info->UnauthAttrs.cAttr; i++)
909 {
910 for (j = 0; j < info->UnauthAttrs.rgAttr[i].cValue; j++)
911 CryptMemFree(info->UnauthAttrs.rgAttr[i].rgValue[j].pbData);
912 CryptMemFree(info->UnauthAttrs.rgAttr[i].rgValue);
913 CryptMemFree(info->UnauthAttrs.rgAttr[i].pszObjId);
914 }
915 CryptMemFree(info->UnauthAttrs.rgAttr);
916}
917
918typedef struct _CSignerHandles
919{
923
924typedef struct _CSignedMsgData
925{
930
931/* Constructs the signer handles for the signerIndex'th signer of msg_data.
932 * Assumes signerIndex is a valid index, and that msg_data's info has already
933 * been constructed.
934 */
936 DWORD signerIndex, HCRYPTPROV *crypt_prov, DWORD *flags)
937{
938 ALG_ID algID;
939 BOOL ret;
940
941 algID = CertOIDToAlgId(
942 msg_data->info->rgSignerInfo[signerIndex].HashAlgorithm.pszObjId);
943
944 if (!*crypt_prov)
945 {
947 if (!*crypt_prov) return FALSE;
948 *flags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
949 }
950
951 ret = CryptCreateHash(*crypt_prov, algID, 0, 0,
952 &msg_data->signerHandles->contentHash);
953 if (ret && msg_data->info->rgSignerInfo[signerIndex].AuthAttrs.cAttr > 0)
954 ret = CryptCreateHash(*crypt_prov, algID, 0, 0,
955 &msg_data->signerHandles->authAttrHash);
956 return ret;
957}
958
959/* Allocates a CSignedMsgData's handles. Assumes its info has already been
960 * constructed.
961 */
963{
964 BOOL ret = TRUE;
965
966 if (msg_data->info->cSignerInfo)
967 {
968 msg_data->signerHandles =
969 CryptMemAlloc(msg_data->info->cSignerInfo * sizeof(CSignerHandles));
970 if (msg_data->signerHandles)
971 {
972 msg_data->cSignerHandle = msg_data->info->cSignerInfo;
973 memset(msg_data->signerHandles, 0,
974 msg_data->info->cSignerInfo * sizeof(CSignerHandles));
975 }
976 else
977 {
978 msg_data->cSignerHandle = 0;
979 ret = FALSE;
980 }
981 }
982 else
983 {
984 msg_data->cSignerHandle = 0;
985 msg_data->signerHandles = NULL;
986 }
987 return ret;
988}
989
991{
992 DWORD i;
993
994 for (i = 0; i < msg_data->cSignerHandle; i++)
995 {
996 if (msg_data->signerHandles[i].contentHash)
998 if (msg_data->signerHandles[i].authAttrHash)
1000 }
1001 CryptMemFree(msg_data->signerHandles);
1002 msg_data->signerHandles = NULL;
1003 msg_data->cSignerHandle = 0;
1004}
1005
1007 const BYTE *pbData, DWORD cbData)
1008{
1009 DWORD i;
1010 BOOL ret = TRUE;
1011
1012 for (i = 0; ret && i < msg_data->cSignerHandle; i++)
1013 ret = CryptHashData(msg_data->signerHandles[i].contentHash, pbData,
1014 cbData, 0);
1015 return ret;
1016}
1017
1019 const CRYPT_ATTRIBUTE *in)
1020{
1021 BOOL ret = FALSE;
1022
1023 out->rgAttr = CryptMemRealloc(out->rgAttr,
1024 (out->cAttr + 1) * sizeof(CRYPT_ATTRIBUTE));
1025 if (out->rgAttr)
1026 {
1027 ret = CRYPT_ConstructAttribute(&out->rgAttr[out->cAttr], in);
1028 if (ret)
1029 out->cAttr++;
1030 }
1031 return ret;
1032}
1033
1035 CSignedMsgData *msg_data, DWORD signerIndex)
1036{
1037 BOOL ret;
1038 CRYPT_HASH_BLOB hash = { 0, NULL }, encodedHash = { 0, NULL };
1039 char messageDigest[] = szOID_RSA_messageDigest;
1040 CRYPT_ATTRIBUTE messageDigestAttr = { messageDigest, 1, &encodedHash };
1041
1042 if (!(ret = extract_hash(msg_data->signerHandles[signerIndex].contentHash, &hash.pbData, &hash.cbData)))
1043 return FALSE;
1044
1045 ret = CRYPT_AsnEncodeOctets(0, NULL, &hash, CRYPT_ENCODE_ALLOC_FLAG, NULL, (LPBYTE)&encodedHash.pbData,
1046 &encodedHash.cbData);
1047 if (ret)
1048 {
1050 &msg_data->info->rgSignerInfo[signerIndex].AuthAttrs,
1051 &messageDigestAttr);
1052 LocalFree(encodedHash.pbData);
1053 }
1054 CryptMemFree(hash.pbData);
1055 return ret;
1056}
1057
1058typedef enum {
1060 Verify
1062
1064 CSignedMsgData *msg_data, SignOrVerify flag)
1065{
1066 DWORD i;
1067 BOOL ret = TRUE;
1068
1069 TRACE("(%p)\n", msg_data);
1070
1071 for (i = 0; ret && i < msg_data->info->cSignerInfo; i++)
1072 {
1073 if (msg_data->info->rgSignerInfo[i].AuthAttrs.cAttr)
1074 {
1075 if (flag == Sign)
1076 {
1077 BYTE oid_rsa_data_encoded[] = { 0x06,0x09,0x2a,0x86,0x48,0x86,
1078 0xf7,0x0d,0x01,0x07,0x01 };
1079 CRYPT_DATA_BLOB content = { sizeof(oid_rsa_data_encoded),
1080 oid_rsa_data_encoded };
1081 char contentType[] = szOID_RSA_contentType;
1082 CRYPT_ATTRIBUTE contentTypeAttr = { contentType, 1, &content };
1083
1084 /* FIXME: does this depend on inner OID? */
1086 &msg_data->info->rgSignerInfo[i].AuthAttrs, &contentTypeAttr);
1087 if (ret)
1089 i);
1090 }
1091 if (ret)
1092 {
1093 LPBYTE encodedAttrs;
1094 DWORD size;
1095
1097 &msg_data->info->rgSignerInfo[i].AuthAttrs,
1098 CRYPT_ENCODE_ALLOC_FLAG, NULL, &encodedAttrs, &size);
1099 if (ret)
1100 {
1102 msg_data->signerHandles[i].authAttrHash, encodedAttrs,
1103 size, 0);
1104 LocalFree(encodedAttrs);
1105 }
1106 }
1107 }
1108 }
1109 TRACE("returning %d\n", ret);
1110 return ret;
1111}
1112
1114{
1115 DWORD i;
1116 BYTE tmp;
1117
1118 for (i = 0; i < hash->cbData / 2; i++)
1119 {
1120 tmp = hash->pbData[hash->cbData - i - 1];
1121 hash->pbData[hash->cbData - i - 1] = hash->pbData[i];
1122 hash->pbData[i] = tmp;
1123 }
1124}
1125
1127{
1128 DWORD i;
1129 BOOL ret = TRUE;
1130
1131 TRACE("(%p)\n", msg_data);
1132
1133 for (i = 0; ret && i < msg_data->info->cSignerInfo; i++)
1134 {
1136 DWORD keySpec = msg_data->info->signerKeySpec[i];
1137
1138 if (!keySpec)
1139 keySpec = AT_SIGNATURE;
1140 if (msg_data->info->rgSignerInfo[i].AuthAttrs.cAttr)
1141 hash = msg_data->signerHandles[i].authAttrHash;
1142 else
1143 hash = msg_data->signerHandles[i].contentHash;
1144 ret = CryptSignHashW(hash, keySpec, NULL, 0, NULL,
1145 &msg_data->info->rgSignerInfo[i].EncryptedHash.cbData);
1146 if (ret)
1147 {
1148 msg_data->info->rgSignerInfo[i].EncryptedHash.pbData =
1150 msg_data->info->rgSignerInfo[i].EncryptedHash.cbData);
1151 if (msg_data->info->rgSignerInfo[i].EncryptedHash.pbData)
1152 {
1153 ret = CryptSignHashW(hash, keySpec, NULL, 0,
1155 &msg_data->info->rgSignerInfo[i].EncryptedHash.cbData);
1156 if (ret)
1158 &msg_data->info->rgSignerInfo[i].EncryptedHash);
1159 }
1160 else
1161 ret = FALSE;
1162 }
1163 }
1164 return ret;
1165}
1166
1168 const BYTE *pbData, DWORD cbData, BOOL fFinal, SignOrVerify flag)
1169{
1170 BOOL ret = CSignedMsgData_UpdateHash(msg_data, pbData, cbData);
1171
1172 if (ret && fFinal)
1173 {
1175 if (ret && flag == Sign)
1176 ret = CSignedMsgData_Sign(msg_data);
1177 }
1178 return ret;
1179}
1180
1181typedef struct _CSignedEncodeMsg
1182{
1188
1189static void CSignedEncodeMsg_Close(HCRYPTMSG hCryptMsg)
1190{
1191 CSignedEncodeMsg *msg = hCryptMsg;
1192 DWORD i;
1193
1194 CryptMemFree(msg->innerOID);
1195 CryptMemFree(msg->data.pbData);
1196 CRYPT_FreeBlobArray(msg->msg_data.info->cCertEncoded,
1197 msg->msg_data.info->rgCertEncoded);
1198 CRYPT_FreeBlobArray(msg->msg_data.info->cCrlEncoded,
1199 msg->msg_data.info->rgCrlEncoded);
1200 for (i = 0; i < msg->msg_data.info->cSignerInfo; i++)
1201 CSignerInfo_Free(&msg->msg_data.info->rgSignerInfo[i]);
1202 CSignedMsgData_CloseHandles(&msg->msg_data);
1203 CryptMemFree(msg->msg_data.info->signerKeySpec);
1204 CryptMemFree(msg->msg_data.info->rgSignerInfo);
1205 CryptMemFree(msg->msg_data.info);
1206}
1207
1208static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
1209 DWORD dwIndex, void *pvData, DWORD *pcbData)
1210{
1211 CSignedEncodeMsg *msg = hCryptMsg;
1212 BOOL ret = FALSE;
1213
1214 switch (dwParamType)
1215 {
1216 case CMSG_CONTENT_PARAM:
1217 {
1219
1221 &info.Content.cbData);
1222 if (ret)
1223 {
1224 info.Content.pbData = CryptMemAlloc(info.Content.cbData);
1225 if (info.Content.pbData)
1226 {
1228 info.Content.pbData, &info.Content.cbData);
1229 if (ret)
1230 {
1231 char oid_rsa_signed[] = szOID_RSA_signedData;
1232
1233 info.pszObjId = oid_rsa_signed;
1236 }
1237 CryptMemFree(info.Content.pbData);
1238 }
1239 else
1240 ret = FALSE;
1241 }
1242 break;
1243 }
1245 {
1247 BOOL freeContent = FALSE;
1248 char oid_rsa_data[] = szOID_RSA_data;
1249
1250 info = *msg->msg_data.info;
1251 if (!msg->innerOID || !strcmp(msg->innerOID, szOID_RSA_data))
1252 {
1253 /* Quirk: OID is only encoded messages if an update has happened */
1254 if (msg->base.state != MsgStateInit)
1255 info.content.pszObjId = oid_rsa_data;
1256 else
1257 info.content.pszObjId = NULL;
1258 if (msg->data.cbData)
1259 {
1260 CRYPT_DATA_BLOB blob = { msg->data.cbData, msg->data.pbData };
1261
1264 &info.content.Content.pbData, &info.content.Content.cbData);
1265 freeContent = TRUE;
1266 }
1267 else
1268 {
1269 info.content.Content.cbData = 0;
1270 info.content.Content.pbData = NULL;
1271 ret = TRUE;
1272 }
1273 }
1274 else
1275 {
1276 info.content.pszObjId = msg->innerOID;
1277 info.content.Content.cbData = msg->data.cbData;
1278 info.content.Content.pbData = msg->data.pbData;
1279 ret = TRUE;
1280 }
1281 if (ret)
1282 {
1284 if (freeContent)
1285 LocalFree(info.content.Content.pbData);
1286 }
1287 break;
1288 }
1290 if (dwIndex >= msg->msg_data.cSignerHandle)
1292 else
1294 msg->msg_data.signerHandles[dwIndex].contentHash, HP_HASHVAL,
1295 pvData, pcbData, 0);
1296 break;
1298 if (dwIndex >= msg->msg_data.info->cSignerInfo)
1300 else
1302 CMS_SIGNER_INFO, &msg->msg_data.info->rgSignerInfo[dwIndex], 0,
1303 NULL, pvData, pcbData);
1304 break;
1305 case CMSG_VERSION_PARAM:
1306 ret = CRYPT_CopyParam(pvData, pcbData, &msg->msg_data.info->version,
1307 sizeof(msg->msg_data.info->version));
1308 break;
1309 default:
1311 }
1312 return ret;
1313}
1314
1315static BOOL CSignedEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
1316 DWORD cbData, BOOL fFinal)
1317{
1318 CSignedEncodeMsg *msg = hCryptMsg;
1319 BOOL ret = FALSE;
1320
1321 if (msg->base.state == MsgStateFinalized)
1323 else if (msg->base.streamed || (msg->base.open_flags & CMSG_DETACHED_FLAG))
1324 {
1325 ret = CSignedMsgData_Update(&msg->msg_data, pbData, cbData, fFinal,
1326 Sign);
1327 if (msg->base.streamed)
1328 FIXME("streamed partial stub\n");
1329 msg->base.state = fFinal ? MsgStateFinalized : MsgStateUpdated;
1330 }
1331 else
1332 {
1333 if (!fFinal)
1335 else
1336 {
1337 if (cbData)
1338 {
1339 msg->data.pbData = CryptMemAlloc(cbData);
1340 if (msg->data.pbData)
1341 {
1342 memcpy(msg->data.pbData, pbData, cbData);
1343 msg->data.cbData = cbData;
1344 ret = TRUE;
1345 }
1346 }
1347 else
1348 ret = TRUE;
1349 if (ret)
1350 ret = CSignedMsgData_Update(&msg->msg_data, pbData, cbData,
1351 fFinal, Sign);
1352 msg->base.state = MsgStateFinalized;
1353 }
1354 }
1355 return ret;
1356}
1357
1359 const void *pvMsgEncodeInfo, LPCSTR pszInnerContentObjID,
1360 PCMSG_STREAM_INFO pStreamInfo)
1361{
1362 const CMSG_SIGNED_ENCODE_INFO_WITH_CMS *info = pvMsgEncodeInfo;
1363 DWORD i;
1365
1366 if (info->cbSize != sizeof(CMSG_SIGNED_ENCODE_INFO) &&
1367 info->cbSize != sizeof(CMSG_SIGNED_ENCODE_INFO_WITH_CMS))
1368 {
1370 return NULL;
1371 }
1372 if (info->cbSize == sizeof(CMSG_SIGNED_ENCODE_INFO_WITH_CMS) &&
1373 info->cAttrCertEncoded)
1374 {
1375 FIXME("CMSG_SIGNED_ENCODE_INFO with CMS fields unsupported\n");
1376 return NULL;
1377 }
1378 for (i = 0; i < info->cSigners; i++)
1379 if (!CRYPT_IsValidSigner(&info->rgSigners[i]))
1380 return NULL;
1382 if (msg)
1383 {
1384 BOOL ret = TRUE;
1385
1386 CryptMsgBase_Init((CryptMsgBase *)msg, dwFlags, pStreamInfo,
1389 if (pszInnerContentObjID)
1390 {
1391 msg->innerOID = CryptMemAlloc(strlen(pszInnerContentObjID) + 1);
1392 if (msg->innerOID)
1393 strcpy(msg->innerOID, pszInnerContentObjID);
1394 else
1395 ret = FALSE;
1396 }
1397 else
1398 msg->innerOID = NULL;
1399 msg->data.cbData = 0;
1400 msg->data.pbData = NULL;
1401 if (ret)
1402 msg->msg_data.info = CryptMemAlloc(sizeof(CRYPT_SIGNED_INFO));
1403 else
1404 msg->msg_data.info = NULL;
1405 if (msg->msg_data.info)
1406 {
1407 memset(msg->msg_data.info, 0, sizeof(CRYPT_SIGNED_INFO));
1408 msg->msg_data.info->version = CMSG_SIGNED_DATA_V1;
1409 }
1410 else
1411 ret = FALSE;
1412 if (ret)
1413 {
1414 if (info->cSigners)
1415 {
1416 msg->msg_data.info->rgSignerInfo =
1417 CryptMemAlloc(info->cSigners * sizeof(CMSG_CMS_SIGNER_INFO));
1418 if (msg->msg_data.info->rgSignerInfo)
1419 {
1420 msg->msg_data.info->cSignerInfo = info->cSigners;
1421 memset(msg->msg_data.info->rgSignerInfo, 0,
1422 msg->msg_data.info->cSignerInfo *
1423 sizeof(CMSG_CMS_SIGNER_INFO));
1425 msg->msg_data.info->signerKeySpec = CryptMemAlloc(info->cSigners * sizeof(DWORD));
1426 if (!msg->msg_data.info->signerKeySpec)
1427 ret = FALSE;
1428 for (i = 0; ret && i < msg->msg_data.info->cSignerInfo; i++)
1429 {
1430 if (info->rgSigners[i].SignerId.dwIdChoice ==
1432 msg->msg_data.info->version = CMSG_SIGNED_DATA_V3;
1434 &msg->msg_data.info->rgSignerInfo[i],
1435 &info->rgSigners[i]);
1436 if (ret)
1437 {
1439 &msg->msg_data, i, &info->rgSigners[i].hCryptProv, &dwFlags);
1441 CryptReleaseContext(info->rgSigners[i].hCryptProv,
1442 0);
1443 }
1444 msg->msg_data.info->signerKeySpec[i] =
1445 info->rgSigners[i].dwKeySpec;
1446 }
1447 }
1448 else
1449 ret = FALSE;
1450 }
1451 else
1452 {
1453 msg->msg_data.info->cSignerInfo = 0;
1454 msg->msg_data.signerHandles = NULL;
1455 msg->msg_data.cSignerHandle = 0;
1456 }
1457 }
1458 if (ret)
1459 ret = CRYPT_ConstructBlobArray(&msg->msg_data.info->cCertEncoded,
1460 &msg->msg_data.info->rgCertEncoded, info->cCertEncoded,
1461 info->rgCertEncoded);
1462 if (ret)
1463 ret = CRYPT_ConstructBlobArray(&msg->msg_data.info->cCrlEncoded,
1464 &msg->msg_data.info->rgCrlEncoded, info->cCrlEncoded,
1465 info->rgCrlEncoded);
1466 if (!ret)
1467 {
1470 msg = NULL;
1471 }
1472 }
1473 return msg;
1474}
1475
1477{
1494
1496{
1505
1508{
1509 out->pszObjId = CryptMemAlloc(strlen(in->pszObjId) + 1);
1510 if (out->pszObjId)
1511 {
1512 strcpy(out->pszObjId, in->pszObjId);
1513 return CRYPT_ConstructBlob(&out->Parameters, &in->Parameters);
1514 }
1515 else
1516 return FALSE;
1517}
1518
1520{
1521 out->cbData = in->cbData;
1522 out->cUnusedBits = in->cUnusedBits;
1523 if (out->cbData)
1524 {
1525 out->pbData = CryptMemAlloc(out->cbData);
1526 if (out->pbData)
1527 memcpy(out->pbData, in->pbData, out->cbData);
1528 else
1529 return FALSE;
1530 }
1531 else
1532 out->pbData = NULL;
1533 return TRUE;
1534}
1535
1537{
1538 static HCRYPTOIDFUNCSET set = NULL;
1540 HCRYPTOIDFUNCADDR hFunc;
1541 BOOL ret;
1542
1543 if (!set)
1546 info->ContentEncryptionAlgorithm.pszObjId, 0, (void **)&genKeyFunc, &hFunc);
1547 if (genKeyFunc)
1548 {
1549 ret = genKeyFunc(info, 0, NULL);
1551 }
1552 else
1553 ret = CryptGenKey(info->hCryptProv, algID, CRYPT_EXPORTABLE,
1554 &info->hContentEncryptKey);
1555 return ret;
1556}
1557
1559 PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo,
1560 PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo,
1561 PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo,
1562 DWORD dwFlags, void *pvReserved)
1563{
1564 CERT_PUBLIC_KEY_INFO keyInfo;
1565 HCRYPTKEY expKey;
1566 BOOL ret;
1567
1569 &pKeyTransEncodeInfo->KeyEncryptionAlgorithm);
1570 if (ret)
1572 &pKeyTransEncodeInfo->RecipientPublicKey);
1573 if (ret)
1574 ret = CryptImportPublicKeyInfo(pKeyTransEncodeInfo->hCryptProv,
1575 X509_ASN_ENCODING, &keyInfo, &expKey);
1576 if (ret)
1577 {
1578 DWORD size;
1579
1580 ret = CryptExportKey(pContentEncryptInfo->hContentEncryptKey, expKey,
1581 SIMPLEBLOB, 0, NULL, &size);
1582 if (ret)
1583 {
1584 BYTE *keyBlob;
1585
1586 keyBlob = CryptMemAlloc(size);
1587 if (keyBlob)
1588 {
1589 ret = CryptExportKey(pContentEncryptInfo->hContentEncryptKey,
1590 expKey, SIMPLEBLOB, 0, keyBlob, &size);
1591 if (ret)
1592 {
1593 DWORD head = sizeof(BLOBHEADER) + sizeof(ALG_ID);
1594
1595 pKeyTransEncryptInfo->EncryptedKey.pbData =
1597 if (pKeyTransEncryptInfo->EncryptedKey.pbData)
1598 {
1599 DWORD i, k = 0;
1600
1601 pKeyTransEncryptInfo->EncryptedKey.cbData = size - head;
1602 for (i = size - 1; i >= head; --i, ++k)
1603 pKeyTransEncryptInfo->EncryptedKey.pbData[k] =
1604 keyBlob[i];
1605 }
1606 else
1607 ret = FALSE;
1608 }
1609 CryptMemFree(keyBlob);
1610 }
1611 else
1612 ret = FALSE;
1613 }
1614 CryptDestroyKey(expKey);
1615 }
1616
1617 CryptMemFree(keyInfo.PublicKey.pbData);
1620 return ret;
1621}
1622
1625{
1626 static HCRYPTOIDFUNCSET set = NULL;
1627 PFN_CMSG_EXPORT_KEY_TRANS exportKeyFunc = NULL;
1628 HCRYPTOIDFUNCADDR hFunc = NULL;
1630 info->rgCmsRecipients[i].pKeyTrans;
1631 CMSG_KEY_TRANS_ENCRYPT_INFO encryptInfo;
1632 BOOL ret;
1633
1634 memset(&encryptInfo, 0, sizeof(encryptInfo));
1635 encryptInfo.cbSize = sizeof(encryptInfo);
1636 encryptInfo.dwRecipientIndex = i;
1638 &encodeInfo->KeyEncryptionAlgorithm);
1639
1640 if (!set)
1643 encryptInfo.KeyEncryptionAlgorithm.pszObjId, 0, (void **)&exportKeyFunc,
1644 &hFunc);
1645 if (!exportKeyFunc)
1646 exportKeyFunc = CRYPT_ExportKeyTrans;
1647 if (ret)
1648 {
1649 ret = exportKeyFunc(info, encodeInfo, &encryptInfo, 0, NULL);
1650 if (ret)
1651 {
1652 key->cbData = encryptInfo.EncryptedKey.cbData;
1653 key->pbData = encryptInfo.EncryptedKey.pbData;
1654 }
1655 }
1656 if (hFunc)
1658
1661 return ret;
1662}
1663
1665{
1666 return CryptMemAlloc(size);
1667}
1668
1670{
1671 CryptMemFree(pv);
1672}
1673
1674
1677{
1678 BOOL ret;
1679
1680 info->cbSize = sizeof(CMSG_CONTENT_ENCRYPT_INFO);
1681 info->hCryptProv = prov;
1682 ret = CRYPT_ConstructAlgorithmId(&info->ContentEncryptionAlgorithm,
1683 &in->ContentEncryptionAlgorithm);
1684 info->pvEncryptionAuxInfo = in->pvEncryptionAuxInfo;
1685 info->cRecipients = in->cRecipients;
1686 if (ret)
1687 {
1688 info->rgCmsRecipients = CryptMemAlloc(in->cRecipients *
1690 if (info->rgCmsRecipients)
1691 {
1692 DWORD i;
1693
1694 for (i = 0; ret && i < in->cRecipients; ++i)
1695 {
1697 CERT_INFO *cert = in->rgpRecipientCert[i];
1698
1699 info->rgCmsRecipients[i].dwRecipientChoice =
1701 encodeInfo = CryptMemAlloc(sizeof(*encodeInfo));
1702 info->rgCmsRecipients[i].pKeyTrans = encodeInfo;
1703 if (encodeInfo)
1704 {
1705 encodeInfo->cbSize = sizeof(*encodeInfo);
1707 &encodeInfo->KeyEncryptionAlgorithm,
1708 &cert->SubjectPublicKeyInfo.Algorithm);
1709 encodeInfo->pvKeyEncryptionAuxInfo = NULL;
1710 encodeInfo->hCryptProv = prov;
1711 if (ret)
1713 &encodeInfo->RecipientPublicKey,
1714 &cert->SubjectPublicKeyInfo.PublicKey);
1715 if (ret)
1718 &cert->Issuer);
1719 if (ret)
1722 &cert->SerialNumber);
1723 }
1724 else
1725 ret = FALSE;
1726 }
1727 }
1728 else
1729 ret = FALSE;
1730 }
1731 info->pfnAlloc = mem_alloc;
1732 info->pfnFree = mem_free;
1733 return ret;
1734}
1735
1737{
1738 CryptMemFree(info->ContentEncryptionAlgorithm.pszObjId);
1739 CryptMemFree(info->ContentEncryptionAlgorithm.Parameters.pbData);
1740 if (info->rgCmsRecipients)
1741 {
1742 DWORD i;
1743
1744 for (i = 0; i < info->cRecipients; ++i)
1745 {
1747 info->rgCmsRecipients[i].pKeyTrans;
1748
1756 CryptMemFree(encodeInfo);
1757 }
1758 CryptMemFree(info->rgCmsRecipients);
1759 }
1760}
1761
1764{
1765 BOOL ret;
1766
1768 info->RecipientId.dwIdChoice = CERT_ID_ISSUER_SERIAL_NUMBER;
1769 ret = CRYPT_ConstructBlob(&info->RecipientId.IssuerSerialNumber.Issuer,
1770 &cert->Issuer);
1771 if (ret)
1773 &info->RecipientId.IssuerSerialNumber.SerialNumber,
1774 &cert->SerialNumber);
1775 if (ret)
1776 ret = CRYPT_ConstructAlgorithmId(&info->KeyEncryptionAlgorithm,
1777 &cert->SubjectPublicKeyInfo.Algorithm);
1778 info->EncryptedKey.cbData = key->cbData;
1779 info->EncryptedKey.pbData = key->pbData;
1780 return ret;
1781}
1782
1784{
1785 CryptMemFree(info->RecipientId.IssuerSerialNumber.Issuer.pbData);
1786 CryptMemFree(info->RecipientId.IssuerSerialNumber.SerialNumber.pbData);
1787 CryptMemFree(info->KeyEncryptionAlgorithm.pszObjId);
1788 CryptMemFree(info->KeyEncryptionAlgorithm.Parameters.pbData);
1789 CryptMemFree(info->EncryptedKey.pbData);
1790}
1791
1793{
1794 CEnvelopedEncodeMsg *msg = hCryptMsg;
1795
1796 CryptMemFree(msg->algo.pszObjId);
1797 CryptMemFree(msg->algo.Parameters.pbData);
1798 if (msg->base.open_flags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG)
1799 CryptReleaseContext(msg->prov, 0);
1800 CryptDestroyKey(msg->key);
1801 if (msg->recipientInfo)
1802 {
1803 DWORD i;
1804
1805 for (i = 0; i < msg->cRecipientInfo; ++i)
1806 CRecipientInfo_Free(&msg->recipientInfo[i]);
1807 CryptMemFree(msg->recipientInfo);
1808 }
1809 CryptMemFree(msg->data.pbData);
1810}
1811
1812static BOOL CEnvelopedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
1813 DWORD dwIndex, void *pvData, DWORD *pcbData)
1814{
1815 CEnvelopedEncodeMsg *msg = hCryptMsg;
1816 BOOL ret = FALSE;
1817
1818 switch (dwParamType)
1819 {
1821 if (msg->base.streamed)
1823 else
1824 {
1825 char oid_rsa_data[] = szOID_RSA_data;
1826 CRYPT_ENVELOPED_DATA envelopedData = {
1828 msg->recipientInfo, { oid_rsa_data, {
1829 msg->algo.pszObjId,
1830 { msg->algo.Parameters.cbData, msg->algo.Parameters.pbData }
1831 },
1832 { msg->data.cbData, msg->data.pbData }
1833 }
1834 };
1835
1837 pcbData);
1838 }
1839 break;
1840 case CMSG_CONTENT_PARAM:
1841 {
1843
1845 &info.Content.cbData);
1846 if (ret)
1847 {
1848 info.Content.pbData = CryptMemAlloc(info.Content.cbData);
1849 if (info.Content.pbData)
1850 {
1852 info.Content.pbData, &info.Content.cbData);
1853 if (ret)
1854 {
1855 char oid_rsa_enveloped[] = szOID_RSA_envelopedData;
1856
1857 info.pszObjId = oid_rsa_enveloped;
1860 }
1861 CryptMemFree(info.Content.pbData);
1862 }
1863 else
1864 ret = FALSE;
1865 }
1866 break;
1867 }
1868 default:
1870 }
1871 return ret;
1872}
1873
1874static BOOL CEnvelopedEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
1875 DWORD cbData, BOOL fFinal)
1876{
1877 CEnvelopedEncodeMsg *msg = hCryptMsg;
1878 BOOL ret = FALSE;
1879
1880 if (msg->base.state == MsgStateFinalized)
1882 else if (msg->base.streamed)
1883 {
1884 FIXME("streamed stub\n");
1885 msg->base.state = fFinal ? MsgStateFinalized : MsgStateUpdated;
1886 ret = TRUE;
1887 }
1888 else
1889 {
1890 if (!fFinal)
1891 {
1892 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
1894 else
1896 }
1897 else
1898 {
1899 if (cbData)
1900 {
1901 DWORD dataLen = cbData;
1902
1903 msg->data.cbData = cbData;
1904 msg->data.pbData = CryptMemAlloc(cbData);
1905 if (msg->data.pbData)
1906 {
1907 memcpy(msg->data.pbData, pbData, cbData);
1908 ret = CryptEncrypt(msg->key, 0, TRUE, 0, msg->data.pbData,
1909 &dataLen, msg->data.cbData);
1910 msg->data.cbData = dataLen;
1911 if (dataLen > cbData)
1912 {
1913 msg->data.pbData = CryptMemRealloc(msg->data.pbData,
1914 dataLen);
1915 if (msg->data.pbData)
1916 {
1917 dataLen = cbData;
1918 ret = CryptEncrypt(msg->key, 0, TRUE, 0,
1919 msg->data.pbData, &dataLen, msg->data.cbData);
1920 }
1921 else
1922 ret = FALSE;
1923 }
1924 if (!ret)
1925 CryptMemFree(msg->data.pbData);
1926 }
1927 else
1928 ret = FALSE;
1929 if (!ret)
1930 {
1931 msg->data.cbData = 0;
1932 msg->data.pbData = NULL;
1933 }
1934 }
1935 else
1936 ret = TRUE;
1937 msg->base.state = MsgStateFinalized;
1938 }
1939 }
1940 return ret;
1941}
1942
1944 const void *pvMsgEncodeInfo, LPCSTR pszInnerContentObjID,
1945 PCMSG_STREAM_INFO pStreamInfo)
1946{
1948 const CMSG_ENVELOPED_ENCODE_INFO_WITH_CMS *info = pvMsgEncodeInfo;
1949 HCRYPTPROV prov;
1950 ALG_ID algID;
1951
1952 if (info->cbSize != sizeof(CMSG_ENVELOPED_ENCODE_INFO) &&
1953 info->cbSize != sizeof(CMSG_ENVELOPED_ENCODE_INFO_WITH_CMS))
1954 {
1956 return NULL;
1957 }
1958 if (info->cbSize == sizeof(CMSG_ENVELOPED_ENCODE_INFO_WITH_CMS))
1959 FIXME("CMS fields unsupported\n");
1960 if (!(algID = CertOIDToAlgId(info->ContentEncryptionAlgorithm.pszObjId)))
1961 {
1963 return NULL;
1964 }
1965 if (info->cRecipients && !info->rgpRecipientCert)
1966 {
1968 return NULL;
1969 }
1970 if (info->hCryptProv)
1971 prov = info->hCryptProv;
1972 else
1973 {
1975 dwFlags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
1976 }
1978 if (msg)
1979 {
1980 CRYPT_DATA_BLOB encryptedKey = { 0, NULL };
1981 CMSG_CONTENT_ENCRYPT_INFO encryptInfo;
1982 BOOL ret;
1983 DWORD i;
1984
1985 CryptMsgBase_Init((CryptMsgBase *)msg, dwFlags, pStreamInfo,
1989 &info->ContentEncryptionAlgorithm);
1990 msg->prov = prov;
1991 msg->data.cbData = 0;
1992 msg->data.pbData = NULL;
1993 msg->cRecipientInfo = info->cRecipients;
1994 msg->recipientInfo = CryptMemAlloc(info->cRecipients *
1996 if (!msg->recipientInfo)
1997 ret = FALSE;
1998 memset(&encryptInfo, 0, sizeof(encryptInfo));
1999 if (ret)
2000 {
2001 ret = CContentEncryptInfo_Construct(&encryptInfo, info, prov);
2002 if (ret)
2003 {
2004 ret = CRYPT_GenKey(&encryptInfo, algID);
2005 if (ret)
2006 msg->key = encryptInfo.hContentEncryptKey;
2007 }
2008 }
2009 for (i = 0; ret && i < msg->cRecipientInfo; ++i)
2010 {
2011 ret = CRYPT_ExportEncryptedKey(&encryptInfo, i, &encryptedKey);
2012 if (ret)
2013 ret = CRecipientInfo_Construct(&msg->recipientInfo[i],
2014 info->rgpRecipientCert[i], &encryptedKey);
2015 }
2016 CContentEncryptInfo_Free(&encryptInfo);
2017 if (!ret)
2018 {
2020 msg = NULL;
2021 }
2022 }
2024 CryptReleaseContext(prov, 0);
2025 return msg;
2026}
2027
2029 DWORD dwMsgType, const void *pvMsgEncodeInfo, LPSTR pszInnerContentObjID,
2030 PCMSG_STREAM_INFO pStreamInfo)
2031{
2032 HCRYPTMSG msg = NULL;
2033
2034 TRACE("(%08lx, %08lx, %08lx, %p, %s, %p)\n", dwMsgEncodingType, dwFlags,
2035 dwMsgType, pvMsgEncodeInfo, debugstr_a(pszInnerContentObjID), pStreamInfo);
2036
2037 if (GET_CMSG_ENCODING_TYPE(dwMsgEncodingType) != PKCS_7_ASN_ENCODING)
2038 {
2040 return NULL;
2041 }
2042 switch (dwMsgType)
2043 {
2044 case CMSG_DATA:
2045 msg = CDataEncodeMsg_Open(dwFlags, pvMsgEncodeInfo,
2046 pszInnerContentObjID, pStreamInfo);
2047 break;
2048 case CMSG_HASHED:
2049 msg = CHashEncodeMsg_Open(dwFlags, pvMsgEncodeInfo,
2050 pszInnerContentObjID, pStreamInfo);
2051 break;
2052 case CMSG_SIGNED:
2053 msg = CSignedEncodeMsg_Open(dwFlags, pvMsgEncodeInfo,
2054 pszInnerContentObjID, pStreamInfo);
2055 break;
2056 case CMSG_ENVELOPED:
2057 msg = CEnvelopedEncodeMsg_Open(dwFlags, pvMsgEncodeInfo,
2058 pszInnerContentObjID, pStreamInfo);
2059 break;
2061 case CMSG_ENCRYPTED:
2062 /* defined but invalid, fall through */
2063 default:
2065 }
2066 return msg;
2067}
2068
2070{
2076
2077typedef struct _CDecodeMsg
2078{
2082 union {
2086 } u;
2091
2092static void CDecodeMsg_Close(HCRYPTMSG hCryptMsg)
2093{
2094 CDecodeMsg *msg = hCryptMsg;
2095
2096 if (msg->crypt_prov && msg->base.open_flags & CMSG_CRYPT_RELEASE_CONTEXT_FLAG)
2097 CryptReleaseContext(msg->crypt_prov, 0);
2098 switch (msg->type)
2099 {
2100 case CMSG_HASHED:
2101 if (msg->u.hash)
2102 CryptDestroyHash(msg->u.hash);
2103 break;
2104 case CMSG_ENVELOPED:
2105 if (msg->u.enveloped_data.crypt_prov)
2106 CryptReleaseContext(msg->u.enveloped_data.crypt_prov, 0);
2107 LocalFree(msg->u.enveloped_data.data);
2108 CryptMemFree(msg->u.enveloped_data.content.pbData);
2109 break;
2110 case CMSG_SIGNED:
2111 if (msg->u.signed_data.info)
2112 {
2113 LocalFree(msg->u.signed_data.info);
2114 CSignedMsgData_CloseHandles(&msg->u.signed_data);
2115 }
2116 break;
2117 }
2118 CryptMemFree(msg->msg_data.pbData);
2119 CryptMemFree(msg->detached_data.pbData);
2120 ContextPropertyList_Free(msg->properties);
2121}
2122
2124 DWORD cbData)
2125{
2126 BOOL ret = TRUE;
2127
2128 if (cbData)
2129 {
2130 if (blob->cbData)
2131 blob->pbData = CryptMemRealloc(blob->pbData,
2132 blob->cbData + cbData);
2133 else
2134 blob->pbData = CryptMemAlloc(cbData);
2135 if (blob->pbData)
2136 {
2137 memcpy(blob->pbData + blob->cbData, pbData, cbData);
2138 blob->cbData += cbData;
2139 }
2140 else
2141 ret = FALSE;
2142 }
2143 return ret;
2144}
2145
2147{
2148 BOOL ret;
2150 DWORD size;
2151
2153 blob->pbData, blob->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &data, &size);
2154 if (ret)
2155 {
2157 CMSG_CONTENT_PARAM, data->pbData, data->cbData);
2158 LocalFree(data);
2159 }
2160 return ret;
2161}
2162
2165{
2166 static const BYTE nullParams[] = { ASN_NULL, 0 };
2169
2170 /* Linearize algorithm id */
2171 len += strlen(id->pszObjId) + 1;
2172 len += id->Parameters.cbData;
2174 if (copy)
2175 {
2176 copy->pszObjId =
2177 (LPSTR)((BYTE *)copy + sizeof(CRYPT_ALGORITHM_IDENTIFIER));
2178 strcpy(copy->pszObjId, id->pszObjId);
2179 copy->Parameters.pbData = (BYTE *)copy->pszObjId + strlen(id->pszObjId)
2180 + 1;
2181 /* Trick: omit NULL parameters */
2182 if (id->Parameters.cbData == sizeof(nullParams) &&
2183 !memcmp(id->Parameters.pbData, nullParams, sizeof(nullParams)))
2184 {
2185 copy->Parameters.cbData = 0;
2186 len -= sizeof(nullParams);
2187 }
2188 else
2189 copy->Parameters.cbData = id->Parameters.cbData;
2190 if (copy->Parameters.cbData)
2191 memcpy(copy->Parameters.pbData, id->Parameters.pbData,
2192 id->Parameters.cbData);
2194 len);
2196 }
2197}
2198
2200{
2201 id->pszObjId = (LPSTR)((BYTE *)id + sizeof(CRYPT_ALGORITHM_IDENTIFIER));
2202 id->Parameters.pbData = (BYTE *)id->pszObjId + strlen(id->pszObjId) + 1;
2203}
2204
2206 const CRYPT_DER_BLOB *blob)
2207{
2208 BOOL ret;
2209 CRYPT_DIGESTED_DATA *digestedData;
2210 DWORD size;
2211
2212 ret = CRYPT_AsnDecodePKCSDigestedData(blob->pbData, blob->cbData,
2214 &size);
2215 if (ret)
2216 {
2218 (const BYTE *)&digestedData->version, sizeof(digestedData->version));
2220 &digestedData->DigestAlgorithm);
2223 (const BYTE *)digestedData->ContentInfo.pszObjId,
2224 digestedData->ContentInfo.pszObjId ?
2225 strlen(digestedData->ContentInfo.pszObjId) + 1 : 0);
2226 if (!(msg->base.open_flags & CMSG_DETACHED_FLAG))
2227 {
2228 if (digestedData->ContentInfo.Content.cbData)
2230 &digestedData->ContentInfo.Content);
2231 else
2234 }
2236 digestedData->hash.pbData, digestedData->hash.cbData);
2237 LocalFree(digestedData);
2238 }
2239 return ret;
2240}
2241
2243 const CRYPT_DER_BLOB *blob)
2244{
2245 BOOL ret;
2246 CRYPT_ENVELOPED_DATA *envelopedData;
2247 DWORD size;
2248
2249 ret = CRYPT_AsnDecodePKCSEnvelopedData(blob->pbData, blob->cbData,
2251 &size);
2252 if (ret)
2253 msg->u.enveloped_data.data = envelopedData;
2254 return ret;
2255}
2256
2258 const CRYPT_DER_BLOB *blob)
2259{
2260 BOOL ret;
2261 CRYPT_SIGNED_INFO *signedInfo;
2262 DWORD size;
2263
2264 ret = CRYPT_AsnDecodeCMSSignedInfo(blob->pbData, blob->cbData,
2266 &size);
2267 if (ret)
2268 msg->u.signed_data.info = signedInfo;
2269 return ret;
2270}
2271
2272/* Decodes the content in blob as the type given, and updates the value
2273 * (type, parameters, etc.) of msg based on what blob contains.
2274 * It doesn't just use msg's type, to allow a recursive call from an implicitly
2275 * typed message once the outer content info has been decoded.
2276 */
2278 DWORD type)
2279{
2280 BOOL ret;
2281
2282 switch (type)
2283 {
2284 case CMSG_DATA:
2286 msg->type = CMSG_DATA;
2287 break;
2288 case CMSG_HASHED:
2290 msg->type = CMSG_HASHED;
2291 break;
2292 case CMSG_ENVELOPED:
2294 msg->type = CMSG_ENVELOPED;
2295 break;
2296 case CMSG_SIGNED:
2298 msg->type = CMSG_SIGNED;
2299 break;
2300 default:
2301 {
2303 DWORD size;
2304
2306 msg->msg_data.pbData, msg->msg_data.cbData, CRYPT_DECODE_ALLOC_FLAG,
2307 NULL, &info, &size);
2308 if (ret)
2309 {
2310 if (!strcmp(info->pszObjId, szOID_RSA_data))
2312 else if (!strcmp(info->pszObjId, szOID_RSA_digestedData))
2313 ret = CDecodeMsg_DecodeContent(msg, &info->Content,
2314 CMSG_HASHED);
2315 else if (!strcmp(info->pszObjId, szOID_RSA_envelopedData))
2316 ret = CDecodeMsg_DecodeContent(msg, &info->Content,
2318 else if (!strcmp(info->pszObjId, szOID_RSA_signedData))
2319 ret = CDecodeMsg_DecodeContent(msg, &info->Content,
2320 CMSG_SIGNED);
2321 else
2322 {
2324 ret = FALSE;
2325 }
2326 LocalFree(info);
2327 }
2328 }
2329 }
2330 return ret;
2331}
2332
2335{
2336 CRYPT_ALGORITHM_IDENTIFIER *hashAlgoID = NULL;
2337 DWORD size = 0;
2338 ALG_ID algID = 0;
2339 BOOL ret;
2340
2342 hashAlgoID = CryptMemAlloc(size);
2344 &size);
2345 if (ret)
2346 algID = CertOIDToAlgId(hashAlgoID->pszObjId);
2347
2348 if (!msg->crypt_prov)
2349 {
2350 msg->crypt_prov = I_CryptGetDefaultCryptProv(algID);
2351 if (msg->crypt_prov)
2352 msg->base.open_flags &= ~CMSG_CRYPT_RELEASE_CONTEXT_FLAG;
2353 }
2354
2355 ret = CryptCreateHash(msg->crypt_prov, algID, 0, 0, &msg->u.hash);
2356 if (ret)
2357 {
2359
2360 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
2361 {
2362 /* Unlike for non-detached messages, the data were never stored as
2363 * the content param, but were saved in msg->detached_data instead.
2364 */
2365 content.pbData = msg->detached_data.pbData;
2366 content.cbData = msg->detached_data.cbData;
2367 }
2368 else
2371 if (ret)
2372 ret = CryptHashData(msg->u.hash, content.pbData, content.cbData, 0);
2373 }
2374 CryptMemFree(hashAlgoID);
2375 return ret;
2376}
2377
2380{
2382
2383 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
2384 content = &msg->detached_data;
2385 else
2386 content =
2387 &msg->u.enveloped_data.data->encryptedContentInfo.encryptedContent;
2388
2389 return CRYPT_ConstructBlob(&msg->u.enveloped_data.content, content);
2390}
2391
2394{
2395 BOOL ret;
2396 DWORD i, size;
2397
2398 ret = CSignedMsgData_AllocateHandles(&msg->u.signed_data);
2399 for (i = 0; ret && i < msg->u.signed_data.info->cSignerInfo; i++)
2401 &msg->crypt_prov, &msg->base.open_flags);
2402 if (ret)
2403 {
2405
2406 /* Now that we have all the content, update the hash handles with
2407 * it. If the message is a detached message, the content is stored
2408 * in msg->detached_data rather than in the signed message's
2409 * content.
2410 */
2411 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
2412 content = &msg->detached_data;
2413 else
2414 content = &msg->u.signed_data.info->content.Content;
2415 if (content->cbData)
2416 {
2417 /* If the message is not detached, have to decode the message's
2418 * content if the type is szOID_RSA_data.
2419 */
2420 if (!(msg->base.open_flags & CMSG_DETACHED_FLAG) &&
2421 !strcmp(msg->u.signed_data.info->content.pszObjId,
2423 {
2424 CRYPT_DATA_BLOB *rsa_blob;
2425
2427 X509_OCTET_STRING, content->pbData, content->cbData,
2428 CRYPT_DECODE_ALLOC_FLAG, NULL, &rsa_blob, &size);
2429 if (ret)
2430 {
2431 ret = CSignedMsgData_Update(&msg->u.signed_data,
2432 rsa_blob->pbData, rsa_blob->cbData, TRUE, Verify);
2433 LocalFree(rsa_blob);
2434 }
2435 }
2436 else
2437 ret = CSignedMsgData_Update(&msg->u.signed_data,
2438 content->pbData, content->cbData, TRUE, Verify);
2439 }
2440 }
2441 return ret;
2442}
2443
2445{
2446 BOOL ret = FALSE;
2447
2448 switch (msg->type)
2449 {
2450 case CMSG_HASHED:
2452 break;
2453 case CMSG_ENVELOPED:
2455 break;
2456 case CMSG_SIGNED:
2458 break;
2459 default:
2460 ret = TRUE;
2461 }
2462 return ret;
2463}
2464
2465static BOOL CDecodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData,
2466 DWORD cbData, BOOL fFinal)
2467{
2468 CDecodeMsg *msg = hCryptMsg;
2469 BOOL ret = FALSE;
2470
2471 TRACE("(%p, %p, %ld, %d)\n", hCryptMsg, pbData, cbData, fFinal);
2472
2473 if (msg->base.state == MsgStateFinalized)
2475 else if (msg->base.streamed)
2476 {
2477 FIXME("(%p, %p, %ld, %d): streamed update stub\n", hCryptMsg, pbData,
2478 cbData, fFinal);
2479 switch (msg->base.state)
2480 {
2481 case MsgStateInit:
2482 ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
2483 if (fFinal)
2484 {
2485 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
2486 msg->base.state = MsgStateDataFinalized;
2487 else
2488 msg->base.state = MsgStateFinalized;
2489 }
2490 else
2491 msg->base.state = MsgStateUpdated;
2492 break;
2493 case MsgStateUpdated:
2494 ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
2495 if (fFinal)
2496 {
2497 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
2498 msg->base.state = MsgStateDataFinalized;
2499 else
2500 msg->base.state = MsgStateFinalized;
2501 }
2502 break;
2504 ret = CDecodeMsg_CopyData(&msg->detached_data, pbData, cbData);
2505 if (fFinal)
2506 msg->base.state = MsgStateFinalized;
2507 break;
2508 default:
2510 break;
2511 }
2512 }
2513 else
2514 {
2515 if (!fFinal)
2517 else
2518 {
2519 switch (msg->base.state)
2520 {
2521 case MsgStateInit:
2522 ret = CDecodeMsg_CopyData(&msg->msg_data, pbData, cbData);
2523 if (msg->base.open_flags & CMSG_DETACHED_FLAG)
2524 msg->base.state = MsgStateDataFinalized;
2525 else
2526 msg->base.state = MsgStateFinalized;
2527 break;
2529 ret = CDecodeMsg_CopyData(&msg->detached_data, pbData, cbData);
2530 msg->base.state = MsgStateFinalized;
2531 break;
2532 default:
2534 }
2535 }
2536 }
2537 if (ret && fFinal &&
2538 ((msg->base.open_flags & CMSG_DETACHED_FLAG && msg->base.state ==
2540 (!(msg->base.open_flags & CMSG_DETACHED_FLAG) && msg->base.state ==
2542 ret = CDecodeMsg_DecodeContent(msg, &msg->msg_data, msg->type);
2543 if (ret && msg->base.state == MsgStateFinalized)
2544 ret = CDecodeMsg_FinalizeContent(msg, &msg->msg_data);
2545 return ret;
2546}
2547
2549 DWORD dwIndex, void *pvData, DWORD *pcbData)
2550{
2551 BOOL ret = FALSE;
2552
2553 switch (dwParamType)
2554 {
2555 case CMSG_TYPE_PARAM:
2556 ret = CRYPT_CopyParam(pvData, pcbData, &msg->type, sizeof(msg->type));
2557 break;
2559 {
2561
2562 ret = ContextPropertyList_FindProperty(msg->properties, dwParamType,
2563 &blob);
2564 if (ret)
2565 {
2566 ret = CRYPT_CopyParam(pvData, pcbData, blob.pbData, blob.cbData);
2567 if (ret && pvData)
2569 }
2570 else
2572 break;
2573 }
2576 break;
2577 default:
2578 {
2580
2581 ret = ContextPropertyList_FindProperty(msg->properties, dwParamType,
2582 &blob);
2583 if (ret)
2584 ret = CRYPT_CopyParam(pvData, pcbData, blob.pbData, blob.cbData);
2585 else
2587 }
2588 }
2589 return ret;
2590}
2591
2592/* nextData is an in/out parameter - on input it's the memory location in
2593 * which a copy of in's data should be made, and on output it's the memory
2594 * location immediately after out's copy of in's data.
2595 */
2597 const CRYPT_DATA_BLOB *in, LPBYTE *nextData)
2598{
2599 out->cbData = in->cbData;
2600 if (in->cbData)
2601 {
2602 out->pbData = *nextData;
2603 memcpy(out->pbData, in->pbData, in->cbData);
2604 *nextData += in->cbData;
2605 }
2606}
2607
2609 const CRYPT_ALGORITHM_IDENTIFIER *in, LPBYTE *nextData)
2610{
2611 if (in->pszObjId)
2612 {
2613 out->pszObjId = (LPSTR)*nextData;
2614 strcpy(out->pszObjId, in->pszObjId);
2615 *nextData += strlen(out->pszObjId) + 1;
2616 }
2617 CRYPT_CopyBlob(&out->Parameters, &in->Parameters, nextData);
2618}
2619
2621 const CRYPT_ATTRIBUTES *in, LPBYTE *nextData)
2622{
2623 out->cAttr = in->cAttr;
2624 if (in->cAttr)
2625 {
2626 DWORD i;
2627
2628 *nextData = POINTER_ALIGN_DWORD_PTR(*nextData);
2629 out->rgAttr = (CRYPT_ATTRIBUTE *)*nextData;
2630 *nextData += in->cAttr * sizeof(CRYPT_ATTRIBUTE);
2631 for (i = 0; i < in->cAttr; i++)
2632 {
2633 if (in->rgAttr[i].pszObjId)
2634 {
2635 out->rgAttr[i].pszObjId = (LPSTR)*nextData;
2636 strcpy(out->rgAttr[i].pszObjId, in->rgAttr[i].pszObjId);
2637 *nextData += strlen(in->rgAttr[i].pszObjId) + 1;
2638 }
2639 if (in->rgAttr[i].cValue)
2640 {
2641 DWORD j;
2642
2643 out->rgAttr[i].cValue = in->rgAttr[i].cValue;
2644 *nextData = POINTER_ALIGN_DWORD_PTR(*nextData);
2645 out->rgAttr[i].rgValue = (PCRYPT_DATA_BLOB)*nextData;
2646 *nextData += in->rgAttr[i].cValue * sizeof(CRYPT_DATA_BLOB);
2647 for (j = 0; j < in->rgAttr[i].cValue; j++)
2648 CRYPT_CopyBlob(&out->rgAttr[i].rgValue[j],
2649 &in->rgAttr[i].rgValue[j], nextData);
2650 }
2651 }
2652 }
2653}
2654
2656{
2657 DWORD size = attr->cAttr * sizeof(CRYPT_ATTRIBUTE), i, j;
2658
2659 for (i = 0; i < attr->cAttr; i++)
2660 {
2661 if (attr->rgAttr[i].pszObjId)
2662 size += strlen(attr->rgAttr[i].pszObjId) + 1;
2663 /* align pointer */
2665 size += attr->rgAttr[i].cValue * sizeof(CRYPT_DATA_BLOB);
2666 for (j = 0; j < attr->rgAttr[i].cValue; j++)
2667 size += attr->rgAttr[i].rgValue[j].cbData;
2668 }
2669 /* align pointer again to be conservative */
2671 return size;
2672}
2673
2675{
2676 static char oid_key_rdn[] = szOID_KEYID_RDN;
2677 DWORD size = 0;
2679 CERT_RDN rdn = { 1, &attr };
2680 CERT_NAME_INFO name = { 1, &rdn };
2681
2682 attr.pszObjId = oid_key_rdn;
2683 attr.dwValueType = CERT_RDN_OCTET_STRING;
2684 attr.Value.cbData = keyId->cbData;
2685 attr.Value.pbData = keyId->pbData;
2687 size++; /* Only include size of special zero serial number on success */
2688 return size;
2689}
2690
2693 LPBYTE *nextData)
2694{
2695 static char oid_key_rdn[] = szOID_KEYID_RDN;
2697 CERT_RDN rdn = { 1, &attr };
2698 CERT_NAME_INFO name = { 1, &rdn };
2699 BOOL ret;
2700
2701 /* Encode special zero serial number */
2702 serialNumber->cbData = 1;
2703 serialNumber->pbData = *nextData;
2704 **nextData = 0;
2705 (*nextData)++;
2706 /* Encode issuer */
2707 issuer->pbData = *nextData;
2708 attr.pszObjId = oid_key_rdn;
2709 attr.dwValueType = CERT_RDN_OCTET_STRING;
2710 attr.Value.cbData = keyId->cbData;
2711 attr.Value.pbData = keyId->pbData;
2713 &encodedLen);
2714 if (ret)
2715 {
2716 *nextData += encodedLen;
2717 issuer->cbData = encodedLen;
2718 }
2719 return ret;
2720}
2721
2723 const CMSG_CMS_SIGNER_INFO *in)
2724{
2725 DWORD size = sizeof(CMSG_SIGNER_INFO), rdnSize = 0;
2726 BOOL ret;
2727
2728 TRACE("(%p, %ld, %p)\n", pvData, pvData ? *pcbData : 0, in);
2729
2730 if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
2731 {
2732 size += in->SignerId.IssuerSerialNumber.Issuer.cbData;
2733 size += in->SignerId.IssuerSerialNumber.SerialNumber.cbData;
2734 }
2735 else
2736 {
2737 rdnSize = CRYPT_SizeOfKeyIdAsIssuerAndSerial(&in->SignerId.KeyId);
2738 size += rdnSize;
2739 }
2740 if (in->HashAlgorithm.pszObjId)
2741 size += strlen(in->HashAlgorithm.pszObjId) + 1;
2742 size += in->HashAlgorithm.Parameters.cbData;
2743 if (in->HashEncryptionAlgorithm.pszObjId)
2744 size += strlen(in->HashEncryptionAlgorithm.pszObjId) + 1;
2745 size += in->HashEncryptionAlgorithm.Parameters.cbData;
2746 size += in->EncryptedHash.cbData;
2747 /* align pointer */
2749 size += CRYPT_SizeOfAttributes(&in->AuthAttrs);
2750 size += CRYPT_SizeOfAttributes(&in->UnauthAttrs);
2751 if (!pvData)
2752 {
2753 ret = TRUE;
2754 }
2755 else if (*pcbData < size)
2756 {
2758 ret = FALSE;
2759 }
2760 else
2761 {
2762 LPBYTE nextData = (BYTE *)pvData + sizeof(CMSG_SIGNER_INFO);
2764
2765 ret = TRUE;
2766 out->dwVersion = in->dwVersion;
2767 if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
2768 {
2769 CRYPT_CopyBlob(&out->Issuer,
2770 &in->SignerId.IssuerSerialNumber.Issuer, &nextData);
2771 CRYPT_CopyBlob(&out->SerialNumber,
2772 &in->SignerId.IssuerSerialNumber.SerialNumber, &nextData);
2773 }
2774 else
2775 ret = CRYPT_CopyKeyIdAsIssuerAndSerial(&out->Issuer, &out->SerialNumber,
2776 &in->SignerId.KeyId, rdnSize, &nextData);
2777 if (ret)
2778 {
2779 CRYPT_CopyAlgorithmId(&out->HashAlgorithm, &in->HashAlgorithm,
2780 &nextData);
2781 CRYPT_CopyAlgorithmId(&out->HashEncryptionAlgorithm,
2782 &in->HashEncryptionAlgorithm, &nextData);
2783 CRYPT_CopyBlob(&out->EncryptedHash, &in->EncryptedHash, &nextData);
2784 nextData = POINTER_ALIGN_DWORD_PTR(nextData);
2785 CRYPT_CopyAttributes(&out->AuthAttrs, &in->AuthAttrs, &nextData);
2786 CRYPT_CopyAttributes(&out->UnauthAttrs, &in->UnauthAttrs, &nextData);
2787 }
2788 }
2789 *pcbData = size;
2790 TRACE("returning %d\n", ret);
2791 return ret;
2792}
2793
2795 const CMSG_CMS_SIGNER_INFO *in)
2796{
2798 BOOL ret;
2799
2800 TRACE("(%p, %ld, %p)\n", pvData, pvData ? *pcbData : 0, in);
2801
2802 if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
2803 {
2804 size += in->SignerId.IssuerSerialNumber.Issuer.cbData;
2805 size += in->SignerId.IssuerSerialNumber.SerialNumber.cbData;
2806 }
2807 else
2808 size += in->SignerId.KeyId.cbData;
2809 if (in->HashAlgorithm.pszObjId)
2810 size += strlen(in->HashAlgorithm.pszObjId) + 1;
2811 size += in->HashAlgorithm.Parameters.cbData;
2812 if (in->HashEncryptionAlgorithm.pszObjId)
2813 size += strlen(in->HashEncryptionAlgorithm.pszObjId) + 1;
2814 size += in->HashEncryptionAlgorithm.Parameters.cbData;
2815 size += in->EncryptedHash.cbData;
2816 /* align pointer */
2818 size += CRYPT_SizeOfAttributes(&in->AuthAttrs);
2819 size += CRYPT_SizeOfAttributes(&in->UnauthAttrs);
2820 if (!pvData)
2821 {
2822 *pcbData = size;
2823 ret = TRUE;
2824 }
2825 else if (*pcbData < size)
2826 {
2827 *pcbData = size;
2829 ret = FALSE;
2830 }
2831 else
2832 {
2833 LPBYTE nextData = (BYTE *)pvData + sizeof(CMSG_CMS_SIGNER_INFO);
2835
2836 out->dwVersion = in->dwVersion;
2837 out->SignerId.dwIdChoice = in->SignerId.dwIdChoice;
2838 if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
2839 {
2840 CRYPT_CopyBlob(&out->SignerId.IssuerSerialNumber.Issuer,
2841 &in->SignerId.IssuerSerialNumber.Issuer, &nextData);
2842 CRYPT_CopyBlob(&out->SignerId.IssuerSerialNumber.SerialNumber,
2843 &in->SignerId.IssuerSerialNumber.SerialNumber, &nextData);
2844 }
2845 else
2846 CRYPT_CopyBlob(&out->SignerId.KeyId, &in->SignerId.KeyId, &nextData);
2847 CRYPT_CopyAlgorithmId(&out->HashAlgorithm, &in->HashAlgorithm,
2848 &nextData);
2849 CRYPT_CopyAlgorithmId(&out->HashEncryptionAlgorithm,
2850 &in->HashEncryptionAlgorithm, &nextData);
2851 CRYPT_CopyBlob(&out->EncryptedHash, &in->EncryptedHash, &nextData);
2852 nextData = POINTER_ALIGN_DWORD_PTR(nextData);
2853 CRYPT_CopyAttributes(&out->AuthAttrs, &in->AuthAttrs, &nextData);
2854 CRYPT_CopyAttributes(&out->UnauthAttrs, &in->UnauthAttrs, &nextData);
2855 ret = TRUE;
2856 }
2857 TRACE("returning %d\n", ret);
2858 return ret;
2859}
2860
2862 const CMSG_CMS_SIGNER_INFO *in)
2863{
2864 DWORD size = sizeof(CERT_INFO), rdnSize = 0;
2865 BOOL ret;
2866
2867 TRACE("(%p, %ld, %p)\n", pvData, pvData ? *pcbData : 0, in);
2868
2869 if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
2870 {
2871 size += in->SignerId.IssuerSerialNumber.Issuer.cbData;
2872 size += in->SignerId.IssuerSerialNumber.SerialNumber.cbData;
2873 }
2874 else
2875 {
2876 rdnSize = CRYPT_SizeOfKeyIdAsIssuerAndSerial(&in->SignerId.KeyId);
2877 size += rdnSize;
2878 }
2879 if (!pvData)
2880 {
2881 *pcbData = size;
2882 ret = TRUE;
2883 }
2884 else if (*pcbData < size)
2885 {
2886 *pcbData = size;
2888 ret = FALSE;
2889 }
2890 else
2891 {
2892 LPBYTE nextData = (BYTE *)pvData + sizeof(CERT_INFO);
2893 CERT_INFO *out = pvData;
2894
2895 memset(out, 0, sizeof(CERT_INFO));
2896 if (in->SignerId.dwIdChoice == CERT_ID_ISSUER_SERIAL_NUMBER)
2897 {
2898 CRYPT_CopyBlob(&out->Issuer,
2899 &in->SignerId.IssuerSerialNumber.Issuer, &nextData);
2900 CRYPT_CopyBlob(&out->SerialNumber,
2901 &in->SignerId.IssuerSerialNumber.SerialNumber, &nextData);
2902 ret = TRUE;
2903 }
2904 else
2905 ret = CRYPT_CopyKeyIdAsIssuerAndSerial(&out->Issuer, &out->SerialNumber,
2906 &in->SignerId.KeyId, rdnSize, &nextData);
2907 }
2908 TRACE("returning %d\n", ret);
2909 return ret;
2910}
2911
2914{
2915 DWORD size = sizeof(CERT_INFO);
2916 BOOL ret;
2917
2918 TRACE("(%p, %ld, %p)\n", pvData, pvData ? *pcbData : 0, in);
2919
2920 size += in->SerialNumber.cbData;
2921 size += in->Issuer.cbData;
2922 if (!pvData)
2923 {
2924 *pcbData = size;
2925 ret = TRUE;
2926 }
2927 else if (*pcbData < size)
2928 {
2929 *pcbData = size;
2931 ret = FALSE;
2932 }
2933 else
2934 {
2935 LPBYTE nextData = (BYTE *)pvData + sizeof(CERT_INFO);
2936 CERT_INFO *out = pvData;
2937
2938 CRYPT_CopyBlob(&out->SerialNumber, &in->SerialNumber, &nextData);
2939 CRYPT_CopyBlob(&out->Issuer, &in->Issuer, &nextData);
2940 ret = TRUE;
2941 }
2942 TRACE("returning %d\n", ret);
2943 return ret;
2944}
2945
2947 DWORD dwIndex, void *pvData, DWORD *pcbData)
2948{
2949 BOOL ret = FALSE;
2950
2951 switch (dwParamType)
2952 {
2953 case CMSG_TYPE_PARAM:
2954 ret = CRYPT_CopyParam(pvData, pcbData, &msg->type, sizeof(msg->type));
2955 break;
2956 case CMSG_CONTENT_PARAM:
2957 if (msg->u.enveloped_data.data)
2959 msg->u.enveloped_data.content.pbData,
2960 msg->u.enveloped_data.content.cbData);
2961 else
2963 break;
2965 if (msg->u.enveloped_data.data)
2967 &msg->u.enveloped_data.data->cRecipientInfo, sizeof(DWORD));
2968 else
2970 break;
2972 if (msg->u.enveloped_data.data)
2973 {
2974 if (dwIndex < msg->u.enveloped_data.data->cRecipientInfo)
2975 {
2976 PCMSG_KEY_TRANS_RECIPIENT_INFO recipientInfo =
2977 &msg->u.enveloped_data.data->rgRecipientInfo[dwIndex];
2978
2980 &recipientInfo->RecipientId.IssuerSerialNumber);
2981 }
2982 else
2984 }
2985 else
2987 break;
2988 default:
2989 FIXME("unimplemented for %ld\n", dwParamType);
2991 }
2992 return ret;
2993}
2994
2996{
2997 DWORD size;
2998 BOOL ret;
2999
3000 TRACE("(%p, %ld, %p)\n", pvData, pvData ? *pcbData : 0, attr);
3001
3003 if (!pvData)
3004 {
3005 *pcbData = size;
3006 ret = TRUE;
3007 }
3008 else if (*pcbData < size)
3009 {
3010 *pcbData = size;
3012 ret = FALSE;
3013 }
3014 else
3016
3017 TRACE("returning %d\n", ret);
3018 return ret;
3019}
3020
3022 DWORD dwIndex, void *pvData, DWORD *pcbData)
3023{
3024 BOOL ret = FALSE;
3025
3026 switch (dwParamType)
3027 {
3028 case CMSG_TYPE_PARAM:
3029 ret = CRYPT_CopyParam(pvData, pcbData, &msg->type, sizeof(msg->type));
3030 break;
3031 case CMSG_CONTENT_PARAM:
3032 if (msg->u.signed_data.info)
3033 {
3034 if (!strcmp(msg->u.signed_data.info->content.pszObjId,
3036 {
3038 DWORD size;
3039
3041 msg->u.signed_data.info->content.Content.pbData,
3042 msg->u.signed_data.info->content.Content.cbData,
3044 if (ret)
3045 {
3047 blob->cbData);
3048 LocalFree(blob);
3049 }
3050 }
3051 else
3053 msg->u.signed_data.info->content.Content.pbData,
3054 msg->u.signed_data.info->content.Content.cbData);
3055 }
3056 else
3058 break;
3060 if (msg->u.signed_data.info)
3062 msg->u.signed_data.info->content.pszObjId,
3063 strlen(msg->u.signed_data.info->content.pszObjId) + 1);
3064 else
3066 break;
3068 if (msg->u.signed_data.info)
3070 &msg->u.signed_data.info->cSignerInfo, sizeof(DWORD));
3071 else
3073 break;
3075 if (msg->u.signed_data.info)
3076 {
3077 if (dwIndex >= msg->u.signed_data.info->cSignerInfo)
3079 else
3081 &msg->u.signed_data.info->rgSignerInfo[dwIndex]);
3082 }
3083 else
3085 break;
3087 if (msg->u.signed_data.info)
3088 {
3089 if (dwIndex >= msg->u.signed_data.info->cSignerInfo)
3091 else
3093 &msg->u.signed_data.info->rgSignerInfo[dwIndex]);
3094 }
3095 else
3097 break;
3099 if (msg->u.signed_data.info)
3101 &msg->u.signed_data.info->cCertEncoded, sizeof(DWORD));
3102 else
3104 break;
3105 case CMSG_CERT_PARAM:
3106 if (msg->u.signed_data.info)
3107 {
3108 if (dwIndex >= msg->u.signed_data.info->cCertEncoded)
3110 else
3112 msg->u.signed_data.info->rgCertEncoded[dwIndex].pbData,
3113 msg->u.signed_data.info->rgCertEncoded[dwIndex].cbData);
3114 }
3115 else
3117 break;
3119 if (msg->u.signed_data.info)
3121 &msg->u.signed_data.info->cCrlEncoded, sizeof(DWORD));
3122 else
3124 break;
3125 case CMSG_CRL_PARAM:
3126 if (msg->u.signed_data.info)
3127 {
3128 if (dwIndex >= msg->u.signed_data.info->cCrlEncoded)
3130 else
3132 msg->u.signed_data.info->rgCrlEncoded[dwIndex].pbData,
3133 msg->u.signed_data.info->rgCrlEncoded[dwIndex].cbData);
3134 }
3135 else
3137 break;
3139 if (msg->u.signed_data.info)
3140 {
3141 if (dwIndex >= msg->u.signed_data.cSignerHandle)
3143 else
3145 msg->u.signed_data.signerHandles[dwIndex].contentHash,
3147 }
3148 else
3150 break;
3152 if (msg->msg_data.pbData)
3153 ret = CRYPT_CopyParam(pvData, pcbData, msg->msg_data.pbData, msg->msg_data.cbData);
3154 else
3156 break;
3158 if (msg->u.signed_data.info)
3159 {
3160 if (dwIndex >= msg->u.signed_data.info->cSignerInfo)
3162 else
3165 &msg->u.signed_data.info->rgSignerInfo[dwIndex], 0, NULL,
3166 pvData, pcbData);
3167 }
3168 else
3170 break;
3172 if (msg->u.signed_data.info)
3173 {
3174 DWORD attrCertCount = 0;
3175
3177 &attrCertCount, sizeof(DWORD));
3178 }
3179 else
3181 break;
3183 if (msg->u.signed_data.info)
3185 else
3187 break;
3189 if (msg->u.signed_data.info)
3190 {
3191 if (dwIndex >= msg->u.signed_data.info->cSignerInfo)
3193 else
3195 &msg->u.signed_data.info->rgSignerInfo[dwIndex]);
3196 }
3197 else
3199 break;
3201 if (msg->u.signed_data.info)
3202 {
3203 if (dwIndex >= msg->u.signed_data.info->cSignerInfo)
3205 else
3207 &msg->u.signed_data.info->rgSignerInfo[dwIndex].AuthAttrs);
3208 }
3209 else
3211 break;
3213 if (msg->u.signed_data.info)
3214 {
3215 if (dwIndex >= msg->u.signed_data.info->cSignerInfo)
3217 else
3219 &msg->u.signed_data.info->rgSignerInfo[dwIndex].UnauthAttrs);
3220 }
3221 else
3223 break;
3224 default:
3225 FIXME("unimplemented for %ld\n", dwParamType);
3227 }
3228 return ret;
3229}
3230
3231static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType,
3232 DWORD dwIndex, void *pvData, DWORD *pcbData)
3233{
3234 CDecodeMsg *msg = hCryptMsg;
3235 BOOL ret = FALSE;
3236
3237 switch (msg->type)
3238 {
3239 case CMSG_HASHED:
3240 ret = CDecodeHashMsg_GetParam(msg, dwParamType, dwIndex, pvData,
3241 pcbData);
3242 break;
3243 case CMSG_ENVELOPED:
3244 ret = CDecodeEnvelopedMsg_GetParam(msg, dwParamType, dwIndex, pvData,
3245 pcbData);
3246 break;
3247 case CMSG_SIGNED:
3248 ret = CDecodeSignedMsg_GetParam(msg, dwParamType, dwIndex, pvData,
3249 pcbData);
3250 break;
3251 default:
3252 switch (dwParamType)
3253 {
3254 case CMSG_TYPE_PARAM:
3256 sizeof(msg->type));
3257 break;
3258 default:
3259 {
3261
3262 ret = ContextPropertyList_FindProperty(msg->properties, dwParamType,
3263 &blob);
3264 if (ret)
3266 blob.cbData);
3267 else
3269 }
3270 }
3271 }
3272 return ret;
3273}
3274
3276{
3277 BOOL ret;
3279
3282 if (ret)
3283 {
3284 DWORD computedHashSize = 0;
3285
3287 &computedHashSize);
3288 if (hashBlob.cbData == computedHashSize)
3289 {
3290 LPBYTE computedHash = CryptMemAlloc(computedHashSize);
3291
3292 if (computedHash)
3293 {
3295 computedHash, &computedHashSize);
3296 if (ret)
3297 {
3298 if (memcmp(hashBlob.pbData, computedHash, hashBlob.cbData))
3299 {
3301 ret = FALSE;
3302 }
3303 }
3304 CryptMemFree(computedHash);
3305 }
3306 else
3307 {
3309 ret = FALSE;
3310 }
3311 }
3312 else
3313 {
3315 ret = FALSE;
3316 }
3317 }
3318 return ret;
3319}
3320
3322{
3323 BYTE *hash_value, *sig_value = NULL;
3324 DWORD hash_len, sig_len;
3326 BOOL ret = FALSE;
3328
3329 if (!CryptImportPublicKeyInfoEx2(X509_ASN_ENCODING, key_info, 0, NULL, &key)) return FALSE;
3330 if (!extract_hash(hash, &hash_value, &hash_len)) goto done;
3332 signer->EncryptedHash.cbData, &sig_value, &sig_len)) goto done;
3333 status = BCryptVerifySignature(key, NULL, hash_value, hash_len, sig_value, sig_len, 0);
3334 if (status)
3335 {
3336 FIXME("Failed to verify signature: %08lx.\n", status);
3338 }
3339 ret = !status;
3340done:
3341 CryptMemFree(sig_value);
3342 CryptMemFree(hash_value);
3344 return ret;
3345}
3346
3348 HCRYPTPROV prov, DWORD signerIndex, PCERT_PUBLIC_KEY_INFO keyInfo)
3349{
3351 HCRYPTKEY key;
3352 BOOL ret;
3353 ALG_ID alg_id = 0;
3354
3355 if (msg->u.signed_data.info->rgSignerInfo[signerIndex].AuthAttrs.cAttr)
3356 hash = msg->u.signed_data.signerHandles[signerIndex].authAttrHash;
3357 else
3358 hash = msg->u.signed_data.signerHandles[signerIndex].contentHash;
3359
3360 if (keyInfo->Algorithm.pszObjId) alg_id = CertOIDToAlgId(keyInfo->Algorithm.pszObjId);
3362 return cng_verify_msg_signature(&msg->u.signed_data.info->rgSignerInfo[signerIndex], hash, keyInfo);
3363
3364 if (!prov)
3365 prov = msg->crypt_prov;
3367 if (ret)
3368 {
3369 CRYPT_HASH_BLOB reversedHash;
3370
3371 ret = CRYPT_ConstructBlob(&reversedHash,
3372 &msg->u.signed_data.info->rgSignerInfo[signerIndex].EncryptedHash);
3373 if (ret)
3374 {
3375 CRYPT_ReverseBytes(&reversedHash);
3376 ret = CryptVerifySignatureW(hash, reversedHash.pbData,
3377 reversedHash.cbData, key, NULL, 0);
3378 CryptMemFree(reversedHash.pbData);
3379 }
3381 }
3382 return ret;
3383}
3384
3386{
3387 BOOL ret = FALSE;
3388 DWORD i;
3389
3390 if (!msg->u.signed_data.signerHandles)
3391 {
3393 return FALSE;
3394 }
3395 for (i = 0; !ret && i < msg->u.signed_data.info->cSignerInfo; i++)
3396 {
3397 PCMSG_CMS_SIGNER_INFO signerInfo =
3398 &msg->u.signed_data.info->rgSignerInfo[i];
3399
3401 {
3403 &signerInfo->SignerId.IssuerSerialNumber.Issuer,
3404 &info->Issuer);
3405 if (ret)
3406 {
3409 &info->SerialNumber);
3410 if (ret)
3411 break;
3412 }
3413 }
3414 else
3415 {
3416 FIXME("signer %ld: unimplemented for key id\n", i);
3417 }
3418 }
3419 if (ret)
3421 &info->SubjectPublicKeyInfo);
3422 else
3424
3425 return ret;
3426}
3427
3430{
3431 BOOL ret = FALSE;
3432
3433 if (para->cbSize != sizeof(CMSG_CTRL_VERIFY_SIGNATURE_EX_PARA))
3435 else if (para->dwSignerIndex >= msg->u.signed_data.info->cSignerInfo)
3437 else if (!msg->u.signed_data.signerHandles)
3439 else
3440 {
3441 switch (para->dwSignerType)
3442 {
3445 para->hCryptProv, para->dwSignerIndex, para->pvSigner);
3446 break;
3448 {
3450
3452 para->dwSignerIndex, &cert->pCertInfo->SubjectPublicKeyInfo);
3453 break;
3454 }
3455 default:
3456 FIXME("unimplemented for signer type %ld\n", para->dwSignerType);
3458 }
3459 }
3460 return ret;
3461}
3462
3464 PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm,
3465 PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara, DWORD dwFlags,
3466 void *pvReserved, HCRYPTKEY *phContentEncryptKey)
3467{
3468 BOOL ret;
3469 HCRYPTKEY key;
3470
3471 ret = CryptGetUserKey(pKeyTransDecryptPara->hCryptProv,
3472 pKeyTransDecryptPara->dwKeySpec ? pKeyTransDecryptPara->dwKeySpec :
3474 if (ret)
3475 {
3477 &pKeyTransDecryptPara->pKeyTrans[pKeyTransDecryptPara->dwRecipientIndex];
3478 CRYPT_DATA_BLOB *encryptedKey = &info->EncryptedKey;
3479 DWORD size = encryptedKey->cbData + sizeof(BLOBHEADER) + sizeof(ALG_ID);
3480 BYTE *keyBlob = CryptMemAlloc(size);
3481
3482 if (keyBlob)
3483 {
3484 DWORD i, k = size - 1;
3485 BLOBHEADER *blobHeader = (BLOBHEADER *)keyBlob;
3486 ALG_ID *algID = (ALG_ID *)(keyBlob + sizeof(BLOBHEADER));
3487
3488 blobHeader->bType = SIMPLEBLOB;
3489 blobHeader->bVersion = CUR_BLOB_VERSION;
3490 blobHeader->reserved = 0;
3491 blobHeader->aiKeyAlg = CertOIDToAlgId(
3492 pContentEncryptionAlgorithm->pszObjId);
3493 *algID = CertOIDToAlgId(info->KeyEncryptionAlgorithm.pszObjId);
3494 for (i = 0; i < encryptedKey->cbData; ++i, --k)
3495 keyBlob[k] = encryptedKey->pbData[i];
3496
3497 ret = CryptImportKey(pKeyTransDecryptPara->hCryptProv, keyBlob,
3498 size, key, 0, phContentEncryptKey);
3499 CryptMemFree(keyBlob);
3500 }
3501 else
3502 ret = FALSE;
3504 }
3505 return ret;
3506}
3507
3510 HCRYPTKEY *key)
3511{
3512 static HCRYPTOIDFUNCSET set = NULL;
3513 PFN_CMSG_IMPORT_KEY_TRANS importKeyFunc = NULL;
3514 HCRYPTOIDFUNCADDR hFunc = NULL;
3516 BOOL ret;
3517
3518 memset(&decryptPara, 0, sizeof(decryptPara));
3519 decryptPara.cbSize = sizeof(decryptPara);
3520 decryptPara.hCryptProv = para->hCryptProv;
3521 decryptPara.dwKeySpec = para->dwKeySpec;
3522 decryptPara.pKeyTrans = info;
3523 decryptPara.dwRecipientIndex = para->dwRecipientIndex;
3524
3525 if (!set)
3528 (void **)&importKeyFunc, &hFunc);
3529 if (!importKeyFunc)
3530 importKeyFunc = CRYPT_ImportKeyTrans;
3531 ret = importKeyFunc(contEncrAlg, &decryptPara, 0, NULL, key);
3532 if (hFunc)
3534 return ret;
3535}
3536
3539{
3540 BOOL ret = FALSE;
3541 CEnvelopedDecodeMsg *enveloped_data = &msg->u.enveloped_data;
3542 CRYPT_ENVELOPED_DATA *data = enveloped_data->data;
3543
3544 if (para->cbSize != sizeof(CMSG_CTRL_DECRYPT_PARA))
3546 else if (!data)
3548 else if (para->dwRecipientIndex >= data->cRecipientInfo)
3550 else if (enveloped_data->decrypted)
3552 else if (!para->hCryptProv)
3554 else if (enveloped_data->content.cbData)
3555 {
3556 HCRYPTKEY key;
3557
3559 &data->encryptedContentInfo.contentEncryptionAlgorithm, para,
3560 data->rgRecipientInfo, &key);
3561 if (ret)
3562 {
3563 ret = CryptDecrypt(key, 0, TRUE, 0, enveloped_data->content.pbData,
3564 &enveloped_data->content.cbData);
3566 }
3567 }
3568 else
3569 ret = TRUE;
3570 if (ret)
3571 enveloped_data->decrypted = TRUE;
3572 return ret;
3573}
3574
3576 DWORD dwCtrlType, const void *pvCtrlPara)
3577{
3578 CDecodeMsg *msg = hCryptMsg;
3579 BOOL ret = FALSE;
3580
3581 switch (dwCtrlType)
3582 {
3584 switch (msg->type)
3585 {
3586 case CMSG_SIGNED:
3588 break;
3589 default:
3591 }
3592 break;
3593 case CMSG_CTRL_DECRYPT:
3594 switch (msg->type)
3595 {
3596 case CMSG_ENVELOPED:
3598 (PCMSG_CTRL_DECRYPT_PARA)pvCtrlPara);
3600 msg->u.enveloped_data.crypt_prov =
3601 ((PCMSG_CTRL_DECRYPT_PARA)pvCtrlPara)->hCryptProv;
3602 break;
3603 default:
3605 }
3606 break;
3608 switch (msg->type)
3609 {
3610 case CMSG_HASHED:
3612 break;
3613 default:
3615 }
3616 break;
3618 switch (msg->type)
3619 {
3620 case CMSG_SIGNED:
3623 break;
3624 default:
3626 }
3627 break;
3628 default:
3630 }
3631 return ret;
3632}
3633
3635 DWORD dwMsgType, HCRYPTPROV_LEGACY hCryptProv, PCERT_INFO pRecipientInfo,
3636 PCMSG_STREAM_INFO pStreamInfo)
3637{
3638 CDecodeMsg *msg;
3639
3640 TRACE("(%08lx, %08lx, %08lx, %08Ix, %p, %p)\n", dwMsgEncodingType,
3641 dwFlags, dwMsgType, hCryptProv, pRecipientInfo, pStreamInfo);
3642
3643 if (GET_CMSG_ENCODING_TYPE(dwMsgEncodingType) != PKCS_7_ASN_ENCODING)
3644 {
3646 return NULL;
3647 }
3648 msg = CryptMemAlloc(sizeof(CDecodeMsg));
3649 if (msg)
3650 {
3651 CryptMsgBase_Init((CryptMsgBase *)msg, dwFlags, pStreamInfo,
3654 msg->type = dwMsgType;
3655 msg->crypt_prov = hCryptProv;
3656 memset(&msg->u, 0, sizeof(msg->u));
3657 msg->msg_data.cbData = 0;
3658 msg->msg_data.pbData = NULL;
3659 msg->detached_data.cbData = 0;
3660 msg->detached_data.pbData = NULL;
3661 msg->properties = ContextPropertyList_Create();
3662 }
3663 return msg;
3664}
3665
3667{
3668 TRACE("(%p)\n", hCryptMsg);
3669
3670 if (hCryptMsg)
3671 {
3672 CryptMsgBase *msg = hCryptMsg;
3673
3675 }
3676 return hCryptMsg;
3677}
3678
3680{
3681 TRACE("(%p)\n", hCryptMsg);
3682
3683 if (hCryptMsg)
3684 {
3685 CryptMsgBase *msg = hCryptMsg;
3686
3687 if (InterlockedDecrement(&msg->ref) == 0)
3688 {
3689 TRACE("freeing %p\n", msg);
3690 if (msg->close)
3691 msg->close(msg);
3693 }
3694 }
3695 return TRUE;
3696}
3697
3698BOOL WINAPI CryptMsgUpdate(HCRYPTMSG hCryptMsg, const BYTE *pbData,
3699 DWORD cbData, BOOL fFinal)
3700{
3701 CryptMsgBase *msg = hCryptMsg;
3702
3703 TRACE("(%p, %p, %ld, %d)\n", hCryptMsg, pbData, cbData, fFinal);
3704
3705 return msg->update(hCryptMsg, pbData, cbData, fFinal);
3706}
3707
3709 DWORD dwIndex, void *pvData, DWORD *pcbData)
3710{
3711 CryptMsgBase *msg = hCryptMsg;
3712
3713 TRACE("(%p, %ld, %ld, %p, %p)\n", hCryptMsg, dwParamType, dwIndex,
3714 pvData, pcbData);
3715 return msg->get_param(hCryptMsg, dwParamType, dwIndex, pvData, pcbData);
3716}
3717
3719 DWORD dwCtrlType, const void *pvCtrlPara)
3720{
3721 CryptMsgBase *msg = hCryptMsg;
3722
3723 TRACE("(%p, %08lx, %ld, %p)\n", hCryptMsg, dwFlags, dwCtrlType,
3724 pvCtrlPara);
3725 return msg->control(hCryptMsg, dwFlags, dwCtrlType, pvCtrlPara);
3726}
3727
3729 DWORD dwSignerIndex)
3730{
3731 CERT_INFO *certInfo = NULL;
3732 DWORD size;
3733
3735 &size))
3736 {
3737 certInfo = CryptMemAlloc(size);
3738 if (certInfo)
3739 {
3741 dwSignerIndex, certInfo, &size))
3742 {
3743 CryptMemFree(certInfo);
3744 certInfo = NULL;
3745 }
3746 }
3747 }
3748 return certInfo;
3749}
3750
3752 HCERTSTORE *rghSignerStore, DWORD dwFlags, PCCERT_CONTEXT *ppSigner,
3753 DWORD *pdwSignerIndex)
3754{
3755 HCERTSTORE store;
3756 DWORD i, signerIndex = 0;
3757 PCCERT_CONTEXT signerCert = NULL;
3758 BOOL ret = FALSE;
3759
3760 TRACE("(%p, %ld, %p, %08lx, %p, %p)\n", hCryptMsg, cSignerStore,
3761 rghSignerStore, dwFlags, ppSigner, pdwSignerIndex);
3762
3763 /* Clear output parameters */
3764 if (ppSigner)
3765 *ppSigner = NULL;
3766 if (pdwSignerIndex && !(dwFlags & CMSG_USE_SIGNER_INDEX_FLAG))
3767 *pdwSignerIndex = 0;
3768
3769 /* Create store to search for signer certificates */
3773 {
3774 HCERTSTORE msgStore = CertOpenStore(CERT_STORE_PROV_MSG, 0, 0, 0,
3775 hCryptMsg);
3776
3777 CertAddStoreToCollection(store, msgStore, 0, 0);
3778 CertCloseStore(msgStore, 0);
3779 }
3780 for (i = 0; i < cSignerStore; i++)
3781 CertAddStoreToCollection(store, rghSignerStore[i], 0, 0);
3782
3783 /* Find signer cert */
3785 {
3786 CERT_INFO *signer = CRYPT_GetSignerCertInfoFromMsg(hCryptMsg,
3787 *pdwSignerIndex);
3788
3789 if (signer)
3790 {
3791 signerIndex = *pdwSignerIndex;
3793 0, CERT_FIND_SUBJECT_CERT, signer, NULL);
3794 CryptMemFree(signer);
3795 }
3796 }
3797 else
3798 {
3799 DWORD count, size = sizeof(count);
3800
3802 &size))
3803 {
3804 for (i = 0; !signerCert && i < count; i++)
3805 {
3806 CERT_INFO *signer = CRYPT_GetSignerCertInfoFromMsg(hCryptMsg,
3807 i);
3808
3809 if (signer)
3810 {
3811 signerCert = CertFindCertificateInStore(store,
3813 NULL);
3814 if (signerCert)
3815 signerIndex = i;
3816 CryptMemFree(signer);
3817 }
3818 }
3819 }
3820 if (!signerCert)
3822 }
3823 if (signerCert)
3824 {
3827 signerCert->pCertInfo);
3828 else
3829 ret = TRUE;
3830 if (ret)
3831 {
3832 if (ppSigner)
3833 *ppSigner = CertDuplicateCertificateContext(signerCert);
3834 if (pdwSignerIndex)
3835 *pdwSignerIndex = signerIndex;
3836 }
3837 CertFreeCertificateContext(signerCert);
3838 }
3839
3840 CertCloseStore(store, 0);
3841 return ret;
3842}
3843
3845 DWORD dwEncodingType, BYTE *pbSignerInfo, DWORD cbSignerInfo,
3846 PBYTE pbSignerInfoCountersignature, DWORD cbSignerInfoCountersignature,
3847 CERT_INFO *pciCountersigner)
3848{
3849 FIXME("(%08Ix, %08lx, %p, %ld, %p, %ld, %p): stub\n", hCryptProv,
3850 dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature,
3851 cbSignerInfoCountersignature, pciCountersigner);
3852 return FALSE;
3853}
3854
3856 DWORD dwEncodingType, PBYTE pbSignerInfo, DWORD cbSignerInfo,
3857 PBYTE pbSignerInfoCountersignature, DWORD cbSignerInfoCountersignature,
3858 DWORD dwSignerType, void *pvSigner, DWORD dwFlags, void *pvReserved)
3859{
3860 FIXME("(%08Ix, %08lx, %p, %ld, %p, %ld, %ld, %p, %08lx, %p): stub\n", hCryptProv,
3861 dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature,
3862 cbSignerInfoCountersignature, dwSignerType, pvSigner, dwFlags, pvReserved);
3863 return FALSE;
3864}
3865
3867 PCTL_INFO pCtlInfo, PCMSG_SIGNED_ENCODE_INFO pSignInfo, DWORD dwFlags,
3868 BYTE *pbEncoded, DWORD *pcbEncoded)
3869{
3870 BOOL ret;
3871 BYTE *pbCtlContent;
3872 DWORD cbCtlContent;
3873
3874 TRACE("(%08lx, %p, %p, %08lx, %p, %p)\n", dwMsgEncodingType, pCtlInfo,
3875 pSignInfo, dwFlags, pbEncoded, pcbEncoded);
3876
3877 if (dwFlags)
3878 {
3879 FIXME("unimplemented for flags %08lx\n", dwFlags);
3880 return FALSE;
3881 }
3882 if ((ret = CryptEncodeObjectEx(dwMsgEncodingType, PKCS_CTL, pCtlInfo,
3883 CRYPT_ENCODE_ALLOC_FLAG, NULL, &pbCtlContent, &cbCtlContent)))
3884 {
3885 ret = CryptMsgSignCTL(dwMsgEncodingType, pbCtlContent, cbCtlContent,
3886 pSignInfo, dwFlags, pbEncoded, pcbEncoded);
3887 LocalFree(pbCtlContent);
3888 }
3889 return ret;
3890}
3891
3892BOOL WINAPI CryptMsgSignCTL(DWORD dwMsgEncodingType, BYTE *pbCtlContent,
3893 DWORD cbCtlContent, PCMSG_SIGNED_ENCODE_INFO pSignInfo, DWORD dwFlags,
3894 BYTE *pbEncoded, DWORD *pcbEncoded)
3895{
3896 static char oid_ctl[] = szOID_CTL;
3897 BOOL ret;
3898 HCRYPTMSG msg;
3899
3900 TRACE("(%08lx, %p, %ld, %p, %08lx, %p, %p)\n", dwMsgEncodingType,
3901 pbCtlContent, cbCtlContent, pSignInfo, dwFlags, pbEncoded, pcbEncoded);
3902
3903 if (dwFlags)
3904 {
3905 FIXME("unimplemented for flags %08lx\n", dwFlags);
3906 return FALSE;
3907 }
3908 msg = CryptMsgOpenToEncode(dwMsgEncodingType, 0, CMSG_SIGNED, pSignInfo,
3909 oid_ctl, NULL);
3910 if (msg)
3911 {
3912 ret = CryptMsgUpdate(msg, pbCtlContent, cbCtlContent, TRUE);
3913 if (ret)
3914 ret = CryptMsgGetParam(msg, CMSG_CONTENT_PARAM, 0, pbEncoded,
3915 pcbEncoded);
3917 }
3918 else
3919 ret = FALSE;
3920 return ret;
3921}
#define close
Definition: acwin.h:99
struct outqueuenode * head
Definition: adnsresfilter.c:66
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define msg(x)
Definition: auth_time.c:54
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAY_SIZE(A)
Definition: main.h:20
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
NTSTATUS WINAPI BCryptDestroyKey(BCRYPT_KEY_HANDLE)
NTSTATUS WINAPI BCryptVerifySignature(BCRYPT_KEY_HANDLE, void *, UCHAR *, ULONG, UCHAR *, ULONG, ULONG)
alg_id
Definition: bcrypt_main.c:263
Definition: _set.h:50
BOOL WINAPI CertAddStoreToCollection(HCERTSTORE hCollectionStore, HCERTSTORE hSiblingStore, DWORD dwUpdateFlags, DWORD dwPriority)
BOOL WINAPI CryptDecodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
Definition: decode.c:6998
void ContextPropertyList_Free(CONTEXT_PROPERTY_LIST *list)
Definition: proplist.c:56
BOOL WINAPI CRYPT_AsnEncodeSequence(DWORD dwCertEncodingType, struct AsnEncodeSequenceItem items[], DWORD cItem, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: encode.c:174
#define POINTER_ALIGN_DWORD_PTR(p)
BOOL CRYPT_AsnEncodePKCSDigestedData(const CRYPT_DIGESTED_DATA *digestedData, void *pvData, DWORD *pcbData)
Definition: encode.c:1946
BOOL WINAPI CRYPT_AsnEncodeOid(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: encode.c:814
CONTEXT_PROPERTY_LIST * ContextPropertyList_Create(void)
Definition: proplist.c:43
BOOL CRYPT_AsnDecodeCMSSignedInfo(const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, CRYPT_SIGNED_INFO *signedInfo, DWORD *pcbSignedInfo)
Definition: decode.c:5936
HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(ALG_ID)
Definition: main.c:215
BOOL CRYPT_AsnEncodePKCSEnvelopedData(const CRYPT_ENVELOPED_DATA *envelopedData, void *pvData, DWORD *pcbData)
Definition: encode.c:4440
BOOL WINAPI CRYPT_AsnEncodeConstructed(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: encode.c:233
BOOL CRYPT_EncodeLen(DWORD len, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: encode.c:132
BOOL CRYPT_EncodeEnsureSpace(DWORD dwFlags, const CRYPT_ENCODE_PARA *pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded, DWORD bytesNeeded)
Definition: encode.c:97
BOOL WINAPI CRYPT_AsnEncodeOctets(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: encode.c:3216
BOOL ContextPropertyList_FindProperty(CONTEXT_PROPERTY_LIST *list, DWORD id, PCRYPT_DATA_BLOB blob)
Definition: proplist.c:72
BOOL CRYPT_AsnEncodeCMSSignedInfo(CRYPT_SIGNED_INFO *, void *pvData, DWORD *pcbData)
Definition: encode.c:4345
BOOL CRYPT_AsnDecodePKCSDigestedData(const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, CRYPT_DIGESTED_DATA *digestedData, DWORD *pcbDigestedData)
Definition: decode.c:3378
#define ALIGN_DWORD_PTR(x)
BOOL ContextPropertyList_SetProperty(CONTEXT_PROPERTY_LIST *list, DWORD id, const BYTE *pbData, size_t cbData)
Definition: proplist.c:95
BOOL CRYPT_AsnDecodePKCSEnvelopedData(const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara, CRYPT_ENVELOPED_DATA *envelopedData, DWORD *pcbEnvelopedData)
Definition: decode.c:6065
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define E_INVALIDARG
Definition: ddrawi.h:101
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define mem_free(ptr, bsize)
Definition: types.h:124
#define NULL
Definition: types.h:112
#define mem_alloc(bsize)
Definition: types.h:123
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI CryptExportKey(HCRYPTKEY hKey, HCRYPTKEY hExpKey, DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: crypt.c:1383
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:715
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1584
BOOL WINAPI CryptDestroyKey(HCRYPTKEY hKey)
Definition: crypt.c:911
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:875
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:641
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1745
BOOL WINAPI CryptGenKey(HCRYPTPROV hProv, ALG_ID Algid, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1423
BOOL WINAPI CryptDecrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
Definition: crypt.c:780
BOOL WINAPI CryptVerifySignatureW(HCRYPTHASH hHash, const BYTE *pbSignature, DWORD dwSigLen, HCRYPTKEY hPubKey, LPCWSTR sDescription, DWORD dwFlags)
Definition: crypt.c:2205
BOOL WINAPI CryptGetUserKey(HCRYPTPROV hProv, DWORD dwKeySpec, HCRYPTKEY *phUserKey)
Definition: crypt.c:1694
BOOL WINAPI CryptSignHashW(HCRYPTHASH hHash, DWORD dwKeySpec, LPCWSTR sDescription, DWORD dwFlags, BYTE *pbSignature, DWORD *pdwSigLen)
Definition: crypt.c:1882
BOOL WINAPI CryptEncrypt(HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen, DWORD dwBufLen)
Definition: crypt.c:1071
BOOL WINAPI CryptImportKey(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
Definition: crypt.c:1820
content
Definition: atl_ax.c:994
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:369
BOOL WINAPI CertCompareCertificateName(DWORD dwCertEncodingType, PCERT_NAME_BLOB pCertName1, PCERT_NAME_BLOB pCertName2)
Definition: cert.c:1250
PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, DWORD dwFlags, DWORD dwType, const void *pvPara, PCCERT_CONTEXT pPrevCertContext)
Definition: cert.c:1830
BOOL cng_prepare_signature(const char *alg_oid, BYTE *encoded_sig, DWORD encoded_sig_len, BYTE **sig_value, DWORD *sig_len)
Definition: cert.c:2822
PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContext)
Definition: cert.c:358
BOOL WINAPI CertCompareIntegerBlob(PCRYPT_INTEGER_BLOB pInt1, PCRYPT_INTEGER_BLOB pInt2)
Definition: cert.c:1291
BOOL WINAPI CryptEncodeObject(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: encode.c:4909
BOOL WINAPI CryptImportPublicKeyInfoEx2(DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, DWORD dwFlags, void *pvAuxInfo, BCRYPT_KEY_HANDLE *phKey)
Definition: encode.c:5309
BOOL WINAPI CryptEncodeObjectEx(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, void *pvEncoded, DWORD *pcbEncoded)
Definition: encode.c:4950
BOOL WINAPI CryptImportPublicKeyInfo(HCRYPTPROV hCryptProv, DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, HCRYPTKEY *phKey)
Definition: encode.c:5210
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:136
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
Definition: main.c:141
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:146
static BOOL CDecodeMsg_DecodeEnvelopedContent(CDecodeMsg *msg, const CRYPT_DER_BLOB *blob)
Definition: msg.c:2242
struct _CEnvelopedDecodeMsg CEnvelopedDecodeMsg
static BOOL CSignedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:1208
static BOOL CDecodeMsg_DecodeSignedContent(CDecodeMsg *msg, const CRYPT_DER_BLOB *blob)
Definition: msg.c:2257
struct _CSignedMsgData CSignedMsgData
enum _CryptMsgState CryptMsgState
static BOOL CRYPT_DefaultMsgControl(HCRYPTMSG hCryptMsg, DWORD dwFlags, DWORD dwCtrlType, const void *pvCtrlPara)
Definition: msg.c:67
HCRYPTMSG WINAPI CryptMsgOpenToEncode(DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, const void *pvMsgEncodeInfo, LPSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:2028
static void CEnvelopedEncodeMsg_Close(HCRYPTMSG hCryptMsg)
Definition: msg.c:1792
static BOOL WINAPI CRYPT_ExportKeyTrans(PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo, PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo, PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo, DWORD dwFlags, void *pvReserved)
Definition: msg.c:1558
_CryptMsgState
Definition: msg.c:75
@ MsgStateDataFinalized
Definition: msg.c:78
@ MsgStateInit
Definition: msg.c:76
@ MsgStateUpdated
Definition: msg.c:77
@ MsgStateFinalized
Definition: msg.c:79
static BOOL CRYPT_EncodeDataContentInfoHeader(const CDataEncodeMsg *msg, CRYPT_DATA_BLOB *header)
Definition: msg.c:166
static BOOL CDecodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:3231
BOOL WINAPI CryptMsgGetAndVerifySigner(HCRYPTMSG hCryptMsg, DWORD cSignerStore, HCERTSTORE *rghSignerStore, DWORD dwFlags, PCCERT_CONTEXT *ppSigner, DWORD *pdwSignerIndex)
Definition: msg.c:3751
struct _CSignerHandles CSignerHandles
static void CRYPT_CopyBlob(CRYPT_DATA_BLOB *out, const CRYPT_DATA_BLOB *in, LPBYTE *nextData)
Definition: msg.c:2596
static CERT_INFO * CRYPT_GetSignerCertInfoFromMsg(HCRYPTMSG msg, DWORD dwSignerIndex)
Definition: msg.c:3728
HCRYPTMSG WINAPI CryptMsgOpenToDecode(DWORD dwMsgEncodingType, DWORD dwFlags, DWORD dwMsgType, HCRYPTPROV_LEGACY hCryptProv, PCERT_INFO pRecipientInfo, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:3634
static void CRYPT_FreeBlobArray(DWORD cBlobs, PCRYPT_DATA_BLOB blobs)
Definition: msg.c:752
static BOOL CRYPT_ConstructAttribute(CRYPT_ATTRIBUTE *out, const CRYPT_ATTRIBUTE *in)
Definition: msg.c:761
static BOOL CDecodeEnvelopedMsg_GetParam(CDecodeMsg *msg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:2946
static void CContentEncryptInfo_Free(CMSG_CONTENT_ENCRYPT_INFO *info)
Definition: msg.c:1736
BOOL WINAPI CryptMsgGetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:3708
static BOOL CRYPT_ImportEncryptedKey(PCRYPT_ALGORITHM_IDENTIFIER contEncrAlg, PCMSG_CTRL_DECRYPT_PARA para, PCMSG_KEY_TRANS_RECIPIENT_INFO info, HCRYPTKEY *key)
Definition: msg.c:3508
static BOOL CSignerInfo_Construct(CMSG_CMS_SIGNER_INFO *info, const CMSG_SIGNER_ENCODE_INFO_WITH_CMS *in)
Definition: msg.c:804
static BOOL CDecodeMsg_FinalizeContent(CDecodeMsg *msg, CRYPT_DER_BLOB *blob)
Definition: msg.c:2444
static BOOL CSignedMsgData_UpdateAuthenticatedAttributes(CSignedMsgData *msg_data, SignOrVerify flag)
Definition: msg.c:1063
BOOL(* CryptMsgUpdateFunc)(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:43
static BOOL CRYPT_CopyAttr(void *pvData, DWORD *pcbData, const CRYPT_ATTRIBUTES *attr)
Definition: msg.c:2995
struct _CDataEncodeMsg CDataEncodeMsg
static BOOL CRYPT_ConstructAlgorithmId(CRYPT_ALGORITHM_IDENTIFIER *out, const CRYPT_ALGORITHM_IDENTIFIER *in)
Definition: msg.c:1506
BOOL WINAPI CryptMsgSignCTL(DWORD dwMsgEncodingType, BYTE *pbCtlContent, DWORD cbCtlContent, PCMSG_SIGNED_ENCODE_INFO pSignInfo, DWORD dwFlags, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: msg.c:3892
static BOOL CDecodeMsg_DecodeContent(CDecodeMsg *msg, const CRYPT_DER_BLOB *blob, DWORD type)
Definition: msg.c:2277
static BOOL CRYPT_CopySignerInfo(void *pvData, DWORD *pcbData, const CMSG_CMS_SIGNER_INFO *in)
Definition: msg.c:2722
static BOOL CRYPT_CopyCMSSignerInfo(void *pvData, DWORD *pcbData, const CMSG_CMS_SIGNER_INFO *in)
Definition: msg.c:2794
BOOL WINAPI CryptMsgUpdate(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:3698
static BOOL CRYPT_ExportEncryptedKey(CMSG_CONTENT_ENCRYPT_INFO *info, DWORD i, CRYPT_DATA_BLOB *key)
Definition: msg.c:1623
BOOL WINAPI CryptMsgControl(HCRYPTMSG hCryptMsg, DWORD dwFlags, DWORD dwCtrlType, const void *pvCtrlPara)
Definition: msg.c:3718
static BOOL CRYPT_EncodePKCSDigestedData(CHashEncodeMsg *msg, void *pvData, DWORD *pcbData)
Definition: msg.c:409
static BOOL CRYPT_ConstructBlobArray(DWORD *outCBlobs, PCRYPT_DATA_BLOB *outPBlobs, DWORD cBlobs, const CRYPT_DATA_BLOB *pBlobs)
Definition: msg.c:729
static BOOL WINAPI CRYPT_EncodeContentLength(DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: msg.c:136
static BOOL CDecodeSignedMsg_VerifySignature(CDecodeMsg *msg, PCERT_INFO info)
Definition: msg.c:3385
static BOOL CDecodeMsg_Control(HCRYPTMSG hCryptMsg, DWORD dwFlags, DWORD dwCtrlType, const void *pvCtrlPara)
Definition: msg.c:3575
static BOOL CSignedMsgData_Sign(CSignedMsgData *msg_data)
Definition: msg.c:1126
BOOL WINAPI CryptMsgEncodeAndSignCTL(DWORD dwMsgEncodingType, PCTL_INFO pCtlInfo, PCMSG_SIGNED_ENCODE_INFO pSignInfo, DWORD dwFlags, BYTE *pbEncoded, DWORD *pcbEncoded)
Definition: msg.c:3866
static void CryptMsgBase_Init(CryptMsgBase *msg, DWORD dwFlags, PCMSG_STREAM_INFO pStreamInfo, CryptMsgCloseFunc close, CryptMsgGetParamFunc get_param, CryptMsgUpdateFunc update, CryptMsgControlFunc control)
Definition: msg.c:95
static void CRYPT_ReverseBytes(CRYPT_HASH_BLOB *hash)
Definition: msg.c:1113
BOOL(* CryptMsgControlFunc)(HCRYPTMSG hCryptMsg, DWORD dwFlags, DWORD dwCtrlType, const void *pvCtrlPara)
Definition: msg.c:46
static BOOL CHashEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:513
static BOOL CHashEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:446
static HCRYPTMSG CEnvelopedEncodeMsg_Open(DWORD dwFlags, const void *pvMsgEncodeInfo, LPCSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:1943
static BOOL CSignedEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:1315
struct _CHashEncodeMsg CHashEncodeMsg
static const BYTE empty_data_content[]
Definition: msg.c:126
static BOOL CRYPT_ConstructBlob(CRYPT_DATA_BLOB *out, const CRYPT_DATA_BLOB *in)
Definition: msg.c:711
static BOOL WINAPI CRYPT_ImportKeyTrans(PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm, PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara, DWORD dwFlags, void *pvReserved, HCRYPTKEY *phContentEncryptKey)
Definition: msg.c:3463
static BOOL CEnvelopedEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:1874
static BOOL CDataEncodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:209
static BOOL CRecipientInfo_Construct(CMSG_KEY_TRANS_RECIPIENT_INFO *info, const CERT_INFO *cert, CRYPT_DATA_BLOB *key)
Definition: msg.c:1762
static BOOL CDecodeSignedMsg_VerifySignatureEx(CDecodeMsg *msg, PCMSG_CTRL_VERIFY_SIGNATURE_EX_PARA para)
Definition: msg.c:3428
struct _CryptMsgBase CryptMsgBase
struct _CMSG_SIGNER_ENCODE_INFO_WITH_CMS CMSG_SIGNER_ENCODE_INFO_WITH_CMS
static BOOL CDecodeMsg_DecodeDataContent(CDecodeMsg *msg, const CRYPT_DER_BLOB *blob)
Definition: msg.c:2146
BOOL WINAPI CryptMsgVerifyCountersignatureEncodedEx(HCRYPTPROV_LEGACY hCryptProv, DWORD dwEncodingType, PBYTE pbSignerInfo, DWORD cbSignerInfo, PBYTE pbSignerInfoCountersignature, DWORD cbSignerInfoCountersignature, DWORD dwSignerType, void *pvSigner, DWORD dwFlags, void *pvReserved)
Definition: msg.c:3855
static void CDecodeMsg_Close(HCRYPTMSG hCryptMsg)
Definition: msg.c:2092
static void CRYPT_CopyAlgorithmId(CRYPT_ALGORITHM_IDENTIFIER *out, const CRYPT_ALGORITHM_IDENTIFIER *in, LPBYTE *nextData)
Definition: msg.c:2608
static void CRYPT_CopyAttributes(CRYPT_ATTRIBUTES *out, const CRYPT_ATTRIBUTES *in, LPBYTE *nextData)
Definition: msg.c:2620
static BOOL CRYPT_ConstructBitBlob(CRYPT_BIT_BLOB *out, const CRYPT_BIT_BLOB *in)
Definition: msg.c:1519
static BOOL CDecodeEnvelopedMsg_CrtlDecrypt(CDecodeMsg *msg, PCMSG_CTRL_DECRYPT_PARA para)
Definition: msg.c:3537
BOOL(* CryptMsgGetParamFunc)(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:40
static HCRYPTMSG CHashEncodeMsg_Open(DWORD dwFlags, const void *pvMsgEncodeInfo, LPSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:555
static BOOL CSignedMsgData_Update(CSignedMsgData *msg_data, const BYTE *pbData, DWORD cbData, BOOL fFinal, SignOrVerify flag)
Definition: msg.c:1167
struct _CMSG_ENVELOPED_ENCODE_INFO_WITH_CMS CMSG_ENVELOPED_ENCODE_INFO_WITH_CMS
HCRYPTMSG WINAPI CryptMsgDuplicate(HCRYPTMSG hCryptMsg)
Definition: msg.c:3666
static BOOL CRYPT_CopyRecipientInfo(void *pvData, DWORD *pcbData, const CERT_ISSUER_SERIAL_NUMBER *in)
Definition: msg.c:2912
static BOOL cng_verify_msg_signature(CMSG_CMS_SIGNER_INFO *signer, HCRYPTHASH hash, CERT_PUBLIC_KEY_INFO *key_info)
Definition: msg.c:3321
static BOOL CSignedMsgData_AppendMessageDigestAttribute(CSignedMsgData *msg_data, DWORD signerIndex)
Definition: msg.c:1034
static void CDecodeMsg_SaveAlgorithmID(CDecodeMsg *msg, DWORD param, const CRYPT_ALGORITHM_IDENTIFIER *id)
Definition: msg.c:2163
static HCRYPTMSG CSignedEncodeMsg_Open(DWORD dwFlags, const void *pvMsgEncodeInfo, LPCSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:1358
struct _CMSG_SIGNED_ENCODE_INFO_WITH_CMS CMSG_SIGNED_ENCODE_INFO_WITH_CMS
struct _CDecodeMsg CDecodeMsg
BOOL WINAPI CryptMsgClose(HCRYPTMSG hCryptMsg)
Definition: msg.c:3679
static BOOL CDecodeHashMsg_VerifyHash(CDecodeMsg *msg)
Definition: msg.c:3275
static void CRecipientInfo_Free(CMSG_KEY_TRANS_RECIPIENT_INFO *info)
Definition: msg.c:1783
static BOOL CSignedMsgData_UpdateHash(CSignedMsgData *msg_data, const BYTE *pbData, DWORD cbData)
Definition: msg.c:1006
static BOOL CDecodeHashMsg_GetParam(CDecodeMsg *msg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:2548
static BOOL CDecodeMsg_FinalizeHashedContent(CDecodeMsg *msg, CRYPT_DER_BLOB *blob)
Definition: msg.c:2333
static BOOL CDecodeMsg_FinalizeEnvelopedContent(CDecodeMsg *msg, CRYPT_DER_BLOB *blob)
Definition: msg.c:2378
static DWORD CRYPT_SizeOfKeyIdAsIssuerAndSerial(const CRYPT_DATA_BLOB *keyId)
Definition: msg.c:2674
static BOOL CSignedMsgData_AllocateHandles(CSignedMsgData *msg_data)
Definition: msg.c:962
static BOOL CDecodeMsg_FinalizeSignedContent(CDecodeMsg *msg, CRYPT_DER_BLOB *blob)
Definition: msg.c:2392
static BOOL CSignedMsgData_ConstructSignerHandles(CSignedMsgData *msg_data, DWORD signerIndex, HCRYPTPROV *crypt_prov, DWORD *flags)
Definition: msg.c:935
static BOOL CDecodeMsg_Update(HCRYPTMSG hCryptMsg, const BYTE *pbData, DWORD cbData, BOOL fFinal)
Definition: msg.c:2465
static BOOL CRYPT_CopyParam(void *pvData, DWORD *pcbData, const void *src, DWORD len)
Definition: msg.c:312
static BOOL CRYPT_GenKey(CMSG_CONTENT_ENCRYPT_INFO *info, ALG_ID algID)
Definition: msg.c:1536
static BOOL CRYPT_AppendAttribute(CRYPT_ATTRIBUTES *out, const CRYPT_ATTRIBUTE *in)
Definition: msg.c:1018
static void CDataEncodeMsg_Close(HCRYPTMSG hCryptMsg)
Definition: msg.c:128
static BOOL CRYPT_CopySignerCertInfo(void *pvData, DWORD *pcbData, const CMSG_CMS_SIGNER_INFO *in)
Definition: msg.c:2861
static HCRYPTMSG CDataEncodeMsg_Open(DWORD dwFlags, const void *pvMsgEncodeInfo, LPSTR pszInnerContentObjID, PCMSG_STREAM_INFO pStreamInfo)
Definition: msg.c:369
static BOOL CContentEncryptInfo_Construct(CMSG_CONTENT_ENCRYPT_INFO *info, const CMSG_ENVELOPED_ENCODE_INFO_WITH_CMS *in, HCRYPTPROV prov)
Definition: msg.c:1675
static void CRYPT_FixUpAlgorithmID(CRYPT_ALGORITHM_IDENTIFIER *id)
Definition: msg.c:2199
static BOOL CRYPT_CopyKeyIdAsIssuerAndSerial(CERT_NAME_BLOB *issuer, CRYPT_INTEGER_BLOB *serialNumber, const CRYPT_DATA_BLOB *keyId, DWORD encodedLen, LPBYTE *nextData)
Definition: msg.c:2691
static BOOL CEnvelopedEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:1812
static void CHashEncodeMsg_Close(HCRYPTMSG hCryptMsg)
Definition: msg.c:399
static BOOL CDecodeMsg_CopyData(CRYPT_DATA_BLOB *blob, const BYTE *pbData, DWORD cbData)
Definition: msg.c:2123
struct _CSignedEncodeMsg CSignedEncodeMsg
SignOrVerify
Definition: msg.c:1058
@ Verify
Definition: msg.c:1060
@ Sign
Definition: msg.c:1059
BOOL WINAPI CryptMsgVerifyCountersignatureEncoded(HCRYPTPROV_LEGACY hCryptProv, DWORD dwEncodingType, BYTE *pbSignerInfo, DWORD cbSignerInfo, PBYTE pbSignerInfoCountersignature, DWORD cbSignerInfoCountersignature, CERT_INFO *pciCountersigner)
Definition: msg.c:3844
struct _CEnvelopedEncodeMsg CEnvelopedEncodeMsg
static BOOL CRYPT_ConstructAttributes(CRYPT_ATTRIBUTES *out, const CRYPT_ATTRIBUTES *in)
Definition: msg.c:778
static void CSignedMsgData_CloseHandles(CSignedMsgData *msg_data)
Definition: msg.c:990
static BOOL CRYPT_IsValidSigner(const CMSG_SIGNER_ENCODE_INFO_WITH_CMS *signer)
Definition: msg.c:633
void(* CryptMsgCloseFunc)(HCRYPTMSG msg)
Definition: msg.c:38
static BOOL CDecodeSignedMsg_GetParam(CDecodeMsg *msg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:3021
static BOOL extract_hash(HCRYPTHASH hash, BYTE **data, DWORD *size)
Definition: msg.c:49
static void CSignerInfo_Free(CMSG_CMS_SIGNER_INFO *info)
Definition: msg.c:886
static void CSignedEncodeMsg_Close(HCRYPTMSG hCryptMsg)
Definition: msg.c:1189
static BOOL CDataEncodeMsg_GetParam(HCRYPTMSG hCryptMsg, DWORD dwParamType, DWORD dwIndex, void *pvData, DWORD *pcbData)
Definition: msg.c:333
static DWORD CRYPT_SizeOfAttributes(const CRYPT_ATTRIBUTES *attr)
Definition: msg.c:2655
static BOOL CDecodeMsg_DecodeHashedContent(CDecodeMsg *msg, const CRYPT_DER_BLOB *blob)
Definition: msg.c:2205
static BOOL CDecodeSignedMsg_VerifySignatureWithKey(CDecodeMsg *msg, HCRYPTPROV prov, DWORD signerIndex, PCERT_PUBLIC_KEY_INFO keyInfo)
Definition: msg.c:3347
static WCHAR issuer[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1972
HCRYPTOIDFUNCSET WINAPI CryptInitOIDFunctionSet(LPCSTR pszFuncName, DWORD dwFlags)
Definition: oid.c:103
BOOL WINAPI CryptGetOIDFunctionAddress(HCRYPTOIDFUNCSET hFuncSet, DWORD dwEncodingType, LPCSTR pszOID, DWORD dwFlags, void **ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
Definition: oid.c:375
LPCSTR WINAPI CertAlgIdToOID(DWORD dwAlgId)
Definition: oid.c:1803
DWORD WINAPI CertOIDToAlgId(LPCSTR pszObjId)
Definition: oid.c:1816
BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr, DWORD dwFlags)
Definition: oid.c:456
HCERTSTORE WINAPI CertOpenStore(LPCSTR lpszStoreProvider, DWORD dwMsgAndCertEncodingType, HCRYPTPROV_LEGACY hCryptProv, DWORD dwFlags, const void *pvPara)
Definition: store.c:809
BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
Definition: store.c:1121
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define __TRY
Definition: compat.h:80
#define __ENDTRY
Definition: compat.h:82
#define __EXCEPT_PAGE_FAULT
Definition: compat.h:81
static const WCHAR version[]
Definition: asmname.c:66
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
return ret
Definition: mutex.c:146
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STATUS_ACCESS_VIOLATION
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum src
Definition: glext.h:6340
GLsizeiptr size
Definition: glext.h:5919
GLuint in
Definition: glext.h:9616
GLbitfield flags
Definition: glext.h:7161
GLfloat param
Definition: glext.h:5796
GLenum GLsizei len
Definition: glext.h:6722
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define debugstr_a
Definition: kernel32.h:31
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static BYTE keyId[]
Definition: encode.c:4925
static const BYTE hashBlob[]
Definition: message.c:597
static BYTE cert[]
Definition: msg.c:1374
static const BYTE serialNumber[]
Definition: msg.c:2714
static LPCWSTR LPVOID pvReserved
Definition: asmcache.c:749
static HCRYPTPROV crypt_prov
Definition: dib.c:34
int k
Definition: mpi.c:3369
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
_In_ LPWSTR _In_ DWORD _In_ LPCVOID pvData
Definition: netsh.h:116
#define BOOL
Definition: nt_native.h:43
static TCHAR * items[]
Definition: page1.c:45
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
_In_opt_ _In_opt_ _In_ _In_ DWORD cbData
Definition: shlwapi.h:761
_In_ _Out_writes_opt_ pcchValueName _Inout_opt_ LPDWORD _Out_opt_ _Out_writes_bytes_to_opt_ pcbData _Inout_opt_ LPDWORD pcbData
Definition: shlwapi.h:757
#define ASN_OCTETSTRING
Definition: snmp.h:105
#define ASN_NULL
Definition: snmp.h:106
strcpy
Definition: string.h:131
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
DWORD bare_content_len
Definition: msg.c:122
CryptMsgBase base
Definition: msg.c:121
LPBYTE bare_content
Definition: msg.c:123
HCRYPTHASH hash
Definition: msg.c:2083
CRYPT_DATA_BLOB detached_data
Definition: msg.c:2088
DWORD type
Definition: msg.c:2080
HCRYPTPROV crypt_prov
Definition: msg.c:2081
CEnvelopedDecodeMsg enveloped_data
Definition: msg.c:2085
union _CDecodeMsg::@343 u
CSignedMsgData signed_data
Definition: msg.c:2084
CryptMsgBase base
Definition: msg.c:2079
CONTEXT_PROPERTY_LIST * properties
Definition: msg.c:2089
CRYPT_DATA_BLOB msg_data
Definition: msg.c:2087
PCERT_INFO pCertInfo
Definition: wincrypt.h:491
CRYPT_HASH_BLOB KeyId
Definition: wincrypt.h:3833
CERT_ISSUER_SERIAL_NUMBER IssuerSerialNumber
Definition: wincrypt.h:3832
DWORD dwIdChoice
Definition: wincrypt.h:3830
CERT_NAME_BLOB Issuer
Definition: wincrypt.h:253
CRYPT_INTEGER_BLOB SerialNumber
Definition: wincrypt.h:251
CERT_NAME_BLOB Issuer
Definition: wincrypt.h:3824
CRYPT_INTEGER_BLOB SerialNumber
Definition: wincrypt.h:3825
CRYPT_BIT_BLOB PublicKey
Definition: wincrypt.h:235
CRYPT_ALGORITHM_IDENTIFIER Algorithm
Definition: wincrypt.h:234
CRYPT_ENVELOPED_DATA * data
Definition: msg.c:2071
HCRYPTPROV crypt_prov
Definition: msg.c:2072
CRYPT_DATA_BLOB content
Definition: msg.c:2073
HCRYPTPROV prov
Definition: msg.c:1499
DWORD cRecipientInfo
Definition: msg.c:1501
HCRYPTKEY key
Definition: msg.c:1500
CryptMsgBase base
Definition: msg.c:1497
CRYPT_DATA_BLOB data
Definition: msg.c:1503
CMSG_KEY_TRANS_RECIPIENT_INFO * recipientInfo
Definition: msg.c:1502
CRYPT_ALGORITHM_IDENTIFIER algo
Definition: msg.c:1498
HCRYPTHASH hash
Definition: msg.c:395
HCRYPTPROV prov
Definition: msg.c:394
CryptMsgBase base
Definition: msg.c:393
CRYPT_DATA_BLOB data
Definition: msg.c:396
CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm
Definition: wincrypt.h:4129
CRYPT_DATA_BLOB EncryptedHash
Definition: wincrypt.h:4131
CRYPT_ATTRIBUTES AuthAttrs
Definition: wincrypt.h:4132
PCMSG_KEY_TRANS_RECIPIENT_INFO pKeyTrans
Definition: wincrypt.h:4242
PCMSG_RECIPIENT_ENCODE_INFO rgCmsRecipients
Definition: msg.c:1484
CRYPT_ALGORITHM_IDENTIFIER ContentEncryptionAlgorithm
Definition: msg.c:1480
HCRYPTPROV_LEGACY hCryptProv
Definition: msg.c:1479
PCRYPT_ATTRIBUTE rgUnprotectedAttr
Definition: msg.c:1492
CRYPT_DATA_BLOB EncryptedKey
Definition: wincrypt.h:4234
CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm
Definition: wincrypt.h:4233
CRYPT_ALGORITHM_IDENTIFIER KeyEncryptionAlgorithm
Definition: wincrypt.h:3910
CMSG_SIGNER_ENCODE_INFO_WITH_CMS * rgSigners
Definition: msg.c:624
CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm
Definition: msg.c:609
PCRYPT_ATTRIBUTE rgAuthAttr
Definition: msg.c:612
PCRYPT_ATTRIBUTE rgUnauthAttr
Definition: msg.c:614
CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm
Definition: msg.c:616
BYTE * pbData
Definition: wincrypt.h:112
CRYPT_OBJID_BLOB Parameters
Definition: wincrypt.h:136
BYTE * pbData
Definition: wincrypt.h:206
CRYPT_DER_BLOB Content
Definition: wincrypt.h:463
CRYPT_CONTENT_INFO ContentInfo
CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm
CRYPT_HASH_BLOB hash
PCMSG_CMS_SIGNER_INFO rgSignerInfo
CryptMsgBase base
Definition: msg.c:1183
CSignedMsgData msg_data
Definition: msg.c:1186
CRYPT_DATA_BLOB data
Definition: msg.c:1185
LPSTR innerOID
Definition: msg.c:1184
CSignerHandles * signerHandles
Definition: msg.c:928
CRYPT_SIGNED_INFO * info
Definition: msg.c:926
DWORD cSignerHandle
Definition: msg.c:927
HCRYPTHASH contentHash
Definition: msg.c:920
HCRYPTHASH authAttrHash
Definition: msg.c:921
DWORD open_flags
Definition: msg.c:85
CryptMsgControlFunc control
Definition: msg.c:92
CryptMsgGetParamFunc get_param
Definition: msg.c:91
CryptMsgState state
Definition: msg.c:88
CMSG_STREAM_INFO stream_info
Definition: msg.c:87
CryptMsgCloseFunc close
Definition: msg.c:89
LONG ref
Definition: msg.c:84
CryptMsgUpdateFunc update
Definition: msg.c:90
BOOL streamed
Definition: msg.c:86
ALG_ID aiKeyAlg
Definition: wincrypt.h:148
Definition: cookie.c:202
Definition: image.c:134
Definition: dialog.c:52
Definition: _hash_fun.h:40
Definition: copy.c:22
Definition: name.c:39
Definition: ps.c:97
const char * LPCSTR
Definition: typedefs.h:52
unsigned char * LPBYTE
Definition: typedefs.h:53
char * LPSTR
Definition: typedefs.h:51
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
struct _CMSG_CONTENT_ENCRYPT_INFO CMSG_CONTENT_ENCRYPT_INFO
#define CMSG_VERSION_PARAM
Definition: wincrypt.h:4115
#define CERT_ID_ISSUER_SERIAL_NUMBER
Definition: wincrypt.h:3838
#define HP_HASHSIZE
Definition: wincrypt.h:2388
struct _CRYPT_ATTRIBUTE CRYPT_ATTRIBUTE
#define HP_ALGID
Definition: wincrypt.h:2386
#define szOID_RSA_envelopedData
Definition: wincrypt.h:3183
#define CMSG_DATA
Definition: wincrypt.h:3844
#define CMSG_SIGNER_INFO_V1
Definition: wincrypt.h:4143
#define X509_NAME
Definition: wincrypt.h:3524
#define CMSG_HASHED
Definition: wincrypt.h:3848
#define CMSG_OID_IMPORT_KEY_TRANS_FUNC
Definition: wincrypt.h:2682
#define CMSG_ATTR_CERT_COUNT_PARAM
Definition: wincrypt.h:4116
#define CERT_STORE_PROV_COLLECTION
Definition: wincrypt.h:2465
#define CMSG_CTRL_VERIFY_HASH
Definition: wincrypt.h:4036
ULONG_PTR HCRYPTPROV_LEGACY
Definition: wincrypt.h:57
#define CMSG_COMPUTED_HASH_PARAM
Definition: wincrypt.h:4110
#define CMSG_BARE_CONTENT_PARAM
Definition: wincrypt.h:4092
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:55
#define X509_OCTET_STRING
Definition: wincrypt.h:3543
#define CMSG_TYPE_PARAM
Definition: wincrypt.h:4090
#define CERT_FIND_SUBJECT_CERT
Definition: wincrypt.h:3048
#define CMSG_CRYPT_RELEASE_CONTEXT_FLAG
Definition: wincrypt.h:4032
#define CMSG_SIGNER_CERT_INFO_PARAM
Definition: wincrypt.h:4096
struct _CRYPTOAPI_BLOB CRYPT_DATA_BLOB
struct _CRYPT_ALGORITHM_IDENTIFIER CRYPT_ALGORITHM_IDENTIFIER
BOOL(WINAPI * PFN_CMSG_IMPORT_KEY_TRANS)(PCRYPT_ALGORITHM_IDENTIFIER pContentEncryptionAlgorithm, PCMSG_CTRL_KEY_TRANS_DECRYPT_PARA pKeyTransDecryptPara, DWORD dwFlags, void *pvReserved, HCRYPTKEY *phContentEncryptKey)
Definition: wincrypt.h:4301
#define CMSG_SIGNED_AND_ENVELOPED
Definition: wincrypt.h:3847
#define CERT_ID_KEY_IDENTIFIER
Definition: wincrypt.h:3839
#define CMSG_SIGNED_DATA_V3
Definition: wincrypt.h:4139
#define CMSG_OID_EXPORT_KEY_TRANS_FUNC
Definition: wincrypt.h:2681
#define CERT_STORE_CREATE_NEW_FLAG
Definition: wincrypt.h:2633
#define szOID_RSA_hashedData
Definition: wincrypt.h:3186
unsigned int ALG_ID
Definition: wincrypt.h:54
#define CMSG_CTRL_VERIFY_SIGNATURE_EX
Definition: wincrypt.h:4050
#define CMSG_SIGNED_DATA_V1
Definition: wincrypt.h:4138
#define CMSG_VERIFY_SIGNER_CERT
Definition: wincrypt.h:4086
#define szOID_RSA_messageDigest
Definition: wincrypt.h:3191
struct _CRYPTOAPI_BLOB * PCRYPT_DATA_BLOB
#define PKCS_CONTENT_INFO
Definition: wincrypt.h:3552
#define szOID_RSA_signedData
Definition: wincrypt.h:3182
#define CALG_OID_INFO_PARAMETERS
Definition: wincrypt.h:1596
#define CMSG_ENCODED_MESSAGE
Definition: wincrypt.h:4114
#define CMSG_ENCODED_SIGNER
Definition: wincrypt.h:4113
#define CALG_OID_INFO_CNG_ONLY
Definition: wincrypt.h:1595
#define AT_KEYEXCHANGE
Definition: wincrypt.h:2239
#define CMSG_CMS_SIGNER_INFO_PARAM
Definition: wincrypt.h:4124
#define X509_ASN_ENCODING
Definition: wincrypt.h:2501
#define CMSG_INNER_CONTENT_TYPE_PARAM
Definition: wincrypt.h:4093
#define CRYPT_DECODE_ALLOC_FLAG
Definition: wincrypt.h:3612
#define CMSG_ENVELOPED
Definition: wincrypt.h:3846
#define CMSG_CTRL_DECRYPT
Definition: wincrypt.h:4035
struct _CMSG_SIGNER_INFO CMSG_SIGNER_INFO
#define CMSG_RECIPIENT_INFO_PARAM
Definition: wincrypt.h:4107
BOOL(WINAPI * PFN_CMSG_GEN_CONTENT_ENCRYPT_KEY)(PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo, DWORD dwFlags, void *pvReserved)
Definition: wincrypt.h:4291
#define CMSG_SIGNER_INFO_PARAM
Definition: wincrypt.h:4095
#define CERT_STORE_PROV_MSG
Definition: wincrypt.h:2454
struct _CMSG_CTRL_DECRYPT_PARA * PCMSG_CTRL_DECRYPT_PARA
#define szOID_RSA_contentType
Definition: wincrypt.h:3190
#define CMSG_DETACHED_FLAG
Definition: wincrypt.h:4027
#define SIMPLEBLOB
Definition: wincrypt.h:2443
ULONG_PTR HCRYPTKEY
Definition: wincrypt.h:58
#define CMSG_SIGNER_ONLY_FLAG
Definition: wincrypt.h:4309
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:59
#define szOID_KEYID_RDN
Definition: wincrypt.h:3443
#define CMSG_ENCRYPTED
Definition: wincrypt.h:3849
#define CMSG_SIGNER_UNAUTH_ATTR_PARAM
Definition: wincrypt.h:4099
#define CMSG_USE_SIGNER_INDEX_FLAG
Definition: wincrypt.h:4310
#define CMSG_SIGNED
Definition: wincrypt.h:3845
BOOL(WINAPI * PFN_CMSG_EXPORT_KEY_TRANS)(PCMSG_CONTENT_ENCRYPT_INFO pContentEncryptInfo, PCMSG_KEY_TRANS_RECIPIENT_ENCODE_INFO pKeyTransEncodeInfo, PCMSG_KEY_TRANS_ENCRYPT_INFO pKeyTransEncryptInfo, DWORD dwFlags, void *pvReserved)
Definition: wincrypt.h:4295
#define CMSG_HASHED_DATA_PKCS_1_5_VERSION
Definition: wincrypt.h:4150
#define CMSG_OID_GEN_CONTENT_ENCRYPT_KEY_FUNC
Definition: wincrypt.h:2680
struct _PUBLICKEYSTRUC BLOBHEADER
struct _CERT_INFO CERT_INFO
#define CMSG_KEY_TRANS_PKCS_1_5_VERSION
Definition: wincrypt.h:4208
#define CMSG_SIGNER_INFO_V3
Definition: wincrypt.h:4144
#define CERT_RDN_OCTET_STRING
Definition: wincrypt.h:2925
#define CMS_SIGNER_INFO
Definition: wincrypt.h:3595
#define CRYPT_ENCODE_ALLOC_FLAG
Definition: wincrypt.h:3599
#define CMSG_KEY_TRANS_RECIPIENT
Definition: wincrypt.h:3977
#define CMSG_CRL_PARAM
Definition: wincrypt.h:4103
#define szOID_CTL
Definition: wincrypt.h:3401
struct _CMSG_CMS_SIGNER_INFO CMSG_CMS_SIGNER_INFO
#define CMSG_SIGNER_COUNT_PARAM
Definition: wincrypt.h:4094
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2503
#define PKCS_ATTRIBUTES
Definition: wincrypt.h:3570
#define CMSG_HASH_ALGORITHM_PARAM
Definition: wincrypt.h:4108
#define AT_SIGNATURE
Definition: wincrypt.h:2240
#define CMSG_SIGNER_AUTH_ATTR_PARAM
Definition: wincrypt.h:4098
#define szOID_RSA_data
Definition: wincrypt.h:3181
#define CMSG_ENVELOPED_DATA_PKCS_1_5_VERSION
Definition: wincrypt.h:4155
#define CMSG_HASH_DATA_PARAM
Definition: wincrypt.h:4109
#define CMSG_TRUSTED_SIGNER_FLAG
Definition: wincrypt.h:4308
#define PKCS_CTL
Definition: wincrypt.h:3556
#define GET_CMSG_ENCODING_TYPE(x)
Definition: wincrypt.h:2497
#define CMSG_ATTR_CERT_PARAM
Definition: wincrypt.h:4117
#define szOID_RSA_digestedData
Definition: wincrypt.h:3185
#define CMSG_CERT_COUNT_PARAM
Definition: wincrypt.h:4100
#define CMSG_VERIFY_SIGNER_PUBKEY
Definition: wincrypt.h:4085
#define CMSG_RECIPIENT_COUNT_PARAM
Definition: wincrypt.h:4105
#define HP_HASHVAL
Definition: wincrypt.h:2387
#define CRYPT_EXPORTABLE
Definition: wincrypt.h:2410
#define CMSG_CONTENT_PARAM
Definition: wincrypt.h:4091
#define CMSG_CRL_COUNT_PARAM
Definition: wincrypt.h:4102
#define CMSG_CERT_PARAM
Definition: wincrypt.h:4101
#define CMSG_CTRL_VERIFY_SIGNATURE
Definition: wincrypt.h:4034
#define CUR_BLOB_VERSION
Definition: wincrypt.h:2451
#define WINAPI
Definition: msvc.h:6
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define CRYPT_E_NO_TRUSTED_SIGNER
Definition: winerror.h:4449
#define CRYPT_E_MSG_ERROR
Definition: winerror.h:4399
#define CRYPT_E_HASH_VALUE
Definition: winerror.h:4405
#define CRYPT_E_INVALID_INDEX
Definition: winerror.h:4406
#define NTE_BAD_SIGNATURE
Definition: winerror.h:4253
#define CRYPT_E_UNKNOWN_ALGO
Definition: winerror.h:4400
#define CRYPT_E_SIGNER_NOT_FOUND
Definition: winerror.h:4412
#define CRYPT_E_INVALID_MSG_TYPE
Definition: winerror.h:4402
#define CRYPT_E_CONTROL_TYPE
Definition: winerror.h:4410
#define CRYPT_E_ALREADY_DECRYPTED
Definition: winerror.h:4407
unsigned char BYTE
Definition: xxhash.c:193