Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: IndData.cpp
  8. //
  9. // Contents: Microsoft Internet Security Catalog Utilities
  10. // implements the Certificate Trust List & persistent storage
  11. //
  12. // Functions: CatalogDecodeIndirectData
  13. // CatalogReallyDecodeIndirectData
  14. // CatalogEncodeIndirectData
  15. //
  16. // History: 16-May-1997 pberkman created
  17. // 01-Oct-1997 pberkman add lazy decode
  18. //
  19. //--------------------------------------------------------------------------
  20. #include "global.hxx"
  21. #include "mscat32.h"
  22. BOOL CatalogDecodeIndirectData(CRYPTCATSTORE *pCat, CRYPTCATMEMBER *pMember, CRYPT_ATTRIBUTE *pAttr)
  23. {
  24. DELETE_OBJECT(pMember->sEncodedIndirectData.pbData);
  25. if (pAttr->rgValue->cbData < 1)
  26. {
  27. return(FALSE);
  28. }
  29. if (!(pMember->sEncodedIndirectData.pbData = (BYTE *)CatalogNew(pAttr->rgValue->cbData)))
  30. {
  31. pMember->sEncodedIndirectData.cbData = 0;
  32. return(FALSE);
  33. }
  34. pMember->sEncodedIndirectData.cbData = pAttr->rgValue->cbData;
  35. memcpy(pMember->sEncodedIndirectData.pbData, pAttr->rgValue->pbData, pAttr->rgValue->cbData);
  36. return(TRUE);
  37. }
  38. BOOL CatalogReallyDecodeIndirectData(CRYPTCATSTORE *pCat, CRYPTCATMEMBER *pMember, CRYPT_ATTR_BLOB *pAttr)
  39. {
  40. DWORD cbDecode;
  41. SIP_INDIRECT_DATA *pInd;
  42. cbDecode = 0;
  43. CryptDecodeObject(pCat->dwEncodingType,
  44. SPC_INDIRECT_DATA_CONTENT_STRUCT,
  45. pAttr->pbData,
  46. pAttr->cbData,
  47. 0,
  48. NULL,
  49. &cbDecode);
  50. if (cbDecode > 0)
  51. {
  52. if (!(pInd = (SIP_INDIRECT_DATA *)CatalogNew(cbDecode)))
  53. {
  54. return(FALSE);
  55. }
  56. if (!(CryptDecodeObject(pCat->dwEncodingType,
  57. SPC_INDIRECT_DATA_CONTENT_STRUCT,
  58. pAttr->pbData,
  59. pAttr->cbData,
  60. 0,
  61. pInd,
  62. &cbDecode)))
  63. {
  64. delete pInd;
  65. return(FALSE);
  66. }
  67. if (!(pMember->pIndirectData = (SIP_INDIRECT_DATA *)CatalogNew(sizeof(SIP_INDIRECT_DATA))))
  68. {
  69. delete pInd;
  70. return(FALSE);
  71. }
  72. memset(pMember->pIndirectData, 0x00, sizeof(SIP_INDIRECT_DATA));
  73. pMember->pIndirectData->Data.pszObjId = (LPSTR)CatalogNew(strlen(pInd->Data.pszObjId) + 1);
  74. if (pInd->Data.Value.cbData > 0)
  75. {
  76. pMember->pIndirectData->Data.Value.pbData =
  77. (BYTE *)CatalogNew(pInd->Data.Value.cbData);
  78. pMember->pIndirectData->Data.Value.cbData = pInd->Data.Value.cbData;
  79. }
  80. pMember->pIndirectData->DigestAlgorithm.pszObjId =
  81. (LPSTR)CatalogNew(strlen(pInd->DigestAlgorithm.pszObjId) + 1);
  82. if (pInd->Digest.cbData > 0)
  83. {
  84. pMember->pIndirectData->Digest.pbData = (BYTE *)CatalogNew(pInd->Digest.cbData);
  85. pMember->pIndirectData->Digest.cbData = pInd->Digest.cbData;
  86. }
  87. if (!(pMember->pIndirectData->Data.pszObjId) ||
  88. ((pInd->Data.Value.cbData > 0) && !(pMember->pIndirectData->Data.Value.pbData)) ||
  89. !(pMember->pIndirectData->DigestAlgorithm.pszObjId) ||
  90. ((pInd->Digest.cbData > 0) && !(pMember->pIndirectData->Digest.pbData)))
  91. {
  92. delete pInd;
  93. return(FALSE);
  94. }
  95. strcpy(pMember->pIndirectData->Data.pszObjId, pInd->Data.pszObjId);
  96. if (pInd->Data.Value.cbData > 0)
  97. {
  98. memcpy(pMember->pIndirectData->Data.Value.pbData,
  99. pInd->Data.Value.pbData, pInd->Data.Value.cbData);
  100. }
  101. strcpy(pMember->pIndirectData->DigestAlgorithm.pszObjId,
  102. pInd->DigestAlgorithm.pszObjId);
  103. if (pInd->Digest.cbData > 0)
  104. {
  105. memcpy(pMember->pIndirectData->Digest.pbData,
  106. pInd->Digest.pbData, pInd->Digest.cbData);
  107. }
  108. delete pInd;
  109. return(TRUE);
  110. }
  111. return(FALSE);
  112. }
  113. BOOL CatalogEncodeIndirectData(CRYPTCATSTORE *pCat, CRYPTCATMEMBER *pMember,
  114. PCRYPT_ATTRIBUTE pCryptAttr)
  115. {
  116. if (!(pCryptAttr->rgValue = (PCRYPT_ATTR_BLOB)CatalogNew(sizeof(CRYPT_ATTR_BLOB))))
  117. {
  118. return(FALSE);
  119. }
  120. pCryptAttr->cValue = 1;
  121. memset(pCryptAttr->rgValue, 0x00, sizeof(CRYPT_ATTR_BLOB));
  122. if (!(pMember->pIndirectData))
  123. {
  124. return(FALSE);
  125. }
  126. pCryptAttr->pszObjId = SPC_INDIRECT_DATA_OBJID;
  127. DWORD cbEncoded;
  128. cbEncoded = 0;
  129. CryptEncodeObject(pCat->dwEncodingType,
  130. pCryptAttr->pszObjId,
  131. pMember->pIndirectData,
  132. NULL,
  133. &cbEncoded);
  134. if (cbEncoded > 0)
  135. {
  136. if (!(pCryptAttr->rgValue->pbData = (BYTE *)CatalogNew(cbEncoded)))
  137. {
  138. return(FALSE);
  139. }
  140. pCryptAttr->rgValue->cbData = cbEncoded;
  141. if (!(CryptEncodeObject(pCat->dwEncodingType,
  142. pCryptAttr->pszObjId,
  143. pMember->pIndirectData,
  144. pCryptAttr->rgValue->pbData,
  145. &cbEncoded)))
  146. {
  147. return(FALSE);
  148. }
  149. return(TRUE);
  150. }
  151. return(FALSE);
  152. }