Source code of Windows XP (NT5)
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.

459 lines
19 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows - Internet Security
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1997
  6. //
  7. // File: mssip.h
  8. //
  9. // Contents: Microsoft SIP Provider Main Include File
  10. //
  11. // History: 19-Feb-1997 pberkman Created
  12. //
  13. //--------------------------------------------------------------------------
  14. #ifndef MSSIP_H
  15. #define MSSIP_H
  16. #ifdef __cplusplus
  17. extern "C"
  18. {
  19. #endif
  20. #pragma pack (8)
  21. typedef CRYPT_HASH_BLOB CRYPT_DIGEST_DATA;
  22. //
  23. // dwflags
  24. //
  25. #define MSSIP_FLAGS_PROHIBIT_RESIZE_ON_CREATE 0x00010000
  26. #define MSSIP_FLAGS_USE_CATALOG 0x00020000
  27. #define SPC_INC_PE_RESOURCES_FLAG 0x80
  28. #define SPC_INC_PE_DEBUG_INFO_FLAG 0x40
  29. #define SPC_INC_PE_IMPORT_ADDR_TABLE_FLAG 0x20
  30. //////////////////////////////////////////////////////////////////////////////
  31. //
  32. // SIP_SUBJECTINFO
  33. //----------------------------------------------------------------------------
  34. // pass this structure to all defined SIPs. Make sure to initialize
  35. // the ENTIRE structure to binary zero before the FIRST call is made. Do
  36. // not initialize it BETWEEN calls!
  37. //
  38. typedef struct SIP_SUBJECTINFO_
  39. {
  40. DWORD cbSize; // set to sizeof(SIP_SUBJECTINFO)
  41. GUID *pgSubjectType; // subject type
  42. HANDLE hFile; // set to File handle that represents the subject
  43. // set to INVALID_HANDLE VALUE to allow
  44. // SIP to use pwsFileName for persistent
  45. // storage types (will handle open/close)
  46. LPCWSTR pwsFileName; // set to file name
  47. LPCWSTR pwsDisplayName; // optional: set to display name of
  48. // subject.
  49. DWORD dwReserved1; // do not use!
  50. DWORD dwIntVersion; // DO NOT SET OR CLEAR THIS.
  51. // This member is used by the sip for
  52. // passing the internal version number
  53. // between the ..get and verify... functions.
  54. HCRYPTPROV hProv;
  55. CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm;
  56. DWORD dwFlags;
  57. DWORD dwEncodingType;
  58. DWORD dwReserved2; // do not use!
  59. DWORD fdwCAPISettings; // setreg settings
  60. DWORD fdwSecuritySettings; // IE security settings
  61. DWORD dwIndex; // message index of last "Get"
  62. DWORD dwUnionChoice;
  63. # define MSSIP_ADDINFO_NONE 0
  64. # define MSSIP_ADDINFO_FLAT 1
  65. # define MSSIP_ADDINFO_CATMEMBER 2
  66. # define MSSIP_ADDINFO_BLOB 3
  67. # define MSSIP_ADDINFO_NONMSSIP 500 // everything < is reserved by MS.
  68. union
  69. {
  70. struct MS_ADDINFO_FLAT_ *psFlat;
  71. struct MS_ADDINFO_CATALOGMEMBER_ *psCatMember;
  72. struct MS_ADDINFO_BLOB_ *psBlob;
  73. };
  74. LPVOID pClientData; // data pased in from client to SIP
  75. } SIP_SUBJECTINFO, *LPSIP_SUBJECTINFO;
  76. //////////////////////////////////////////////////////////////////////////////
  77. //
  78. // MS_ADDINFO_FLAT
  79. //----------------------------------------------------------------------------
  80. // Flat or End-To-End types
  81. // needed for flat type files during indirect calls
  82. // "Digest" of file.
  83. //
  84. typedef struct MS_ADDINFO_FLAT_
  85. {
  86. DWORD cbStruct;
  87. struct SIP_INDIRECT_DATA_ *pIndirectData;
  88. } MS_ADDINFO_FLAT, *PMS_ADDINFO_FLAT;
  89. //////////////////////////////////////////////////////////////////////////////
  90. //
  91. // MS_ADDINFO_CATALOGMEMBER
  92. //----------------------------------------------------------------------------
  93. // Catalog Member verification.
  94. //
  95. typedef struct MS_ADDINFO_CATALOGMEMBER_
  96. {
  97. DWORD cbStruct; // = sizeof(MS_ADDINFO_CATALOGMEMBER)
  98. struct CRYPTCATSTORE_ *pStore; // defined in mscat.h
  99. struct CRYPTCATMEMBER_ *pMember; // defined in mscat.h
  100. } MS_ADDINFO_CATALOGMEMBER, *PMS_ADDINFO_CATALOGMEMBER;
  101. //////////////////////////////////////////////////////////////////////////////
  102. //
  103. // MS_ADDINFO_BLOB
  104. //----------------------------------------------------------------------------
  105. // Memory "blob" verification.
  106. //
  107. typedef struct MS_ADDINFO_BLOB_
  108. {
  109. DWORD cbStruct;
  110. DWORD cbMemObject;
  111. BYTE *pbMemObject;
  112. DWORD cbMemSignedMsg;
  113. BYTE *pbMemSignedMsg;
  114. } MS_ADDINFO_BLOB, *PMS_ADDINFO_BLOB;
  115. //////////////////////////////////////////////////////////////////////////////
  116. //
  117. // SIP_INDIRECT_DATA
  118. //----------------------------------------------------------------------------
  119. // Indirect data structure is used to store the hash of the subject
  120. // along with data that is relevant to the subject. This can include
  121. // names etc.
  122. //
  123. typedef struct SIP_INDIRECT_DATA_
  124. {
  125. CRYPT_ATTRIBUTE_TYPE_VALUE Data; // Encoded attribute
  126. CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm; // Digest algorithm used to hash
  127. CRYPT_HASH_BLOB Digest; // Hash of subject
  128. } SIP_INDIRECT_DATA, *PSIP_INDIRECT_DATA;
  129. #pragma pack()
  130. //////////////////////////////////////////////////////////////////////////////
  131. //
  132. // CryptSIPGetSignedDataMsg
  133. //----------------------------------------------------------------------------
  134. // Returns the message specified by the index count. Data, specific to
  135. // the subject is passed in through pSubjectInfo. To retrieve the
  136. // size of the signature, set pbData to NULL.
  137. //
  138. // Returns:
  139. // TRUE: No fatal errors
  140. // FALSE: Errors occured. See GetLastError()
  141. //
  142. // Last Errors:
  143. // ERROR_NOT_ENOUGH_MEMORY: error allocating memory
  144. // TRUST_E_SUBJECT_FORM_UNKNOWN: unknown subject type.
  145. // ERROR_INVALID_PARAMETER: bad argument passed in
  146. // ERROR_BAD_FORMAT: file/data format is not correct
  147. // for the requested SIP.
  148. // CRYPT_E_NO_MATCH: the signature could not be found
  149. // based on the dwIndex provided.
  150. // ERROR_INSUFFICIENT_BUFFER: the pbSignedDataMsg was not big
  151. // enough to hold the data. pcbSignedDataMsg
  152. // contains the required size.
  153. //
  154. extern BOOL WINAPI CryptSIPGetSignedDataMsg(
  155. IN SIP_SUBJECTINFO *pSubjectInfo,
  156. OUT DWORD *pdwEncodingType,
  157. IN DWORD dwIndex,
  158. IN OUT DWORD *pcbSignedDataMsg,
  159. OUT BYTE *pbSignedDataMsg);
  160. typedef BOOL (WINAPI * pCryptSIPGetSignedDataMsg)(
  161. IN SIP_SUBJECTINFO *pSubjectInfo,
  162. OUT DWORD *pdwEncodingType,
  163. IN DWORD dwIndex,
  164. IN OUT DWORD *pcbSignedDataMsg,
  165. OUT BYTE *pbSignedDataMsg);
  166. //////////////////////////////////////////////////////////////////////////////
  167. //
  168. // CryptSIPPuttSignedDataMsg
  169. //----------------------------------------------------------------------------
  170. // Adds a signature to the subject. The index that it was
  171. // stored with is returned for future reference.
  172. //
  173. // Returns:
  174. // TRUE: No fatal errors
  175. // FALSE: Errors occured. See GetLastError()
  176. //
  177. // Last Errors:
  178. // ERROR_NOT_ENOUGH_MEMORY: error allocating memory
  179. // TRUST_E_SUBJECT_FORM_UNKNOWN: unknown subject type.
  180. // CRYPT_E_BAD_LEN: the length specified in
  181. // psData->dwSignature was
  182. // insufficient.
  183. // CRYPT_E_NO_MATCH: could not find the specified index
  184. // ERROR_INVALID_PARAMETER: bad argument passed in
  185. // ERROR_BAD_FORMAT: file/data format is not correct
  186. // for the requested SIP.
  187. // CRYPT_E_FILERESIZED: returned when signing a fixed-length
  188. // file (e.g.: CABs) and the message
  189. // is larger than the pre-allocated
  190. // size. The 'put' function will re-
  191. // size the file and return this error.
  192. // The CreateIndirect function MUST be
  193. // called again to recalculate the
  194. // indirect data (hash). Then, call the
  195. // 'put' function again.
  196. //
  197. extern BOOL WINAPI CryptSIPPutSignedDataMsg(
  198. IN SIP_SUBJECTINFO *pSubjectInfo,
  199. IN DWORD dwEncodingType,
  200. OUT DWORD *pdwIndex,
  201. IN DWORD cbSignedDataMsg,
  202. IN BYTE *pbSignedDataMsg);
  203. typedef BOOL (WINAPI * pCryptSIPPutSignedDataMsg)(
  204. IN SIP_SUBJECTINFO *pSubjectInfo,
  205. IN DWORD dwEncodingType,
  206. OUT DWORD *pdwIndex,
  207. IN DWORD cbSignedDataMsg,
  208. IN BYTE *pbSignedDataMsg);
  209. //////////////////////////////////////////////////////////////////////////////
  210. //
  211. // CryptSIPCreateIndirectData
  212. //----------------------------------------------------------------------------
  213. // Returns a PSIP_INDIRECT_DATA structure filled in the hash, digest alogrithm
  214. // and an encoded attribute. If pcIndirectData points to a DWORD and
  215. // psIndirect data points to null the the size of the data should be returned
  216. // in pcIndirectData.
  217. //
  218. // Returns:
  219. // TRUE: No fatal errors
  220. // FALSE: Errors occured. See GetLastError()
  221. //
  222. // Last Errors:
  223. // NTE_BAD_ALGID: Bad Algorithm Identifyer
  224. // ERROR_NOT_ENOUGH_MEMORY: error allocating memory
  225. // TRUST_E_SUBJECT_FORM_UNKNOWN: unknown subject type.
  226. // ERROR_INVALID_PARAMETER: bad argument passed in
  227. // ERROR_BAD_FORMAT: file/data format is not correct
  228. // for the requested SIP.
  229. //
  230. extern BOOL WINAPI CryptSIPCreateIndirectData(
  231. IN SIP_SUBJECTINFO *pSubjectInfo,
  232. IN OUT DWORD *pcbIndirectData,
  233. OUT SIP_INDIRECT_DATA *pIndirectData);
  234. typedef BOOL (WINAPI * pCryptSIPCreateIndirectData)(
  235. IN SIP_SUBJECTINFO *pSubjectInfo,
  236. IN OUT DWORD *pcbIndirectData,
  237. OUT SIP_INDIRECT_DATA *pIndirectData);
  238. //////////////////////////////////////////////////////////////////////////////
  239. //
  240. // CryptSIPVerifyIndirectData
  241. //----------------------------------------------------------------------------
  242. // Takes the information stored in the indirect data and compares it to the
  243. // subject.
  244. //
  245. // Returns:
  246. // TRUE: No fatal errors
  247. // FALSE: Errors occured. See GetLastError()
  248. //
  249. // Last Errors:
  250. // NTE_BAD_ALGID: Bad Algorithm Identifyer
  251. // ERROR_NOT_ENOUGH_MEMORY: error allocating memory
  252. // TRUST_E_SUBJECT_FORM_UNKNOWN: unknown subject type.
  253. // CRYPT_E_NO_MATCH: could not find the specified index
  254. // CRYPT_E_SECURITY_SETTINGS: due to security settings, the file
  255. // was not verified.
  256. // ERROR_INVALID_PARAMETER: bad argument passed in
  257. // ERROR_BAD_FORMAT: file/data format is not correct
  258. // for the requested SIP.
  259. extern BOOL WINAPI CryptSIPVerifyIndirectData(
  260. IN SIP_SUBJECTINFO *pSubjectInfo,
  261. IN SIP_INDIRECT_DATA *pIndirectData);
  262. typedef BOOL (WINAPI * pCryptSIPVerifyIndirectData)(
  263. IN SIP_SUBJECTINFO *pSubjectInfo,
  264. IN SIP_INDIRECT_DATA *pIndirectData);
  265. //////////////////////////////////////////////////////////////////////////////
  266. //
  267. // CryptSIPRemoveSignedDataMsg
  268. //----------------------------------------------------------------------------
  269. // Removes the signature at the specified index
  270. //
  271. // Returns:
  272. // TRUE: No fatal errors
  273. // FALSE: Errors occured. See GetLastError()
  274. //
  275. // Last Errors:
  276. // TRUST_E_SUBJECT_FORM_UNKNOWN: unknown subject type.
  277. // CRYPT_E_NO_MATCH: could not find the specified index
  278. // ERROR_INVALID_PARAMETER: bad argument passed in
  279. // ERROR_BAD_FORMAT: file/data format is not correct
  280. // for the requested SIP.
  281. //
  282. extern BOOL WINAPI CryptSIPRemoveSignedDataMsg(
  283. IN SIP_SUBJECTINFO *pSubjectInfo,
  284. IN DWORD dwIndex);
  285. typedef BOOL (WINAPI * pCryptSIPRemoveSignedDataMsg)(
  286. IN SIP_SUBJECTINFO *pSubjectInfo,
  287. IN DWORD dwIndex);
  288. #pragma pack(8)
  289. //////////////////////////////////////////////////////////////////////////////
  290. //
  291. // SIP_DISPATCH_INFO
  292. //----------------------------------------------------------------------------
  293. //
  294. typedef struct SIP_DISPATCH_INFO_
  295. {
  296. DWORD cbSize; // = sizeof(SIP_DISPATCH_INFO)
  297. HANDLE hSIP; // used internal
  298. pCryptSIPGetSignedDataMsg pfGet;
  299. pCryptSIPPutSignedDataMsg pfPut;
  300. pCryptSIPCreateIndirectData pfCreate;
  301. pCryptSIPVerifyIndirectData pfVerify;
  302. pCryptSIPRemoveSignedDataMsg pfRemove;
  303. } SIP_DISPATCH_INFO, *LPSIP_DISPATCH_INFO;
  304. //
  305. // the sip exports this function to allow verification and signing
  306. // processes to pass in the file handle and check if the sip supports
  307. // this type of file. if it does, the sip will return TRUE and fill
  308. // out the pgSubject with the appropiate GUID.
  309. //
  310. typedef BOOL (WINAPI *pfnIsFileSupported)(IN HANDLE hFile,
  311. OUT GUID *pgSubject);
  312. typedef BOOL (WINAPI *pfnIsFileSupportedName)(IN WCHAR *pwszFileName,
  313. OUT GUID *pgSubject);
  314. typedef struct SIP_ADD_NEWPROVIDER_
  315. {
  316. DWORD cbStruct;
  317. GUID *pgSubject;
  318. WCHAR *pwszDLLFileName;
  319. WCHAR *pwszMagicNumber; // optional
  320. WCHAR *pwszIsFunctionName; // optiona: pfnIsFileSupported
  321. WCHAR *pwszGetFuncName;
  322. WCHAR *pwszPutFuncName;
  323. WCHAR *pwszCreateFuncName;
  324. WCHAR *pwszVerifyFuncName;
  325. WCHAR *pwszRemoveFuncName;
  326. WCHAR *pwszIsFunctionNameFmt2; // optiona: pfnIsFileSupported
  327. } SIP_ADD_NEWPROVIDER, *PSIP_ADD_NEWPROVIDER;
  328. #define SIP_MAX_MAGIC_NUMBER 4
  329. #pragma pack()
  330. //////////////////////////////////////////////////////////////////////////////
  331. //
  332. // CryptLoadSIP
  333. //----------------------------------------------------------------------------
  334. //
  335. // Returns:
  336. // TRUE: No fatal errors
  337. // FALSE: Errors occured. See GetLastError()
  338. //
  339. extern BOOL WINAPI CryptSIPLoad(IN const GUID *pgSubject, // GUID for the requried sip
  340. IN DWORD dwFlags, // Reserved - MUST BE ZERO
  341. IN OUT SIP_DISPATCH_INFO *pSipDispatch); // Table of functions
  342. //////////////////////////////////////////////////////////////////////////////
  343. //
  344. // CryptSIPRetrieveSubjectGuid (defined in crypt32.dll)
  345. //----------------------------------------------------------------------------
  346. // looks at the file's "Magic Number" and tries to determine which
  347. // SIP's object ID is right for the file type.
  348. //
  349. // NOTE: This function only supports the MSSIP32.DLL set of SIPs.
  350. //
  351. // Returns:
  352. // TRUE: No fatal errors
  353. // FALSE: Errors occured. See GetLastError()
  354. //
  355. extern BOOL WINAPI CryptSIPRetrieveSubjectGuid(IN LPCWSTR FileName, // wide file name
  356. IN OPTIONAL HANDLE hFileIn, // or handle of open file
  357. OUT GUID *pgSubject); // defined SIP's GUID
  358. //////////////////////////////////////////////////////////////////////////////
  359. //
  360. // CryptSIPRetrieveSubjectGuidForCatalogFile (defined in crypt32.dll)
  361. //----------------------------------------------------------------------------
  362. // looks at the file's "Magic Number" and tries to determine which
  363. // SIP's object ID is right for the file type.
  364. //
  365. // NOTE: This function only supports SIPs that are used for catalog files (either PE, CAB, or flat).
  366. //
  367. // Returns:
  368. // TRUE: No fatal errors
  369. // FALSE: Errors occured. See GetLastError()
  370. //
  371. extern BOOL WINAPI CryptSIPRetrieveSubjectGuidForCatalogFile(IN LPCWSTR FileName, // wide file name
  372. IN OPTIONAL HANDLE hFileIn, // or handle of open file
  373. OUT GUID *pgSubject); // defined SIP's GUID
  374. //////////////////////////////////////////////////////////////////////////////
  375. //
  376. // CryptSIPAddProvider
  377. //----------------------------------------------------------------------------
  378. //
  379. // Returns:
  380. // TRUE: No fatal errors
  381. // FALSE: Errors occured. See GetLastError()
  382. //
  383. extern BOOL WINAPI CryptSIPAddProvider(IN SIP_ADD_NEWPROVIDER *psNewProv);
  384. //////////////////////////////////////////////////////////////////////////////
  385. //
  386. // CryptSIPRemoveProvider
  387. //----------------------------------------------------------------------------
  388. //
  389. // Returns:
  390. // TRUE: No fatal errors
  391. // FALSE: Errors occured. See GetLastError()
  392. //
  393. extern BOOL WINAPI CryptSIPRemoveProvider(IN GUID *pgProv);
  394. #ifdef __cplusplus
  395. }
  396. #endif
  397. #endif // MSSIP_H