home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / mssip.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  20KB  |  456 lines

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