mssip.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:20k
源码类别:

模拟服务器

开发平台:

C/C++

  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.                                 
  113.     DWORD                       cbMemSignedMsg;
  114.     BYTE                        *pbMemSignedMsg;
  115. } MS_ADDINFO_BLOB, *PMS_ADDINFO_BLOB;
  116. //////////////////////////////////////////////////////////////////////////////
  117. //
  118. // SIP_INDIRECT_DATA
  119. //----------------------------------------------------------------------------
  120. // Indirect data structure is used to store the hash of the subject 
  121. // along with data that is relevant to the subject.  This can include 
  122. // names etc.
  123. //
  124. typedef struct SIP_INDIRECT_DATA_
  125. {
  126.     CRYPT_ATTRIBUTE_TYPE_VALUE    Data;            // Encoded attribute
  127.     CRYPT_ALGORITHM_IDENTIFIER    DigestAlgorithm; // Digest algorithm used to hash
  128.     CRYPT_HASH_BLOB               Digest;          // Hash of subject
  129. } SIP_INDIRECT_DATA, *PSIP_INDIRECT_DATA;
  130. #pragma pack()
  131. //////////////////////////////////////////////////////////////////////////////
  132. //
  133. // CryptSIPGetSignedDataMsg
  134. //----------------------------------------------------------------------------
  135. // Returns the message specified by the index count. Data, specific to 
  136. // the subject is passed in through pSubjectInfo. To retrieve the
  137. // size of the signature, set pbData to NULL.
  138. //
  139. // Returns:
  140. //      TRUE:                           No fatal errors
  141. //      FALSE:                          Errors occured.  See GetLastError()
  142. //
  143. // Last Errors:
  144. //      ERROR_NOT_ENOUGH_MEMORY:        error allocating memory
  145. //      TRUST_E_SUBJECT_FORM_UNKNOWN:   unknown subject type.
  146. //      ERROR_INVALID_PARAMETER:        bad argument passed in
  147. //      ERROR_BAD_FORMAT:               file/data format is not correct
  148. //                                      for the requested SIP.
  149. //      CRYPT_E_NO_MATCH:               the signature could not be found
  150. //                                      based on the dwIndex provided.
  151. //      ERROR_INSUFFICIENT_BUFFER:      the pbSignedDataMsg was not big
  152. //                                      enough to hold the data.  pcbSignedDataMsg
  153. //                                      contains the required size.
  154. //
  155. extern BOOL WINAPI CryptSIPGetSignedDataMsg(   
  156.                                 IN      SIP_SUBJECTINFO *pSubjectInfo,
  157.                                 OUT     DWORD           *pdwEncodingType,
  158.                                 IN      DWORD           dwIndex,
  159.                                 IN OUT  DWORD           *pcbSignedDataMsg,
  160.                                 OUT     BYTE            *pbSignedDataMsg);
  161. typedef BOOL (WINAPI * pCryptSIPGetSignedDataMsg)(   
  162.                                 IN      SIP_SUBJECTINFO *pSubjectInfo,
  163.                                 OUT     DWORD           *pdwEncodingType,
  164.                                 IN      DWORD           dwIndex,
  165.                                 IN OUT  DWORD           *pcbSignedDataMsg,
  166.                                 OUT     BYTE            *pbSignedDataMsg);
  167. //////////////////////////////////////////////////////////////////////////////
  168. //
  169. // CryptSIPPuttSignedDataMsg
  170. //----------------------------------------------------------------------------
  171. // Adds a signature to the subject. The index that it was 
  172. // stored with is returned for future reference.
  173. //
  174. // Returns:
  175. //      TRUE:                           No fatal errors
  176. //      FALSE:                        Errors occured.  See GetLastError()
  177. //
  178. // Last Errors:
  179. //      ERROR_NOT_ENOUGH_MEMORY:        error allocating memory
  180. //      TRUST_E_SUBJECT_FORM_UNKNOWN:   unknown subject type.
  181. //      CRYPT_E_BAD_LEN:                the length specified in 
  182. //                                      psData->dwSignature was
  183. //                                      insufficient.
  184. //      CRYPT_E_NO_MATCH:               could not find the specified index
  185. //      ERROR_INVALID_PARAMETER:        bad argument passed in
  186. //      ERROR_BAD_FORMAT:               file/data format is not correct
  187. //                                      for the requested SIP.
  188. //      CRYPT_E_FILERESIZED:            returned when signing a fixed-length
  189. //                                      file (e.g.: CABs) and the message
  190. //                                      is larger than the pre-allocated
  191. //                                      size.  The 'put' function will re-
  192. //                                      size the file and return this error.
  193. //                                      The CreateIndirect function MUST be
  194. //                                      called again to recalculate the 
  195. //                                      indirect data (hash).  Then, call the
  196. //                                      'put' function again.
  197. //
  198. extern BOOL WINAPI CryptSIPPutSignedDataMsg(   
  199.                                 IN      SIP_SUBJECTINFO *pSubjectInfo,
  200.                                 IN      DWORD           dwEncodingType,
  201.                                 OUT     DWORD           *pdwIndex,
  202.                                 IN      DWORD           cbSignedDataMsg,
  203.                                 IN      BYTE            *pbSignedDataMsg);
  204. typedef BOOL (WINAPI * pCryptSIPPutSignedDataMsg)(   
  205.                                 IN      SIP_SUBJECTINFO *pSubjectInfo,
  206.                                 IN      DWORD           dwEncodingType,
  207.                                 OUT     DWORD           *pdwIndex,
  208.                                 IN      DWORD           cbSignedDataMsg,
  209.                                 IN      BYTE            *pbSignedDataMsg);
  210. //////////////////////////////////////////////////////////////////////////////
  211. //
  212. // CryptSIPCreateIndirectData
  213. //----------------------------------------------------------------------------
  214. // Returns a PSIP_INDIRECT_DATA structure filled in the hash, digest alogrithm
  215. // and an encoded attribute. If pcIndirectData points to a DWORD and 
  216. // psIndirect data points to null the the size of the data should be returned
  217. // in pcIndirectData.
  218. //
  219. // Returns:
  220. //      TRUE:                           No fatal errors
  221. //      FALSE:                          Errors occured.  See GetLastError()
  222. //
  223. // Last Errors:
  224. //      NTE_BAD_ALGID:                  Bad Algorithm Identifyer
  225. //      ERROR_NOT_ENOUGH_MEMORY:        error allocating memory
  226. //      TRUST_E_SUBJECT_FORM_UNKNOWN:   unknown subject type.
  227. //      ERROR_INVALID_PARAMETER:        bad argument passed in
  228. //      ERROR_BAD_FORMAT:               file/data format is not correct
  229. //                                      for the requested SIP.
  230. //
  231. extern BOOL WINAPI CryptSIPCreateIndirectData(
  232.                                 IN      SIP_SUBJECTINFO     *pSubjectInfo,
  233.                                 IN OUT  DWORD               *pcbIndirectData,
  234.                                 OUT     SIP_INDIRECT_DATA   *pIndirectData);
  235. typedef BOOL (WINAPI * pCryptSIPCreateIndirectData)(
  236.                                 IN      SIP_SUBJECTINFO     *pSubjectInfo,
  237.                                 IN OUT  DWORD               *pcbIndirectData,
  238.                                 OUT     SIP_INDIRECT_DATA   *pIndirectData);
  239. //////////////////////////////////////////////////////////////////////////////
  240. //
  241. // CryptSIPVerifyIndirectData
  242. //----------------------------------------------------------------------------
  243. // Takes the information stored in the indirect data and compares it to the
  244. // subject. 
  245. //
  246. // Returns: 
  247. //      TRUE:                           No fatal errors
  248. //      FALSE:                          Errors occured.  See GetLastError()
  249. //
  250. // Last Errors:
  251. //      NTE_BAD_ALGID:                  Bad Algorithm Identifyer
  252. //      ERROR_NOT_ENOUGH_MEMORY:        error allocating memory
  253. //      TRUST_E_SUBJECT_FORM_UNKNOWN:   unknown subject type.
  254. //      CRYPT_E_NO_MATCH:               could not find the specified index
  255. //      CRYPT_E_SECURITY_SETTINGS:      due to security settings, the file
  256. //                                      was not verified.
  257. //      ERROR_INVALID_PARAMETER:        bad argument passed in
  258. //      ERROR_BAD_FORMAT:               file/data format is not correct
  259. //                                      for the requested SIP.
  260. extern BOOL WINAPI CryptSIPVerifyIndirectData(
  261.                                 IN      SIP_SUBJECTINFO     *pSubjectInfo,
  262.                                 IN      SIP_INDIRECT_DATA   *pIndirectData);
  263. typedef BOOL (WINAPI * pCryptSIPVerifyIndirectData)(
  264.                                 IN      SIP_SUBJECTINFO     *pSubjectInfo,
  265.                                 IN      SIP_INDIRECT_DATA   *pIndirectData);
  266. //////////////////////////////////////////////////////////////////////////////
  267. //
  268. // CryptSIPRemoveSignedDataMsg
  269. //----------------------------------------------------------------------------
  270. // Removes the signature at the specified index
  271. //
  272. // Returns: 
  273. //      TRUE:                           No fatal errors
  274. //      FALSE:                          Errors occured.  See GetLastError()
  275. //
  276. // Last Errors:
  277. //      TRUST_E_SUBJECT_FORM_UNKNOWN:   unknown subject type.
  278. //      CRYPT_E_NO_MATCH:               could not find the specified index
  279. //      ERROR_INVALID_PARAMETER:        bad argument passed in
  280. //      ERROR_BAD_FORMAT:               file/data format is not correct
  281. //                                      for the requested SIP.
  282. //
  283. extern BOOL WINAPI CryptSIPRemoveSignedDataMsg(
  284.                                 IN      SIP_SUBJECTINFO     *pSubjectInfo,
  285.                                 IN      DWORD               dwIndex);
  286. typedef BOOL (WINAPI * pCryptSIPRemoveSignedDataMsg)(
  287.                                 IN      SIP_SUBJECTINFO     *pSubjectInfo,
  288.                                 IN      DWORD               dwIndex);
  289. #pragma pack(8)
  290. //////////////////////////////////////////////////////////////////////////////
  291. //
  292. // SIP_DISPATCH_INFO
  293. //----------------------------------------------------------------------------
  294. //
  295. typedef struct SIP_DISPATCH_INFO_
  296. {
  297.     DWORD                           cbSize;     // = sizeof(SIP_DISPATCH_INFO)
  298.     HANDLE                          hSIP;       // used internal
  299.     pCryptSIPGetSignedDataMsg       pfGet;
  300.     pCryptSIPPutSignedDataMsg       pfPut;
  301.     pCryptSIPCreateIndirectData     pfCreate;
  302.     pCryptSIPVerifyIndirectData     pfVerify;
  303.     pCryptSIPRemoveSignedDataMsg    pfRemove;
  304. } SIP_DISPATCH_INFO, *LPSIP_DISPATCH_INFO;
  305. //
  306. // the sip exports this function to allow verification and signing
  307. // processes to pass in the file handle and check if the sip supports
  308. // this type of file.  if it does, the sip will return TRUE and fill
  309. // out the pgSubject with the appropiate GUID.
  310. //
  311. typedef BOOL (WINAPI *pfnIsFileSupported)(IN  HANDLE  hFile,
  312.                                    OUT GUID    *pgSubject);
  313. typedef BOOL (WINAPI *pfnIsFileSupportedName)(IN WCHAR *pwszFileName,
  314.                                        OUT GUID *pgSubject);
  315. typedef struct SIP_ADD_NEWPROVIDER_
  316. {
  317.     DWORD                           cbStruct;
  318.     GUID                            *pgSubject;
  319.     WCHAR                           *pwszDLLFileName;
  320.     WCHAR                           *pwszMagicNumber;   // optional
  321.     
  322.     WCHAR                           *pwszIsFunctionName; // optiona: pfnIsFileSupported
  323.     WCHAR                           *pwszGetFuncName;
  324.     WCHAR                           *pwszPutFuncName;
  325.     WCHAR                           *pwszCreateFuncName;
  326.     WCHAR                           *pwszVerifyFuncName;
  327.     WCHAR                           *pwszRemoveFuncName;
  328.     WCHAR                           *pwszIsFunctionNameFmt2; // optiona: pfnIsFileSupported
  329. } SIP_ADD_NEWPROVIDER, *PSIP_ADD_NEWPROVIDER;
  330. #define SIP_MAX_MAGIC_NUMBER        4
  331. #pragma pack()
  332. //////////////////////////////////////////////////////////////////////////////
  333. //
  334. // CryptLoadSIP 
  335. //----------------------------------------------------------------------------
  336. //
  337. // Returns: 
  338. //      TRUE:                           No fatal errors
  339. //      FALSE:                          Errors occured.  See GetLastError()
  340. //
  341. extern BOOL WINAPI CryptSIPLoad(IN const GUID               *pgSubject,     // GUID for the requried sip
  342.                                 IN DWORD                    dwFlags,        // Reserved - MUST BE ZERO
  343.                                 IN OUT SIP_DISPATCH_INFO    *pSipDispatch); // Table of functions
  344. //////////////////////////////////////////////////////////////////////////////
  345. //
  346. // CryptSIPRetrieveSubjectGuid (defined in crypt32.dll)
  347. //----------------------------------------------------------------------------
  348. // looks at the file's "Magic Number" and tries to determine which
  349. // SIP's object ID is right for the file type.
  350. // 
  351. // NOTE:  This function only supports the MSSIP32.DLL set of SIPs.
  352. //
  353. // Returns: 
  354. //      TRUE:                           No fatal errors
  355. //      FALSE:                          Errors occured.  See GetLastError()
  356. //
  357. extern BOOL WINAPI CryptSIPRetrieveSubjectGuid(IN LPCWSTR FileName,   // wide file name
  358.                                                IN OPTIONAL HANDLE hFileIn,     // or handle of open file
  359.                                                OUT GUID *pgSubject);           // defined SIP's GUID
  360.                                                //////////////////////////////////////////////////////////////////////////////
  361. //
  362. // CryptSIPRetrieveSubjectGuidForCatalogFile (defined in crypt32.dll)
  363. //----------------------------------------------------------------------------
  364. // looks at the file's "Magic Number" and tries to determine which
  365. // SIP's object ID is right for the file type.
  366. // 
  367. // NOTE:  This function only supports SIPs that are used for catalog files (either PE, CAB, or flat).
  368. //
  369. // Returns: 
  370. //      TRUE:                           No fatal errors
  371. //      FALSE:                          Errors occured.  See GetLastError()
  372. //
  373. extern BOOL WINAPI CryptSIPRetrieveSubjectGuidForCatalogFile(IN LPCWSTR FileName,   // wide file name
  374.                                                              IN OPTIONAL HANDLE hFileIn,     // or handle of open file
  375.                                                              OUT GUID *pgSubject);           // defined SIP's GUID
  376. //////////////////////////////////////////////////////////////////////////////
  377. //
  378. // CryptSIPAddProvider
  379. //----------------------------------------------------------------------------
  380. //
  381. // Returns: 
  382. //      TRUE:                           No fatal errors
  383. //      FALSE:                          Errors occured.  See GetLastError()
  384. //
  385. extern BOOL WINAPI CryptSIPAddProvider(IN SIP_ADD_NEWPROVIDER *psNewProv);
  386. //////////////////////////////////////////////////////////////////////////////
  387. //
  388. // CryptSIPRemoveProvider
  389. //----------------------------------------------------------------------------
  390. //
  391. // Returns: 
  392. //      TRUE:                           No fatal errors
  393. //      FALSE:                          Errors occured.  See GetLastError()
  394. //
  395. extern BOOL WINAPI CryptSIPRemoveProvider(IN GUID *pgProv);
  396. #ifdef __cplusplus
  397. }
  398. #endif
  399. #endif // MSSIP_H