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.

270 lines
7.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: pfxcmn.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _PFXCMN_H_
  11. #define _PFXCMN_H_
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef DWORD PFXERR;
  16. typedef HANDLE HPFXITEM;
  17. typedef HANDLE HPFX;
  18. typedef LPSTR OID;
  19. #define PFXAPI __stdcall
  20. // define allocators
  21. #define SSAlloc(__x__) LocalAlloc(LMEM_FIXED, __x__)
  22. #define SSFree(__x__) LocalFree(__x__)
  23. #define SSReAlloc(__x__, __y__) LocalReAlloc(__x__, __y__, LMEM_MOVEABLE)
  24. // PFXExportCertStoreEx -> PFXExportCertStore internal param
  25. #define PKCS12_ENHANCED_STRENGTH_ENCODING 0xffff0008
  26. #define PKCS12_ENCR_PWD_ITERATIONS 2000
  27. #define PKCS12_MAC_PWD_ITERATIONS 2000
  28. #define MAKEZERO(arg) ZeroMemory( &arg, sizeof(arg))
  29. // count the number of bytes needed to fully store a WSZ
  30. #define WSZ_BYTECOUNT(__z__) \
  31. ( (__z__ == NULL) ? 0 : (wcslen(__z__)+1)*sizeof(WCHAR) )
  32. typedef struct _PFX_INFO {
  33. #define NSCP_BLOB 1
  34. #define PFX_BLOB 2
  35. DWORD dwBlobType; // NSCP, PFX?
  36. LPWSTR szPassword;
  37. DWORD dwPrivacyMode;
  38. DWORD dwIntegrityMode;
  39. DWORD dwTransportMode;
  40. CRYPT_ALGORITHM_IDENTIFIER aiKeyShroudingEncryptionAlgid;
  41. CRYPT_ALGORITHM_IDENTIFIER aiSafePDUEncryptionAlgid;
  42. void** rgSecrets; // SafeBag* [] -- array of safebag*'s
  43. DWORD cSecrets;
  44. void** rgCertcrls; // SafeBag* [] -- array of safebag*'s
  45. DWORD cCertcrls;
  46. void** rgKeys; // SafeBag* [] -- array of safebag*'s
  47. DWORD cKeys;
  48. void** rgShroudedKeys; // SafeBag* [] -- array of safebag*'s
  49. DWORD cShroudedKeys;
  50. } PFX_INFO, *PPFX_INFO;
  51. // -------------------------------------------------------------------------
  52. // begin nscp.cpp entry points
  53. // -------------------------------------------------------------------------
  54. BOOL InitNSCP();
  55. BOOL TerminateNSCP();
  56. ////////////////////
  57. // import pb, cb, return HPFX
  58. BOOL
  59. PFXAPI
  60. NSCPImportBlob
  61. (
  62. LPCWSTR szPassword,
  63. PBYTE pbIn,
  64. DWORD cbIn,
  65. SAFE_CONTENTS **ppSafeContents
  66. );
  67. // -------------------------------------------------------------------------
  68. // end nscp.cpp entry points
  69. // -------------------------------------------------------------------------
  70. // -------------------------------------------------------------------------
  71. // begin PFX.cpp entry points
  72. // -------------------------------------------------------------------------
  73. BOOL InitPFX();
  74. BOOL TerminatePFX();
  75. ////////////////////
  76. // returns HPFX, prepares PFX export
  77. HPFX
  78. PFXAPI
  79. PfxExportCreate (
  80. LPCWSTR szPassword
  81. );
  82. ////////////////////
  83. // Do header wrap of specified HPFX
  84. BOOL
  85. PFXAPI
  86. PfxExportBlob
  87. (
  88. HPFX hpfx,
  89. PBYTE pbOut,
  90. DWORD* pcbOut,
  91. DWORD dwFlags
  92. );
  93. ////////////////////
  94. // Unwrap pb cb, return handle to new HPFX
  95. HPFX
  96. PFXAPI
  97. PfxImportBlob
  98. (
  99. LPCWSTR szPassword,
  100. PBYTE pbIn,
  101. DWORD cbIn,
  102. DWORD dwFlags
  103. );
  104. ////////////////////
  105. // Free all resources associated with the hpfx
  106. BOOL
  107. PFXAPI
  108. PfxCloseHandle(
  109. IN HPFX hpfx
  110. );
  111. //
  112. // functions for checking if somethings is a pfx blob
  113. //
  114. BOOL
  115. PFXAPI
  116. IsRealPFXBlob
  117. (
  118. CRYPT_DATA_BLOB* pPFX
  119. );
  120. BOOL
  121. PFXAPI
  122. IsNetscapePFXBlob
  123. (
  124. CRYPT_DATA_BLOB* pPFX
  125. );
  126. // -------------------------------------------------------------------------
  127. // end PFX.cpp entry points
  128. // -------------------------------------------------------------------------
  129. // new entry points for loading up the HPFX
  130. BOOL PfxGetKeysAndCerts(
  131. HPFX hPfx,
  132. SAFE_CONTENTS* pContents
  133. );
  134. BOOL PfxAddSafeBags(
  135. HPFX hPfx,
  136. SAFE_BAG* pSafeBags,
  137. DWORD cSafeBags
  138. );
  139. BOOL
  140. MakeEncodedCertBag(
  141. BYTE *pbEncodedCert,
  142. DWORD cbEncodedCert,
  143. BYTE *pbEncodedCertBag,
  144. DWORD *pcbEncodedCertBag
  145. );
  146. BOOL
  147. GetEncodedCertFromEncodedCertBag(
  148. BYTE *pbEncodedCertBag,
  149. DWORD cbEncodedCertBag,
  150. BYTE *pbEncodedCert,
  151. DWORD *pcbEncodedCert
  152. );
  153. BOOL
  154. SetSaltAndIterationCount(
  155. BYTE **ppbParameters,
  156. DWORD *pcbParameters,
  157. BYTE *pbSalt,
  158. DWORD cbSalt,
  159. int iIterationCount
  160. );
  161. BOOL
  162. GetSaltAndIterationCount(
  163. BYTE *pbParameters,
  164. DWORD cbParameters,
  165. BYTE **ppbSalt,
  166. DWORD *pcbSalt,
  167. int *piIterationCount
  168. );
  169. ///////////////////////////////////////////////////////////////////////////////////
  170. // The real PKCS #12 Object Identifiers
  171. #define szOID_PKCS_12_PbeIds szOID_PKCS_12 ".1"
  172. #define szOID_PKCS_12_pbeWithSHA1And128BitRC4 szOID_PKCS_12_PbeIds ".1"
  173. #define szOID_PKCS_12_pbeWithSHA1And40BitRC4 szOID_PKCS_12_PbeIds ".2"
  174. #define szOID_PKCS_12_pbeWithSHA1And3KeyTripleDES szOID_PKCS_12_PbeIds ".3"
  175. #define szOID_PKCS_12_pbeWithSHA1And2KeyTripleDES szOID_PKCS_12_PbeIds ".4"
  176. #define szOID_PKCS_12_pbeWithSHA1And128BitRC2 szOID_PKCS_12_PbeIds ".5"
  177. #define szOID_PKCS_12_pbeWithSHA1And40BitRC2 szOID_PKCS_12_PbeIds ".6"
  178. #define szOID_PKCS_12_EnvelopingIds OLD_szOID_PKCS_12_OIDs ".2"
  179. #define szOID_PKCS_12_rsaEncryptionWith128BitRC4 OLD_szOID_PKCS_12_EnvelopingIds ".1"
  180. #define szOID_PKCS_12_rsaEncryptionWith40BitRC4 OLD_szOID_PKCS_12_EnvelopingIds ".2"
  181. #define szOID_PKCS_12_rsaEncryptionWithTripleDES OLD_szOID_PKCS_12_EnvelopingIds ".3"
  182. #define szOID_PKCS_12_SignatureIds OLD_szOID_PKCS_12_OIDs ".3"
  183. #define szOID_PKCS_12_rsaSignatureWithSHA1Digest OLD_szOID_PKCS_12_SignatureIds ".1"
  184. #define szOID_PKCS_12_PkekIDs szOID_PKCS_12 ".6" // 1.2.840.113549.1.12.6
  185. #define szOID_PKCS_12_UserCertPkekId szOID_PKCS_12_PkekIDs ".1" // 1.2.840.113549.1.12.6.1
  186. #define szOID_PKCS_12_CACertPkekId szOID_PKCS_12_PkekIDs ".2" // 1.2.840.113549.1.12.6.2
  187. #define szOID_PKCS_12_SelfSignedPkekId szOID_PKCS_12_PkekIDs ".3" // 1.2.840.113549.1.12.6.3
  188. #define szOID_PKCS_12_Version1 szOID_PKCS_12 ".10"
  189. #define szOID_PKCS_12_BagIDs szOID_PKCS_12_Version1 ".1"
  190. #define szOID_PKCS_12_KeyBag szOID_PKCS_12_BagIDs ".1"
  191. #define szOID_PKCS_12_ShroudedKeyBag szOID_PKCS_12_BagIDs ".2"
  192. #define szOID_PKCS_12_CertBag szOID_PKCS_12_BagIDs ".3"
  193. #define szOID_PKCS_12_CRLBag szOID_PKCS_12_BagIDs ".4"
  194. #define szOID_PKCS_12_SecretBag szOID_PKCS_12_BagIDs ".5"
  195. #define szOID_PKCS_12_SafeContentsBag szOID_PKCS_12_BagIDs ".6"
  196. // new oids 6/30/97
  197. #define szOID_PKCS_12_FriendlyName szOID_PKCS_9 ".20"
  198. #define szOID_PKCS_12_LocalKeyID szOID_PKCS_9 ".21"
  199. #define szOID_PKCS_12_CertTypes szOID_PKCS_9 ".22"
  200. #define szOID_PKCS_12_CRLTypes szOID_PKCS_9 ".23"
  201. #define szOID_PKCS_12_x509Cert szOID_PKCS_12_CertTypes ".1"
  202. #define szOID_PKCS_12_SDSICert szOID_PKCS_12_CertTypes ".2"
  203. #define szOID_PKCS_12_x509CRL szOID_PKCS_12_CRLTypes ".1"
  204. #ifdef __cplusplus
  205. } // extern "C"
  206. #endif
  207. #endif // _PFXCMN_H_