home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_StrongName_h________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-07-24  |  12.1 KB  |  223 lines

  1. // ==++==
  2. // 
  3. //   Copyright (c) Microsoft Corporation.  All rights reserved.
  4. // 
  5. // ==--==
  6. #ifndef __STRONG_NAME_H
  7. #define __STRONG_NAME_H
  8.  
  9. // ===========================================================================
  10. // File: StrongName.h
  11. // 
  12. // Wrappers for signing and hashing functions needed to implement strong names
  13. // ===========================================================================
  14.  
  15.  
  16. #include <windows.h>
  17. #include <wincrypt.h>
  18. #include <ole2.h>
  19. #include <corerror.h>
  20.  
  21.  
  22. #ifdef __cplusplus
  23. extern "C"{
  24. #endif 
  25.  
  26.  
  27. // Public key blob binary format.
  28. typedef struct {
  29.     unsigned int SigAlgID;       // (ALG_ID) signature algorithm used to create the signature
  30.     unsigned int HashAlgID;      // (ALG_ID) hash algorithm used to create the signature
  31.     ULONG        cbPublicKey;    // length of the key in bytes
  32.     BYTE         PublicKey[1];   // variable length byte array containing the key value in format output by CryptoAPI
  33. } PublicKeyBlob;
  34.  
  35.  
  36. // Location in the registry (under HKLM) that strong name configuration info is
  37. // stored.
  38. #define SN_CONFIG_KEY               "Software\\Microsoft\\StrongName"
  39. #define SN_CONFIG_CSP               "CSP"                   // REG_SZ
  40. #define SN_CONFIG_MACHINE_KEYSET    "MachineKeyset"         // REG_DWORD
  41. #define SN_CONFIG_HASH_ALG          "HashAlgorithm"         // REG_DWORD
  42. #define SN_CONFIG_SIGN_ALG          "SignAlgorithm"         // REG_DWORD
  43. #define SN_CONFIG_VERIFICATION      "Verification"          // Registry subkey
  44. #define SN_CONFIG_USERLIST          "UserList"              // REG_MULTI_SZ
  45. #define SN_CONFIG_CACHE_VERIFY      "CacheVerify"           // REG_DWORD
  46.  
  47. #define SN_CONFIG_KEY_W             L"Software\\Microsoft\\StrongName"
  48. #define SN_CONFIG_CSP_W             L"CSP"                  // REG_SZ
  49. #define SN_CONFIG_MACHINE_KEYSET_W  L"MachineKeyset"        // REG_DWORD
  50. #define SN_CONFIG_HASH_ALG_W        L"HashAlgorithm"        // REG_DWORD
  51. #define SN_CONFIG_SIGN_ALG_W        L"SignAlgorithm"        // REG_DWORD
  52. #define SN_CONFIG_VERIFICATION_W    L"Verification"         // Registry subkey
  53. #define SN_CONFIG_USERLIST_W        L"UserList"             // REG_MULTI_SZ
  54. #define SN_CONFIG_CACHE_VERIFY_W    L"CacheVerify"          // REG_DWORD
  55.  
  56.  
  57. #ifdef SNAPI_INTERNAL
  58. #define SNAPI __declspec(dllexport) BOOLEAN __stdcall
  59. #define SNAPI_(_type) __declspec(dllexport) _type __stdcall
  60. #else
  61. #define SNAPI __declspec(dllimport) BOOLEAN __stdcall
  62. #define SNAPI_(_type) __declspec(dllimport) _type __stdcall
  63. #endif
  64.  
  65.  
  66. // Return last error.
  67. SNAPI_(DWORD) StrongNameErrorInfo(VOID);
  68.  
  69.  
  70. // Free buffer allocated by routines below.
  71. SNAPI_(VOID) StrongNameFreeBuffer(BYTE *pbMemory);  // [in] address of memory to free
  72.  
  73.  
  74. // Generate a new key pair for strong name use.
  75. SNAPI StrongNameKeyGen(LPCWSTR  wszKeyContainer,    // [in] desired key container name
  76.                        DWORD    dwFlags,            // [in] flags (see below)
  77.                        BYTE   **ppbKeyBlob,         // [out] public/private key blob
  78.                        ULONG   *pcbKeyBlob);
  79.  
  80. // Flags for StrongNameKeyGen.
  81. #define SN_LEAVE_KEY    0x00000001                  // Leave key pair registered with CSP
  82.  
  83.  
  84. // Import key pair into a key container.
  85. SNAPI StrongNameKeyInstall(LPCWSTR  wszKeyContainer,// [in] desired key container name, must be a non-empty string
  86.                            BYTE    *pbKeyBlob,      // [in] public/private key pair blob
  87.                            ULONG    cbKeyBlob);
  88.  
  89.  
  90. // Delete a key pair.
  91. SNAPI StrongNameKeyDelete(LPCWSTR wszKeyContainer); // [in] desired key container name
  92.  
  93.  
  94. // Retrieve the public portion of a key pair.
  95. SNAPI StrongNameGetPublicKey (LPCWSTR   wszKeyContainer,    // [in] desired key container name
  96.                               BYTE     *pbKeyBlob,          // [in] public/private key blob (optional)
  97.                               ULONG     cbKeyBlob,
  98.                               BYTE    **ppbPublicKeyBlob,   // [out] public key blob
  99.                               ULONG    *pcbPublicKeyBlob);
  100.  
  101.  
  102. // Hash and sign a manifest.
  103. SNAPI StrongNameSignatureGeneration(LPCWSTR     wszFilePath,        // [in] valid path to the PE file for the assembly
  104.                                     LPCWSTR     wszKeyContainer,    // [in] desired key container name
  105.                                     BYTE       *pbKeyBlob,          // [in] public/private key blob (optional)
  106.                                     ULONG       cbKeyBlob,
  107.                                     BYTE      **ppbSignatureBlob,   // [out] signature blob
  108.                                     ULONG      *pcbSignatureBlob);
  109.  
  110.  
  111. // Create a strong name token from an assembly file.
  112. SNAPI StrongNameTokenFromAssembly(LPCWSTR   wszFilePath,            // [in] valid path to the PE file for the assembly
  113.                                   BYTE    **ppbStrongNameToken,     // [out] strong name token 
  114.                                   ULONG    *pcbStrongNameToken);
  115.  
  116. // Create a strong name token from an assembly file and additionally return the full public key.
  117. SNAPI StrongNameTokenFromAssemblyEx(LPCWSTR   wszFilePath,            // [in] valid path to the PE file for the assembly
  118.                                     BYTE    **ppbStrongNameToken,     // [out] strong name token 
  119.                                     ULONG    *pcbStrongNameToken,
  120.                                     BYTE    **ppbPublicKeyBlob,       // [out] public key blob
  121.                                     ULONG    *pcbPublicKeyBlob);
  122.  
  123. // Create a strong name token from a public key blob.
  124. SNAPI StrongNameTokenFromPublicKey(BYTE    *pbPublicKeyBlob,        // [in] public key blob
  125.                                    ULONG    cbPublicKeyBlob,
  126.                                    BYTE   **ppbStrongNameToken,     // [out] strong name token 
  127.                                    ULONG   *pcbStrongNameToken);
  128.  
  129.  
  130. // Verify a strong name/manifest against a public key blob.
  131. SNAPI StrongNameSignatureVerification(LPCWSTR wszFilePath,      // [in] valid path to the PE file for the assembly
  132.                                       DWORD   dwInFlags,        // [in] flags modifying behaviour (see below)
  133.                                       DWORD  *pdwOutFlags);     // [out] additional output info (see below)
  134.  
  135.  
  136. // Verify a strong name/manifest against a public key blob.
  137. SNAPI StrongNameSignatureVerificationEx(LPCWSTR     wszFilePath,        // [in] valid path to the PE file for the assembly
  138.                                         BOOLEAN     fForceVerification, // [in] verify even if settings in the registry disable it
  139.                                         BOOLEAN    *pfWasVerified);     // [out] set to false if verify succeeded due to registry settings
  140.  
  141.  
  142. // Verify a strong name/manifest against a public key blob when the assembly is
  143. // already memory mapped.
  144. SNAPI StrongNameSignatureVerificationFromImage(BYTE     *pbBase,             // [in] base address of mapped manifest file
  145.                                                DWORD     dwLength,           // [in] length of mapped image in bytes
  146.                                                DWORD     dwInFlags,          // [in] flags modifying behaviour (see below)
  147.                                                DWORD    *pdwOutFlags);       // [out] additional output info (see below)
  148.  
  149. // Flags for use with the verify routines.
  150. #define SN_INFLAG_FORCE_VER      0x00000001     // verify even if settings in the registry disable it
  151. #define SN_INFLAG_INSTALL        0x00000002     // verification is the first (on entry to the cache)
  152. #define SN_INFLAG_ADMIN_ACCESS   0x00000004     // cache protects assembly from all but admin access
  153. #define SN_INFLAG_USER_ACCESS    0x00000008     // cache protects user's assembly from other users
  154. #define SN_INFLAG_ALL_ACCESS     0x00000010     // cache provides no access restriction guarantees
  155. #define SN_INFLAG_RUNTIME        0x80000000     // internal debugging use only 
  156.  
  157. #define SN_OUTFLAG_WAS_VERIFIED  0x00000001     // set to false if verify succeeded due to registry settings
  158.  
  159.  
  160. // Verify that two assemblies differ only by signature blob.
  161. SNAPI StrongNameCompareAssemblies(LPCWSTR   wszAssembly1,           // [in] file name of first assembly
  162.                                   LPCWSTR   wszAssembly2,           // [in] file name of second assembly
  163.                                   DWORD    *pdwResult);             // [out] result of comparison (see codes below)
  164.  
  165. #define SN_CMP_DIFFERENT    0   // Assemblies contain different data
  166. #define SN_CMP_IDENTICAL    1   // Assemblies are exactly the same, even signatures
  167. #define SN_CMP_SIGONLY      2   // Assemblies differ only by signature (and checksum etc.)
  168.  
  169.  
  170. // Compute the size of buffer needed to hold a hash for a given hash algorithm.
  171. SNAPI StrongNameHashSize(ULONG  ulHashAlg,  // [in] hash algorithm
  172.                          DWORD *pcbSize);   // [out] size of the hash in bytes
  173.  
  174.  
  175. // Compute the size that needs to be allocated for a signature in an assembly.
  176. SNAPI StrongNameSignatureSize(BYTE    *pbPublicKeyBlob,    // [in] public key blob
  177.                               ULONG    cbPublicKeyBlob,
  178.                               DWORD   *pcbSize);           // [out] size of the signature in bytes
  179.  
  180.  
  181. SNAPI_(DWORD) GetHashFromAssemblyFile(LPCSTR szFilePath, // [IN] location of file to be hashed
  182.                                       unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
  183.                                       BYTE   *pbHash,    // [OUT] hash buffer
  184.                                       DWORD  cchHash,    // [IN]  max size of buffer
  185.                                       DWORD  *pchHash);  // [OUT] length of hash byte array
  186.     
  187. SNAPI_(DWORD) GetHashFromAssemblyFileW(LPCWSTR wszFilePath, // [IN] location of file to be hashed
  188.                                        unsigned int *piHashAlg, // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
  189.                                        BYTE   *pbHash,    // [OUT] hash buffer
  190.                                        DWORD  cchHash,    // [IN]  max size of buffer
  191.                                        DWORD  *pchHash);  // [OUT] length of hash byte array
  192.     
  193. SNAPI_(DWORD) GetHashFromFile(LPCSTR szFilePath, // [IN] location of file to be hashed
  194.                               unsigned int *piHashAlg,   // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
  195.                               BYTE   *pbHash,    // [OUT] hash buffer
  196.                               DWORD  cchHash,    // [IN]  max size of buffer
  197.                               DWORD  *pchHash);  // [OUT] length of hash byte array
  198.     
  199. SNAPI_(DWORD) GetHashFromFileW(LPCWSTR wszFilePath, // [IN] location of file to be hashed
  200.                                unsigned int *piHashAlg,   // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
  201.                                BYTE   *pbHash,    // [OUT] hash buffer
  202.                                DWORD  cchHash,    // [IN]  max size of buffer
  203.                                DWORD  *pchHash);  // [OUT] length of hash byte array
  204.     
  205. SNAPI_(DWORD) GetHashFromHandle(HANDLE hFile,      // [IN] handle of file to be hashed
  206.                                 unsigned int *piHashAlg,   // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
  207.                                 BYTE   *pbHash,    // [OUT] hash buffer
  208.                                 DWORD  cchHash,    // [IN]  max size of buffer
  209.                                 DWORD  *pchHash);  // [OUT] length of hash byte array
  210.  
  211. SNAPI_(DWORD) GetHashFromBlob(BYTE   *pbBlob,       // [IN] pointer to memory block to hash
  212.                               DWORD  cchBlob,       // [IN] length of blob
  213.                               unsigned int *piHashAlg,  // [IN/OUT] constant specifying the hash algorithm (set to 0 if you want the default)
  214.                               BYTE   *pbHash,       // [OUT] hash buffer
  215.                               DWORD  cchHash,       // [IN]  max size of buffer
  216.                               DWORD  *pchHash);     // [OUT] length of hash byte array
  217.  
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221.  
  222. #endif
  223.