Removed unused functions, fixed feature define guards

This commit is contained in:
Armin Novak 2017-12-21 11:30:21 +01:00
parent 50a0968c6a
commit a0b49f4e07
3 changed files with 133 additions and 170 deletions

View File

@ -3,7 +3,7 @@
* Schannel Security Package * Schannel Security Package
* *
* Copyright 2012-2014 Marc-Andre Moreau <marcandre.moreau@gmail.com> * Copyright 2012-2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
@ -33,8 +33,8 @@ char* SCHANNEL_PACKAGE_NAME = "Schannel";
SCHANNEL_CONTEXT* schannel_ContextNew() SCHANNEL_CONTEXT* schannel_ContextNew()
{ {
SCHANNEL_CONTEXT* context; SCHANNEL_CONTEXT* context;
context = (SCHANNEL_CONTEXT*) calloc(1, sizeof(SCHANNEL_CONTEXT)); context = (SCHANNEL_CONTEXT*) calloc(1, sizeof(SCHANNEL_CONTEXT));
if (!context) if (!context)
return NULL; return NULL;
@ -55,16 +55,13 @@ void schannel_ContextFree(SCHANNEL_CONTEXT* context)
return; return;
schannel_openssl_free(context->openssl); schannel_openssl_free(context->openssl);
free(context); free(context);
} }
SCHANNEL_CREDENTIALS* schannel_CredentialsNew() SCHANNEL_CREDENTIALS* schannel_CredentialsNew()
{ {
SCHANNEL_CREDENTIALS* credentials; SCHANNEL_CREDENTIALS* credentials;
credentials = (SCHANNEL_CREDENTIALS*) calloc(1, sizeof(SCHANNEL_CREDENTIALS)); credentials = (SCHANNEL_CREDENTIALS*) calloc(1, sizeof(SCHANNEL_CREDENTIALS));
return credentials; return credentials;
} }
@ -82,57 +79,52 @@ static ALG_ID schannel_SupportedAlgs[] =
CALG_DSS_SIGN, CALG_ECDSA CALG_DSS_SIGN, CALG_ECDSA
}; };
SECURITY_STATUS SEC_ENTRY schannel_QueryCredentialsAttributesW(PCredHandle phCredential, ULONG ulAttribute, void* pBuffer) SECURITY_STATUS SEC_ENTRY schannel_QueryCredentialsAttributesW(PCredHandle phCredential,
ULONG ulAttribute, void* pBuffer)
{ {
if (ulAttribute == SECPKG_ATTR_SUPPORTED_ALGS) if (ulAttribute == SECPKG_ATTR_SUPPORTED_ALGS)
{ {
PSecPkgCred_SupportedAlgs SupportedAlgs = (PSecPkgCred_SupportedAlgs) pBuffer; PSecPkgCred_SupportedAlgs SupportedAlgs = (PSecPkgCred_SupportedAlgs) pBuffer;
SupportedAlgs->cSupportedAlgs = sizeof(schannel_SupportedAlgs) / sizeof(ALG_ID); SupportedAlgs->cSupportedAlgs = sizeof(schannel_SupportedAlgs) / sizeof(ALG_ID);
SupportedAlgs->palgSupportedAlgs = (ALG_ID*) schannel_SupportedAlgs; SupportedAlgs->palgSupportedAlgs = (ALG_ID*) schannel_SupportedAlgs;
return SEC_E_OK; return SEC_E_OK;
} }
else if (ulAttribute == SECPKG_ATTR_CIPHER_STRENGTHS) else if (ulAttribute == SECPKG_ATTR_CIPHER_STRENGTHS)
{ {
PSecPkgCred_CipherStrengths CipherStrengths = (PSecPkgCred_CipherStrengths) pBuffer; PSecPkgCred_CipherStrengths CipherStrengths = (PSecPkgCred_CipherStrengths) pBuffer;
CipherStrengths->dwMinimumCipherStrength = 40; CipherStrengths->dwMinimumCipherStrength = 40;
CipherStrengths->dwMaximumCipherStrength = 256; CipherStrengths->dwMaximumCipherStrength = 256;
return SEC_E_OK; return SEC_E_OK;
} }
else if (ulAttribute == SECPKG_ATTR_SUPPORTED_PROTOCOLS) else if (ulAttribute == SECPKG_ATTR_SUPPORTED_PROTOCOLS)
{ {
PSecPkgCred_SupportedProtocols SupportedProtocols = (PSecPkgCred_SupportedProtocols) pBuffer; PSecPkgCred_SupportedProtocols SupportedProtocols = (PSecPkgCred_SupportedProtocols) pBuffer;
/* Observed SupportedProtocols: 0x208A0 */ /* Observed SupportedProtocols: 0x208A0 */
SupportedProtocols->grbitProtocol = (SP_PROT_CLIENTS | SP_PROT_SERVERS); SupportedProtocols->grbitProtocol = (SP_PROT_CLIENTS | SP_PROT_SERVERS);
return SEC_E_OK; return SEC_E_OK;
} }
return SEC_E_UNSUPPORTED_FUNCTION; return SEC_E_UNSUPPORTED_FUNCTION;
} }
SECURITY_STATUS SEC_ENTRY schannel_QueryCredentialsAttributesA(PCredHandle phCredential, ULONG ulAttribute, void* pBuffer) SECURITY_STATUS SEC_ENTRY schannel_QueryCredentialsAttributesA(PCredHandle phCredential,
ULONG ulAttribute, void* pBuffer)
{ {
return schannel_QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer); return schannel_QueryCredentialsAttributesW(phCredential, ulAttribute, pBuffer);
} }
SECURITY_STATUS SEC_ENTRY schannel_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal, SEC_WCHAR* pszPackage, SECURITY_STATUS SEC_ENTRY schannel_AcquireCredentialsHandleW(SEC_WCHAR* pszPrincipal,
ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, SEC_WCHAR* pszPackage,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry) ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
{ {
SCHANNEL_CREDENTIALS* credentials; SCHANNEL_CREDENTIALS* credentials;
if (fCredentialUse == SECPKG_CRED_OUTBOUND) if (fCredentialUse == SECPKG_CRED_OUTBOUND)
{ {
SCHANNEL_CRED* cred; SCHANNEL_CRED* cred;
credentials = schannel_CredentialsNew(); credentials = schannel_CredentialsNew();
credentials->fCredentialUse = fCredentialUse; credentials->fCredentialUse = fCredentialUse;
cred = (SCHANNEL_CRED*) pAuthData; cred = (SCHANNEL_CRED*) pAuthData;
if (cred) if (cred)
@ -142,41 +134,35 @@ SECURITY_STATUS SEC_ENTRY schannel_AcquireCredentialsHandleW(SEC_WCHAR* pszPrinc
sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials); sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials);
sspi_SecureHandleSetUpperPointer(phCredential, (void*) SCHANNEL_PACKAGE_NAME); sspi_SecureHandleSetUpperPointer(phCredential, (void*) SCHANNEL_PACKAGE_NAME);
return SEC_E_OK; return SEC_E_OK;
} }
else if (fCredentialUse == SECPKG_CRED_INBOUND) else if (fCredentialUse == SECPKG_CRED_INBOUND)
{ {
credentials = schannel_CredentialsNew(); credentials = schannel_CredentialsNew();
credentials->fCredentialUse = fCredentialUse; credentials->fCredentialUse = fCredentialUse;
sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials); sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials);
sspi_SecureHandleSetUpperPointer(phCredential, (void*) SCHANNEL_PACKAGE_NAME); sspi_SecureHandleSetUpperPointer(phCredential, (void*) SCHANNEL_PACKAGE_NAME);
return SEC_E_OK; return SEC_E_OK;
} }
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY schannel_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal, SEC_CHAR* pszPackage, SECURITY_STATUS SEC_ENTRY schannel_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal,
ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn, SEC_CHAR* pszPackage,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry) ULONG fCredentialUse, void* pvLogonID, void* pAuthData, SEC_GET_KEY_FN pGetKeyFn,
void* pvGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry)
{ {
SECURITY_STATUS status; SECURITY_STATUS status;
SEC_WCHAR* pszPrincipalW = NULL; SEC_WCHAR* pszPrincipalW = NULL;
SEC_WCHAR* pszPackageW = NULL; SEC_WCHAR* pszPackageW = NULL;
ConvertToUnicode(CP_UTF8, 0, pszPrincipal, -1, &pszPrincipalW, 0); ConvertToUnicode(CP_UTF8, 0, pszPrincipal, -1, &pszPrincipalW, 0);
ConvertToUnicode(CP_UTF8, 0, pszPackage, -1, &pszPackageW, 0); ConvertToUnicode(CP_UTF8, 0, pszPackage, -1, &pszPackageW, 0);
status = schannel_AcquireCredentialsHandleW(pszPrincipalW, pszPackageW, fCredentialUse, pvLogonID, status = schannel_AcquireCredentialsHandleW(pszPrincipalW, pszPackageW, fCredentialUse, pvLogonID,
pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential, ptsExpiry); pAuthData, pGetKeyFn, pvGetKeyArgument, phCredential, ptsExpiry);
free(pszPrincipalW); free(pszPrincipalW);
free(pszPackageW); free(pszPackageW);
return status;
return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY schannel_FreeCredentialsHandle(PCredHandle phCredential) SECURITY_STATUS SEC_ENTRY schannel_FreeCredentialsHandle(PCredHandle phCredential)
@ -192,19 +178,18 @@ SECURITY_STATUS SEC_ENTRY schannel_FreeCredentialsHandle(PCredHandle phCredentia
return SEC_E_INVALID_HANDLE; return SEC_E_INVALID_HANDLE;
schannel_CredentialsFree(credentials); schannel_CredentialsFree(credentials);
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY schannel_InitializeSecurityContextW(PCredHandle phCredential, PCtxtHandle phContext, SECURITY_STATUS SEC_ENTRY schannel_InitializeSecurityContextW(PCredHandle phCredential,
SEC_WCHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PCtxtHandle phContext,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, SEC_WCHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry) PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
{ {
SECURITY_STATUS status; SECURITY_STATUS status;
SCHANNEL_CONTEXT* context; SCHANNEL_CONTEXT* context;
SCHANNEL_CREDENTIALS* credentials; SCHANNEL_CREDENTIALS* credentials;
context = sspi_SecureHandleGetLowerPointer(phContext); context = sspi_SecureHandleGetLowerPointer(phContext);
if (!context) if (!context)
@ -215,25 +200,22 @@ SECURITY_STATUS SEC_ENTRY schannel_InitializeSecurityContextW(PCredHandle phCred
return SEC_E_INSUFFICIENT_MEMORY; return SEC_E_INSUFFICIENT_MEMORY;
credentials = (SCHANNEL_CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential); credentials = (SCHANNEL_CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential);
context->server = FALSE; context->server = FALSE;
CopyMemory(&context->cred, &credentials->cred, sizeof(SCHANNEL_CRED)); CopyMemory(&context->cred, &credentials->cred, sizeof(SCHANNEL_CRED));
sspi_SecureHandleSetLowerPointer(phNewContext, context); sspi_SecureHandleSetLowerPointer(phNewContext, context);
sspi_SecureHandleSetUpperPointer(phNewContext, (void*) SCHANNEL_PACKAGE_NAME); sspi_SecureHandleSetUpperPointer(phNewContext, (void*) SCHANNEL_PACKAGE_NAME);
schannel_openssl_client_init(context->openssl); schannel_openssl_client_init(context->openssl);
} }
status = schannel_openssl_client_process_tokens(context->openssl, pInput, pOutput); status = schannel_openssl_client_process_tokens(context->openssl, pInput, pOutput);
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY schannel_InitializeSecurityContextA(PCredHandle phCredential, PCtxtHandle phContext, SECURITY_STATUS SEC_ENTRY schannel_InitializeSecurityContextA(PCredHandle phCredential,
SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, PCtxtHandle phContext,
PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, SEC_CHAR* pszTargetName, ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry) PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsExpiry)
{ {
SECURITY_STATUS status; SECURITY_STATUS status;
SEC_WCHAR* pszTargetNameW = NULL; SEC_WCHAR* pszTargetNameW = NULL;
@ -244,22 +226,18 @@ SECURITY_STATUS SEC_ENTRY schannel_InitializeSecurityContextA(PCredHandle phCred
} }
status = schannel_InitializeSecurityContextW(phCredential, phContext, pszTargetNameW, fContextReq, status = schannel_InitializeSecurityContextW(phCredential, phContext, pszTargetNameW, fContextReq,
Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry); Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
free(pszTargetNameW); free(pszTargetNameW);
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY schannel_AcceptSecurityContext(PCredHandle phCredential, PCtxtHandle phContext, SECURITY_STATUS SEC_ENTRY schannel_AcceptSecurityContext(PCredHandle phCredential,
PSecBufferDesc pInput, ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext, PCtxtHandle phContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp) PSecBufferDesc pInput, ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, PULONG pfContextAttr, PTimeStamp ptsTimeStamp)
{ {
SECURITY_STATUS status; SECURITY_STATUS status;
SCHANNEL_CONTEXT* context; SCHANNEL_CONTEXT* context;
SCHANNEL_CREDENTIALS* credentials;
status = SEC_E_OK;
context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext); context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext);
if (!context) if (!context)
@ -269,36 +247,30 @@ SECURITY_STATUS SEC_ENTRY schannel_AcceptSecurityContext(PCredHandle phCredentia
if (!context) if (!context)
return SEC_E_INSUFFICIENT_MEMORY; return SEC_E_INSUFFICIENT_MEMORY;
credentials = (SCHANNEL_CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential);
context->server = TRUE; context->server = TRUE;
sspi_SecureHandleSetLowerPointer(phNewContext, context); sspi_SecureHandleSetLowerPointer(phNewContext, context);
sspi_SecureHandleSetUpperPointer(phNewContext, (void*) SCHANNEL_PACKAGE_NAME); sspi_SecureHandleSetUpperPointer(phNewContext, (void*) SCHANNEL_PACKAGE_NAME);
schannel_openssl_server_init(context->openssl); schannel_openssl_server_init(context->openssl);
} }
status = schannel_openssl_server_process_tokens(context->openssl, pInput, pOutput); status = schannel_openssl_server_process_tokens(context->openssl, pInput, pOutput);
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY schannel_DeleteSecurityContext(PCtxtHandle phContext) SECURITY_STATUS SEC_ENTRY schannel_DeleteSecurityContext(PCtxtHandle phContext)
{ {
SCHANNEL_CONTEXT* context; SCHANNEL_CONTEXT* context;
context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext); context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext);
if (!context) if (!context)
return SEC_E_INVALID_HANDLE; return SEC_E_INVALID_HANDLE;
schannel_ContextFree(context); schannel_ContextFree(context);
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY schannel_QueryContextAttributes(PCtxtHandle phContext, ULONG ulAttribute, void* pBuffer) SECURITY_STATUS SEC_ENTRY schannel_QueryContextAttributes(PCtxtHandle phContext, ULONG ulAttribute,
void* pBuffer)
{ {
if (!phContext) if (!phContext)
return SEC_E_INVALID_HANDLE; return SEC_E_INVALID_HANDLE;
@ -309,67 +281,63 @@ SECURITY_STATUS SEC_ENTRY schannel_QueryContextAttributes(PCtxtHandle phContext,
if (ulAttribute == SECPKG_ATTR_SIZES) if (ulAttribute == SECPKG_ATTR_SIZES)
{ {
SecPkgContext_Sizes* Sizes = (SecPkgContext_Sizes*) pBuffer; SecPkgContext_Sizes* Sizes = (SecPkgContext_Sizes*) pBuffer;
Sizes->cbMaxToken = 0x6000; Sizes->cbMaxToken = 0x6000;
Sizes->cbMaxSignature = 16; Sizes->cbMaxSignature = 16;
Sizes->cbBlockSize = 0; Sizes->cbBlockSize = 0;
Sizes->cbSecurityTrailer = 16; Sizes->cbSecurityTrailer = 16;
return SEC_E_OK; return SEC_E_OK;
} }
else if (ulAttribute == SECPKG_ATTR_STREAM_SIZES) else if (ulAttribute == SECPKG_ATTR_STREAM_SIZES)
{ {
SecPkgContext_StreamSizes* StreamSizes = (SecPkgContext_StreamSizes*) pBuffer; SecPkgContext_StreamSizes* StreamSizes = (SecPkgContext_StreamSizes*) pBuffer;
StreamSizes->cbHeader = 5; StreamSizes->cbHeader = 5;
StreamSizes->cbTrailer = 36; StreamSizes->cbTrailer = 36;
StreamSizes->cbMaximumMessage = 0x4000; StreamSizes->cbMaximumMessage = 0x4000;
StreamSizes->cBuffers = 4; StreamSizes->cBuffers = 4;
StreamSizes->cbBlockSize = 16; StreamSizes->cbBlockSize = 16;
return SEC_E_OK; return SEC_E_OK;
} }
return SEC_E_UNSUPPORTED_FUNCTION; return SEC_E_UNSUPPORTED_FUNCTION;
} }
SECURITY_STATUS SEC_ENTRY schannel_MakeSignature(PCtxtHandle phContext, ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo) SECURITY_STATUS SEC_ENTRY schannel_MakeSignature(PCtxtHandle phContext, ULONG fQOP,
PSecBufferDesc pMessage, ULONG MessageSeqNo)
{ {
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY schannel_VerifySignature(PCtxtHandle phContext, PSecBufferDesc pMessage, ULONG MessageSeqNo, ULONG* pfQOP) SECURITY_STATUS SEC_ENTRY schannel_VerifySignature(PCtxtHandle phContext, PSecBufferDesc pMessage,
ULONG MessageSeqNo, ULONG* pfQOP)
{ {
return SEC_E_OK; return SEC_E_OK;
} }
SECURITY_STATUS SEC_ENTRY schannel_EncryptMessage(PCtxtHandle phContext, ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo) SECURITY_STATUS SEC_ENTRY schannel_EncryptMessage(PCtxtHandle phContext, ULONG fQOP,
PSecBufferDesc pMessage, ULONG MessageSeqNo)
{ {
SECURITY_STATUS status; SECURITY_STATUS status;
SCHANNEL_CONTEXT* context; SCHANNEL_CONTEXT* context;
context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext); context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext);
if (!context) if (!context)
return SEC_E_INVALID_HANDLE; return SEC_E_INVALID_HANDLE;
status = schannel_openssl_encrypt_message(context->openssl, pMessage); status = schannel_openssl_encrypt_message(context->openssl, pMessage);
return status; return status;
} }
SECURITY_STATUS SEC_ENTRY schannel_DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage, ULONG MessageSeqNo, ULONG* pfQOP) SECURITY_STATUS SEC_ENTRY schannel_DecryptMessage(PCtxtHandle phContext, PSecBufferDesc pMessage,
ULONG MessageSeqNo, ULONG* pfQOP)
{ {
SECURITY_STATUS status; SECURITY_STATUS status;
SCHANNEL_CONTEXT* context; SCHANNEL_CONTEXT* context;
context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext); context = (SCHANNEL_CONTEXT*) sspi_SecureHandleGetLowerPointer(phContext);
if (!context) if (!context)
return SEC_E_INVALID_HANDLE; return SEC_E_INVALID_HANDLE;
status = schannel_openssl_decrypt_message(context->openssl, pMessage); status = schannel_openssl_decrypt_message(context->openssl, pMessage);
return status; return status;
} }
@ -447,13 +415,13 @@ const SecPkgInfoA SCHANNEL_SecPkgInfoA =
"Schannel Security Package" /* Comment */ "Schannel Security Package" /* Comment */
}; };
WCHAR SCHANNEL_SecPkgInfoW_Name[] = { 'S','c','h','a','n','n','e','l','\0' }; WCHAR SCHANNEL_SecPkgInfoW_Name[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', '\0' };
WCHAR SCHANNEL_SecPkgInfoW_Comment[] = WCHAR SCHANNEL_SecPkgInfoW_Comment[] =
{ {
'S','c','h','a','n','n','e','l',' ', 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l', ' ',
'S','e','c','u','r','i','t','y',' ', 'S', 'e', 'c', 'u', 'r', 'i', 't', 'y', ' ',
'P','a','c','k','a','g','e','\0' 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\0'
}; };
const SecPkgInfoW SCHANNEL_SecPkgInfoW = const SecPkgInfoW SCHANNEL_SecPkgInfoW =

View File

@ -114,11 +114,13 @@ BOOL InitializeSspiModule_Native(void)
static BOOL CALLBACK InitializeSspiModuleInt(PINIT_ONCE once, PVOID param, PVOID* context) static BOOL CALLBACK InitializeSspiModuleInt(PINIT_ONCE once, PVOID param, PVOID* context)
{ {
BOOL status = FALSE; BOOL status = FALSE;
#if defined(WITH_NATIVE_SSPI)
DWORD flags = 0; DWORD flags = 0;
if (param) if (param)
flags = *(DWORD*)param; flags = *(DWORD*)param;
#endif
sspi_GlobalInit(); sspi_GlobalInit();
g_Log = WLog_Get("com.winpr.sspi"); g_Log = WLog_Get("com.winpr.sspi");
#if defined(WITH_NATIVE_SSPI) #if defined(WITH_NATIVE_SSPI)

View File

@ -65,20 +65,20 @@ extern const SecurityFunctionTableW SCHANNEL_SecurityFunctionTableW;
static const SecPkgInfoA* SecPkgInfoA_LIST[] = static const SecPkgInfoA* SecPkgInfoA_LIST[] =
{ {
&NTLM_SecPkgInfoA, &NTLM_SecPkgInfoA,
&KERBEROS_SecPkgInfoA, &KERBEROS_SecPkgInfoA,
&NEGOTIATE_SecPkgInfoA, &NEGOTIATE_SecPkgInfoA,
&CREDSSP_SecPkgInfoA, &CREDSSP_SecPkgInfoA,
&SCHANNEL_SecPkgInfoA &SCHANNEL_SecPkgInfoA
}; };
static const SecPkgInfoW* SecPkgInfoW_LIST[] = static const SecPkgInfoW* SecPkgInfoW_LIST[] =
{ {
&NTLM_SecPkgInfoW, &NTLM_SecPkgInfoW,
&KERBEROS_SecPkgInfoW, &KERBEROS_SecPkgInfoW,
&NEGOTIATE_SecPkgInfoW, &NEGOTIATE_SecPkgInfoW,
&CREDSSP_SecPkgInfoW, &CREDSSP_SecPkgInfoW,
&SCHANNEL_SecPkgInfoW &SCHANNEL_SecPkgInfoW
}; };
static SecurityFunctionTableA winpr_SecurityFunctionTableA; static SecurityFunctionTableA winpr_SecurityFunctionTableA;
@ -100,11 +100,11 @@ typedef struct _SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME;
static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] = static const SecurityFunctionTableA_NAME SecurityFunctionTableA_NAME_LIST[] =
{ {
{ "NTLM", &NTLM_SecurityFunctionTableA }, { "NTLM", &NTLM_SecurityFunctionTableA },
{ "Kerberos", &KERBEROS_SecurityFunctionTableA }, { "Kerberos", &KERBEROS_SecurityFunctionTableA },
{ "Negotiate", &NEGOTIATE_SecurityFunctionTableA }, { "Negotiate", &NEGOTIATE_SecurityFunctionTableA },
{ "CREDSSP", &CREDSSP_SecurityFunctionTableA }, { "CREDSSP", &CREDSSP_SecurityFunctionTableA },
{ "Schannel", &SCHANNEL_SecurityFunctionTableA } { "Schannel", &SCHANNEL_SecurityFunctionTableA }
}; };
static const WCHAR NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' }; static const WCHAR NTLM_NAME_W[] = { 'N', 'T', 'L', 'M', '\0' };
@ -115,11 +115,11 @@ static const WCHAR SCHANNEL_NAME_W[] = { 'S', 'c', 'h', 'a', 'n', 'n', 'e', 'l',
static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] = static const SecurityFunctionTableW_NAME SecurityFunctionTableW_NAME_LIST[] =
{ {
{ NTLM_NAME_W, &NTLM_SecurityFunctionTableW }, { NTLM_NAME_W, &NTLM_SecurityFunctionTableW },
{ KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW }, { KERBEROS_NAME_W, &KERBEROS_SecurityFunctionTableW },
{ NEGOTIATE_NAME_W, &NEGOTIATE_SecurityFunctionTableW }, { NEGOTIATE_NAME_W, &NEGOTIATE_SecurityFunctionTableW },
{ CREDSSP_NAME_W, &CREDSSP_SecurityFunctionTableW }, { CREDSSP_NAME_W, &CREDSSP_SecurityFunctionTableW },
{ SCHANNEL_NAME_W, &SCHANNEL_SecurityFunctionTableW } { SCHANNEL_NAME_W, &SCHANNEL_SecurityFunctionTableW }
}; };
#define SecHandle_LOWER_MAX 0xFFFFFFFF #define SecHandle_LOWER_MAX 0xFFFFFFFF
@ -353,18 +353,17 @@ int sspi_SetAuthIdentity(SEC_WINNT_AUTH_IDENTITY* identity, const char* user, co
{ {
int unicodePasswordLenW; int unicodePasswordLenW;
LPWSTR unicodePassword = NULL; LPWSTR unicodePassword = NULL;
unicodePasswordLenW = ConvertToUnicode(CP_UTF8, 0, password, -1, &unicodePassword, 0); unicodePasswordLenW = ConvertToUnicode(CP_UTF8, 0, password, -1, &unicodePassword, 0);
if (unicodePasswordLenW <= 0) if (unicodePasswordLenW <= 0)
return -1; return -1;
return sspi_SetAuthIdentityWithUnicodePassword(identity, user, domain, unicodePassword, return sspi_SetAuthIdentityWithUnicodePassword(identity, user, domain, unicodePassword,
(ULONG)(unicodePasswordLenW - 1)); (ULONG)(unicodePasswordLenW - 1));
} }
int sspi_SetAuthIdentityWithUnicodePassword(SEC_WINNT_AUTH_IDENTITY* identity, const char *user, int sspi_SetAuthIdentityWithUnicodePassword(SEC_WINNT_AUTH_IDENTITY* identity, const char* user,
const char *domain, LPWSTR password, ULONG passwordLength) const char* domain, LPWSTR password, ULONG passwordLength)
{ {
int status; int status;
identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; identity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
@ -398,12 +397,12 @@ int sspi_SetAuthIdentityWithUnicodePassword(SEC_WINNT_AUTH_IDENTITY* identity, c
free(identity->Password); free(identity->Password);
identity->Password = (UINT16*) calloc(1, (passwordLength + 1) * sizeof(WCHAR)); identity->Password = (UINT16*) calloc(1, (passwordLength + 1) * sizeof(WCHAR));
if (!identity->Password) if (!identity->Password)
return -1; return -1;
CopyMemory(identity->Password, password, passwordLength * sizeof(WCHAR)); CopyMemory(identity->Password, password, passwordLength * sizeof(WCHAR));
identity->PasswordLength = passwordLength; identity->PasswordLength = passwordLength;
return 1; return 1;
} }
@ -500,7 +499,6 @@ void sspi_GlobalInit(void)
{ {
static INIT_ONCE once = INIT_ONCE_STATIC_INIT; static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
DWORD flags = 0; DWORD flags = 0;
InitOnceExecuteOnce(&once, sspi_init, &flags, NULL); InitOnceExecuteOnce(&once, sspi_init, &flags, NULL);
} }
@ -526,11 +524,6 @@ static SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameA(const SEC_C
return NULL; return NULL;
} }
static SecurityFunctionTableA* sspi_GetSecurityFunctionTableAByNameW(const SEC_WCHAR* Name)
{
return NULL;
}
static SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name) static SecurityFunctionTableW* sspi_GetSecurityFunctionTableWByNameW(const SEC_WCHAR* Name)
{ {
int index; int index;
@ -583,13 +576,13 @@ static void sspi_ContextBufferFree(void* contextBuffer)
switch (allocatorIndex) switch (allocatorIndex)
{ {
case EnumerateSecurityPackagesIndex: case EnumerateSecurityPackagesIndex:
FreeContextBuffer_EnumerateSecurityPackages(contextBuffer); FreeContextBuffer_EnumerateSecurityPackages(contextBuffer);
break; break;
case QuerySecurityPackageInfoIndex: case QuerySecurityPackageInfoIndex:
FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer); FreeContextBuffer_QuerySecurityPackageInfo(contextBuffer);
break; break;
} }
} }
} }
@ -1552,64 +1545,64 @@ static SECURITY_STATUS SEC_ENTRY winpr_VerifySignature(PCtxtHandle phContext,
static SecurityFunctionTableA winpr_SecurityFunctionTableA = static SecurityFunctionTableA winpr_SecurityFunctionTableA =
{ {
1, /* dwVersion */ 1, /* dwVersion */
winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */ winpr_EnumerateSecurityPackagesA, /* EnumerateSecurityPackages */
winpr_QueryCredentialsAttributesA, /* QueryCredentialsAttributes */ winpr_QueryCredentialsAttributesA, /* QueryCredentialsAttributes */
winpr_AcquireCredentialsHandleA, /* AcquireCredentialsHandle */ winpr_AcquireCredentialsHandleA, /* AcquireCredentialsHandle */
winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */ winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
NULL, /* Reserved2 */ NULL, /* Reserved2 */
winpr_InitializeSecurityContextA, /* InitializeSecurityContext */ winpr_InitializeSecurityContextA, /* InitializeSecurityContext */
winpr_AcceptSecurityContext, /* AcceptSecurityContext */ winpr_AcceptSecurityContext, /* AcceptSecurityContext */
winpr_CompleteAuthToken, /* CompleteAuthToken */ winpr_CompleteAuthToken, /* CompleteAuthToken */
winpr_DeleteSecurityContext, /* DeleteSecurityContext */ winpr_DeleteSecurityContext, /* DeleteSecurityContext */
winpr_ApplyControlToken, /* ApplyControlToken */ winpr_ApplyControlToken, /* ApplyControlToken */
winpr_QueryContextAttributesA, /* QueryContextAttributes */ winpr_QueryContextAttributesA, /* QueryContextAttributes */
winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */ winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
winpr_RevertSecurityContext, /* RevertSecurityContext */ winpr_RevertSecurityContext, /* RevertSecurityContext */
winpr_MakeSignature, /* MakeSignature */ winpr_MakeSignature, /* MakeSignature */
winpr_VerifySignature, /* VerifySignature */ winpr_VerifySignature, /* VerifySignature */
winpr_FreeContextBuffer, /* FreeContextBuffer */ winpr_FreeContextBuffer, /* FreeContextBuffer */
winpr_QuerySecurityPackageInfoA, /* QuerySecurityPackageInfo */ winpr_QuerySecurityPackageInfoA, /* QuerySecurityPackageInfo */
NULL, /* Reserved3 */ NULL, /* Reserved3 */
NULL, /* Reserved4 */ NULL, /* Reserved4 */
winpr_ExportSecurityContext, /* ExportSecurityContext */ winpr_ExportSecurityContext, /* ExportSecurityContext */
winpr_ImportSecurityContextA, /* ImportSecurityContext */ winpr_ImportSecurityContextA, /* ImportSecurityContext */
NULL, /* AddCredentials */ NULL, /* AddCredentials */
NULL, /* Reserved8 */ NULL, /* Reserved8 */
winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */ winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
winpr_EncryptMessage, /* EncryptMessage */ winpr_EncryptMessage, /* EncryptMessage */
winpr_DecryptMessage, /* DecryptMessage */ winpr_DecryptMessage, /* DecryptMessage */
winpr_SetContextAttributesA, /* SetContextAttributes */ winpr_SetContextAttributesA, /* SetContextAttributes */
}; };
static SecurityFunctionTableW winpr_SecurityFunctionTableW = static SecurityFunctionTableW winpr_SecurityFunctionTableW =
{ {
1, /* dwVersion */ 1, /* dwVersion */
winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */ winpr_EnumerateSecurityPackagesW, /* EnumerateSecurityPackages */
winpr_QueryCredentialsAttributesW, /* QueryCredentialsAttributes */ winpr_QueryCredentialsAttributesW, /* QueryCredentialsAttributes */
winpr_AcquireCredentialsHandleW, /* AcquireCredentialsHandle */ winpr_AcquireCredentialsHandleW, /* AcquireCredentialsHandle */
winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */ winpr_FreeCredentialsHandle, /* FreeCredentialsHandle */
NULL, /* Reserved2 */ NULL, /* Reserved2 */
winpr_InitializeSecurityContextW, /* InitializeSecurityContext */ winpr_InitializeSecurityContextW, /* InitializeSecurityContext */
winpr_AcceptSecurityContext, /* AcceptSecurityContext */ winpr_AcceptSecurityContext, /* AcceptSecurityContext */
winpr_CompleteAuthToken, /* CompleteAuthToken */ winpr_CompleteAuthToken, /* CompleteAuthToken */
winpr_DeleteSecurityContext, /* DeleteSecurityContext */ winpr_DeleteSecurityContext, /* DeleteSecurityContext */
winpr_ApplyControlToken, /* ApplyControlToken */ winpr_ApplyControlToken, /* ApplyControlToken */
winpr_QueryContextAttributesW, /* QueryContextAttributes */ winpr_QueryContextAttributesW, /* QueryContextAttributes */
winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */ winpr_ImpersonateSecurityContext, /* ImpersonateSecurityContext */
winpr_RevertSecurityContext, /* RevertSecurityContext */ winpr_RevertSecurityContext, /* RevertSecurityContext */
winpr_MakeSignature, /* MakeSignature */ winpr_MakeSignature, /* MakeSignature */
winpr_VerifySignature, /* VerifySignature */ winpr_VerifySignature, /* VerifySignature */
winpr_FreeContextBuffer, /* FreeContextBuffer */ winpr_FreeContextBuffer, /* FreeContextBuffer */
winpr_QuerySecurityPackageInfoW, /* QuerySecurityPackageInfo */ winpr_QuerySecurityPackageInfoW, /* QuerySecurityPackageInfo */
NULL, /* Reserved3 */ NULL, /* Reserved3 */
NULL, /* Reserved4 */ NULL, /* Reserved4 */
winpr_ExportSecurityContext, /* ExportSecurityContext */ winpr_ExportSecurityContext, /* ExportSecurityContext */
winpr_ImportSecurityContextW, /* ImportSecurityContext */ winpr_ImportSecurityContextW, /* ImportSecurityContext */
NULL, /* AddCredentials */ NULL, /* AddCredentials */
NULL, /* Reserved8 */ NULL, /* Reserved8 */
winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */ winpr_QuerySecurityContextToken, /* QuerySecurityContextToken */
winpr_EncryptMessage, /* EncryptMessage */ winpr_EncryptMessage, /* EncryptMessage */
winpr_DecryptMessage, /* DecryptMessage */ winpr_DecryptMessage, /* DecryptMessage */
winpr_SetContextAttributesW, /* SetContextAttributes */ winpr_SetContextAttributesW, /* SetContextAttributes */
}; };