AcquireCredentialsHandle (Schannel) function

The AcquireCredentialsHandle (Schannel) function acquires a handle to preexisting credentials of a security principal. This handle is required by the InitializeSecurityContext (Schannel) and AcceptSecurityContext (Schannel) functions. These can be either preexisting credentials, which are established through a system logon that is not described here, or the caller can provide alternative credentials.


This is not a "log on to the network" and does not imply gathering of credentials.


SECURITY_STATUS SEC_Entry AcquireCredentialsHandle(
  _In_opt_  SEC_CHAR       *pszPrincipal,
  _In_      SEC_CHAR       *pszPackage,
  _In_      ULONG          fCredentialUse,
  _In_opt_  PLUID          pvLogonID,
  _In_opt_  PVOID          pAuthData,
  _In_opt_  SEC_GET_KEY_FN pGetKeyFn,
  _In_opt_  PVOID          pvGetKeyArgument,
  _Out_     PCredHandle    phCredential,
  _Out_opt_ PTimeStamp     ptsExpiry


pszPrincipal [in, optional]

A pointer to a null-terminated string that specifies the name of the principal whose credentials the handle will reference.

When using the Schannel SSP, this parameter is not used and should be set to NULL.


If the process that requests the handle does not have access to the credentials, the function returns an error. A null string indicates that the process requires a handle to the credentials of the user under whose security context it is executing.

pszPackage [in]

A pointer to a null-terminated string that specifies the name of the security package with which these credentials will be used. This is a security package name returned in the Name member of a SecPkgInfo structure returned by the EnumerateSecurityPackages function. After a context is established, QueryContextAttributes (Schannel) can be called with ulAttribute set to SECPKG_ATTR_PACKAGE_INFO to return information on the security package in use.

When using the Schannel SSP, set this parameter to UNISP_NAME.


Kernel mode callers who encounter issues when calling InitializeSecurityContext (Schannel) after calling AcquireCredentialsHandle (Schannel) can alternatively set pszPackage to SCHANNEL_NAME.

fCredentialUse [in]

A flag that indicates how these credentials will be used. This parameter can be one of the following values.

Value Meaning
SECPKG_CRED_INBOUND Validate an incoming server credential. Inbound credentials might be validated by using an authenticating authority when InitializeSecurityContext (Schannel) or AcceptSecurityContext (Schannel) is called. If such an authority is not available, the function will fail and return SEC_E_NO_AUTHENTICATING_AUTHORITY. Validation is package specific.
SECPKG_CRED_OUTBOUND Allow a local client credential to prepare an outgoing token.

pvLogonID [in, optional]

A pointer to a locally unique identifier (LUID) that identifies the user. This parameter is provided for file-system processes such as network redirectors. This parameter can be NULL.

When using the Schannel SSP, this parameter is not used and should be set to NULL.

pAuthData [in, optional]

A pointer to package-specific data. This parameter can be NULL, which indicates that the default credentials for that security package must be used. To use supplied credentials, pass a SEC_WINNT_AUTH_IDENTITY structure that includes those credentials in this parameter. The RPC run time passes whatever was provided in RpcBindingSetAuthInfo.

When using the Schannel SSP, specify an SCH_CREDENTIALS structure that indicates the protocol to use and the settings for various customizable channel features.

pGetKeyFn [in, optional]

This parameter is not used and should be set to NULL.

pvGetKeyArgument [in, optional]

This parameter is not used and should be set to NULL.

phCredential [out]

A pointer to a CredHandle structure to receive the credential handle.

ptsExpiry [out, optional]

A pointer to a TimeStamp structure that receives the time at which the returned credentials expire. The value returned in this TimeStamp structure depends on the constrained delegation. The security package must return this value in local time.

When using the Schannel SSP, this parameter is optional. When the credential to be used for authentication is a certificate, this parameter receives the expiration time for that certificate. If no certificate was supplied, then a maximum time value is returned.

Return value

If the function succeeds, the function returns SEC_E_OK.

If the function fails, it returns one of the following error codes.

Return code Description
SEC_E_INSUFFICIENT_MEMORY There is not enough memory available to complete the requested action.
SEC_E_INTERNAL_ERROR An error occurred that did not map to an SSPI error code.
SEC_E_NO_CREDENTIALS No credentials are available in the constrained delegation.
SEC_E_NOT_OWNER The caller of the function does not have the necessary credentials.
SEC_E_SECPKG_NOT_FOUND The requested security package does not exist.
SEC_E_UNKNOWN_CREDENTIALS The credentials supplied to the package were not recognized.


The AcquireCredentialsHandle (Schannel) function returns a handle to the credentials of a principal, such as a user or client, as used by a specific constrained delegation. This can be the handle to preexisting credentials, or the function can create a new set of credentials and return it. This handle can be used in subsequent calls to the AcceptSecurityContext (Schannel) and InitializeSecurityContext (Schannel) functions.

In general, AcquireCredentialsHandle (Schannel) does not allow a process to obtain a handle to the credentials of other users logged on to the same computer. However, a caller with SE_TCB_NAME privilege has the option of specifying the logon identifier (LUID) of any existing logon session token to get a handle to that session's credentials. Typically, this is used by kernel-mode modules that must act on behalf of a logged-on user.

A package might call the function in pGetKeyFn provided by the RPC run-time transport. If the transport does not support the notion of callback to retrieve credentials, this parameter must be NULL.

For kernel mode callers, the following differences must be noted:

  • The two string parameters must be Unicode strings.
  • The buffer values must be allocated in process virtual memory, not from the pool.

When you have finished using the returned credentials, free the memory used by the credentials by calling the FreeCredentialsHandle function.


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Header Sspi.h (include Security.h)
Library Secur32.lib
DLL Secur32.dll
Unicode and ANSI names AcquireCredentialsHandleW (Unicode) and AcquireCredentialsHandleA (ANSI)

See also

AcceptSecurityContext (Schannel)


InitializeSecurityContext (Schannel)


SSPI Functions