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.

170 lines
4.5 KiB

  1. /*
  2. * tprtsec.h
  3. *
  4. * Copyright (c) 1997 by Microsoft Corp.
  5. *
  6. * Author:
  7. * Claus T. Giloi
  8. */
  9. #ifndef _TPRTSEC
  10. #define _TPRTSEC
  11. #define SECURITY_WIN32
  12. #include "sspi.h"
  13. #include "spseal.h"
  14. #include "schnlsp.h"
  15. typedef BOOL (WINAPI *PFN_SSL_EMPTY_CACHE)(VOID);
  16. #define SZ_SSLEMPTYCACHE "SslEmptyCache"
  17. #ifdef UNICODE
  18. #error "Compile time character width conflict"
  19. // Above entry point strings need to be changed to unicode equivalents
  20. // or abstracted.
  21. #endif // UNICODE
  22. /*
  23. * This typedef defines the errors that can be returned from calls that are
  24. * specific to TransportSecurity classes.
  25. */
  26. typedef enum
  27. {
  28. TPRTSEC_NOERROR,
  29. TPRTSEC_NODLL,
  30. TPRTSEC_NOENTRYPT,
  31. TPRTSEC_SSPIFAIL,
  32. TPRTSEC_NOMEM,
  33. TPRTSEC_INVALID_PARAMETER,
  34. TPRTSEC_INCOMPLETE_CONTEXT,
  35. TPRTSEC_INVALID_STATE
  36. } TransportSecurityError;
  37. /*
  38. * This typedef defines the states that a security context object can be
  39. * in.
  40. */
  41. typedef enum
  42. {
  43. SECCTX_STATE_NEW,
  44. SECCTX_STATE_INIT,
  45. SECCTX_STATE_ACCEPT,
  46. SECCTX_STATE_INIT_COMPLETE,
  47. SECCTX_STATE_ACCEPT_COMPLETE,
  48. SECCTX_STATE_ERROR
  49. } SecurityContextState;
  50. /*
  51. * This is simply a forward reference for the class defined below. It is used
  52. * in the definition of the owner callback structure defined in this section.
  53. */
  54. class SecurityInterface;
  55. typedef SecurityInterface * PSecurityInterface;
  56. class SecurityContext;
  57. typedef SecurityContext * PSecurityContext;
  58. #ifdef DEBUG
  59. extern void dumpbytes(PSTR szComment, PBYTE p, int cb);
  60. #endif // DEBUG
  61. extern BOOL InitCertList ( SecurityInterface * pSI, HWND hwnd);
  62. extern BOOL SetUserPreferredCert ( SecurityInterface * pSI, DWORD dwCertID);
  63. class SecurityInterface
  64. {
  65. friend class SecurityContext;
  66. public:
  67. SecurityInterface ();
  68. ~SecurityInterface ();
  69. TransportSecurityError Initialize ();
  70. TransportSecurityError InitializeCreds (PCCERT_CONTEXT);
  71. TransportSecurityError GetLastError(VOID) { return LastError; };
  72. BOOL GetUserCert(PBYTE pInfo, PDWORD pcbInfo);
  73. private:
  74. HINSTANCE hSecurityDll;
  75. INIT_SECURITY_INTERFACE pfnInitSecurityInterface;
  76. PSecurityFunctionTable pfnTable;
  77. PFN_SSL_EMPTY_CACHE pfn_SslEmptyCache;
  78. PBYTE m_pbEncodedCert;
  79. DWORD m_cbEncodedCert;
  80. BOOL bInboundCredentialValid;
  81. BOOL bOutboundCredentialValid;
  82. CredHandle hInboundCredential;
  83. CredHandle hOutboundCredential;
  84. TimeStamp tsExpiry;
  85. TransportSecurityError LastError;
  86. };
  87. class SecurityContext
  88. {
  89. public:
  90. SecurityContext (PSecurityInterface pSI, LPCSTR szHostName);
  91. ~SecurityContext ();
  92. TransportSecurityError Initialize (PBYTE pData, DWORD cbData);
  93. TransportSecurityError Accept (PBYTE pData, DWORD cbData);
  94. TransportSecurityError Encrypt(LPBYTE pBufIn1, UINT cbBufIn1,
  95. LPBYTE pBufIn2, UINT cbBufIn2,
  96. LPBYTE *ppBufOut, UINT *pcbBufOut);
  97. TransportSecurityError Decrypt( PBYTE pszBuf,
  98. DWORD cbBuf);
  99. PVOID GetTokenBuf(VOID) { return OutBuffers[0].pvBuffer; };
  100. ULONG GetTokenSiz(VOID) { return OutBuffers[0].cbBuffer; };
  101. BOOL ContinueNeeded(VOID) { return fContinueNeeded; };
  102. BOOL StateComplete(VOID) { return
  103. scstate == SECCTX_STATE_INIT_COMPLETE ||
  104. scstate == SECCTX_STATE_ACCEPT_COMPLETE; };
  105. BOOL WaitingForPacket(VOID) { return
  106. scstate == SECCTX_STATE_NEW ||
  107. scstate == SECCTX_STATE_ACCEPT ||
  108. scstate == SECCTX_STATE_INIT; };
  109. TransportSecurityError AdvanceState(PBYTE pBuf,DWORD cbBuf);
  110. BOOL EncryptOutgoing(VOID)
  111. { return scstate == SECCTX_STATE_INIT_COMPLETE; };
  112. BOOL DecryptIncoming(VOID)
  113. { return scstate == SECCTX_STATE_ACCEPT_COMPLETE; };
  114. ULONG GetStreamHeaderSize(VOID) { return Sizes.cbHeader; };
  115. ULONG GetStreamTrailerSize(VOID) { return Sizes.cbTrailer; };
  116. TransportSecurityError GetLastError(VOID) { return LastError; };
  117. BOOL GetUserCert(PBYTE pInfo, PDWORD pcbInfo);
  118. BOOL Verify(VOID);
  119. private:
  120. TransportSecurityError InitContextAttributes(VOID);
  121. PSecurityInterface pSecurityInterface;
  122. SecurityContextState scstate;
  123. CHAR szTargetName[128]; // Long enough for any dotted-decimal
  124. // address, followed by 2 dwords in
  125. // hex.
  126. BOOL bContextHandleValid;
  127. CtxtHandle hContext;
  128. TimeStamp Expiration;
  129. SecPkgContext_StreamSizes Sizes;
  130. SecBufferDesc OutputBufferDescriptor;
  131. SecBufferDesc InputBufferDescriptor;
  132. SecBuffer OutBuffers[1];
  133. SecBuffer InBuffers[2];
  134. ULONG ContextRequirements;
  135. ULONG ContextAttributes;
  136. BOOL fContinueNeeded;
  137. TransportSecurityError LastError;
  138. };
  139. // Codes used for GetSecurityInfo()
  140. #define NOT_DIRECTLY_CONNECTED -1
  141. #endif // _TPRTSEC