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.

212 lines
5.8 KiB

  1. // CryptCtx.h -- Cryptographic Context class header
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #if !defined(SLBCSP_CRYPTCTX_H)
  8. #define SLBCSP_CRYPTCTX_H
  9. #include <memory> // for auto_ptr
  10. #include <windef.h>
  11. #include <wincrypt.h> // required by cspdk.h
  12. #include <cspdk.h> // for CRYPT_RETURN_HWND &
  13. // PVTableProvStruc
  14. #include <handles.h>
  15. #include <scuArrayP.h>
  16. #include "Lockable.h"
  17. #include "HAdptvCntr.h"
  18. #include "CntrEnum.h"
  19. #include "AuxContext.h"
  20. #include "LoginId.h"
  21. #include "Blob.h"
  22. #include "AlignedBlob.h"
  23. class CSpec;
  24. class CHashContext;
  25. class CKeyContext;
  26. class CPublicKeyContext;
  27. class CSessionKeyContext;
  28. // Maintains the context acquired and used to access a CAPI container.
  29. class CryptContext
  30. : public CHandle,
  31. public Lockable
  32. {
  33. public:
  34. // Types
  35. // C'tors/D'tors
  36. CryptContext(CSpec const &CntrSpec,
  37. PVTableProvStruc const pVTable,
  38. bool fGuiEnabled,
  39. bool fCreateContainer = false,
  40. bool fEphemeralContainer = false);
  41. ~CryptContext();
  42. // Operators
  43. // Operations
  44. HCRYPTHASH
  45. Add(std::auto_ptr<CHashContext> &rapHashCtx);
  46. HCRYPTKEY
  47. Add(std::auto_ptr<CKeyContext> &rapKeyCtx);
  48. HCRYPTKEY
  49. Add(std::auto_ptr<CPublicKeyContext> &rapPublicKeyCtx);
  50. HCRYPTKEY
  51. Add(std::auto_ptr<CSessionKeyContext> &rapSessionKeyCtx);
  52. std::auto_ptr<CHashContext>
  53. CloseHash(HCRYPTHASH const hHash);
  54. std::auto_ptr<CKeyContext>
  55. CloseKey(HCRYPTKEY const hKey);
  56. void
  57. CntrEnumerator(ContainerEnumerator const &rce);
  58. void
  59. EnumAlgorithms(DWORD dwPara,
  60. DWORD dwFlags,
  61. bool fPostAdvanceIterator,
  62. AlignedBlob &rabAlgInfo);
  63. HCRYPTKEY
  64. GenerateKey(ALG_ID algid,
  65. DWORD dwFlags);
  66. std::auto_ptr<CPublicKeyContext>
  67. ImportPrivateKey(Blob const &rblbMsPrivateKey,
  68. DWORD dwKeySpec,
  69. bool fExportable,
  70. HCRYPTKEY hEncKey);
  71. std::auto_ptr<CPublicKeyContext>
  72. ImportPublicKey(Blob const &rblbMsPublicKey,
  73. DWORD dwKeySpec);
  74. void
  75. Login(LoginIdentity const &rlid);
  76. void
  77. Pin(LoginIdentity const &rlid,
  78. char const *pszPin);
  79. void
  80. RemoveContainer();
  81. std::auto_ptr<CSessionKeyContext>
  82. UseSessionKey(BYTE const *pbKeyBlob,
  83. DWORD cbKeyBlobLen,
  84. HCRYPTKEY hAuxImpKey,
  85. DWORD dwFlags);
  86. // Access
  87. HAdaptiveContainer
  88. AdaptiveContainer() const;
  89. HCRYPTPROV
  90. AuxContext() const;
  91. ContainerEnumerator
  92. CntrEnumerator(bool fReset);
  93. CHashContext *
  94. LookupHash(HCRYPTHASH hHash);
  95. CKeyContext *
  96. LookupKey(HCRYPTKEY hKey);
  97. CPublicKeyContext *
  98. LookupPublicKey(HCRYPTKEY hKey);
  99. CSessionKeyContext *
  100. LookupSessionKey(HCRYPTKEY hKey);
  101. HWND
  102. Window() const;
  103. // Predicates
  104. bool
  105. GuiEnabled() const;
  106. bool
  107. IsEphemeral() const;
  108. protected:
  109. // Types
  110. // C'tors/D'tors
  111. // Operators
  112. // Operations
  113. // Access
  114. // Predicates
  115. // Variables
  116. private:
  117. // Types
  118. // C'tors/D'tors
  119. // Operators
  120. // Operations
  121. void
  122. CreateNewContainer(CSpec const &rcspec);
  123. void
  124. DeleteContainer(Secured<HCardContext> &rhscardctx,
  125. cci::CContainer &rhcntr);
  126. void
  127. Login(LoginIdentity const &rlid,
  128. Secured<HCardContext> &rhscardctx);
  129. void
  130. OkDeletingCredentials() const;
  131. // Access
  132. HCardContext
  133. CardContext() const;
  134. CKeyContext *
  135. LookupChecked(HCRYPTKEY hKey,
  136. DWORD const dwKeyType);
  137. void
  138. OpenExistingContainer(CSpec const &rcspec);
  139. // Predicates
  140. // Variables
  141. // Id of thread that created this context, making it the owner
  142. DWORD const m_dwOwnerThreadId;
  143. HAdaptiveContainer m_hacntr;
  144. // If CRYPT_VERIFYCONTEXT was used when creating this context.
  145. bool const m_fEphemeralContainer;
  146. // If the client specified the GUI was enabled/disabled using CRYPT_SILENT
  147. bool const m_fGuiEnabled;
  148. // Window to use when interacting with the user
  149. HWND m_hwnd;
  150. // Hashes and keys (both session and those on the card) created/acquired
  151. // in this context.
  152. CHandleList m_hlHashes;
  153. CHandleList m_hlKeys;
  154. ::AuxContext const m_auxcontext;
  155. ContainerEnumerator m_ce; // used by CPGetProvParam
  156. std::auto_ptr<AlignedBlob> m_apabCachedAlg;
  157. };
  158. #endif // SLBCSP_CRYPTCTX_H