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.

548 lines
10 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. secclnt.hxx
  5. Abstract:
  6. This file contains an abstraction to the security support for clients
  7. and that which is common to both servers and clients.
  8. Author:
  9. Michael Montague (mikemon) 10-Apr-1992
  10. Revision History:
  11. --*/
  12. #ifndef __SECCLNT_HXX__
  13. #define __SECCLNT_HXX__
  14. typedef SecBufferDesc SECURITY_BUFFER_DESCRIPTOR;
  15. typedef SecBuffer SECURITY_BUFFER;
  16. #define MAXIMUM_SECURITY_BLOCK_SIZE 16
  17. enum PACKAGE_LEG_COUNT
  18. {
  19. LegsUnknown,
  20. ThreeLegs,
  21. EvenNumberOfLegs
  22. };
  23. typedef struct
  24. {
  25. #ifdef UNICODE
  26. SecPkgInfoW PackageInfo;
  27. #else
  28. SecPkgInfoA PackageInfo;
  29. #endif
  30. SECURITY_CREDENTIALS *ServerSecurityCredentials;
  31. PACKAGE_LEG_COUNT LegCount;
  32. } SECURITY_PACKAGE_INFO;
  33. typedef struct
  34. {
  35. unsigned long Count;
  36. SECURITY_PACKAGE_INFO * SecurityPackages;
  37. PSecurityFunctionTable RpcSecurityInterface;
  38. void * ProviderDll;
  39. RPC_CHAR *ProviderDllName;
  40. } SECURITY_PROVIDER_INFO;
  41. extern SECURITY_PROVIDER_INFO PAPI * ProviderList;
  42. extern unsigned long NumberOfProviders;
  43. extern unsigned long LoadedProviders;
  44. extern unsigned long AvailableProviders;
  45. extern int SecuritySupportLoaded;
  46. extern int FailedToLoad;
  47. extern PSecurityFunctionTable RpcSecurityInterface;
  48. extern SecPkgInfo PAPI * SecurityPackages;
  49. extern unsigned long NumberOfSecurityPackages;
  50. extern MUTEX * SecurityCritSect;
  51. extern RPC_STATUS
  52. InsureSecuritySupportLoaded (
  53. );
  54. extern RPC_STATUS
  55. IsAuthenticationServiceSupported (
  56. IN unsigned long AuthenticationService
  57. );
  58. extern RPC_STATUS
  59. FindServerCredentials (
  60. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
  61. IN void __RPC_FAR * Arg,
  62. IN unsigned long AuthenticationService,
  63. IN unsigned long AuthenticationLevel,
  64. IN RPC_CHAR __RPC_FAR * Principal,
  65. IN OUT SECURITY_CREDENTIALS ** SecurityCredentials
  66. );
  67. extern RPC_STATUS
  68. RemoveCredentialsFromCache (
  69. IN unsigned long AuthenticationService
  70. );
  71. extern PACKAGE_LEG_COUNT
  72. GetPackageLegCount(
  73. DWORD id
  74. );
  75. extern BOOL
  76. ReadPackageLegInfo();
  77. extern DWORD * FourLeggedPackages;
  78. class SECURITY_CREDENTIALS
  79. /*++
  80. Class Description:
  81. This class is an abstraction of the credential handle provided by
  82. the Security APIs.
  83. Fields:
  84. PackageIndex - Contains the index for this package in the array of
  85. packages pointed to by SecurityPackages.
  86. Credentials - Contains the credential handle used by the security
  87. package.
  88. --*/
  89. {
  90. friend RPC_STATUS
  91. FindServerCredentials (
  92. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
  93. IN void __RPC_FAR * Arg,
  94. IN unsigned long AuthenticationService,
  95. IN unsigned long AuthenticationLevel,
  96. IN RPC_CHAR __RPC_FAR * Principal,
  97. IN OUT SECURITY_CREDENTIALS ** SecurityCredentials
  98. );
  99. public:
  100. unsigned AuthenticationService;
  101. private:
  102. BOOL Valid;
  103. unsigned int ProviderIndex;
  104. unsigned int PackageIndex;
  105. CredHandle CredentialsHandle;
  106. unsigned int ReferenceCount;
  107. MUTEX CredentialsMutex;
  108. BOOL bServerCredentials;
  109. BOOL fDeleted;
  110. SEC_CHAR __SEC_FAR * DefaultPrincName;
  111. public:
  112. SECURITY_CREDENTIALS (
  113. IN OUT RPC_STATUS PAPI * Status
  114. );
  115. ~SECURITY_CREDENTIALS ();
  116. RPC_STATUS
  117. AcquireCredentialsForServer (
  118. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
  119. IN void __RPC_FAR * Arg,
  120. IN unsigned long AuthenticationService,
  121. IN unsigned long AuthenticationLevel,
  122. IN RPC_CHAR __RPC_FAR * Principal
  123. );
  124. RPC_STATUS
  125. AcquireCredentialsForClient (
  126. IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity,
  127. IN unsigned long AuthenticationService,
  128. IN unsigned long AuthenticationLevel
  129. );
  130. RPC_STATUS
  131. InquireDefaultPrincName (
  132. OUT SEC_CHAR __SEC_FAR **MyDefaultPrincName
  133. );
  134. void
  135. FreeCredentials (
  136. );
  137. unsigned int
  138. MaximumTokenLength (
  139. );
  140. PCredHandle
  141. InquireCredHandle (
  142. );
  143. void
  144. ReferenceCredentials(
  145. );
  146. void
  147. DereferenceCredentials(
  148. BOOL fRemoveIt = FALSE OPTIONAL
  149. );
  150. PSecurityFunctionTable
  151. InquireProviderFunctionTable (
  152. );
  153. int
  154. CompareCredentials(
  155. SECURITY_CREDENTIALS PAPI * Creds
  156. );
  157. };
  158. inline
  159. int
  160. SECURITY_CREDENTIALS::CompareCredentials(
  161. SECURITY_CREDENTIALS PAPI * Creds
  162. )
  163. {
  164. CredHandle * Cookie = Creds->InquireCredHandle();
  165. if ( (CredentialsHandle.dwLower == Cookie->dwLower)
  166. &&(CredentialsHandle.dwUpper == Cookie->dwUpper) )
  167. {
  168. return 0;
  169. }
  170. return 1;
  171. }
  172. inline unsigned int
  173. SECURITY_CREDENTIALS::MaximumTokenLength (
  174. )
  175. /*++
  176. Return Value:
  177. The maximum size, in bytes, of the tokens passed around at security
  178. context initialization time.
  179. --*/
  180. {
  181. return(ProviderList[ProviderIndex].SecurityPackages[PackageIndex].PackageInfo.cbMaxToken);
  182. }
  183. inline PSecurityFunctionTable
  184. SECURITY_CREDENTIALS::InquireProviderFunctionTable(
  185. )
  186. /*++
  187. Return Value:
  188. --*/
  189. {
  190. return(ProviderList[ProviderIndex].RpcSecurityInterface);
  191. }
  192. inline PCredHandle
  193. SECURITY_CREDENTIALS::InquireCredHandle (
  194. )
  195. /*++
  196. Return Value:
  197. The credential handle for this object will be returned.
  198. --*/
  199. {
  200. return(&CredentialsHandle);
  201. }
  202. class SECURITY_CONTEXT : public CLIENT_AUTH_INFO
  203. /*++
  204. Class Description:
  205. This is an abstraction of a security context. It allows you to use
  206. it to generate signatures and then verify them, as well as, sealing
  207. and unsealing messages.
  208. Fields:
  209. DontForgetToDelete - Contains a flag indicating whether or not there
  210. is a valid security context which needs to be deleted. A value
  211. of non-zero indicates there is a valid security context.
  212. SecurityContext - Contains a handle to the security context maintained
  213. by the security package on our behalf.
  214. MaxHeaderLength - Contains the maximum size of a header for this
  215. security context.
  216. MaxSignatureLength - Contains the maximum size of a signature for
  217. this security context.
  218. --*/
  219. {
  220. public:
  221. unsigned AuthContextId;
  222. unsigned Flags;
  223. unsigned long ContextAttributes;
  224. PACKAGE_LEG_COUNT Legs;
  225. SECURITY_CONTEXT (
  226. CLIENT_AUTH_INFO *myAuthInfo,
  227. unsigned myAuthContextId,
  228. BOOL fUseDatagram,
  229. RPC_STATUS __RPC_FAR * pStatus
  230. );
  231. inline ~SECURITY_CONTEXT (
  232. void
  233. )
  234. {
  235. DeleteSecurityContext();
  236. }
  237. RPC_STATUS
  238. SetMaximumLengths (
  239. );
  240. unsigned int
  241. MaximumHeaderLength (
  242. );
  243. unsigned int
  244. MaximumSignatureLength (
  245. );
  246. unsigned int
  247. BlockSize (
  248. );
  249. RPC_STATUS
  250. CompleteSecurityToken (
  251. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor
  252. );
  253. RPC_STATUS
  254. SignOrSeal (
  255. IN unsigned long Sequence,
  256. IN unsigned int SignNotSealFlag,
  257. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor
  258. );
  259. RPC_STATUS
  260. VerifyOrUnseal (
  261. IN unsigned long Sequence,
  262. IN unsigned int VerifyNotUnsealFlag,
  263. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor
  264. );
  265. BOOL
  266. FullyConstructed()
  267. {
  268. return fFullyConstructed;
  269. }
  270. // client-side calls
  271. RPC_STATUS
  272. InitializeFirstTime(
  273. IN SECURITY_CREDENTIALS * Credentials,
  274. IN RPC_CHAR * ServerPrincipal,
  275. IN unsigned long AuthenticationLevel,
  276. IN OUT SECURITY_BUFFER_DESCRIPTOR * BufferDescriptor,
  277. IN OUT unsigned char *NewAuthType = NULL
  278. );
  279. RPC_STATUS
  280. InitializeThirdLeg(
  281. IN SECURITY_CREDENTIALS * Credentials,
  282. IN unsigned long DataRep,
  283. IN SECURITY_BUFFER_DESCRIPTOR * In,
  284. IN OUT SECURITY_BUFFER_DESCRIPTOR * Out
  285. );
  286. RPC_STATUS
  287. GetWireIdForSnego(
  288. OUT unsigned char *WireId
  289. );
  290. // server-side calls
  291. void
  292. DeletePac (
  293. void PAPI * Pac
  294. );
  295. RPC_STATUS
  296. AcceptFirstTime (
  297. IN SECURITY_CREDENTIALS * Credentials,
  298. IN SECURITY_BUFFER_DESCRIPTOR PAPI * InputBufferDescriptor,
  299. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * OutputBufferDescriptor,
  300. IN unsigned long AuthenticationLevel,
  301. IN unsigned long DataRepresentation,
  302. IN unsigned long NewContextNeededFlag
  303. );
  304. RPC_STATUS
  305. AcceptThirdLeg (
  306. IN unsigned long DataRepresentation,
  307. IN SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor,
  308. OUT SECURITY_BUFFER_DESCRIPTOR PAPI * OutBufferDescriptor
  309. );
  310. unsigned long
  311. InquireAuthorizationService (
  312. );
  313. RPC_AUTHZ_HANDLE
  314. InquirePrivileges (
  315. );
  316. RPC_STATUS
  317. ImpersonateClient (
  318. );
  319. void
  320. RevertToSelf (
  321. );
  322. RPC_STATUS
  323. GetAccessToken (
  324. OUT HANDLE *ImpersonationToken,
  325. OUT BOOL *fNeedToCloseToken
  326. );
  327. inline AUTHZ_CLIENT_CONTEXT_HANDLE
  328. GetAuthzContext (
  329. void
  330. )
  331. {
  332. return AuthzClientContext;
  333. }
  334. inline PAUTHZ_CLIENT_CONTEXT_HANDLE
  335. GetAuthzContextAddress (
  336. void
  337. )
  338. {
  339. return &AuthzClientContext;
  340. }
  341. DWORD
  342. GetDceInfo (
  343. RPC_AUTHZ_HANDLE __RPC_FAR * PacHandle,
  344. unsigned long __RPC_FAR * AuthzSvc
  345. );
  346. void
  347. DeleteSecurityContext (
  348. void
  349. );
  350. RPC_STATUS
  351. CheckForFailedThirdLeg (
  352. void
  353. );
  354. protected:
  355. unsigned char fFullyConstructed;
  356. unsigned char DontForgetToDelete;
  357. unsigned char fDatagram;
  358. CtxtHandle SecurityContext;
  359. unsigned int MaxHeaderLength;
  360. unsigned int MaxSignatureLength;
  361. unsigned int cbBlockSize;
  362. PSecurityFunctionTable RpcSecurityInterface;
  363. int FailedContext;
  364. ExtendedErrorInfo *FailedContextEEInfo;
  365. AUTHZ_CLIENT_CONTEXT_HANDLE AuthzClientContext;
  366. DWORD VerifyCertificate();
  367. public:
  368. CtxtHandle *
  369. InqSecurityContext ()
  370. {
  371. return &SecurityContext;
  372. }
  373. };
  374. typedef SECURITY_CONTEXT * PSECURITY_CONTEXT;
  375. inline unsigned int
  376. SECURITY_CONTEXT::MaximumHeaderLength (
  377. )
  378. /*++
  379. Return Value:
  380. The maximum size of the header used by SECURITY_CONTEXT::SealMessage
  381. will be returned. This is in bytes.
  382. --*/
  383. {
  384. return(MaxHeaderLength);
  385. }
  386. inline unsigned int
  387. SECURITY_CONTEXT::BlockSize (
  388. )
  389. /*++
  390. Return Value:
  391. For best effect, buffers to be signed or sealed should be a multiple
  392. of this length.
  393. --*/
  394. {
  395. return(cbBlockSize);
  396. }
  397. inline unsigned int
  398. SECURITY_CONTEXT::MaximumSignatureLength (
  399. )
  400. /*++
  401. Return Value:
  402. The maximum size, in bytes, of the signature used by
  403. SECURITY_CONTEXT::MakeSignature will be returned.
  404. --*/
  405. {
  406. return(MaxSignatureLength);
  407. }
  408. #endif // __SECCLNT_HXX__