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.

173 lines
4.7 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 (BOOL bService);
  68. ~SecurityInterface ();
  69. TransportSecurityError Initialize ();
  70. TransportSecurityError InitializeCreds (PCCERT_CONTEXT);
  71. TransportSecurityError GetLastError(VOID) { return LastError; };
  72. BOOL GetUserCert(PBYTE pInfo, PDWORD pcbInfo);
  73. BOOL IsInServiceContext(VOID) { return bInServiceContext; }
  74. private:
  75. HINSTANCE hSecurityDll;
  76. INIT_SECURITY_INTERFACE pfnInitSecurityInterface;
  77. PSecurityFunctionTable pfnTable;
  78. PFN_SSL_EMPTY_CACHE pfn_SslEmptyCache;
  79. PBYTE m_pbEncodedCert;
  80. DWORD m_cbEncodedCert;
  81. BOOL bInboundCredentialValid;
  82. BOOL bOutboundCredentialValid;
  83. BOOL bInServiceContext;
  84. CredHandle hInboundCredential;
  85. CredHandle hOutboundCredential;
  86. TimeStamp tsExpiry;
  87. TransportSecurityError LastError;
  88. };
  89. class SecurityContext
  90. {
  91. public:
  92. SecurityContext (PSecurityInterface pSI, LPCSTR szHostName);
  93. ~SecurityContext ();
  94. TransportSecurityError Initialize (PBYTE pData, DWORD cbData);
  95. TransportSecurityError Accept (PBYTE pData, DWORD cbData);
  96. TransportSecurityError Encrypt(LPBYTE pBufIn1, UINT cbBufIn1,
  97. LPBYTE pBufIn2, UINT cbBufIn2,
  98. LPBYTE *ppBufOut, UINT *pcbBufOut);
  99. TransportSecurityError Decrypt( PBYTE pszBuf,
  100. DWORD cbBuf);
  101. PVOID GetTokenBuf(VOID) { return OutBuffers[0].pvBuffer; };
  102. ULONG GetTokenSiz(VOID) { return OutBuffers[0].cbBuffer; };
  103. BOOL ContinueNeeded(VOID) { return fContinueNeeded; };
  104. BOOL StateComplete(VOID) { return
  105. scstate == SECCTX_STATE_INIT_COMPLETE ||
  106. scstate == SECCTX_STATE_ACCEPT_COMPLETE; };
  107. BOOL WaitingForPacket(VOID) { return
  108. scstate == SECCTX_STATE_NEW ||
  109. scstate == SECCTX_STATE_ACCEPT ||
  110. scstate == SECCTX_STATE_INIT; };
  111. TransportSecurityError AdvanceState(PBYTE pBuf,DWORD cbBuf);
  112. BOOL EncryptOutgoing(VOID)
  113. { return scstate == SECCTX_STATE_INIT_COMPLETE; };
  114. BOOL DecryptIncoming(VOID)
  115. { return scstate == SECCTX_STATE_ACCEPT_COMPLETE; };
  116. ULONG GetStreamHeaderSize(VOID) { return Sizes.cbHeader; };
  117. ULONG GetStreamTrailerSize(VOID) { return Sizes.cbTrailer; };
  118. TransportSecurityError GetLastError(VOID) { return LastError; };
  119. BOOL GetUserCert(PBYTE pInfo, PDWORD pcbInfo);
  120. BOOL Verify(VOID);
  121. private:
  122. TransportSecurityError InitContextAttributes(VOID);
  123. PSecurityInterface pSecurityInterface;
  124. SecurityContextState scstate;
  125. CHAR szTargetName[128]; // Long enough for any dotted-decimal
  126. // address, followed by 2 dwords in
  127. // hex.
  128. BOOL bContextHandleValid;
  129. CtxtHandle hContext;
  130. TimeStamp Expiration;
  131. SecPkgContext_StreamSizes Sizes;
  132. SecBufferDesc OutputBufferDescriptor;
  133. SecBufferDesc InputBufferDescriptor;
  134. SecBuffer OutBuffers[1];
  135. SecBuffer InBuffers[2];
  136. ULONG ContextRequirements;
  137. ULONG ContextAttributes;
  138. BOOL fContinueNeeded;
  139. TransportSecurityError LastError;
  140. };
  141. // Codes used for GetSecurityInfo()
  142. #define NOT_DIRECTLY_CONNECTED -1
  143. #endif // _TPRTSEC