Author: sserapion Date: Sat May 7 20:16:15 2011 New Revision: 51631
URL: http://svn.reactos.org/svn/reactos?rev=51631&view=rev Log: Add and stub 'ntlmssp' a module that implements a NTLM Security Support Provider(SSP). This is not yet an SSP/AP, therefore, therefore I didn't name it 'msv1_0'. SSP/APs have much more extensive functionality that hooks into LSA (SpLsaModeInitialize) and secur32 loads them with SpUsermodeInitialize. Since neither secur32 nor lsasrv are even close to supporting these I have, for the time being, decided to work on the core NTLM protocol functionality only. Furthermore msv1_0 has other interfaces, mostly the concept of sub authorities (now mostly deprecated)...
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/base64_codec.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/context.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/credentials.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/dllmain.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/hmac_md5.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/md4-5.h (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/messages.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.h (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.rbuild (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.spec (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/sign.c (with props) branches/sspi-bringup/reactos/dll/win32/ntlmssp/util.c (with props) Modified: branches/sspi-bringup/reactos/dll/win32/win32.rbuild
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ ------------------------------------------------------------------------------ --- bugtraq:logregex (added) +++ bugtraq:logregex Sat May 7 20:16:15 2011 @@ -1,0 +1,2 @@ +([Ii]ssue|[Bb]ug)s? #?(\d+)(,? ?#?(\d+))*(,? ?(and |or )?#?(\d+))? +(\d+)
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ ------------------------------------------------------------------------------ bugtraq:message = See issue #%BUGID% for more details.
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ ------------------------------------------------------------------------------ bugtraq:url = http://www.reactos.org/bugzilla/show_bug.cgi?id=%BUGID%
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ ------------------------------------------------------------------------------ tsvn:logminsize = 10
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/base64_codec.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/base64_codec.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/base64_codec.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,189 @@ +/* + * base64 encoder/decoder + * + * Copyright 2005 by Kai Blin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +static const char b64[] = +"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +SECURITY_STATUS encodeBase64(PBYTE in_buf, int in_len, char* out_buf, + int max_len, int *out_len) +{ + int div, i; + PBYTE d = in_buf; + int bytes = (in_len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0; + + TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes); + *out_len = bytes + pad_bytes; + + if(bytes + pad_bytes + 1 > max_len) + return SEC_E_BUFFER_TOO_SMALL; + + /* Three bytes of input give 4 chars of output */ + div = in_len / 3; + + i = 0; + while(div > 0) + { + /* first char is the first 6 bits of the first byte*/ + out_buf[i + 0] = b64[ ( d[0] >> 2) & 0x3f ]; + /* second char is the last 2 bits of the first byte and the first 4 + * bits of the second byte */ + out_buf[i + 1] = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)]; + /* third char is the last 4 bits of the second byte and the first 2 + * bits of the third byte */ + out_buf[i + 2] = b64[ ((d[1] << 2) & 0x3c) | (d[2] >> 6 & 0x03)]; + /* fourth char is the remaining 6 bits of the third byte */ + out_buf[i + 3] = b64[ d[2] & 0x3f]; + i += 4; + d += 3; + div--; + } + + switch(pad_bytes) + { + case 1: + /* first char is the first 6 bits of the first byte*/ + out_buf[i + 0] = b64[ ( d[0] >> 2) & 0x3f ]; + /* second char is the last 2 bits of the first byte and the first 4 + * bits of the second byte */ + out_buf[i + 1] = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)]; + /* third char is the last 4 bits of the second byte padded with + * two zeroes */ + out_buf[i + 2] = b64[ ((d[1] << 2) & 0x3c) ]; + /* fourth char is a = to indicate one byte of padding */ + out_buf[i + 3] = '='; + out_buf[i + 4] = 0; + break; + case 2: + /* first char is the first 6 bits of the first byte*/ + out_buf[i + 0] = b64[ ( d[0] >> 2) & 0x3f ]; + /* second char is the last 2 bits of the first byte padded with + * four zeroes*/ + out_buf[i + 1] = b64[ ((d[0] << 4) & 0x30)]; + /* third char is = to indicate padding */ + out_buf[i + 2] = '='; + /* fourth char is = to indicate padding */ + out_buf[i + 3] = '='; + out_buf[i + 4] = 0; + break; + default: + out_buf[i] = 0; + } + + return SEC_E_OK; +} + +static inline BYTE decode(char c) +{ + if( c >= 'A' && c <= 'Z') + return c - 'A'; + if( c >= 'a' && c <= 'z') + return c - 'a' + 26; + if( c >= '0' && c <= '9') + return c - '0' + 52; + if( c == '+') + return 62; + if( c == '/') + return 63; + else + return 64; +} + +SECURITY_STATUS decodeBase64(char *in_buf, int in_len, PBYTE out_buf, + int max_len, int *out_len) +{ + int len = in_len, i; + char *d = in_buf; + int ip0, ip1, ip2, ip3; + + TRACE("in_len: %d\n", in_len); + + if((in_len % 4) != 0) + return SEC_E_INVALID_TOKEN; + + if(in_len > max_len) + return SEC_E_BUFFER_TOO_SMALL; + + i = 0; + while(len > 4) + { + if((ip0 = decode(d[0])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip1 = decode(d[1])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip2 = decode(d[2])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip3 = decode(d[3])) > 63) + return SEC_E_INVALID_TOKEN; + + out_buf[i + 0] = (ip0 << 2) | (ip1 >> 4); + out_buf[i + 1] = (ip1 << 4) | (ip2 >> 2); + out_buf[i + 2] = (ip2 << 6) | ip3; + len -= 4; + i += 3; + d += 4; + } + + if(d[2] == '=') + { + if((ip0 = decode(d[0])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip1 = decode(d[1])) > 63) + return SEC_E_INVALID_TOKEN; + + out_buf[i] = (ip0 << 2) | (ip1 >> 4); + i++; + } + else if(d[3] == '=') + { + if((ip0 = decode(d[0])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip1 = decode(d[1])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip2 = decode(d[2])) > 63) + return SEC_E_INVALID_TOKEN; + + out_buf[i + 0] = (ip0 << 2) | (ip1 >> 4); + out_buf[i + 1] = (ip1 << 4) | (ip2 >> 2); + i += 2; + } + else + { + if((ip0 = decode(d[0])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip1 = decode(d[1])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip2 = decode(d[2])) > 63) + return SEC_E_INVALID_TOKEN; + if((ip3 = decode(d[3])) > 63) + return SEC_E_INVALID_TOKEN; + + + out_buf[i + 0] = (ip0 << 2) | (ip1 >> 4); + out_buf[i + 1] = (ip1 << 4) | (ip2 >> 2); + out_buf[i + 2] = (ip2 << 6) | ip3; + i += 3; + } + *out_len = i; + return SEC_E_OK; +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/base64_codec.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/context.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/context.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/context.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,175 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +/*********************************************************************** + * InitializeSecurityContextW + */ +SECURITY_STATUS SEC_ENTRY InitializeSecurityContextW( + PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName, + ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, + PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, + PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry) +{ + SECURITY_STATUS ret = SEC_E_INVALID_HANDLE; + + TRACE("%p %p %s 0x%08x %d %d %p %d %p %p %p %p\n", phCredential, phContext, + debugstr_w(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput, + Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry); + + FIXME("AcceptSecurityContext Unimplemented\n"); + + return ret; +} + +/*********************************************************************** + * InitializeSecurityContextA + */ +SECURITY_STATUS SEC_ENTRY InitializeSecurityContextA( + PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName, + ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, + PSecBufferDesc pInput,ULONG Reserved2, PCtxtHandle phNewContext, + PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry) +{ + SECURITY_STATUS ret; + SEC_WCHAR *target = NULL; + + TRACE("%p %p %s %d %d %d %p %d %p %p %p %p\n", phCredential, phContext, + debugstr_a(pszTargetName), fContextReq, Reserved1, TargetDataRep, pInput, + Reserved1, phNewContext, pOutput, pfContextAttr, ptsExpiry); + + if(pszTargetName != NULL) + { + int target_size = MultiByteToWideChar(CP_ACP, 0, pszTargetName, + strlen(pszTargetName)+1, NULL, 0); + target = HeapAlloc(GetProcessHeap(), 0, target_size * + sizeof(SEC_WCHAR)); + MultiByteToWideChar(CP_ACP, 0, pszTargetName, strlen(pszTargetName)+1, + target, target_size); + } + + ret = InitializeSecurityContextW(phCredential, phContext, target, + fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, + phNewContext, pOutput, pfContextAttr, ptsExpiry); + + HeapFree(GetProcessHeap(), 0, target); + return ret; +} + +/*********************************************************************** + * QueryContextAttributesW + */ +SECURITY_STATUS SEC_ENTRY QueryContextAttributesW(PCtxtHandle phContext, + ULONG ulAttribute, void *pBuffer) +{ + TRACE("%p %d %p\n", phContext, ulAttribute, pBuffer); + if (!phContext) + return SEC_E_INVALID_HANDLE; + + return SEC_E_UNSUPPORTED_FUNCTION; +} + + +/*********************************************************************** + * QueryContextAttributesA + */ +SECURITY_STATUS SEC_ENTRY QueryContextAttributesA(PCtxtHandle phContext, + ULONG ulAttribute, void *pBuffer) +{ + return QueryContextAttributesW(phContext, ulAttribute, pBuffer); +} + +SECURITY_STATUS SEC_ENTRY AcceptSecurityContext( + PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput, + ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext, + PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry) +{ + SECURITY_STATUS ret = SEC_E_INVALID_HANDLE; + + TRACE("%p %p %p %d %d %p %p %p %p\n", phCredential, phContext, pInput, + fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, + ptsExpiry); + + FIXME("AcceptSecurityContext Unimplemented\n"); + + return ret; +} + +/*********************************************************************** + * DeleteSecurityContext + */ +SECURITY_STATUS SEC_ENTRY DeleteSecurityContext(PCtxtHandle phContext) +{ + if (!phContext) + { + ERR("Delete NULL context!\n"); + return SEC_E_INVALID_HANDLE; + } + + FIXME("Delete context %p unimplemented\n", phContext); + return SEC_E_OK; +} + +/*********************************************************************** + * ImpersonateSecurityContext + */ +SECURITY_STATUS SEC_ENTRY ImpersonateSecurityContext(PCtxtHandle phContext) +{ + SECURITY_STATUS ret; + + TRACE("%p\n", phContext); + if (phContext) + { + ret = SEC_E_UNSUPPORTED_FUNCTION; + } + else + { + ret = SEC_E_INVALID_HANDLE; + } + return ret; +} + +/*********************************************************************** + * RevertSecurityContext + */ +SECURITY_STATUS SEC_ENTRY RevertSecurityContext(PCtxtHandle phContext) +{ + SECURITY_STATUS ret; + + TRACE("%p\n", phContext); + if (phContext) + { + ret = SEC_E_UNSUPPORTED_FUNCTION; + } + else + { + ret = SEC_E_INVALID_HANDLE; + } + return ret; +} + +SECURITY_STATUS SEC_ENTRY FreeContextBuffer(PVOID pv) +{ + HeapFree(GetProcessHeap(), 0, pv); + + return SEC_E_OK; +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/context.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/credentials.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/credentials.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/credentials.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,286 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +/*********************************************************************** + * QueryCredentialsAttributesW + */ +SECURITY_STATUS SEC_ENTRY QueryCredentialsAttributesW( + PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer) +{ + SECURITY_STATUS ret; + + TRACE("(%p, %d, %p)\n", phCredential, ulAttribute, pBuffer); + + if(ulAttribute == SECPKG_ATTR_NAMES) + { + FIXME("SECPKG_CRED_ATTR_NAMES: stub\n"); + ret = SEC_E_UNSUPPORTED_FUNCTION; + } + else + ret = SEC_E_UNSUPPORTED_FUNCTION; + + return ret; +} + + +/*********************************************************************** + * QueryCredentialsAttributesA + */ +SECURITY_STATUS SEC_ENTRY QueryCredentialsAttributesA( + PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer) +{ + SECURITY_STATUS ret; + + TRACE("(%p, %d, %p)\n", phCredential, ulAttribute, pBuffer); + + if(ulAttribute == SECPKG_ATTR_NAMES) + { + FIXME("SECPKG_CRED_ATTR_NAMES: stub\n"); + ret = SEC_E_UNSUPPORTED_FUNCTION; + } + else + ret = SEC_E_UNSUPPORTED_FUNCTION; + + return ret; +} + +/*********************************************************************** + * AcquireCredentialsHandleW + */ +SECURITY_STATUS SEC_ENTRY AcquireCredentialsHandleW( + SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse, + PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn, + PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry) +{ + SECURITY_STATUS ret = SEC_E_UNSUPPORTED_FUNCTION; + PNtlmCredentials cred = NULL; + SEC_WCHAR *username = NULL, *domain = NULL; + + ERR("(%s, %s, 0x%08x, %p, %p, %p, %p, %p, %p)\n", + debugstr_w(pszPrincipal), debugstr_w(pszPackage), fCredentialUse, + pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry); + + FIXME("AcquireCredentialsHandleW Unimplemented\n"); + switch(fCredentialUse) + { + case SECPKG_CRED_INBOUND: + cred = HeapAlloc(GetProcessHeap(), 0, sizeof(*cred)); + if (!cred) + ret = SEC_E_INSUFFICIENT_MEMORY; + else + { + cred->mode = NTLM_SERVER; + cred->username_arg = NULL; + cred->domain_arg = NULL; + cred->password = NULL; + cred->pwlen = 0; + phCredential->dwUpper = fCredentialUse; + phCredential->dwLower = (ULONG_PTR)cred; + ret = SEC_E_OK; + } + break; + case SECPKG_CRED_OUTBOUND: + { + cred = HeapAlloc(GetProcessHeap(), 0, sizeof(*cred)); + if (!cred) + { + ret = SEC_E_INSUFFICIENT_MEMORY; + break; + } + cred->mode = NTLM_CLIENT; + cred->username_arg = NULL; + cred->domain_arg = NULL; + cred->password = NULL; + cred->pwlen = 0; + + if(pAuthData != NULL) + { + PSEC_WINNT_AUTH_IDENTITY_W auth_data = pAuthData; + + TRACE("Username is %s\n", debugstr_wn(auth_data->User, auth_data->UserLength)); + TRACE("Domain name is %s\n", debugstr_wn(auth_data->Domain, auth_data->DomainLength)); + + //cred->username_arg = GetUsernameArg(auth_data->User, auth_data->UserLength); + //cred->domain_arg = GetDomainArg(auth_data->Domain, auth_data->DomainLength); + } + + phCredential->dwUpper = fCredentialUse; + phCredential->dwLower = (ULONG_PTR)cred; + TRACE("ACH phCredential->dwUpper: 0x%08lx, dwLower: 0x%08lx\n", + phCredential->dwUpper, phCredential->dwLower); + ret = SEC_E_OK; + break; + } + case SECPKG_CRED_BOTH: + FIXME("AcquireCredentialsHandle: SECPKG_CRED_BOTH stub\n"); + ret = SEC_E_UNSUPPORTED_FUNCTION; + phCredential = NULL; + break; + default: + phCredential = NULL; + ret = SEC_E_UNKNOWN_CREDENTIALS; + } + + HeapFree(GetProcessHeap(), 0, username); + HeapFree(GetProcessHeap(), 0, domain); + + return ret; +} + + +/*********************************************************************** + * AcquireCredentialsHandleA + */ +SECURITY_STATUS SEC_ENTRY AcquireCredentialsHandleA( + SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse, + PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn, + PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry) +{ + SECURITY_STATUS ret; + int user_sizeW, domain_sizeW, passwd_sizeW; + + SEC_WCHAR *user = NULL, *domain = NULL, *passwd = NULL, *package = NULL; + + PSEC_WINNT_AUTH_IDENTITY_W pAuthDataW = NULL; + PSEC_WINNT_AUTH_IDENTITY_A identity = NULL; + + ERR("(%s, %s, 0x%08x, %p, %p, %p, %p, %p, %p)\n", + debugstr_a(pszPrincipal), debugstr_a(pszPackage), fCredentialUse, + pLogonID, pAuthData, pGetKeyFn, pGetKeyArgument, phCredential, ptsExpiry); + + if(pszPackage != NULL) + { + int package_sizeW = MultiByteToWideChar(CP_ACP, 0, pszPackage, -1, + NULL, 0); + + package = HeapAlloc(GetProcessHeap(), 0, package_sizeW * + sizeof(SEC_WCHAR)); + MultiByteToWideChar(CP_ACP, 0, pszPackage, -1, package, package_sizeW); + } + + + if(pAuthData != NULL) + { + identity = pAuthData; + + if(identity->Flags == SEC_WINNT_AUTH_IDENTITY_ANSI) + { + pAuthDataW = HeapAlloc(GetProcessHeap(), 0, + sizeof(SEC_WINNT_AUTH_IDENTITY_W)); + + if(identity->UserLength != 0) + { + user_sizeW = MultiByteToWideChar(CP_ACP, 0, + (LPCSTR)identity->User, identity->UserLength, NULL, 0); + user = HeapAlloc(GetProcessHeap(), 0, user_sizeW * + sizeof(SEC_WCHAR)); + MultiByteToWideChar(CP_ACP, 0, (LPCSTR)identity->User, + identity->UserLength, user, user_sizeW); + } + else + { + user_sizeW = 0; + } + + if(identity->DomainLength != 0) + { + domain_sizeW = MultiByteToWideChar(CP_ACP, 0, + (LPCSTR)identity->Domain, identity->DomainLength, NULL, 0); + domain = HeapAlloc(GetProcessHeap(), 0, domain_sizeW + * sizeof(SEC_WCHAR)); + MultiByteToWideChar(CP_ACP, 0, (LPCSTR)identity->Domain, + identity->DomainLength, domain, domain_sizeW); + } + else + { + domain_sizeW = 0; + } + + if(identity->PasswordLength != 0) + { + passwd_sizeW = MultiByteToWideChar(CP_ACP, 0, + (LPCSTR)identity->Password, identity->PasswordLength, + NULL, 0); + passwd = HeapAlloc(GetProcessHeap(), 0, passwd_sizeW + * sizeof(SEC_WCHAR)); + MultiByteToWideChar(CP_ACP, 0, (LPCSTR)identity->Password, + identity->PasswordLength, passwd, passwd_sizeW); + } + else + { + passwd_sizeW = 0; + } + + pAuthDataW->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; + pAuthDataW->User = user; + pAuthDataW->UserLength = user_sizeW; + pAuthDataW->Domain = domain; + pAuthDataW->DomainLength = domain_sizeW; + pAuthDataW->Password = passwd; + pAuthDataW->PasswordLength = passwd_sizeW; + } + else + { + pAuthDataW = (PSEC_WINNT_AUTH_IDENTITY_W)identity; + } + } + + ret = AcquireCredentialsHandleW(NULL, package, fCredentialUse, + pLogonID, pAuthDataW, pGetKeyFn, pGetKeyArgument, phCredential, + ptsExpiry); + + HeapFree(GetProcessHeap(), 0, package); + HeapFree(GetProcessHeap(), 0, user); + HeapFree(GetProcessHeap(), 0, domain); + HeapFree(GetProcessHeap(), 0, passwd); + if(pAuthDataW != (PSEC_WINNT_AUTH_IDENTITY_W)identity) + HeapFree(GetProcessHeap(), 0, pAuthDataW); + + return ret; +} + +/*********************************************************************** + * FreeCredentialsHandle + */ +SECURITY_STATUS SEC_ENTRY FreeCredentialsHandle( + PCredHandle phCredential) +{ + SECURITY_STATUS ret; + + if(phCredential){ + PNtlmCredentials cred = (PNtlmCredentials) phCredential->dwLower; + phCredential->dwUpper = 0; + phCredential->dwLower = 0; + if (cred->password) + memset(cred->password, 0, cred->pwlen); + HeapFree(GetProcessHeap(), 0, cred->password); + HeapFree(GetProcessHeap(), 0, cred->username_arg); + HeapFree(GetProcessHeap(), 0, cred->domain_arg); + HeapFree(GetProcessHeap(), 0, cred); + ret = SEC_E_OK; + } + else + ret = SEC_E_OK; + + return ret; +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/credentials.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/dllmain.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/dllmain.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/dllmain.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,31 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + TRACE("(0x%p, %d, %p)\n",hinstDLL,fdwReason,lpvReserved); + + if (fdwReason == DLL_PROCESS_ATTACH) + DisableThreadLibraryCalls(hinstDLL); + + return TRUE; +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/dllmain.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/hmac_md5.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/hmac_md5.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/hmac_md5.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,77 @@ +/* + * Copyright 2006 Kai Blin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * This file implements RFC 2104 (HMAC) for the MD5 provider. + * It is needed for NTLM2 signing and sealing. + */ + +#include "md4-5.h" + +void HMACMD5Init(HMAC_MD5_CTX *ctx, const unsigned char *key, unsigned int key_len) +{ + int i; + unsigned char inner_padding[64]; + unsigned char temp_key[16]; + + if(key_len > 64) + { + MD5_CTX temp_ctx; + + MD5Init(&temp_ctx); + MD5Update(&temp_ctx, key, key_len); + MD5Final(&temp_ctx); + memcpy(temp_key, temp_ctx.digest, 16); + + key = temp_key; + key_len = 16; + } + + memset(inner_padding, 0, 64); + memset(ctx->outer_padding, 0, 64); + memcpy(inner_padding, key, key_len); + memcpy(ctx->outer_padding, key, key_len); + + for(i = 0; i < 64; ++i) + { + inner_padding[i] ^= 0x36; + ctx->outer_padding[i] ^= 0x5c; + } + + MD5Init(&(ctx->ctx)); + MD5Update(&(ctx->ctx), inner_padding, 64); +} + +void HMACMD5Update(HMAC_MD5_CTX *ctx, const unsigned char *data, unsigned int data_len) +{ + MD5Update(&(ctx->ctx), data, data_len); +} + +void HMACMD5Final(HMAC_MD5_CTX *ctx, unsigned char *digest) +{ + MD5_CTX outer_ctx; + unsigned char inner_digest[16]; + + MD5Final(&(ctx->ctx)); + memcpy(inner_digest, ctx->ctx.digest, 16); + + MD5Init(&outer_ctx); + MD5Update(&outer_ctx, ctx->outer_padding, 64); + MD5Update(&outer_ctx, inner_digest, 16); + MD5Final(&outer_ctx); + + memcpy(digest, outer_ctx.digest, 16); +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/hmac_md5.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/md4-5.h URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/md4-5.h (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/md4-5.h [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,58 @@ +/* + * Copyright 2011 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + +#ifndef _HMAC_MD5_H_ +#define _HMAC_MD5_H_ + +#include <string.h> +#include "windef.h" + +typedef struct +{ + unsigned int buf[4]; + unsigned int i[2]; + unsigned char in[64]; + unsigned char digest[16]; +} MD4_CTX; + +typedef struct +{ + unsigned int i[2]; + unsigned int buf[4]; + unsigned char in[64]; + unsigned char digest[16]; +} MD5_CTX; + +typedef struct +{ + MD5_CTX ctx; + unsigned char outer_padding[64]; +} HMAC_MD5_CTX; + +VOID WINAPI MD4Init( MD4_CTX *ctx ); +VOID WINAPI MD4Update( MD4_CTX *ctx, const unsigned char *buf, unsigned int len ); +VOID WINAPI MD4Final( MD4_CTX *ctx ); +void WINAPI MD5Init( MD5_CTX *ctx ); +void WINAPI MD5Update( MD5_CTX *ctx, const unsigned char *buf, unsigned int len ); +void WINAPI MD5Final( MD5_CTX *ctx ); + +void HMACMD5Init(HMAC_MD5_CTX *ctx, const unsigned char *key, unsigned int key_len); +void HMACMD5Update(HMAC_MD5_CTX *ctx, const unsigned char *data, unsigned int data_len); +void HMACMD5Final(HMAC_MD5_CTX *ctx, unsigned char *digest); +#endif /*_HMAC_MD5_H_*/
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/md4-5.h ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/messages.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/messages.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/messages.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,93 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +/*********************************************************************** + * EncryptMessage + */ +SECURITY_STATUS SEC_ENTRY EncryptMessage(PCtxtHandle phContext, + ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo) +{ + SECURITY_STATUS ret = SEC_E_UNSUPPORTED_FUNCTION; + //int token_idx, data_idx; + + TRACE("(%p %d %p %d)\n", phContext, fQOP, pMessage, MessageSeqNo); + + if(!phContext) + return SEC_E_INVALID_HANDLE; + + if(fQOP) + FIXME("Ignoring fQOP\n"); + + if(MessageSeqNo) + FIXME("Ignoring MessageSeqNo\n"); + + if(!pMessage || !pMessage->pBuffers || pMessage->cBuffers < 2) + return SEC_E_INVALID_TOKEN; + + //if((token_idx = GetTokenBufferIndex(pMessage)) == -1) + // return SEC_E_INVALID_TOKEN; + + //if((data_idx = GetDataBufferIndex(pMessage)) ==-1 ) + // return SEC_E_INVALID_TOKEN; + + //if(pMessage->pBuffers[token_idx].cbBuffer < 16) + // return SEC_E_BUFFER_TOO_SMALL; + + FIXME("EncryptMessage Unimplemented\n"); + + return ret; + +} + +/*********************************************************************** + * DecryptMessage + */ +SECURITY_STATUS SEC_ENTRY DecryptMessage(PCtxtHandle phContext, + PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP) +{ + //int token_idx, data_idx; + SECURITY_STATUS ret = SEC_E_UNSUPPORTED_FUNCTION; + + TRACE("(%p %p %d %p)\n", phContext, pMessage, MessageSeqNo, pfQOP); + + if(!phContext) + return SEC_E_INVALID_HANDLE; + + if(MessageSeqNo) + FIXME("Ignoring MessageSeqNo\n"); + + if(!pMessage || !pMessage->pBuffers || pMessage->cBuffers < 2) + return SEC_E_INVALID_TOKEN; + + //if((token_idx = GetTokenBufferIndex(pMessage)) == -1) + // return SEC_E_INVALID_TOKEN; + + //if((data_idx = GetDataBufferIndex(pMessage)) ==-1) + // return SEC_E_INVALID_TOKEN; + + //if(pMessage->pBuffers[token_idx].cbBuffer < 16) + // return SEC_E_BUFFER_TOO_SMALL; + + FIXME("DecryptMessage Unimplemented\n"); + + return ret; +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/messages.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,234 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +static SecurityFunctionTableA ntlmTableA = { + SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, + EnumerateSecurityPackagesA, + QueryCredentialsAttributesA, /* QueryCredentialsAttributesA */ + AcquireCredentialsHandleA, /* AcquireCredentialsHandleA */ + FreeCredentialsHandle, /* FreeCredentialsHandle */ + NULL, /* Reserved2 */ + InitializeSecurityContextA, /* InitializeSecurityContextA */ + AcceptSecurityContext, /* AcceptSecurityContext */ + CompleteAuthToken, /* CompleteAuthToken */ + DeleteSecurityContext, /* DeleteSecurityContext */ + NULL, /* ApplyControlToken */ + QueryContextAttributesA, /* QueryContextAttributesA */ + ImpersonateSecurityContext, /* ImpersonateSecurityContext */ + RevertSecurityContext, /* RevertSecurityContext */ + MakeSignature, /* MakeSignature */ + VerifySignature, /* VerifySignature */ + FreeContextBuffer, /* FreeContextBuffer */ + NULL, /* QuerySecurityPackageInfoA */ + NULL, /* Reserved3 */ + NULL, /* Reserved4 */ + NULL, /* ExportSecurityContext */ + NULL, /* ImportSecurityContextA */ + NULL, /* AddCredentialsA */ + NULL, /* Reserved8 */ + NULL, /* QuerySecurityContextToken */ + EncryptMessage, /* EncryptMessage */ + DecryptMessage, /* DecryptMessage */ + NULL, /* SetContextAttributesA */ +}; + +static SecurityFunctionTableW ntlmTableW = { + SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION, + EnumerateSecurityPackagesW, /* EnumerateSecurityPackagesW */ + QueryCredentialsAttributesW, /* QueryCredentialsAttributesW */ + AcquireCredentialsHandleW, /* AcquireCredentialsHandleW */ + FreeCredentialsHandle, /* FreeCredentialsHandle */ + NULL, /* Reserved2 */ + InitializeSecurityContextW, /* InitializeSecurityContextW */ + AcceptSecurityContext, /* AcceptSecurityContext */ + CompleteAuthToken, /* CompleteAuthToken */ + DeleteSecurityContext, /* DeleteSecurityContext */ + NULL, /* ApplyControlToken */ + QueryContextAttributesW, /* QueryContextAttributesW */ + ImpersonateSecurityContext, /* ImpersonateSecurityContext */ + RevertSecurityContext, /* RevertSecurityContext */ + MakeSignature, /* MakeSignature */ + VerifySignature, /* VerifySignature */ + FreeContextBuffer, /* FreeContextBuffer */ + NULL, /* QuerySecurityPackageInfoW */ + NULL, /* Reserved3 */ + NULL, /* Reserved4 */ + NULL, /* ExportSecurityContext */ + NULL, /* ImportSecurityContextW */ + NULL, /* AddCredentialsW */ + NULL, /* Reserved8 */ + NULL, /* QuerySecurityContextToken */ + EncryptMessage, /* EncryptMessage */ + DecryptMessage, /* DecryptMessage */ + NULL, /* SetContextAttributesW */ +}; + +SECURITY_STATUS +SEC_ENTRY +EnumerateSecurityPackagesA(OUT unsigned long* pcPackages, + OUT PSecPkgInfoA * ppPackageInfo) +{ + SECURITY_STATUS ret; + + ret = QuerySecurityPackageInfoA(NULL, ppPackageInfo); + + *pcPackages = 1; + ERR("EnumerateSecurityPackagesW returning! \n"); + return ret; +} + +SECURITY_STATUS +SEC_ENTRY +EnumerateSecurityPackagesW(OUT unsigned long* pcPackages, + OUT PSecPkgInfoW * ppPackageInfo) +{ + SECURITY_STATUS ret; + + ret = QuerySecurityPackageInfoW(NULL, ppPackageInfo); + + *pcPackages = 1; + ERR("EnumerateSecurityPackagesW returning! \n"); + return ret; +} + + +PSecurityFunctionTableA +SEC_ENTRY +InitSecurityInterfaceA(void) +{ + return &ntlmTableA; +} + +PSecurityFunctionTableW +SEC_ENTRY +InitSecurityInterfaceW(void) +{ + return &ntlmTableW; +} + +SECURITY_STATUS +SEC_ENTRY +QuerySecurityPackageInfoA(SEC_CHAR *pszPackageName, + PSecPkgInfoA *ppPackageInfo) +{ + SECURITY_STATUS ret; + size_t bytesNeeded = sizeof(SecPkgInfoA); + int nameLen = 0, commentLen = 0; + + TRACE("%s %p\n", pszPackageName, ppPackageInfo); + + /* get memory needed */ + nameLen = strlen(NTLM_NAME_A) + 1; + bytesNeeded += nameLen * sizeof(CHAR); + commentLen = strlen(NTLM_COMMENT_A) + 1; + bytesNeeded += commentLen * sizeof(CHAR); + + /* allocate it */ + *ppPackageInfo = HeapAlloc(GetProcessHeap(), 0, bytesNeeded); + + if (*ppPackageInfo) + { + PSTR nextString = (PSTR)((PBYTE)*ppPackageInfo + + sizeof(SecPkgInfoA)); + + /* copy easy stuff */ + (*ppPackageInfo)->fCapabilities = NTLM_CAPS; + (*ppPackageInfo)->wVersion = 1; + (*ppPackageInfo)->wRPCID = RPC_C_AUTHN_WINNT; + (*ppPackageInfo)->cbMaxToken = NTLM_MAX_BUF; + + /* copy strings */ + (*ppPackageInfo)->Name = nextString; + strncpy(nextString, NTLM_NAME_A, nameLen); + nextString += nameLen; + + (*ppPackageInfo)->Comment = nextString; + strncpy(nextString, NTLM_COMMENT_A, commentLen); + nextString += commentLen; + + ret = SEC_E_OK; + } + else + ret = SEC_E_INSUFFICIENT_MEMORY; + return ret; +} + +SECURITY_STATUS +SEC_ENTRY +QuerySecurityPackageInfoW(SEC_WCHAR *pszPackageName, + PSecPkgInfoW *ppPackageInfo) +{ + SECURITY_STATUS ret; + size_t bytesNeeded = sizeof(SecPkgInfoW); + int nameLen = 0, commentLen = 0; + + TRACE("%s %p\n", debugstr_w(pszPackageName), ppPackageInfo); + + /* get memory needed */ + nameLen = lstrlenW(NTLM_NAME_W) + 1; + bytesNeeded += nameLen * sizeof(WCHAR); + commentLen = lstrlenW(NTLM_COMMENT_W) + 1; + bytesNeeded += commentLen * sizeof(WCHAR); + + /* allocate it */ + *ppPackageInfo = HeapAlloc(GetProcessHeap(), 0, bytesNeeded); + + if (*ppPackageInfo) + { + PWSTR nextString = (PWSTR)((PBYTE)*ppPackageInfo + + sizeof(SecPkgInfoW)); + + /* copy easy stuff */ + (*ppPackageInfo)->fCapabilities = NTLM_CAPS; + (*ppPackageInfo)->wVersion = 1; + (*ppPackageInfo)->wRPCID = RPC_C_AUTHN_WINNT; + (*ppPackageInfo)->cbMaxToken = NTLM_MAX_BUF; + + /* copy strings */ + (*ppPackageInfo)->Name = nextString; + lstrcpynW(nextString, NTLM_NAME_W, nameLen); + nextString += nameLen; + + (*ppPackageInfo)->Comment = nextString; + lstrcpynW(nextString, NTLM_COMMENT_W, commentLen); + nextString += commentLen; + + ret = SEC_E_OK; + } + else + ret = SEC_E_INSUFFICIENT_MEMORY; + return ret; +} + + +/*********************************************************************** + * CompleteAuthToken + */ +SECURITY_STATUS SEC_ENTRY CompleteAuthToken(PCtxtHandle phContext, + PSecBufferDesc pToken) +{ + TRACE("%p %p\n", phContext, pToken); + if (!phContext) + return SEC_E_INVALID_HANDLE; + + return SEC_E_OK; +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.h URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.h (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.h [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,251 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ +#ifndef _NTLMSSP_H +#define _NTLMSSP_H + +#include <assert.h> +#include <stdarg.h> +#include <stdio.h> + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windows.h" +#define SECURITY_WIN32 +#define _NO_KSECDD_IMPORT_ +#include "rpc.h" +#include "sspi.h" +#include "ntsecapi.h" +#include "ntsecpkg.h" + +#include "wine/unicode.h" +#include "wine/debug.h" + +#define NTLM_NAME_A "NTLM\0" +#define NTLM_NAME_W L"NTLM\0" + +#define NTLM_COMMENT_A "NTLM Security Package\0" +#define NTLM_COMMENT_W L"NTLM Security Package\0" + +/* According to Windows, NTLM has the following capabilities. */ +#define NTLM_CAPS ( \ + SECPKG_FLAG_INTEGRITY | \ + SECPKG_FLAG_PRIVACY | \ + SECPKG_FLAG_TOKEN_ONLY | \ + SECPKG_FLAG_CONNECTION | \ + SECPKG_FLAG_MULTI_REQUIRED | \ + SECPKG_FLAG_IMPERSONATION | \ + SECPKG_FLAG_ACCEPT_WIN32_NAME | \ + SECPKG_FLAG_READONLY_WITH_CHECKSUM) + +#define NTLM_MAX_BUF 1904 /* wtf? */ + +/* NTLMSSP flags indicating the negotiated features */ +#define NTLMSSP_NEGOTIATE_UNICODE 0x00000001 +#define NTLMSSP_NEGOTIATE_OEM 0x00000002 +#define NTLMSSP_REQUEST_TARGET 0x00000004 +#define NTLMSSP_NEGOTIATE_SIGN 0x00000010 +#define NTLMSSP_NEGOTIATE_SEAL 0x00000020 +#define NTLMSSP_NEGOTIATE_DATAGRAM_STYLE 0x00000040 +#define NTLMSSP_NEGOTIATE_LM_SESSION_KEY 0x00000080 +#define NTLMSSP_NEGOTIATE_NTLM 0x00000200 +#define NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED 0x00001000 +#define NTLMSSP_NEGOTIATE_WORKSTATION_SUPPLIED 0x00002000 +#define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x00004000 +#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x00008000 +#define NTLMSSP_NEGOTIATE_TARGET_TYPE_DOMAIN 0x00010000 +#define NTLMSSP_NEGOTIATE_TARGET_TYPE_SERVER 0x00020000 +#define NTLMSSP_NEGOTIATE_NTLM2 0x00080000 +#define NTLMSSP_NEGOTIATE_TARGET_INFO 0x00800000 +#define NTLMSSP_NEGOTIATE_128 0x20000000 +#define NTLMSSP_NEGOTIATE_KEY_EXCHANGE 0x40000000 +#define NTLMSSP_NEGOTIATE_56 0x80000000 + +typedef struct tag_arc4_info { + unsigned char x, y; + unsigned char state[256]; +} arc4_info; + +typedef enum _helper_mode /* remove? */ +{ + NTLM_SERVER, + NTLM_CLIENT, + NUM_HELPER_MODES +} HelperMode; + +typedef struct _NtlmCredentials /* remove? */ +{ + HelperMode mode; + char *username_arg; + char *domain_arg; + char *password; + int pwlen; +} NtlmCredentials, *PNtlmCredentials; + +typedef struct _NegoHelper { /* remove? */ + HelperMode mode; + int pipe_in; + int pipe_out; + int major; + int minor; + int micro; + char *com_buf; + int com_buf_size; + int com_buf_offset; + BYTE *session_key; + ULONG neg_flags; + struct { + struct { + ULONG seq_num; + arc4_info *a4i; + } ntlm; + struct { + BYTE *send_sign_key; + BYTE *send_seal_key; + BYTE *recv_sign_key; + BYTE *recv_seal_key; + ULONG send_seq_no; + ULONG recv_seq_no; + arc4_info *send_a4i; + arc4_info *recv_a4i; + } ntlm2; + } crypt; +} NegoHelper, *PNegoHelper; + +typedef enum _sign_direction { /* remove? */ + NTLM_SEND, + NTLM_RECV +} SignDirection; + +/* functions */ + +SECURITY_STATUS +SEC_ENTRY +ntlm_QueryCredentialsAttributesA( + PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer); + +SECURITY_STATUS +SEC_ENTRY +ntlm_AcquireCredentialsHandleA( + SEC_CHAR *pszPrincipal, SEC_CHAR *pszPackage, ULONG fCredentialUse, + PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn, + PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry); + +SECURITY_STATUS +SEC_ENTRY +ntlm_FreeCredentialsHandle( + PCredHandle phCredential); + +SECURITY_STATUS +SEC_ENTRY +ntlm_InitializeSecurityContextA( + PCredHandle phCredential, PCtxtHandle phContext, SEC_CHAR *pszTargetName, + ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, + PSecBufferDesc pInput,ULONG Reserved2, PCtxtHandle phNewContext, + PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry); + +SECURITY_STATUS +SEC_ENTRY +ntlm_AcceptSecurityContext( + PCredHandle phCredential, PCtxtHandle phContext, PSecBufferDesc pInput, + ULONG fContextReq, ULONG TargetDataRep, PCtxtHandle phNewContext, + PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry); + +SECURITY_STATUS +SEC_ENTRY +ntlm_CompleteAuthToken(PCtxtHandle phContext, + PSecBufferDesc pToken); + +SECURITY_STATUS +SEC_ENTRY +ntlm_DeleteSecurityContext( + PCtxtHandle phContext); + +SECURITY_STATUS +SEC_ENTRY +ntlm_QueryContextAttributesA( + PCtxtHandle phContext, + ULONG ulAttribute, void *pBuffer); + +SECURITY_STATUS +SEC_ENTRY +ntlm_ImpersonateSecurityContext( + PCtxtHandle phContext); + +SECURITY_STATUS +SEC_ENTRY +ntlm_RevertSecurityContext( + PCtxtHandle phContext); + +SECURITY_STATUS +SEC_ENTRY +ntlm_MakeSignature( + PCtxtHandle phContext, ULONG fQOP, + PSecBufferDesc pMessage, ULONG MessageSeqNo); + +SECURITY_STATUS +SEC_ENTRY +ntlm_VerifySignature( + PCtxtHandle phContext, + PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP); + +SECURITY_STATUS +SEC_ENTRY +ntlm_EncryptMessage( + PCtxtHandle phContext, + ULONG fQOP, PSecBufferDesc pMessage, ULONG MessageSeqNo); + +SECURITY_STATUS +SEC_ENTRY +ntlm_DecryptMessage( + PCtxtHandle phContext, + PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP); + +SECURITY_STATUS +SEC_ENTRY +ntlm_QueryCredentialsAttributesW( + PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer); + +SECURITY_STATUS +SEC_ENTRY +ntlm_QueryCredentialsAttributesA( + PCredHandle phCredential, ULONG ulAttribute, PVOID pBuffer); + +SECURITY_STATUS +SEC_ENTRY +ntlm_AcquireCredentialsHandleW( + SEC_WCHAR *pszPrincipal, SEC_WCHAR *pszPackage, ULONG fCredentialUse, + PLUID pLogonID, PVOID pAuthData, SEC_GET_KEY_FN pGetKeyFn, + PVOID pGetKeyArgument, PCredHandle phCredential, PTimeStamp ptsExpiry); + +SECURITY_STATUS +SEC_ENTRY +ntlm_InitializeSecurityContextW( + PCredHandle phCredential, PCtxtHandle phContext, SEC_WCHAR *pszTargetName, + ULONG fContextReq, ULONG Reserved1, ULONG TargetDataRep, + PSecBufferDesc pInput, ULONG Reserved2, PCtxtHandle phNewContext, + PSecBufferDesc pOutput, ULONG *pfContextAttr, PTimeStamp ptsExpiry); + +SECURITY_STATUS +SEC_ENTRY +ntlm_QueryContextAttributesW( + PCtxtHandle phContext, + ULONG ulAttribute, void *pBuffer); + + +#endif
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlm.h ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.rbuild URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.rbuild (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.rbuild [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,20 @@ +<?xml version="1.0"?> +<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd"> +<module name="ntlmssp" type="win32dll" baseaddress="${BASEADDRESS_SCHANNEL}" installbase="system32" installname="ntlmssp.dll" allowwarnings="true"> + <importlibrary definition="ntlmssp.spec" /> + <include base="ntlmssp">.</include> + <library>wine</library> + <library>advapi32</library> + <library>ntdll</library> + <file>base64_codec.c</file> + <file>context.c</file> + <file>credentials.c</file> + <file>hmac_md5.c</file> + <file>messages.c</file> + <file>ntlm.c</file> + <file>sign.c</file> + <file>util.c</file> + <file>dllmain.c</file> +</module> + +
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.rbuild ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.spec URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.spec (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.spec [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,24 @@ +@ stdcall AcceptSecurityContext(ptr ptr ptr long long ptr ptr ptr ptr) +@ stdcall AcquireCredentialsHandleA(str str long ptr ptr ptr ptr ptr ptr) +@ stdcall AcquireCredentialsHandleW(wstr wstr long ptr ptr ptr ptr ptr ptr)secur32.AcquireCredentialsHandleW +#@ stdcall ApplyControlToken(ptr ptr) +@ stdcall CompleteAuthToken(ptr ptr) +@ stdcall DeleteSecurityContext(ptr) +@ stdcall EnumerateSecurityPackagesA(ptr ptr) +@ stdcall EnumerateSecurityPackagesW(ptr ptr) +@ stdcall FreeContextBuffer(ptr) +@ stdcall FreeCredentialsHandle(ptr) +@ stdcall ImpersonateSecurityContext(ptr) +@ stdcall InitSecurityInterfaceA() +@ stdcall InitSecurityInterfaceW() +@ stdcall InitializeSecurityContextA(ptr ptr str long long long ptr long ptr ptr ptr ptr) +@ stdcall InitializeSecurityContextW(ptr ptr wstr long long long ptr long ptr ptr ptr ptr) +@ stdcall MakeSignature(ptr long ptr long) +@ stdcall QueryContextAttributesA(ptr long ptr) +@ stdcall QueryContextAttributesW(ptr long ptr) +@ stdcall QuerySecurityPackageInfoA(str ptr) +@ stdcall QuerySecurityPackageInfoW(wstr ptr) +@ stdcall RevertSecurityContext(ptr) +@ stdcall SealMessage (ptr long ptr long) EncryptMessage +@ stdcall UnsealMessage(ptr ptr long ptr) DecryptMessage +@ stdcall VerifySignature(ptr ptr long ptr)
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/ntlmssp.spec ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/sign.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/sign.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/sign.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,80 @@ +/* + * Copyright 2011 Samuel Serapión + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ +#include "ntlm.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +/*********************************************************************** + * MakeSignature + */ +SECURITY_STATUS SEC_ENTRY MakeSignature(PCtxtHandle phContext, ULONG fQOP, + PSecBufferDesc pMessage, ULONG MessageSeqNo) +{ + //int token_idx; + SECURITY_STATUS ret = SEC_E_UNSUPPORTED_FUNCTION; + + TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, fQOP); + if(!phContext) + return SEC_E_INVALID_HANDLE; + + if(!pMessage || !pMessage->pBuffers || pMessage->cBuffers < 2) + return SEC_E_INVALID_TOKEN; + + //if((token_idx = GetTokenBufferIndex(pMessage)) == -1) + // return SEC_E_INVALID_TOKEN; + + //if(pMessage->pBuffers[token_idx].cbBuffer < 16) + // return SEC_E_BUFFER_TOO_SMALL; + + if(MessageSeqNo) + FIXME("Ignoring MessageSeqNo\n"); + + FIXME("MakeSignature unimplemented\n"); + return ret; +} + +/*********************************************************************** + * VerifySignature + */ +SECURITY_STATUS SEC_ENTRY VerifySignature(PCtxtHandle phContext, + PSecBufferDesc pMessage, ULONG MessageSeqNo, PULONG pfQOP) +{ + SECURITY_STATUS ret = SEC_E_UNSUPPORTED_FUNCTION; + //int token_idx; + + TRACE("%p %p %d %p\n", phContext, pMessage, MessageSeqNo, pfQOP); + if(!phContext) + return SEC_E_INVALID_HANDLE; + + if(!pMessage || !pMessage->pBuffers || pMessage->cBuffers < 2) + return SEC_E_INVALID_TOKEN; + + //if((token_idx = GetTokenBufferIndex(pMessage)) == -1) + // return SEC_E_INVALID_TOKEN; + + //if(pMessage->pBuffers[token_idx].cbBuffer < 16) + // return SEC_E_BUFFER_TOO_SMALL; + + if(MessageSeqNo) + FIXME("Ignoring MessageSeqNo\n"); + + FIXME("VerifySignature unimplemented\n"); + return ret; +} +
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/sign.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/sspi-bringup/reactos/dll/win32/ntlmssp/util.c URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/n... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/ntlmssp/util.c (added) +++ branches/sspi-bringup/reactos/dll/win32/ntlmssp/util.c [iso-8859-1] Sat May 7 20:16:15 2011 @@ -1,0 +1,222 @@ +/* + * Copyright 2006 Kai Blin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + * This file contains various helper functions needed for NTLM and maybe others + */ + +#include "ntlm.h" +#include "md4-5.h" + +WINE_DEFAULT_DEBUG_CHANNEL(ntlm); + +/* The CRC32 code is copyright (C) 1986 Gary S. Brown and was placed in the + * public domain. + * CRC polynomial 0xedb88320 + */ +static const ULONG CRC_table[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +static const char client_to_server_sign_constant[] = "session key to client-to-server signing key magic constant"; +static const char client_to_server_seal_constant[] = "session key to client-to-server sealing key magic constant"; +static const char server_to_client_sign_constant[] = "session key to server-to-client signing key magic constant"; +static const char server_to_client_seal_constant[] = "session key to server-to-client sealing key magic constant"; + +ULONG ComputeCrc32(const BYTE *pData, INT iLen, ULONG initial_crc) +{ + ULONG crc = ~initial_crc; + + while (iLen > 0) + { + crc = CRC_table[(crc ^ *pData) & 0xff] ^ (crc >> 8); + pData++; + iLen--; + } + return ~crc; +} + +SECURITY_STATUS SECUR32_CreateNTLM1SessionKey(PBYTE password, int len, PBYTE session_key) +{ + MD4_CTX ctx; + BYTE ntlm_hash[16]; + + TRACE("(%p, %p)\n", password, session_key); + + MD4Init(&ctx); + MD4Update(&ctx, password, len); + MD4Final(&ctx); + + memcpy(ntlm_hash, ctx.digest, 0x10); + + MD4Init(&ctx); + MD4Update(&ctx, ntlm_hash, 0x10u); + MD4Final(&ctx); + + memcpy(session_key, ctx.digest, 0x10); + + return SEC_E_OK; +} + +static void SECUR32_CalcNTLM2Subkey(const BYTE *session_key, const char *magic, PBYTE subkey) +{ + MD5_CTX ctx; + + MD5Init(&ctx); + MD5Update(&ctx, session_key, 16); + MD5Update(&ctx, (const unsigned char*)magic, lstrlenA(magic)+1); + MD5Final(&ctx); + memcpy(subkey, ctx.digest, 16); +} + +/* This assumes we do have a valid NTLM2 user session key */ +SECURITY_STATUS SECUR32_CreateNTLM2SubKeys(PNegoHelper helper) +{ + helper->crypt.ntlm2.send_sign_key = HeapAlloc(GetProcessHeap(), 0, 16); + helper->crypt.ntlm2.send_seal_key = HeapAlloc(GetProcessHeap(), 0, 16); + helper->crypt.ntlm2.recv_sign_key = HeapAlloc(GetProcessHeap(), 0, 16); + helper->crypt.ntlm2.recv_seal_key = HeapAlloc(GetProcessHeap(), 0, 16); + + if(helper->mode == NTLM_CLIENT) + { + SECUR32_CalcNTLM2Subkey(helper->session_key, client_to_server_sign_constant, + helper->crypt.ntlm2.send_sign_key); + SECUR32_CalcNTLM2Subkey(helper->session_key, client_to_server_seal_constant, + helper->crypt.ntlm2.send_seal_key); + SECUR32_CalcNTLM2Subkey(helper->session_key, server_to_client_sign_constant, + helper->crypt.ntlm2.recv_sign_key); + SECUR32_CalcNTLM2Subkey(helper->session_key, server_to_client_seal_constant, + helper->crypt.ntlm2.recv_seal_key); + } + else + { + SECUR32_CalcNTLM2Subkey(helper->session_key, server_to_client_sign_constant, + helper->crypt.ntlm2.send_sign_key); + SECUR32_CalcNTLM2Subkey(helper->session_key, server_to_client_seal_constant, + helper->crypt.ntlm2.send_seal_key); + SECUR32_CalcNTLM2Subkey(helper->session_key, client_to_server_sign_constant, + helper->crypt.ntlm2.recv_sign_key); + SECUR32_CalcNTLM2Subkey(helper->session_key, client_to_server_seal_constant, + helper->crypt.ntlm2.recv_seal_key); + } + + return SEC_E_OK; +} + +arc4_info *SECUR32_arc4Alloc(void) +{ + arc4_info *a4i = HeapAlloc(GetProcessHeap(), 0, sizeof(arc4_info)); + return a4i; +} + +/* + * The arc4 code is based on dlls/advapi32/crypt_arc4.c by Mike McCormack, + * which in turn is based on public domain code by Wei Dai + */ +void SECUR32_arc4Init(arc4_info *a4i, const BYTE *key, unsigned int keyLen) +{ + unsigned int keyIndex = 0, stateIndex = 0; + unsigned int i, a; + + TRACE("(%p, %p, %d)\n", a4i, key, keyLen); + + a4i->x = a4i->y = 0; + + for (i=0; i<256; i++) + a4i->state[i] = i; + + for (i=0; i<256; i++) + { + a = a4i->state[i]; + stateIndex += key[keyIndex] + a; + stateIndex &= 0xff; + a4i->state[i] = a4i->state[stateIndex]; + a4i->state[stateIndex] = a; + if (++keyIndex >= keyLen) + keyIndex = 0; + } + +} + +void SECUR32_arc4Process(arc4_info *a4i, BYTE *inoutString, unsigned int length) +{ + BYTE *const s=a4i->state; + unsigned int x = a4i->x; + unsigned int y = a4i->y; + unsigned int a, b; + + while(length--) + { + x = (x+1) & 0xff; + a = s[x]; + y = (y+a) & 0xff; + b = s[y]; + s[x] = b; + s[y] = a; + *inoutString++ ^= s[(a+b) & 0xff]; + } + + a4i->x = x; + a4i->y = y; +} + +void SECUR32_arc4Cleanup(arc4_info *a4i) +{ + HeapFree(GetProcessHeap(), 0, a4i); +}
Propchange: branches/sspi-bringup/reactos/dll/win32/ntlmssp/util.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/sspi-bringup/reactos/dll/win32/win32.rbuild URL: http://svn.reactos.org/svn/reactos/branches/sspi-bringup/reactos/dll/win32/w... ============================================================================== --- branches/sspi-bringup/reactos/dll/win32/win32.rbuild [iso-8859-1] (original) +++ branches/sspi-bringup/reactos/dll/win32/win32.rbuild [iso-8859-1] Sat May 7 20:16:15 2011 @@ -352,6 +352,9 @@ <directory name="ntlanman"> <xi:include href="ntlanman/ntlanman.rbuild" /> </directory> +<directory name="ntlmssp"> + <xi:include href="ntlmssp/ntlmssp.rbuild" /> +</directory> <directory name="ntmarta"> <xi:include href="ntmarta/ntmarta.rbuild" /> </directory>