static int nla_server_init(rdpNla* nla)
{
	rdpTls* tls;
	freerdp_peer* peer;
	SEC_WINNT_AUTH_IDENTITY_WINPR* identity;

	WINPR_ASSERT(nla);

	tls = transport_get_tls(nla->transport);
	WINPR_ASSERT(tls);

	if (!nla_sec_buffer_alloc_from_data(&nla->PublicKey, tls->PublicKey, 0, tls->PublicKeyLength))
	{
		WLog_ERR(TAG, "Failed to allocate SecBuffer for public key");
		return -1;
	}

	if (!nla_sspi_module_init(nla))
		return -1;

	if (!nla_setup_kerberos(nla))
		return -1;

	WINPR_ASSERT(nla->rdpcontext);
	WINPR_ASSERT(nla->rdpcontext->peer);

	peer = nla->rdpcontext->peer;
	WINPR_ASSERT(peer);

	identity = &nla->identityWinPr;
	identity->ntlmSettings.hashCallback = peer->SspiNtlmHashCallback;
	identity->ntlmSettings.hashCallbackArg = peer;
	identity->ntlmSettings.samFile = nla->SamFile;

	nla->status = nla_update_package_name(nla);

	if (nla->status != SEC_E_OK)
		return -1;

	nla->status = nla->table->AcquireCredentialsHandle(NULL, NLA_PKG_NAME, SECPKG_CRED_INBOUND,
	                                                   NULL, nla->identity, NULL, NULL,
	                                                   &nla->credentials, &nla->expiration);

	if (nla->status != SEC_E_OK)
	{
		WLog_ERR(TAG, "AcquireCredentialsHandle status %s [0x%08" PRIX32 "]",
		         GetSecurityStatusString(nla->status), nla->status);
		return -1;
	}

	nla->haveContext = FALSE;
	nla->haveInputBuffer = FALSE;
	nla->havePubKeyAuth = FALSE;

	ZeroMemory(&nla->ContextSizes, sizeof(SecPkgContext_Sizes));
	/*
	 * from tspkg.dll: 0x00000112
	 * ASC_REQ_MUTUAL_AUTH
	 * ASC_REQ_CONFIDENTIALITY
	 * ASC_REQ_ALLOCATE_MEMORY
	 */
	nla->fContextReq = 0;
	nla->fContextReq |= ASC_REQ_MUTUAL_AUTH;
	nla->fContextReq |= ASC_REQ_CONFIDENTIALITY;
	nla->fContextReq |= ASC_REQ_CONNECTION;
	nla->fContextReq |= ASC_REQ_USE_SESSION_KEY;
	nla->fContextReq |= ASC_REQ_REPLAY_DETECT;
	nla->fContextReq |= ASC_REQ_SEQUENCE_DETECT;
	nla->fContextReq |= ASC_REQ_EXTENDED_ERROR;
	nla_set_state(nla, NLA_STATE_INITIAL);
	return 1;
}
static int nla_server_init(rdpNla* nla)
{
	rdpTls* tls;
	freerdp_peer* peer;
	SEC_WINNT_AUTH_IDENTITY_WINPR* identity;

	WINPR_ASSERT(nla);

	tls = transport_get_tls(nla->transport);
	WINPR_ASSERT(tls);

	if (!nla_sec_buffer_alloc_from_data(&nla->PublicKey, tls->PublicKey, 0, tls->PublicKeyLength))
	{
		WLog_ERR(TAG, "Failed to allocate SecBuffer for public key");
		return -1;
	}

	if (!nla_sspi_module_init(nla))
		return -1;

	if (!nla_setup_kerberos(nla))
		return -1;

	WINPR_ASSERT(nla->rdpcontext);
	WINPR_ASSERT(nla->rdpcontext->peer);

	peer = nla->rdpcontext->peer;
	WINPR_ASSERT(peer);

	identity = &nla->identityWinPr;
	identity->ntlmSettings.hashCallback = peer->SspiNtlmHashCallback;
	identity->ntlmSettings.hashCallbackArg = peer;
	identity->ntlmSettings.samFile = nla->SamFile;

	nla->status = nla_update_package_name(nla);

	if (nla->status != SEC_E_OK)
		return -1;

	nla->status = nla->table->AcquireCredentialsHandle(NULL, NLA_PKG_NAME, SECPKG_CRED_INBOUND,
	                                                   NULL, nla->identity, NULL, NULL,
	                                                   &nla->credentials, &nla->expiration);

	if (nla->status != SEC_E_OK)
	{
		WLog_ERR(TAG, "AcquireCredentialsHandle status %s [0x%08" PRIX32 "]",
		         GetSecurityStatusString(nla->status), nla->status);
		return -1;
	}

	nla->haveContext = FALSE;
	nla->haveInputBuffer = FALSE;
	nla->havePubKeyAuth = FALSE;

	ZeroMemory(&nla->ContextSizes, sizeof(SecPkgContext_Sizes));
	 
	nla->fContextReq = 0;
	nla->fContextReq |= ASC_REQ_MUTUAL_AUTH;
	nla->fContextReq |= ASC_REQ_CONFIDENTIALITY;
	nla->fContextReq |= ASC_REQ_CONNECTION;
	nla->fContextReq |= ASC_REQ_USE_SESSION_KEY;
	nla->fContextReq |= ASC_REQ_REPLAY_DETECT;
	nla->fContextReq |= ASC_REQ_SEQUENCE_DETECT;
	nla->fContextReq |= ASC_REQ_EXTENDED_ERROR;
	nla_set_state(nla, NLA_STATE_INITIAL);
	return 1;
}