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.

487 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: package.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 10-02-96 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "sslp.h"
  18. #include <ntmsv1_0.h>
  19. #include <wow64t.h>
  20. #define UNISP_NAME_WO L"Microsoft Unified Security Protocol Provider"
  21. #define SSL2SP_NAME_WO L"Microsoft SSL"
  22. #define SSL3SP_NAME_WO L"Microsoft SSL 3.0"
  23. #define PCT1SP_NAME_WO L"Microsoft PCT"
  24. #define SCHANNEL_PACKAGE_NAME L"Schannel"
  25. #define SCHANNEL_PACKAGE_COMMENT L"Schannel Security Package"
  26. #define SCHANNEL_DLL_NAME L"schannel.dll"
  27. DWORD dwSchannelPackageCapabilities = SECPKG_FLAG_INTEGRITY |
  28. SECPKG_FLAG_PRIVACY |
  29. SECPKG_FLAG_CONNECTION |
  30. SECPKG_FLAG_MULTI_REQUIRED |
  31. SECPKG_FLAG_EXTENDED_ERROR |
  32. SECPKG_FLAG_IMPERSONATION |
  33. SECPKG_FLAG_ACCEPT_WIN32_NAME |
  34. // SECPKG_FLAG_NEGOTIABLE |
  35. SECPKG_FLAG_MUTUAL_AUTH |
  36. SECPKG_FLAG_STREAM;
  37. BOOL SslGlobalStrongEncryptionPermitted = FALSE;
  38. // List of (QueryContextAttributes) attributes that are to be
  39. // thunked down to the LSA process.
  40. ULONG ThunkedContextLevels[] = {
  41. SECPKG_ATTR_AUTHORITY,
  42. SECPKG_ATTR_ISSUER_LIST,
  43. SECPKG_ATTR_ISSUER_LIST_EX,
  44. SECPKG_ATTR_LOCAL_CERT_CONTEXT,
  45. SECPKG_ATTR_LOCAL_CRED,
  46. SECPKG_ATTR_EAP_KEY_BLOCK,
  47. SECPKG_ATTR_USE_VALIDATED,
  48. SECPKG_ATTR_CREDENTIAL_NAME,
  49. SECPKG_ATTR_TARGET_INFORMATION,
  50. SECPKG_ATTR_APP_DATA
  51. };
  52. //
  53. // This package exports the following: A unified ssl/tls/pct provider,
  54. // and the same unified provider under a different name. We have to
  55. // keep the original one for backward compatibility, but whistler
  56. // components can start using the new friendlier name.
  57. //
  58. SECPKG_FUNCTION_TABLE SpTable[] = {
  59. { // The Unified Provider
  60. NULL,
  61. NULL,
  62. SpCallPackage,
  63. SpLogonTerminated,
  64. SpCallPackageUntrusted,
  65. SpCallPackagePassthrough,
  66. NULL,
  67. NULL,
  68. SpInitialize,
  69. SpShutdown,
  70. SpUniGetInfo,
  71. SpAcceptCredentials,
  72. SpUniAcquireCredentialsHandle,
  73. SpQueryCredentialsAttributes,
  74. SpFreeCredentialsHandle,
  75. SpSaveCredentials,
  76. SpGetCredentials,
  77. SpDeleteCredentials,
  78. SpInitLsaModeContext,
  79. SpAcceptLsaModeContext,
  80. SpDeleteContext,
  81. SpApplyControlToken,
  82. SpGetUserInfo,
  83. SpGetExtendedInformation,
  84. SpLsaQueryContextAttributes,
  85. NULL,
  86. NULL,
  87. SpSetContextAttributes
  88. },
  89. { // The Unified Provider
  90. NULL,
  91. NULL,
  92. SpCallPackage,
  93. SpLogonTerminated,
  94. SpCallPackageUntrusted,
  95. SpCallPackagePassthrough,
  96. NULL,
  97. NULL,
  98. SpInitialize,
  99. SpShutdown,
  100. SpSslGetInfo,
  101. SpAcceptCredentials,
  102. SpUniAcquireCredentialsHandle,
  103. SpQueryCredentialsAttributes,
  104. SpFreeCredentialsHandle,
  105. SpSaveCredentials,
  106. SpGetCredentials,
  107. SpDeleteCredentials,
  108. SpInitLsaModeContext,
  109. SpAcceptLsaModeContext,
  110. SpDeleteContext,
  111. SpApplyControlToken,
  112. SpGetUserInfo,
  113. SpGetExtendedInformation,
  114. SpLsaQueryContextAttributes,
  115. NULL,
  116. NULL,
  117. SpSetContextAttributes
  118. }
  119. };
  120. ULONG_PTR SpPackageId;
  121. PLSA_SECPKG_FUNCTION_TABLE LsaTable ;
  122. BOOL SpInitialized = FALSE ;
  123. HINSTANCE hDllInstance ;
  124. BOOL ReplaceBaseProvider = TRUE;
  125. TOKEN_SOURCE SslTokenSource ;
  126. SECURITY_STRING SslNamePrefix = { 8, 10, L"X509" };
  127. SECURITY_STRING SslComputerName ;
  128. SECURITY_STRING SslDomainName ;
  129. SECURITY_STRING SslPackageName ;
  130. SECURITY_STRING SslMsvName ;
  131. extern PWSTR SslDnsDomainName ;
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Function: SpLsaModeInitialize
  135. //
  136. // Synopsis: LSA Mode Initialization Function
  137. //
  138. // Arguments: [LsaVersion] --
  139. // [PackageVersion] --
  140. // [Table] --
  141. // [TableCount] --
  142. //
  143. // History: 10-03-96 RichardW Created
  144. //
  145. // Notes:
  146. //
  147. //----------------------------------------------------------------------------
  148. SECURITY_STATUS
  149. SEC_ENTRY
  150. SpLsaModeInitialize(
  151. IN ULONG LsaVersion,
  152. OUT PULONG PackageVersion,
  153. OUT PSECPKG_FUNCTION_TABLE * Table,
  154. OUT PULONG TableCount)
  155. {
  156. HKEY hKey;
  157. int err;
  158. DWORD type;
  159. DWORD size;
  160. *PackageVersion = SECPKG_INTERFACE_VERSION_2;
  161. *Table = SpTable ;
  162. *TableCount = sizeof( SpTable ) / sizeof( SECPKG_FUNCTION_TABLE );
  163. return( SEC_E_OK );
  164. }
  165. //+---------------------------------------------------------------------------
  166. //
  167. // Function: SpInitialize
  168. //
  169. // Synopsis: Package Initialization Function
  170. //
  171. // Arguments: [dwPackageID] --
  172. // [pParameters] --
  173. // [Table] --
  174. //
  175. // History: 10-03-96 RichardW Created
  176. //
  177. // Notes:
  178. //
  179. //----------------------------------------------------------------------------
  180. SECURITY_STATUS
  181. SEC_ENTRY
  182. SpInitialize(
  183. ULONG_PTR dwPackageID,
  184. PSECPKG_PARAMETERS pParameters,
  185. PLSA_SECPKG_FUNCTION_TABLE Table)
  186. {
  187. WCHAR ComputerName[ 32 ];
  188. DWORD Size ;
  189. UNICODE_STRING Temp ;
  190. if ( !SpInitialized )
  191. {
  192. SpPackageId = dwPackageID ;
  193. LsaTable = Table ;
  194. CopyMemory( SslTokenSource.SourceName, "SChannel", 8 );
  195. AllocateLocallyUniqueId( &SslTokenSource.SourceIdentifier );
  196. Size = sizeof( ComputerName ) / sizeof( WCHAR );
  197. GetComputerName( ComputerName, &Size );
  198. RtlInitUnicodeString( &Temp, ComputerName );
  199. SslDuplicateString( &SslComputerName, &Temp );
  200. SslDuplicateString( &SslDomainName, &pParameters->DomainName );
  201. RtlInitUnicodeString( &SslPackageName, UNISP_NAME_W );
  202. RtlCreateUnicodeStringFromAsciiz( &SslMsvName, MSV1_0_PACKAGE_NAME );
  203. if ( !SslDnsDomainName )
  204. {
  205. DWORD DnsDomainLength = 0 ;
  206. GetComputerNameEx( ComputerNameDnsDomain, NULL, &DnsDomainLength );
  207. SslDnsDomainName = LocalAlloc( LMEM_FIXED,
  208. (DnsDomainLength + 1) * sizeof(WCHAR) );
  209. if ( SslDnsDomainName )
  210. {
  211. DnsDomainLength++ ;
  212. GetComputerNameEx( ComputerNameDnsDomain, SslDnsDomainName, &DnsDomainLength );
  213. }
  214. }
  215. if ((pParameters->MachineState & SECPKG_STATE_STRONG_ENCRYPTION_PERMITTED) != 0)
  216. {
  217. SslGlobalStrongEncryptionPermitted = TRUE;
  218. }
  219. SpInitialized = TRUE;
  220. }
  221. return(S_OK);
  222. }
  223. //+---------------------------------------------------------------------------
  224. //
  225. // Function: SpUniGetInfo
  226. //
  227. // Synopsis: Get Package Information
  228. //
  229. // Arguments: [pInfo] --
  230. //
  231. // History: 10-03-96 RichardW Created
  232. //
  233. // Notes:
  234. //
  235. //----------------------------------------------------------------------------
  236. SECURITY_STATUS
  237. SEC_ENTRY
  238. SpUniGetInfo(
  239. PSecPkgInfo pInfo
  240. )
  241. {
  242. pInfo->wVersion = 1;
  243. pInfo->wRPCID = UNISP_RPC_ID;
  244. pInfo->fCapabilities = dwSchannelPackageCapabilities;
  245. pInfo->cbMaxToken = 0x4000;
  246. pInfo->Name = ReplaceBaseProvider ? UNISP_NAME_WO : UNISP_NAME_W ;
  247. pInfo->Comment = UNISP_NAME_W ;
  248. return(S_OK);
  249. }
  250. //+---------------------------------------------------------------------------
  251. //
  252. // Function: SpSslGetInfo
  253. //
  254. // Synopsis: Get Package Information
  255. //
  256. // Arguments: [pInfo] --
  257. //
  258. // History: 10-03-96 RichardW Created
  259. //
  260. // Notes:
  261. //
  262. //----------------------------------------------------------------------------
  263. SECURITY_STATUS
  264. SEC_ENTRY
  265. SpSslGetInfo(
  266. PSecPkgInfo pInfo
  267. )
  268. {
  269. pInfo->wVersion = 1;
  270. pInfo->wRPCID = UNISP_RPC_ID;
  271. pInfo->fCapabilities = dwSchannelPackageCapabilities;
  272. pInfo->cbMaxToken = 0x4000;
  273. pInfo->Name = SCHANNEL_PACKAGE_NAME;
  274. pInfo->Comment = SCHANNEL_PACKAGE_COMMENT;
  275. return(S_OK);
  276. }
  277. //+---------------------------------------------------------------------------
  278. //
  279. // Function: SslDuplicateString
  280. //
  281. // Synopsis: Duplicate a unicode string
  282. //
  283. // Arguments: [Dest] --
  284. // [Source] --
  285. //
  286. // History: 10-18-96 RichardW Created
  287. //
  288. // Notes:
  289. //
  290. //----------------------------------------------------------------------------
  291. NTSTATUS
  292. SslDuplicateString(
  293. PUNICODE_STRING Dest,
  294. PUNICODE_STRING Source
  295. )
  296. {
  297. Dest->Buffer = (PWSTR) SPExternalAlloc( Source->Length + sizeof(WCHAR) );
  298. if ( Dest->Buffer )
  299. {
  300. Dest->Length = Source->Length ;
  301. Dest->MaximumLength = Source->Length + sizeof(WCHAR) ;
  302. CopyMemory( Dest->Buffer, Source->Buffer, Source->Length );
  303. Dest->Buffer[ Dest->Length / 2 ] = L'\0';
  304. return( STATUS_SUCCESS );
  305. }
  306. return( STATUS_NO_MEMORY );
  307. }
  308. //+---------------------------------------------------------------------------
  309. //
  310. // Function: SpGetExtendedInformation
  311. //
  312. // Synopsis: Return extended information to the LSA
  313. //
  314. // Arguments: [Class] -- Information Class
  315. // [pInfo] -- Returned Information Pointer
  316. //
  317. // History: 3-24-97 ramas Created
  318. //
  319. // Notes:
  320. //
  321. //----------------------------------------------------------------------------
  322. SECURITY_STATUS
  323. SEC_ENTRY
  324. SpGetExtendedInformation(
  325. SECPKG_EXTENDED_INFORMATION_CLASS Class,
  326. PSECPKG_EXTENDED_INFORMATION * pInfo
  327. )
  328. {
  329. PSECPKG_EXTENDED_INFORMATION Info ;
  330. PWSTR pszPath;
  331. SECURITY_STATUS Status ;
  332. ULONG Size ;
  333. switch ( Class )
  334. {
  335. case SecpkgContextThunks:
  336. Info = (PSECPKG_EXTENDED_INFORMATION) LsaTable->AllocateLsaHeap(
  337. sizeof( SECPKG_EXTENDED_INFORMATION ) +
  338. sizeof( ThunkedContextLevels ) );
  339. if ( Info )
  340. {
  341. Info->Class = Class ;
  342. Info->Info.ContextThunks.InfoLevelCount =
  343. sizeof( ThunkedContextLevels ) / sizeof( ULONG );
  344. CopyMemory( Info->Info.ContextThunks.Levels,
  345. ThunkedContextLevels,
  346. sizeof( ThunkedContextLevels ) );
  347. Status = SEC_E_OK ;
  348. }
  349. else
  350. {
  351. Status = SEC_E_INSUFFICIENT_MEMORY ;
  352. }
  353. break;
  354. #ifdef LATER
  355. case SecpkgGssInfo:
  356. Info = (PSECPKG_EXTENDED_INFORMATION) LsaTable->AllocateLsaHeap(
  357. sizeof( SECPKG_EXTENDED_INFORMATION ) +
  358. sizeof( Md5Oid ) );
  359. if ( Info )
  360. {
  361. Info->Class = Class ;
  362. Info->Info.GssInfo.EncodedIdLength = sizeof( Md5Oid );
  363. CopyMemory( Info->Info.GssInfo.EncodedId,
  364. Md5Oid,
  365. sizeof( Md5Oid ) );
  366. Status = SEC_E_OK ;
  367. }
  368. else
  369. {
  370. Status = SEC_E_INSUFFICIENT_MEMORY ;
  371. }
  372. #endif
  373. case SecpkgWowClientDll:
  374. //
  375. // This indicates that we're smart enough to handle wow client processes
  376. //
  377. Info = (PSECPKG_EXTENDED_INFORMATION)
  378. LsaTable->AllocateLsaHeap( sizeof( SECPKG_EXTENDED_INFORMATION ) +
  379. (MAX_PATH * sizeof(WCHAR) ) );
  380. if ( Info == NULL )
  381. {
  382. Status = STATUS_INSUFFICIENT_RESOURCES ;
  383. break;
  384. }
  385. pszPath = (PWSTR) (Info + 1);
  386. Size = GetSystemWow64Directory(pszPath, MAX_PATH);
  387. if(Size == 0)
  388. {
  389. // This call will fail on x86 platforms.
  390. Status = SEC_E_UNSUPPORTED_FUNCTION;
  391. LsaTable->FreeLsaHeap(Info);
  392. break;
  393. }
  394. if(Size + 1 + wcslen(SCHANNEL_DLL_NAME) >= MAX_PATH)
  395. {
  396. Status = STATUS_INSUFFICIENT_RESOURCES ;
  397. LsaTable->FreeLsaHeap(Info);
  398. break;
  399. }
  400. wcscat(pszPath, L"\\");
  401. wcscat(pszPath, SCHANNEL_DLL_NAME);
  402. Size += 1 + wcslen(SCHANNEL_DLL_NAME);
  403. Info->Class = SecpkgWowClientDll ;
  404. Info->Info.WowClientDll.WowClientDllPath.Buffer = pszPath;
  405. Info->Info.WowClientDll.WowClientDllPath.Length = (USHORT) (Size * sizeof(WCHAR));
  406. Info->Info.WowClientDll.WowClientDllPath.MaximumLength = (USHORT) ((Size + 1) * sizeof(WCHAR) );
  407. Status = SEC_E_OK;
  408. break;
  409. default:
  410. Status = SEC_E_UNSUPPORTED_FUNCTION ;
  411. Info = NULL ;
  412. break;
  413. }
  414. *pInfo = Info ;
  415. return Status ;
  416. }