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.

192 lines
6.4 KiB

  1. /*
  2. ** c a p i s t m . h
  3. **
  4. ** Purpose: declaration of an IStream that can talk to the
  5. ** CAPI streaming methods
  6. **
  7. ** Owner: t-erikne
  8. ** Created: 6/15/97
  9. **
  10. ** Copyright (C) Microsoft Corp. 1997
  11. */
  12. #ifndef __WINCRYPT_H__
  13. #include <wincrypt.h>
  14. #endif
  15. //
  16. // forwards
  17. //
  18. class CMimePropertyContainer; // containx.h
  19. class CInternetConverter; // inetconv.h
  20. typedef struct SMIMEINFOtag SMIMEINFO; //smime.h
  21. #ifndef WIN16
  22. enum CSstate; // capistm.cpp
  23. #else // WIN16
  24. enum CSstate {
  25. STREAM_NOT_BEGUN,
  26. STREAM_QUESTION_TIME,
  27. STREAM_QUESTION_TIME_FINAL,
  28. STREAM_SETUP_DECRYPT,
  29. STREAM_FIRST_WRITE_OUT,
  30. STREAM_TEST_NESTING,
  31. STREAM_DETACHED_OCCURING,
  32. STREAM_DETACHED_FINAL, // must be +1 of DO
  33. STREAM_OCCURING, // must be +1 of DF
  34. STREAM_FINAL, // must be +1 of SO
  35. STREAM_ERROR,
  36. STREAM_GOTTYPE,
  37. };
  38. #endif // !WIN16
  39. //
  40. // errors
  41. //
  42. #define CAPISTM_E_MSG_CLOSED MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x1414)
  43. #define CAPISTM_E_NOT_BEGUN MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x1415)
  44. #define CAPISTM_E_OVERDONE MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x1416)
  45. #define CAPISTM_E_GOTTYPE MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x1417)
  46. //
  47. // flags
  48. //
  49. #define CSTM_GO_ALL_THE_WAY 0x00000000
  50. #define CSTM_TYPE_ONLY 0x00000001
  51. #define CSTM_DETACHED 0x00000002
  52. #define CSTM_ALLFLAGS 0x0000ffff
  53. // high word is reserved. see .cpp file
  54. // NOTES on flags:
  55. // CSTM_TYPE_ONLY -- Can't be called with CSTM_DETACHED. You ever heard
  56. // of detached encryption? Also, calling EndStreaming is optional in this
  57. // case since I'll fail my Write() eventually. Call it and I'll noop. Hmm,
  58. // having said that I recommend calling it. Less pain in the future if it
  59. // becomes needed. Don't use this flag on encode, K?
  60. //
  61. // defines
  62. //
  63. //
  64. // class
  65. //
  66. class CCAPIStm : public IStream
  67. {
  68. public:
  69. CCAPIStm(LPSTREAM lpstmOut);
  70. ~CCAPIStm(void);
  71. // --------------------------------------------------------------------
  72. // IUnknown
  73. // --------------------------------------------------------------------
  74. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  75. STDMETHODIMP_(ULONG) AddRef(void);
  76. STDMETHODIMP_(ULONG) Release(void);
  77. // --------------------------------------------------------------------
  78. // IStream
  79. // --------------------------------------------------------------------
  80. STDMETHODIMP Seek(LARGE_INTEGER, DWORD, ULARGE_INTEGER *);
  81. #ifndef WIN16
  82. STDMETHODIMP Write(const void *, ULONG, ULONG *);
  83. STDMETHODIMP Read(LPVOID, ULONG, ULONG *)
  84. #else
  85. STDMETHODIMP Write(const void HUGEP *, ULONG, ULONG *);
  86. STDMETHODIMP Read(VOID HUGEP *, ULONG, ULONG *)
  87. #endif // !WIN16
  88. { return E_ACCESSDENIED; }
  89. STDMETHODIMP CopyTo(LPSTREAM, ULARGE_INTEGER, ULARGE_INTEGER *, ULARGE_INTEGER *)
  90. { return E_NOTIMPL; }
  91. STDMETHODIMP Stat(STATSTG *, DWORD)
  92. { return E_NOTIMPL; }
  93. STDMETHODIMP Clone(LPSTREAM *)
  94. { return E_NOTIMPL; }
  95. STDMETHODIMP SetSize(ULARGE_INTEGER)
  96. { return E_NOTIMPL; }
  97. STDMETHODIMP Commit(DWORD)
  98. { return E_NOTIMPL; }
  99. STDMETHODIMP Revert(void)
  100. { return E_NOTIMPL; }
  101. STDMETHODIMP LockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD)
  102. { return E_NOTIMPL; }
  103. STDMETHODIMP UnlockRegion(ULARGE_INTEGER, ULARGE_INTEGER, DWORD)
  104. { return E_NOTIMPL; }
  105. // --------------------------------------------------------------------
  106. // CCAPIStm
  107. // --------------------------------------------------------------------
  108. HRESULT HrInitialize(DWORD dwFlagsSEF, const HWND hwndParent, const BOOL fEncode, SMIMEINFO *const psi, DWORD dwFlagsStm, IMimeSecurityCallback * pCallback, PSECURITY_LAYER_DATA psld);
  109. HRESULT HrInnerInitialize(DWORD dwFlagsSEF, const HWND hwndParent, DWORD dwFlagsStm, IMimeSecurityCallback * pCallback, PSECURITY_LAYER_DATA psld);
  110. HRESULT EndStreaming();
  111. PSECURITY_LAYER_DATA GetSecurityLayerData() const;
  112. static HRESULT DuplicateSecurityLayerData(const PSECURITY_LAYER_DATA pcsldIn, PSECURITY_LAYER_DATA *const ppsldOut);
  113. static void FreeSecurityLayerData(PSECURITY_LAYER_DATA psld);
  114. protected:
  115. static void FreeSecurityLayerData(PSECURITY_LAYER_DATA psld, BOOL fStackVar);
  116. BOOL SniffForEndOfHeader( BYTE *pbData, DWORD cbData);
  117. private:
  118. DWORD m_cRef;
  119. CSstate m_csStatus;
  120. CSstate m_csStream;
  121. HCRYPTMSG m_hMsg;
  122. HCRYPTPROV m_hProv;
  123. CCAPIStm * m_pCapiInner;
  124. IStream * m_pstmOut;
  125. PCCERT_CONTEXT m_pUserCertDecrypt;
  126. DWORD m_dwFlagsStm;
  127. DWORD m_cStores;
  128. HCERTSTORE * m_rgStores;
  129. ULONG m_cbBeginWrite;
  130. ULONG m_cbBeginSize;
  131. CInternetConverter *m_pConverter;
  132. PSECURITY_LAYER_DATA m_psldData;
  133. PCRYPT_ATTRIBUTES m_pattrAuth;
  134. #ifndef MAC
  135. #ifdef DEBUG
  136. IStream * m_pstmDebugFile;
  137. #endif
  138. #endif // !MAC
  139. #ifdef SMIME_V3
  140. IMimeSecurityCallback * m_pSmimeCallback;
  141. HWND m_hwnd;
  142. DWORD m_dwFlagsSEF;
  143. UNALIGNED WCHAR * m_pwszKeyPrompt;
  144. #endif // SMIME_V3
  145. LPBYTE m_pbBuffer;
  146. DWORD m_cbBuffer;
  147. HRESULT BeginEncodeStreaming(SMIMEINFO *const psi);
  148. HRESULT BeginDecodeStreaming(SMIMEINFO *const psi);
  149. HRESULT InitInner();
  150. HRESULT InitInner(SMIMEINFO *const psi, CCAPIStm *pOuter = NULL, PSECURITY_LAYER_DATA psldOuter = NULL);
  151. #ifdef SMIME_V3
  152. HRESULT FindKeyFor(HWND hwnd, DWORD dwFlags, DWORD dwRecipientIndex,
  153. const CMSG_CMS_RECIPIENT_INFO * pRecipInfo,
  154. HCERTSTORE hcertstor, DWORD * pdwCtrl,
  155. CMS_CTRL_DECRYPT_INFO * pDecryptInfo,
  156. PCCERT_CONTEXT * ppccertDecrypt);
  157. PCCERT_CONTEXT GetOuterDecryptCert();
  158. #endif // SMIME_V3
  159. HRESULT VerifySignedMessage();
  160. BOOL HandleEnveloped();
  161. HRESULT HandleNesting(CMimePropertyContainer *pContHeader);
  162. static BOOL WINAPI CBStreamOutput(const void *pvArg, BYTE *pbData, DWORD cbData, BOOL fFinal);
  163. BOOL StreamOutput(BYTE *pbData, DWORD cbData, BOOL fFinal);
  164. };
  165. #ifdef SMIME_V3
  166. HRESULT HrBuildContentEncryptionAlg(PSECURITY_LAYER_DATA psld, BLOB * pblob);
  167. HRESULT HrDeriveKeyWrapAlg(PSECURITY_LAYER_DATA psld, CMSG_KEY_AGREE_RECIPIENT_ENCODE_INFO * pAgree);
  168. #endif // SMIME_V3