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.

236 lines
8.8 KiB

  1. /*
  2. ** s e c u t i l . h
  3. **
  4. ** Purpose: helper functions for message security
  5. **
  6. ** Owner: t-erikne
  7. ** Created: 1/10/97
  8. **
  9. ** Copyright (C) Microsoft Corp. 1997.
  10. */
  11. #ifndef __SECUTIL_H
  12. #define __SECUTIL_H
  13. /////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Depends on
  16. //
  17. #include <mimeole.h>
  18. #include <wab.h>
  19. class CWabal;
  20. class CSecMsgService;
  21. interface IBodyObj;
  22. interface IBodyObj2;
  23. typedef CWabal *LPWABAL;
  24. typedef struct tagADRINFO ADRINFO;
  25. typedef const struct _CERT_CONTEXT *PCCERT_CONTEXT;
  26. interface IImnAccount;
  27. interface IHeaderSite;
  28. /////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Structures
  31. //
  32. /* SECSTATE structure
  33. **
  34. ** type - security type
  35. ** user_validity - user set validity bits
  36. ** ro_msg_validity - mimeole set validity/trust bits
  37. ** fHaveCert - TRUE if there is a cert in the message
  38. ** szSignerEmail - points to email address of signer
  39. ** szSenderEmail - points to email address of sender
  40. */
  41. struct SECSTATEtag
  42. {
  43. ULONG type;
  44. ULONG user_validity;
  45. ULONG ro_msg_validity;
  46. BOOL fHaveCert;
  47. LPTSTR szSignerEmail;
  48. LPTSTR szSenderEmail;
  49. };
  50. typedef struct SECSTATEtag SECSTATE;
  51. // Structure for send resource ID to
  52. // signing certificate error dialog
  53. typedef struct tagErrIds
  54. {
  55. UINT idsText1;
  56. UINT idsText2;
  57. } ERRIDS;
  58. typedef struct tagCertErrParam
  59. {
  60. BOOL fForceEncryption;
  61. IMimeAddressTable *pAdrTable;
  62. } CERTERRPARAM;
  63. /* ALG_LIST/ALG_NODE struct
  64. **
  65. ** aid - CAPI algorithm id
  66. ** dwBits - number of bits in the algorithm
  67. ** szName - text name of algorithm
  68. */
  69. struct ALG_LISTtag;
  70. typedef struct ALG_LISTtag {
  71. ALG_ID aid;
  72. DWORD dwBits;
  73. char szName[20];
  74. ALG_LISTtag *next;
  75. } ALG_LIST, ALG_NODE;
  76. extern CRYPT_ENCODE_PARA CryptEncodeAlloc;
  77. extern CRYPT_DECODE_PARA CryptDecodeAlloc;
  78. /////////////////////////////////////////////////////////////////////////////
  79. //
  80. // Definitions
  81. //
  82. // in use 0x xxx xx
  83. #define ATHSEC_TRUSTED 0x00000000
  84. #define ATHSEC_NOTRUSTNOTTRUSTED 0X00000001
  85. #define ATHSEC_NOTRUSTUNKNOWN 0X00000002
  86. #define ATHSEC_TRUSTSTATEMASK 0x000000ff
  87. // these are ordered as the idsWrnSecurityTrust* in resource.h
  88. // change these, change them
  89. #define ATHSEC_NOTRUSTWRONGADDR 0X00010000
  90. #define ATHSEC_NOTRUSTREVOKED 0x00020000
  91. #define ATHSEC_NOTRUSTOTHER 0X00040000
  92. #define ATHSEC_NOTRUSTREVFAIL 0x00080000
  93. #define ATHSEC_NUMVALIDITYBITS 3 // update this if you add one
  94. #define ATHSEC_TRUSTREASONMASK 0x0fff0000
  95. // Flags for HrAddCertToWabContact & HrAddCertToWab
  96. #define WFF_SHOWUI 0x00000001 // we are allowed to show UI
  97. #define WFF_CREATE 0x00000010 // we are allowed to create an entry if not found
  98. /////////////////////////////////////////////////////////////////////////////
  99. //
  100. // Constants
  101. //
  102. extern const BYTE c_RC2_40_ALGORITHM_ID[];
  103. extern const ULONG cbRC2_40_ALGORITHM_ID;
  104. /////////////////////////////////////////////////////////////////////////////
  105. //
  106. // Prototypes
  107. //
  108. BOOL IsSecure(DWORD dwMST);
  109. BOOL IsSecure(LPMIMEMESSAGE pMsg, const HBODY hBodyToCheck = HBODY_ROOT);
  110. BOOL IsSigned(LPMIMEMESSAGE pMsg, BOOL fIncludeDescendents);
  111. BOOL IsSigned(LPMIMEMESSAGE pMsg, const HBODY hBodyToCheck, BOOL fIncludeDescendents);
  112. BOOL IsSigned(DWORD dwMST);
  113. BOOL IsSignTrusted(SECSTATE *pSecState);
  114. BOOL IsEncrypted(LPMIMEMESSAGE pMsg, BOOL fIncludeDescendents);
  115. BOOL IsEncrypted(LPMIMEMESSAGE pMsg, const HBODY hBodyToCheck, BOOL fIncludeDescendents);
  116. BOOL IsEncrypted(DWORD dwMST);
  117. BOOL IsEncryptionOK(SECSTATE *pSecState);
  118. HRESULT CommonUI_ViewSigningProperties(HWND hwnd, PCCERT_CONTEXT pCert, HCERTSTORE hcMsg, UINT nStartPage);
  119. HRESULT CommonUI_ViewSigningCertificate(HWND hwnd, PCCERT_CONTEXT pCert, HCERTSTORE hcMsg);
  120. HRESULT CommonUI_ViewSigningCertificateTrust(HWND hwnd, PCCERT_CONTEXT pCert, HCERTSTORE hcMsg);
  121. HRESULT HrHaveAnyMyCerts(void);
  122. HRESULT HrGetThumbprint(LPWABAL lpWabal, ADRINFO *pAdrInfo, THUMBBLOB *pThumbprint, BLOB * pSymCaps, FILETIME * pSigningTime);
  123. DWORD DwGetSecurityOfMessage(LPMIMEMESSAGE pMsg, const HBODY hBodyToCheck = HBODY_ROOT);
  124. HRESULT HrInitSecurityOptions(LPMIMEMESSAGE pMsg, ULONG ulSecurityType);
  125. #ifdef SMIME_V3
  126. BOOL FNameInList(LPSTR szAddr, DWORD cReceiptFromList, CERT_NAME_BLOB *rgReceiptFromList);
  127. HRESULT SendSecureMailToOutBox(IStoreCallback *pStoreCB, LPMIMEMESSAGE pMsg, BOOL fSendImmediate, BOOL fNoUI, BOOL fMail, IHeaderSite *pHeaderSite);
  128. #else
  129. HRESULT SendSecureMailToOutBox(IStoreCallback *pStoreCB, LPMIMEMESSAGE pMsg, BOOL fSendImmediate, BOOL fNoUI, BOOL fMail);
  130. #endif // SMIME_V3
  131. DWORD DwGenerateTrustedChain(HWND hwnd, IMimeMessage *pMsg, PCCERT_CONTEXT pcCertToTest, DWORD dwIgnore, BOOL fFullSearch, DWORD *pcChain, PCCERT_CONTEXT **prgChain);
  132. HRESULT HrGetSecurityState(LPMIMEMESSAGE, SECSTATE *, HBODY *phBody);
  133. VOID CleanupSECSTATE(SECSTATE *psecstate);
  134. HRESULT HandleSecurity(HWND hwndOwner, LPMIMEMESSAGE);
  135. HRESULT LoadResourceToHTMLStream(LPCTSTR szResName, IStream **ppstm);
  136. HRESULT HrGetMyCerts(PCCERT_CONTEXT ** pprgcc, ULONG * pccc);
  137. void FreeCertArray(PCCERT_CONTEXT * rgcc, ULONG ccc);
  138. HRESULT GetSigningCert(IMimeMessage * pMsg, PCCERT_CONTEXT * ppcSigningCert, THUMBBLOB * ptbSigner, BLOB * pblSymCaps, FILETIME * pftSigningTime);
  139. HRESULT GetSignerEncryptionCert(IMimeMessage * pMsg, PCCERT_CONTEXT * ppcEncryptCert,
  140. THUMBBLOB * ptbEncrypt, BLOB * pblSymCaps,
  141. FILETIME * pftSigningTime);
  142. HRESULT HrSaveCACerts(HCERTSTORE hcCA, HCERTSTORE hcMsg);
  143. BOOL IsThumbprintInMVPBin(SPropValue spv, THUMBBLOB * lpThumbprint, ULONG * lpIndex, BLOB * pblSymCaps,
  144. FILETIME * lpftSigningTime, BOOL * lpfDefault);
  145. HRESULT HrAddSenderCertToWab(HWND hwnd, LPMIMEMESSAGE pMsg, LPWABAL lpWabal, THUMBBLOB *pSenderThumbprint,
  146. BLOB *pblSymCaps, FILETIME ftSigningTime, DWORD dwFlags);
  147. HRESULT HrAddCertToWab(HWND hwnd, LPWABAL lpWabal, THUMBBLOB *pThumbprint,
  148. PCCERT_CONTEXT pcCertContext, LPWSTR lpwszEmailAddress, LPWSTR lpwszDisplayName, BLOB *pblSymCaps,
  149. FILETIME ftSigningTime, DWORD dwFlags);
  150. ULONG GetHighestEncryptionStrength(void);
  151. HRESULT HrGetHighestSymcaps(LPBYTE * ppbSymcap, LPULONG cbSymcap);
  152. HRESULT ShowSecurityPopup(HWND hwnd, DWORD cmdID, POINT *pPoint, IMimeMessage *pMsg);
  153. void ShowDigitalIDs(HWND hWnd);
  154. BOOL CheckCDPinCert(LPMIMEMESSAGE pMsg);
  155. BOOL CheckCDPinCert(PCCERT_CONTEXT pcCertToTest);
  156. HRESULT HrGetLabelString(LPMIMEMESSAGE pMsg, LPWSTR *pwStr);
  157. HRESULT CheckSecReceipt(LPMIMEMESSAGE pMsg);
  158. HRESULT HrShowSecurityProperty(HWND hwnd, LPMIMEMESSAGE pMsg);
  159. HRESULT HandleSecReceipt(LPMIMEMESSAGE pMsg, IImnAccount * pAcct, HWND hWnd, TCHAR **ppszSubject, TCHAR **ppszFrom, FILETIME *pftSentTime, FILETIME *pftSigningTime);
  160. void CreateContentIdentifier(TCHAR *pchContentID, DWORD cchSize, LPMIMEMESSAGE pMsg);
  161. HRESULT _HrFindMyCertForAccount(HWND hwnd, PCCERT_CONTEXT * ppcCertContext, IImnAccount * pAccount, BOOL fEncrypt);
  162. HRESULT CheckDecodedForReceipt(LPMIMEMESSAGE pMsg, PSMIME_RECEIPT * ppSecReceipt);
  163. HRESULT HrGetInnerLayer(LPMIMEMESSAGE pMsg, HBODY *phBody);
  164. /////////////////////////////////////////////////////////////////////////////
  165. //
  166. // Predicate wrappers
  167. //
  168. inline BOOL IsSecure(DWORD dwMst)
  169. { return (MST_NONE != dwMst); }
  170. inline BOOL IsSecure(LPMIMEMESSAGE pMsg, const HBODY hBodyToCheck)
  171. { return (MST_NONE != DwGetSecurityOfMessage(pMsg, hBodyToCheck)); }
  172. inline BOOL IsSigned(LPMIMEMESSAGE pMsg, BOOL fIncludeDescendents)
  173. { return IsSigned(pMsg, HBODY_ROOT, fIncludeDescendents); }
  174. inline BOOL IsSigned(DWORD dwMST)
  175. { return (BOOL)(dwMST & MST_SIGN_MASK); }
  176. inline BOOL IsSignTrusted(SECSTATE *pSecState)
  177. { return (BOOL)((ATHSEC_TRUSTED == pSecState->user_validity) &&
  178. (MSV_OK == (pSecState->ro_msg_validity & ~MSV_ENCRYPT_MASK))); }
  179. inline BOOL IsEncrypted(LPMIMEMESSAGE pMsg, BOOL fIncludeDescendents)
  180. { return IsEncrypted(pMsg, HBODY_ROOT, fIncludeDescendents); }
  181. inline BOOL IsEncrypted(DWORD dwMST)
  182. { return (BOOL)(dwMST & MST_ENCRYPT_MASK); }
  183. inline BOOL IsEncryptionOK(SECSTATE *pSecState)
  184. { return (BOOL) (MSV_OK == ((MSV_MSG_MASK|MSV_ENCRYPT_MASK) & pSecState->ro_msg_validity));}
  185. /////////////////////////////////////////////////////////////////////////////
  186. //
  187. // Other wrappers
  188. //
  189. inline HRESULT CommonUI_ViewSigningCertificate(HWND hwnd, PCCERT_CONTEXT pCert, HCERTSTORE hcMsg)
  190. { return CommonUI_ViewSigningProperties(hwnd, pCert, hcMsg, 0); }
  191. inline HRESULT CommonUI_ViewSigningCertificateTrust(HWND hwnd, PCCERT_CONTEXT pCert, HCERTSTORE hcMsg)
  192. { return CommonUI_ViewSigningProperties(hwnd, pCert, hcMsg, 2); }
  193. #endif // include once