2014-06-29 00:04:49 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Remote Assistance
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
#include <errno.h>
|
|
|
|
|
2017-08-29 10:09:38 +03:00
|
|
|
#include <winpr/wtypes.h>
|
2014-06-29 00:04:49 +04:00
|
|
|
#include <winpr/crt.h>
|
2016-02-24 22:39:49 +03:00
|
|
|
#include <winpr/crypto.h>
|
2014-06-29 20:36:28 +04:00
|
|
|
#include <winpr/print.h>
|
2014-06-29 00:04:49 +04:00
|
|
|
#include <winpr/windows.h>
|
2019-02-25 12:37:30 +03:00
|
|
|
#include <winpr/ssl.h>
|
2021-05-31 12:42:03 +03:00
|
|
|
#include <winpr/file.h>
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2014-06-29 00:04:49 +04:00
|
|
|
#include <freerdp/client/file.h>
|
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
|
2014-06-30 17:40:24 +04:00
|
|
|
#include <freerdp/assistance.h>
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("common")
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
struct rdp_assistance_file
|
|
|
|
{
|
|
|
|
UINT32 Type;
|
|
|
|
|
|
|
|
char* Username;
|
|
|
|
char* LHTicket;
|
|
|
|
char* RCTicket;
|
|
|
|
char* PassStub;
|
|
|
|
UINT32 DtStart;
|
|
|
|
UINT32 DtLength;
|
|
|
|
BOOL LowSpeed;
|
|
|
|
BOOL RCTicketEncrypted;
|
|
|
|
|
|
|
|
char* ConnectionString1;
|
|
|
|
char* ConnectionString2;
|
|
|
|
|
|
|
|
BYTE* EncryptedPassStub;
|
|
|
|
size_t EncryptedPassStubLength;
|
|
|
|
|
|
|
|
BYTE* EncryptedLHTicket;
|
|
|
|
size_t EncryptedLHTicketLength;
|
|
|
|
|
|
|
|
UINT32 MachineCount;
|
|
|
|
char** MachineAddresses;
|
|
|
|
UINT32* MachinePorts;
|
|
|
|
|
|
|
|
char* RASessionId;
|
|
|
|
char* RASpecificParams;
|
|
|
|
|
|
|
|
char* filename;
|
|
|
|
char* password;
|
|
|
|
};
|
|
|
|
|
2014-06-29 20:36:28 +04:00
|
|
|
/**
|
|
|
|
* Password encryption in establishing a remote assistance session of type 1:
|
|
|
|
* http://blogs.msdn.com/b/openspecification/archive/2011/10/31/password-encryption-in-establishing-a-remote-assistance-session-of-type-1.aspx
|
|
|
|
*
|
|
|
|
* Creation of PassStub for the Remote Assistance Ticket:
|
|
|
|
* http://social.msdn.microsoft.com/Forums/en-US/6316c3f4-ea09-4343-a4a1-9cca46d70d28/creation-of-passstub-for-the-remote-assistance-ticket?forum=os_windowsprotocols
|
|
|
|
*/
|
|
|
|
|
2014-06-29 00:04:49 +04:00
|
|
|
/**
|
|
|
|
* CryptDeriveKey Function:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa379916/
|
|
|
|
*
|
|
|
|
* Let n be the required derived key length, in bytes.
|
|
|
|
* The derived key is the first n bytes of the hash value after the hash computation
|
|
|
|
* has been completed by CryptDeriveKey. If the hash is not a member of the SHA-2
|
|
|
|
* family and the required key is for either 3DES or AES, the key is derived as follows:
|
|
|
|
*
|
|
|
|
* Form a 64-byte buffer by repeating the constant 0x36 64 times.
|
|
|
|
* Let k be the length of the hash value that is represented by the input parameter hBaseData.
|
|
|
|
* Set the first k bytes of the buffer to the result of an XOR operation of the first k bytes
|
|
|
|
* of the buffer with the hash value that is represented by the input parameter hBaseData.
|
|
|
|
*
|
|
|
|
* Form a 64-byte buffer by repeating the constant 0x5C 64 times.
|
|
|
|
* Set the first k bytes of the buffer to the result of an XOR operation of the first k bytes
|
|
|
|
* of the buffer with the hash value that is represented by the input parameter hBaseData.
|
|
|
|
*
|
|
|
|
* Hash the result of step 1 by using the same hash algorithm as that used to compute the hash
|
|
|
|
* value that is represented by the hBaseData parameter.
|
|
|
|
*
|
|
|
|
* Hash the result of step 2 by using the same hash algorithm as that used to compute the hash
|
|
|
|
* value that is represented by the hBaseData parameter.
|
|
|
|
*
|
|
|
|
* Concatenate the result of step 3 with the result of step 4.
|
|
|
|
* Use the first n bytes of the result of step 5 as the derived key.
|
|
|
|
*/
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
static BOOL freerdp_assistance_crypt_derive_key_sha1(BYTE* hash, size_t hashLength, BYTE* key,
|
2019-11-06 17:24:51 +03:00
|
|
|
size_t keyLength)
|
2014-06-30 02:48:37 +04:00
|
|
|
{
|
2018-11-08 11:27:57 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
size_t i;
|
2014-06-30 02:48:37 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
BYTE pad1[64];
|
|
|
|
BYTE pad2[64];
|
|
|
|
memset(pad1, 0x36, 64);
|
|
|
|
memset(pad2, 0x5C, 64);
|
|
|
|
|
|
|
|
for (i = 0; i < hashLength; i++)
|
|
|
|
{
|
|
|
|
pad1[i] ^= hash[i];
|
|
|
|
pad2[i] ^= hash[i];
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
buffer = (BYTE*)calloc(hashLength, 2);
|
2014-06-30 02:48:37 +04:00
|
|
|
|
|
|
|
if (!buffer)
|
2016-03-07 13:51:13 +03:00
|
|
|
goto fail;
|
|
|
|
|
2016-11-21 19:28:54 +03:00
|
|
|
if (!winpr_Digest(WINPR_MD_SHA1, pad1, 64, buffer, hashLength))
|
2016-03-07 13:51:13 +03:00
|
|
|
goto fail;
|
|
|
|
|
2016-11-21 19:28:54 +03:00
|
|
|
if (!winpr_Digest(WINPR_MD_SHA1, pad2, 64, &buffer[hashLength], hashLength))
|
2016-03-07 13:51:13 +03:00
|
|
|
goto fail;
|
2014-06-30 02:48:37 +04:00
|
|
|
|
|
|
|
CopyMemory(key, buffer, keyLength);
|
2018-11-08 11:27:57 +03:00
|
|
|
rc = TRUE;
|
2016-03-07 13:51:13 +03:00
|
|
|
fail:
|
2014-06-30 02:48:37 +04:00
|
|
|
free(buffer);
|
2016-03-07 13:51:13 +03:00
|
|
|
return rc;
|
2014-06-29 00:04:49 +04:00
|
|
|
}
|
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
static BOOL reallocate(rdpAssistanceFile* file, const char* host, UINT32 port)
|
2014-06-30 04:38:33 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
void *tmp1, *tmp2;
|
2018-11-09 16:42:10 +03:00
|
|
|
file->MachineCount++;
|
|
|
|
tmp1 = realloc(file->MachinePorts, sizeof(UINT32) * file->MachineCount);
|
|
|
|
tmp2 = realloc(file->MachineAddresses, sizeof(char*) * file->MachineCount);
|
2018-11-08 11:27:57 +03:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
if (!tmp1 || !tmp2)
|
2018-11-21 17:03:30 +03:00
|
|
|
{
|
|
|
|
free(tmp1);
|
|
|
|
free(tmp2);
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2018-11-21 17:03:30 +03:00
|
|
|
}
|
2014-07-01 01:17:06 +04:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
file->MachinePorts = tmp1;
|
|
|
|
file->MachineAddresses = tmp2;
|
|
|
|
file->MachinePorts[file->MachineCount - 1] = port;
|
|
|
|
file->MachineAddresses[file->MachineCount - 1] = _strdup(host);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2014-07-01 01:17:06 +04:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
static BOOL append_address(rdpAssistanceFile* file, const char* host, const char* port)
|
|
|
|
{
|
|
|
|
unsigned long p;
|
|
|
|
errno = 0;
|
|
|
|
p = strtoul(port, NULL, 0);
|
2015-05-06 23:32:45 +03:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
if ((errno != 0) || (p == 0) || (p > UINT16_MAX))
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 invalid port value %s",
|
|
|
|
port);
|
2018-11-09 16:42:10 +03:00
|
|
|
return FALSE;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2015-05-06 23:32:45 +03:00
|
|
|
|
2018-11-22 13:21:57 +03:00
|
|
|
return reallocate(file, host, (UINT16)p);
|
2018-11-09 16:42:10 +03:00
|
|
|
}
|
2015-05-06 23:32:45 +03:00
|
|
|
|
2018-11-22 13:17:13 +03:00
|
|
|
static BOOL freerdp_assistance_parse_address_list(rdpAssistanceFile* file, char* list)
|
2018-11-09 16:42:10 +03:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
|
|
|
char* p;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
if (!file || !list)
|
|
|
|
return FALSE;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
p = list;
|
2015-05-06 23:32:45 +03:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
while ((p = strchr(p, ';')) != NULL)
|
2014-07-01 01:17:06 +04:00
|
|
|
{
|
2018-11-09 16:42:10 +03:00
|
|
|
char* q = strchr(p, ':');
|
2014-07-01 01:17:06 +04:00
|
|
|
|
|
|
|
if (!q)
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out;
|
2014-07-01 01:17:06 +04:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
*q = '\0';
|
2014-07-01 01:17:06 +04:00
|
|
|
q++;
|
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
if (!append_address(file, p, q))
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
p = q;
|
2014-07-01 01:17:06 +04:00
|
|
|
}
|
2015-05-06 23:32:45 +03:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
rc = TRUE;
|
2015-06-17 23:08:02 +03:00
|
|
|
out:
|
2018-11-22 13:17:13 +03:00
|
|
|
return rc;
|
2014-07-01 01:17:06 +04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
static BOOL freerdp_assistance_parse_connection_string1(rdpAssistanceFile* file)
|
2014-07-01 01:17:06 +04:00
|
|
|
{
|
2018-11-08 11:27:57 +03:00
|
|
|
size_t i;
|
2014-07-01 01:17:06 +04:00
|
|
|
char* str;
|
|
|
|
int count;
|
2018-11-08 11:27:57 +03:00
|
|
|
size_t length;
|
2014-06-30 04:38:33 +04:00
|
|
|
char* tokens[8];
|
2018-11-08 11:27:57 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
|
|
|
if (!file || !file->RCTicket)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
/**
|
|
|
|
* <ProtocolVersion>,<protocolType>,<machineAddressList>,<assistantAccountPwd>,
|
|
|
|
* <RASessionID>,<RASessionName>,<RASessionPwd>,<protocolSpecificParms>
|
|
|
|
*/
|
|
|
|
count = 1;
|
|
|
|
str = _strdup(file->RCTicket);
|
|
|
|
|
|
|
|
if (!str)
|
2018-11-08 11:27:57 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
length = strlen(str);
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if (str[i] == ',')
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count != 8)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
tokens[count++] = str;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
if (str[i] == ',')
|
|
|
|
{
|
|
|
|
str[i] = '\0';
|
|
|
|
tokens[count++] = &str[i + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(tokens[0], "65538") != 0)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
if (strcmp(tokens[1], "1") != 0)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
if (strcmp(tokens[3], "*") != 0)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
if (strcmp(tokens[5], "*") != 0)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
if (strcmp(tokens[6], "*") != 0)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
file->RASessionId = _strdup(tokens[4]);
|
|
|
|
|
|
|
|
if (!file->RASessionId)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
file->RASpecificParams = _strdup(tokens[7]);
|
|
|
|
|
|
|
|
if (!file->RASpecificParams)
|
2016-05-12 11:01:30 +03:00
|
|
|
goto error;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
if (!freerdp_assistance_parse_address_list(file, tokens[2]))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
rc = TRUE;
|
2016-05-12 11:01:30 +03:00
|
|
|
error:
|
2014-06-30 04:38:33 +04:00
|
|
|
free(str);
|
2018-11-08 11:27:57 +03:00
|
|
|
return rc;
|
2014-06-30 04:38:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrypted Connection String 2:
|
|
|
|
*
|
|
|
|
* <E>
|
2019-11-06 17:24:51 +03:00
|
|
|
* <A KH="BNRjdu97DyczQSRuMRrDWoue+HA="
|
|
|
|
* ID="+ULZ6ifjoCa6cGPMLQiGHRPwkg6VyJqGwxMnO6GcelwUh9a6/FBq3It5ADSndmLL"/> <C> <T ID="1" SID="0"> <L
|
|
|
|
* P="49228" N="fe80::1032:53d9:5a01:909b%3"/> <L P="49229" N="fe80::3d8f:9b2d:6b4e:6aa%6"/> <L
|
|
|
|
* P="49230" N="192.168.1.200"/> <L P="49231" N="169.254.6.170"/>
|
2014-06-30 04:38:33 +04:00
|
|
|
* </T>
|
|
|
|
* </C>
|
|
|
|
* </E>
|
|
|
|
*/
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
static BOOL freerdp_assistance_parse_connection_string2(rdpAssistanceFile* file)
|
2014-06-30 04:38:33 +04:00
|
|
|
{
|
|
|
|
char* str;
|
2015-06-17 23:08:02 +03:00
|
|
|
char* tag;
|
|
|
|
char* end;
|
|
|
|
char* p;
|
2018-11-08 11:27:57 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
|
|
|
|
if (!file || !file->ConnectionString2)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
str = file->ConnectionString2;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!strstr(str, "<E>"))
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 missing field <E>");
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!strstr(str, "<C>"))
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 missing field <C>");
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
str = _strdup(file->ConnectionString2);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!str)
|
2018-11-08 11:27:57 +03:00
|
|
|
goto out_fail;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!(tag = strstr(str, "<A")))
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 missing field <A");
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
/* Parse Auth String Node (<A>) */
|
|
|
|
end = strstr(tag, "/>");
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
if (!end)
|
|
|
|
goto out_fail;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
*end = '\0';
|
|
|
|
p = strstr(tag, "KH=\"");
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
if (p)
|
|
|
|
{
|
2017-11-14 18:10:52 +03:00
|
|
|
char* q;
|
2015-06-17 23:08:02 +03:00
|
|
|
size_t length;
|
2014-06-30 04:38:33 +04:00
|
|
|
p += sizeof("KH=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
|
|
|
|
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 invalid field KH=%s",
|
|
|
|
q);
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(
|
|
|
|
TAG,
|
|
|
|
"Failed to parse ASSISTANCE file: ConnectionString2 invalid field order for KH");
|
|
|
|
goto out_fail;
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
length = q - p;
|
|
|
|
free(file->RASpecificParams);
|
2019-11-06 17:24:51 +03:00
|
|
|
file->RASpecificParams = (char*)malloc(length + 1);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
if (!file->RASpecificParams)
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
CopyMemory(file->RASpecificParams, p, length);
|
|
|
|
file->RASpecificParams[length] = '\0';
|
|
|
|
}
|
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
p = strstr(tag, "ID=\"");
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
if (p)
|
|
|
|
{
|
2017-11-14 18:10:52 +03:00
|
|
|
char* q;
|
2015-06-17 23:08:02 +03:00
|
|
|
size_t length;
|
2014-06-30 04:38:33 +04:00
|
|
|
p += sizeof("ID=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
|
|
|
|
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 invalid field ID=%s",
|
|
|
|
q);
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 invalid field "
|
|
|
|
"order for ID");
|
2021-04-27 11:04:47 +03:00
|
|
|
goto out_fail;
|
2020-05-29 18:24:15 +03:00
|
|
|
}
|
2014-06-30 04:38:33 +04:00
|
|
|
length = q - p;
|
|
|
|
free(file->RASessionId);
|
2019-11-06 17:24:51 +03:00
|
|
|
file->RASessionId = (char*)malloc(length + 1);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
if (!file->RASessionId)
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2014-06-30 04:38:33 +04:00
|
|
|
|
|
|
|
CopyMemory(file->RASessionId, p, length);
|
|
|
|
file->RASessionId[length] = '\0';
|
|
|
|
}
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
*end = '/';
|
2015-06-17 23:08:02 +03:00
|
|
|
/* Parse <L last address is used */
|
|
|
|
p = strstr(str, "<L P=\"");
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2014-08-15 02:41:22 +04:00
|
|
|
while (p)
|
|
|
|
{
|
2018-11-09 16:42:10 +03:00
|
|
|
char* port;
|
2017-11-14 18:10:52 +03:00
|
|
|
char* q;
|
2015-06-17 23:08:02 +03:00
|
|
|
size_t length;
|
2014-08-15 02:41:22 +04:00
|
|
|
p += sizeof("<L P=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
|
|
|
|
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"Failed to parse ASSISTANCE file: ConnectionString2 invalid field <L P=%s", q);
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-08-15 02:41:22 +04:00
|
|
|
|
|
|
|
q[0] = '\0';
|
|
|
|
q++;
|
2018-11-09 16:42:10 +03:00
|
|
|
port = p;
|
2014-08-15 02:41:22 +04:00
|
|
|
p = strstr(q, " N=\"");
|
|
|
|
|
|
|
|
if (!p)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 invalid field N=%s",
|
|
|
|
p);
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-08-15 02:41:22 +04:00
|
|
|
|
|
|
|
p += sizeof(" N=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
|
|
|
|
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: ConnectionString2 invalid field N=%s",
|
|
|
|
q);
|
2015-06-17 23:08:02 +03:00
|
|
|
goto out_fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-08-15 02:41:22 +04:00
|
|
|
|
|
|
|
q[0] = '\0';
|
|
|
|
q++;
|
|
|
|
length = strlen(p);
|
|
|
|
|
|
|
|
if (length > 8)
|
|
|
|
{
|
2018-11-09 16:42:10 +03:00
|
|
|
if (!append_address(file, p, port))
|
|
|
|
goto out_fail;
|
2014-08-15 02:41:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
p = strstr(q, "<L P=\"");
|
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
rc = TRUE;
|
2015-06-17 23:08:02 +03:00
|
|
|
out_fail:
|
2014-06-30 04:38:33 +04:00
|
|
|
free(str);
|
2018-11-08 11:27:57 +03:00
|
|
|
return rc;
|
2014-06-30 04:38:33 +04:00
|
|
|
}
|
|
|
|
|
2014-06-30 20:51:27 +04:00
|
|
|
char* freerdp_assistance_construct_expert_blob(const char* name, const char* pass)
|
|
|
|
{
|
2018-11-08 11:27:57 +03:00
|
|
|
size_t size;
|
|
|
|
size_t nameLength;
|
|
|
|
size_t passLength;
|
2014-06-30 20:51:27 +04:00
|
|
|
char* ExpertBlob = NULL;
|
|
|
|
|
|
|
|
if (!name || !pass)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nameLength = strlen(name) + strlen("NAME=");
|
|
|
|
passLength = strlen(pass) + strlen("PASS=");
|
|
|
|
size = nameLength + passLength + 64;
|
2019-11-06 17:24:51 +03:00
|
|
|
ExpertBlob = (char*)calloc(1, size);
|
2014-06-30 20:51:27 +04:00
|
|
|
|
|
|
|
if (!ExpertBlob)
|
|
|
|
return NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(ExpertBlob, size, "%" PRIdz ";NAME=%s%" PRIdz ";PASS=%s", nameLength, name,
|
|
|
|
passLength, pass);
|
2014-06-30 20:51:27 +04:00
|
|
|
return ExpertBlob;
|
|
|
|
}
|
|
|
|
|
2014-07-16 04:09:19 +04:00
|
|
|
char* freerdp_assistance_generate_pass_stub(DWORD flags)
|
|
|
|
{
|
|
|
|
UINT32 nums[14];
|
|
|
|
char* passStub = NULL;
|
|
|
|
char set1[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789*_";
|
|
|
|
char set2[12] = "!@#$&^*()-+=";
|
|
|
|
char set3[10] = "0123456789";
|
|
|
|
char set4[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
char set5[26] = "abcdefghijklmnopqrstuvwxyz";
|
2019-11-06 17:24:51 +03:00
|
|
|
passStub = (char*)malloc(15);
|
2014-07-16 04:09:19 +04:00
|
|
|
|
|
|
|
if (!passStub)
|
2014-08-14 01:48:57 +04:00
|
|
|
return NULL;
|
2014-07-16 04:09:19 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PassStub generation:
|
|
|
|
*
|
|
|
|
* Characters 0 and 5-13 are from the set A-Z a-z 0-9 * _
|
|
|
|
* Character 1 is from the set !@#$&^*()-+=
|
|
|
|
* Character 2 is from the set 0-9
|
|
|
|
* Character 3 is from the set A-Z
|
|
|
|
* Character 4 is from the set a-z
|
|
|
|
*
|
|
|
|
* Example: WB^6HsrIaFmEpi
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
winpr_RAND((BYTE*)nums, sizeof(nums));
|
|
|
|
passStub[0] = set1[nums[0] % sizeof(set1)]; /* character 0 */
|
|
|
|
passStub[1] = set2[nums[1] % sizeof(set2)]; /* character 1 */
|
|
|
|
passStub[2] = set3[nums[2] % sizeof(set3)]; /* character 2 */
|
|
|
|
passStub[3] = set4[nums[3] % sizeof(set4)]; /* character 3 */
|
|
|
|
passStub[4] = set5[nums[4] % sizeof(set5)]; /* character 4 */
|
|
|
|
passStub[5] = set1[nums[5] % sizeof(set1)]; /* character 5 */
|
|
|
|
passStub[6] = set1[nums[6] % sizeof(set1)]; /* character 6 */
|
|
|
|
passStub[7] = set1[nums[7] % sizeof(set1)]; /* character 7 */
|
|
|
|
passStub[8] = set1[nums[8] % sizeof(set1)]; /* character 8 */
|
|
|
|
passStub[9] = set1[nums[9] % sizeof(set1)]; /* character 9 */
|
2014-07-16 04:09:19 +04:00
|
|
|
passStub[10] = set1[nums[10] % sizeof(set1)]; /* character 10 */
|
|
|
|
passStub[11] = set1[nums[11] % sizeof(set1)]; /* character 11 */
|
|
|
|
passStub[12] = set1[nums[12] % sizeof(set1)]; /* character 12 */
|
|
|
|
passStub[13] = set1[nums[13] % sizeof(set1)]; /* character 13 */
|
|
|
|
passStub[14] = '\0';
|
|
|
|
return passStub;
|
|
|
|
}
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, const char* passStub,
|
2019-11-06 17:24:51 +03:00
|
|
|
size_t* pEncryptedSize)
|
2014-06-29 01:03:16 +04:00
|
|
|
{
|
2016-03-07 13:51:13 +03:00
|
|
|
BOOL rc;
|
2014-06-29 01:03:16 +04:00
|
|
|
int status;
|
2018-11-08 11:27:57 +03:00
|
|
|
size_t cbPasswordW;
|
|
|
|
size_t cbPassStubW;
|
|
|
|
size_t EncryptedSize;
|
2016-02-24 23:45:09 +03:00
|
|
|
BYTE PasswordHash[WINPR_MD5_DIGEST_LENGTH];
|
2018-11-08 11:27:57 +03:00
|
|
|
WINPR_CIPHER_CTX* rc4Ctx = NULL;
|
|
|
|
BYTE* pbIn = NULL;
|
|
|
|
BYTE* pbOut = NULL;
|
2016-03-07 13:51:13 +03:00
|
|
|
size_t cbOut, cbIn, cbFinal;
|
2014-06-30 20:51:27 +04:00
|
|
|
WCHAR* PasswordW = NULL;
|
|
|
|
WCHAR* PassStubW = NULL;
|
2014-06-29 01:03:16 +04:00
|
|
|
status = ConvertToUnicode(CP_UTF8, 0, password, -1, &PasswordW, 0);
|
|
|
|
|
|
|
|
if (status <= 0)
|
2014-06-30 20:51:27 +04:00
|
|
|
return NULL;
|
2014-06-29 01:03:16 +04:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
cbPasswordW = (size_t)(status - 1) * 2UL;
|
2014-06-29 20:36:28 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!winpr_Digest(WINPR_MD_MD5, (BYTE*)PasswordW, cbPasswordW, (BYTE*)PasswordHash,
|
2017-11-14 18:10:52 +03:00
|
|
|
sizeof(PasswordHash)))
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 01:03:16 +04:00
|
|
|
|
2014-06-30 20:51:27 +04:00
|
|
|
status = ConvertToUnicode(CP_UTF8, 0, passStub, -1, &PassStubW, 0);
|
2014-06-29 20:36:28 +04:00
|
|
|
|
|
|
|
if (status <= 0)
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 20:36:28 +04:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
cbPassStubW = (size_t)(status - 1) * 2UL;
|
2014-06-30 20:51:27 +04:00
|
|
|
EncryptedSize = cbPassStubW + 4;
|
2019-11-06 17:24:51 +03:00
|
|
|
pbIn = (BYTE*)calloc(1, EncryptedSize);
|
|
|
|
pbOut = (BYTE*)calloc(1, EncryptedSize);
|
2014-06-29 01:03:16 +04:00
|
|
|
|
2014-11-17 00:58:36 +03:00
|
|
|
if (!pbIn || !pbOut)
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 01:03:16 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
*((UINT32*)pbIn) = (UINT32)cbPassStubW;
|
2014-06-30 20:51:27 +04:00
|
|
|
CopyMemory(&pbIn[4], PassStubW, cbPassStubW);
|
2019-11-06 17:24:51 +03:00
|
|
|
rc4Ctx = winpr_Cipher_New(WINPR_CIPHER_ARC4_128, WINPR_ENCRYPT, PasswordHash, NULL);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
if (!rc4Ctx)
|
2014-06-30 02:48:37 +04:00
|
|
|
{
|
2020-02-12 15:47:35 +03:00
|
|
|
WLog_ERR(TAG, "winpr_Cipher_New failure");
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-30 02:48:37 +04:00
|
|
|
}
|
|
|
|
|
2014-06-30 17:21:45 +04:00
|
|
|
cbOut = cbFinal = 0;
|
2014-06-30 20:51:27 +04:00
|
|
|
cbIn = EncryptedSize;
|
2016-03-07 13:51:13 +03:00
|
|
|
rc = winpr_Cipher_Update(rc4Ctx, pbIn, cbIn, pbOut, &cbOut);
|
2014-06-30 02:48:37 +04:00
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
if (!rc)
|
2014-06-30 02:48:37 +04:00
|
|
|
{
|
2020-02-12 15:47:35 +03:00
|
|
|
WLog_ERR(TAG, "winpr_Cipher_Update failure");
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-30 02:48:37 +04:00
|
|
|
}
|
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
if (!winpr_Cipher_Final(rc4Ctx, pbOut + cbOut, &cbFinal))
|
2014-06-30 02:48:37 +04:00
|
|
|
{
|
2020-02-12 15:47:35 +03:00
|
|
|
WLog_ERR(TAG, "winpr_Cipher_Final failure");
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-30 02:48:37 +04:00
|
|
|
}
|
2014-06-29 01:03:16 +04:00
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
winpr_Cipher_Free(rc4Ctx);
|
2018-11-08 11:27:57 +03:00
|
|
|
free(pbIn);
|
|
|
|
free(PasswordW);
|
|
|
|
free(PassStubW);
|
2014-06-30 20:51:27 +04:00
|
|
|
*pEncryptedSize = EncryptedSize;
|
|
|
|
return pbOut;
|
2018-11-08 11:27:57 +03:00
|
|
|
fail:
|
|
|
|
winpr_Cipher_Free(rc4Ctx);
|
|
|
|
free(PasswordW);
|
|
|
|
free(PassStubW);
|
|
|
|
free(pbIn);
|
|
|
|
free(pbOut);
|
|
|
|
return NULL;
|
2014-06-29 01:03:16 +04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
static BOOL freerdp_assistance_decrypt2(rdpAssistanceFile* file, const char* password)
|
2014-06-29 00:04:49 +04:00
|
|
|
{
|
2018-11-08 11:27:57 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
int status = 0;
|
|
|
|
size_t cbPasswordW;
|
2014-06-30 04:38:33 +04:00
|
|
|
int cchOutW = 0;
|
|
|
|
WCHAR* pbOutW = NULL;
|
2018-11-08 11:27:57 +03:00
|
|
|
WINPR_CIPHER_CTX* aesDec = NULL;
|
2014-06-29 00:04:49 +04:00
|
|
|
WCHAR* PasswordW = NULL;
|
2018-11-08 11:27:57 +03:00
|
|
|
BYTE* pbIn = NULL;
|
|
|
|
BYTE* pbOut = NULL;
|
2016-03-07 13:51:13 +03:00
|
|
|
size_t cbOut, cbIn, cbFinal;
|
|
|
|
BYTE DerivedKey[WINPR_AES_BLOCK_SIZE];
|
|
|
|
BYTE InitializationVector[WINPR_AES_BLOCK_SIZE];
|
|
|
|
BYTE PasswordHash[WINPR_SHA1_DIGEST_LENGTH];
|
2018-11-08 11:27:57 +03:00
|
|
|
|
|
|
|
if (!file || !password)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-06-29 00:04:49 +04:00
|
|
|
status = ConvertToUnicode(CP_UTF8, 0, password, -1, &PasswordW, 0);
|
|
|
|
|
|
|
|
if (status <= 0)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Conversion from UCS2 to UTF8 failed");
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
cbPasswordW = (size_t)(status - 1) * 2UL;
|
2014-06-30 02:48:37 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!winpr_Digest(WINPR_MD_SHA1, (BYTE*)PasswordW, cbPasswordW, PasswordHash,
|
|
|
|
sizeof(PasswordHash)))
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_assistance_crypt_derive_key_sha1(PasswordHash, sizeof(PasswordHash), DerivedKey,
|
|
|
|
sizeof(DerivedKey)))
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2014-06-30 03:57:46 +04:00
|
|
|
ZeroMemory(InitializationVector, sizeof(InitializationVector));
|
2019-11-06 17:24:51 +03:00
|
|
|
aesDec =
|
|
|
|
winpr_Cipher_New(WINPR_CIPHER_AES_128_CBC, WINPR_DECRYPT, DerivedKey, InitializationVector);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
if (!aesDec)
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2014-06-30 02:48:37 +04:00
|
|
|
cbOut = cbFinal = 0;
|
2018-11-08 11:27:57 +03:00
|
|
|
cbIn = (size_t)file->EncryptedLHTicketLength;
|
2019-11-06 17:24:51 +03:00
|
|
|
pbIn = (BYTE*)file->EncryptedLHTicket;
|
|
|
|
pbOut = (BYTE*)calloc(1, cbIn + WINPR_AES_BLOCK_SIZE + 2);
|
2014-06-30 02:48:37 +04:00
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
if (!pbOut)
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
if (!winpr_Cipher_Update(aesDec, pbIn, cbIn, pbOut, &cbOut))
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2016-03-07 13:51:13 +03:00
|
|
|
if (!winpr_Cipher_Final(aesDec, pbOut + cbOut, &cbFinal))
|
2014-06-30 02:48:37 +04:00
|
|
|
{
|
2020-02-12 15:47:35 +03:00
|
|
|
WLog_ERR(TAG, "winpr_Cipher_Final failure");
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2014-06-30 02:48:37 +04:00
|
|
|
}
|
|
|
|
|
2014-06-30 04:38:33 +04:00
|
|
|
cbOut += cbFinal;
|
|
|
|
cbFinal = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
pbOutW = (WCHAR*)pbOut;
|
2018-11-08 11:27:57 +03:00
|
|
|
|
|
|
|
if (cbOut > INT_MAX / 2)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
cchOutW = (int)cbOut / 2;
|
2014-06-30 04:38:33 +04:00
|
|
|
file->ConnectionString2 = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, pbOutW, cchOutW, &file->ConnectionString2, 0, NULL, NULL);
|
2014-06-30 04:38:33 +04:00
|
|
|
|
2014-11-17 00:58:36 +03:00
|
|
|
if (status <= 0)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Conversion from UCS2 to UTF8 failed");
|
2018-11-08 11:27:57 +03:00
|
|
|
goto fail;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-11-17 00:58:36 +03:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
if (!freerdp_assistance_parse_connection_string2(file))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
|
|
|
winpr_Cipher_Free(aesDec);
|
|
|
|
free(PasswordW);
|
|
|
|
free(pbOut);
|
2014-09-12 16:36:29 +04:00
|
|
|
WLog_DBG(TAG, "freerdp_assistance_parse_connection_string2: %d", status);
|
2018-11-08 11:27:57 +03:00
|
|
|
return rc;
|
2014-06-29 00:04:49 +04:00
|
|
|
}
|
|
|
|
|
2019-01-29 18:14:55 +03:00
|
|
|
BYTE* freerdp_assistance_hex_string_to_bin(const void* raw, size_t* size)
|
2014-06-29 00:04:49 +04:00
|
|
|
{
|
2021-04-19 11:06:14 +03:00
|
|
|
BYTE* buffer = NULL;
|
|
|
|
size_t length, rc;
|
|
|
|
if (!raw || !size)
|
2014-06-29 00:04:49 +04:00
|
|
|
return NULL;
|
2021-04-19 11:06:14 +03:00
|
|
|
*size = 0;
|
|
|
|
length = strlen(raw);
|
|
|
|
buffer = calloc(length, sizeof(BYTE));
|
2014-06-29 00:04:49 +04:00
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
2021-04-19 11:06:14 +03:00
|
|
|
rc = winpr_HexStringToBinBuffer(raw, length, buffer, length);
|
|
|
|
if (rc == 0)
|
2014-06-29 00:04:49 +04:00
|
|
|
{
|
2021-04-19 11:06:14 +03:00
|
|
|
free(buffer);
|
|
|
|
return NULL;
|
2014-06-29 00:04:49 +04:00
|
|
|
}
|
2021-04-19 11:06:14 +03:00
|
|
|
*size = rc;
|
2014-06-29 00:04:49 +04:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2019-01-29 18:14:55 +03:00
|
|
|
char* freerdp_assistance_bin_to_hex_string(const void* raw, size_t size)
|
2014-06-30 20:51:27 +04:00
|
|
|
{
|
2021-04-19 11:06:14 +03:00
|
|
|
return winpr_BinToHexString(raw, size, FALSE);
|
2014-06-30 20:51:27 +04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, const char* buffer, size_t size,
|
2019-11-06 17:24:51 +03:00
|
|
|
const char* password)
|
2014-06-29 00:04:49 +04:00
|
|
|
{
|
|
|
|
char* p;
|
|
|
|
char* q;
|
|
|
|
char* r;
|
2014-06-29 01:03:16 +04:00
|
|
|
int status;
|
2014-06-29 00:04:49 +04:00
|
|
|
size_t length;
|
2020-11-09 11:19:53 +03:00
|
|
|
|
|
|
|
free(file->password);
|
|
|
|
file->password = _strdup(password);
|
|
|
|
|
2014-06-29 00:04:49 +04:00
|
|
|
p = strstr(buffer, "UPLOADINFO");
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
{
|
2019-01-03 22:58:40 +03:00
|
|
|
p = strstr(p + sizeof("UPLOADINFO") - 1, "TYPE=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!p)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Missing UPLOADINFO TYPE");
|
2014-06-29 00:04:49 +04:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
p = strstr(buffer, "UPLOADDATA");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!p)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Missing UPLOADDATA");
|
2014-06-29 00:04:49 +04:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse USERNAME */
|
|
|
|
p = strstr(buffer, "USERNAME=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p += sizeof("USERNAME=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid USERNAME=%s", p);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for USERNAME");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
file->Username = (char*)malloc(length + 1);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!file->Username)
|
|
|
|
return -1;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
CopyMemory(file->Username, p, length);
|
|
|
|
file->Username[length] = '\0';
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse LHTICKET */
|
|
|
|
p = strstr(buffer, "LHTICKET=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p += sizeof("LHTICKET=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid LHTICKET=%s", p);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for LHTICKET");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
file->LHTicket = (char*)malloc(length + 1);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!file->LHTicket)
|
|
|
|
return -1;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
CopyMemory(file->LHTicket, p, length);
|
|
|
|
file->LHTicket[length] = '\0';
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse RCTICKET */
|
|
|
|
p = strstr(buffer, "RCTICKET=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p += sizeof("RCTICKET=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid RCTICKET=%s", p);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for RCTICKET");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
file->RCTicket = (char*)malloc(length + 1);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!file->RCTicket)
|
|
|
|
return -1;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
CopyMemory(file->RCTicket, p, length);
|
|
|
|
file->RCTicket[length] = '\0';
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse RCTICKETENCRYPTED */
|
|
|
|
p = strstr(buffer, "RCTICKETENCRYPTED=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p += sizeof("RCTICKETENCRYPTED=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid RCTICKETENCRYPTED=%s", p);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for RCTICKETENCRYPTED");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if ((length == 1) && (p[0] == '1'))
|
|
|
|
file->RCTicketEncrypted = TRUE;
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse PassStub */
|
|
|
|
p = strstr(buffer, "PassStub=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p += sizeof("PassStub=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid PassStub=%s", p);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for PassStub");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
file->PassStub = (char*)malloc(length + 1);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!file->PassStub)
|
|
|
|
return -1;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
CopyMemory(file->PassStub, p, length);
|
|
|
|
file->PassStub[length] = '\0';
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse DtStart */
|
|
|
|
p = strstr(buffer, "DtStart=\"");
|
|
|
|
|
|
|
|
if (p)
|
2017-11-14 18:10:52 +03:00
|
|
|
{
|
2019-01-03 22:58:40 +03:00
|
|
|
p += sizeof("DtStart=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid DtStart=%s", p);
|
2017-11-14 18:10:52 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for DtStart");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
r = (char*)malloc(length + 1);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!r)
|
|
|
|
return -1;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
CopyMemory(r, p, length);
|
|
|
|
r[length] = '\0';
|
|
|
|
errno = 0;
|
|
|
|
{
|
|
|
|
unsigned long val = strtoul(r, NULL, 0);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if ((errno != 0) || (val > UINT32_MAX))
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid DtStart value %s", r);
|
2019-01-16 17:00:13 +03:00
|
|
|
free(r);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-16 17:00:13 +03:00
|
|
|
free(r);
|
2019-01-03 22:58:40 +03:00
|
|
|
file->DtStart = val;
|
|
|
|
}
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse DtLength */
|
|
|
|
p = strstr(buffer, "DtLength=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
2017-11-14 18:10:52 +03:00
|
|
|
{
|
2019-01-03 22:58:40 +03:00
|
|
|
p += sizeof("DtLength=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid DtLength=%s", p);
|
2017-11-14 18:10:52 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for DtLength");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
r = (char*)malloc(length + 1);
|
2019-01-03 22:58:40 +03:00
|
|
|
|
|
|
|
if (!r)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
CopyMemory(r, p, length);
|
|
|
|
r[length] = '\0';
|
|
|
|
errno = 0;
|
|
|
|
{
|
|
|
|
unsigned long val = strtoul(r, NULL, 0);
|
|
|
|
|
|
|
|
if ((errno != 0) || (val > UINT32_MAX))
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid DtLength value %s", r);
|
2019-01-16 17:00:13 +03:00
|
|
|
free(r);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2019-01-03 22:58:40 +03:00
|
|
|
|
2019-01-16 17:00:13 +03:00
|
|
|
free(r);
|
2019-01-03 22:58:40 +03:00
|
|
|
file->DtLength = val;
|
|
|
|
}
|
2017-11-14 18:10:52 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
/* Parse L (LowSpeed) */
|
|
|
|
p = strstr(buffer, " L=\"");
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p += sizeof(" L=\"") - 1;
|
|
|
|
q = strchr(p, '"');
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Invalid L=%s", p);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field "
|
|
|
|
"order for L");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
length = q - p;
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if ((length == 1) && (p[0] == '1'))
|
|
|
|
file->LowSpeed = TRUE;
|
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
file->Type = (file->LHTicket) ? 2 : 1;
|
|
|
|
status = 0;
|
2014-06-29 20:36:28 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
switch (file->Type)
|
|
|
|
{
|
2019-01-16 17:00:13 +03:00
|
|
|
case 2:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
file->EncryptedLHTicket = freerdp_assistance_hex_string_to_bin(
|
|
|
|
file->LHTicket, &file->EncryptedLHTicketLength);
|
2018-11-12 11:19:38 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_assistance_decrypt2(file, password))
|
|
|
|
status = -1;
|
|
|
|
}
|
|
|
|
break;
|
2018-11-12 11:19:38 +03:00
|
|
|
|
2019-01-16 17:00:13 +03:00
|
|
|
case 1:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
if (!freerdp_assistance_parse_connection_string1(file))
|
|
|
|
status = -1;
|
|
|
|
}
|
|
|
|
break;
|
2018-11-12 11:19:38 +03:00
|
|
|
|
2019-01-16 17:00:13 +03:00
|
|
|
default:
|
|
|
|
return -1;
|
2019-01-03 22:58:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "freerdp_assistance_parse_connection_string1 failure: %d", status);
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
file->EncryptedPassStub = freerdp_assistance_encrypt_pass_stub(
|
|
|
|
password, file->PassStub, &file->EncryptedPassStubLength);
|
2019-01-03 22:58:40 +03:00
|
|
|
|
|
|
|
if (!file->EncryptedPassStub)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 1;
|
2018-11-08 11:27:57 +03:00
|
|
|
}
|
2014-06-29 01:03:16 +04:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
p = strstr(buffer, "<E>");
|
2019-01-16 17:00:13 +03:00
|
|
|
|
|
|
|
if (p)
|
2014-06-29 01:03:16 +04:00
|
|
|
{
|
2019-01-03 22:58:40 +03:00
|
|
|
q = strstr(buffer, "</E>");
|
2019-01-16 17:00:13 +03:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!q)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Missing </E> tag");
|
2019-01-03 22:58:40 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2020-05-29 18:24:15 +03:00
|
|
|
if (p > q)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: invalid field order for <E>");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
q += sizeof("</E>") - 1;
|
|
|
|
length = q - p;
|
2019-11-06 17:24:51 +03:00
|
|
|
file->ConnectionString2 = (char*)malloc(length + 1);
|
2019-01-16 17:00:13 +03:00
|
|
|
|
2018-12-11 11:27:32 +03:00
|
|
|
if (!file->ConnectionString2)
|
|
|
|
return -1;
|
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
CopyMemory(file->ConnectionString2, p, length);
|
|
|
|
file->ConnectionString2[length] = '\0';
|
2018-11-12 11:19:38 +03:00
|
|
|
|
2019-01-03 22:58:40 +03:00
|
|
|
if (!freerdp_assistance_parse_connection_string2(file))
|
|
|
|
return -1;
|
2019-01-07 15:00:48 +03:00
|
|
|
|
|
|
|
return 1;
|
2019-01-03 22:58:40 +03:00
|
|
|
}
|
2018-11-12 11:19:38 +03:00
|
|
|
|
2018-12-11 11:27:32 +03:00
|
|
|
WLog_ERR(TAG, "Failed to parse ASSISTANCE file: Neither UPLOADINFO nor <E> found");
|
2019-01-07 15:00:48 +03:00
|
|
|
return -1;
|
2014-06-29 00:04:49 +04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
int freerdp_assistance_parse_file(rdpAssistanceFile* file, const char* name, const char* password)
|
2014-06-29 02:33:46 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
BYTE* buffer;
|
|
|
|
FILE* fp = NULL;
|
|
|
|
size_t readSize;
|
2021-06-16 15:50:14 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
INT64 i64;
|
|
|
|
size_t s;
|
|
|
|
} fileSize;
|
2018-02-19 12:00:23 +03:00
|
|
|
|
|
|
|
if (!name)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "ASSISTANCE file %s invalid name", name);
|
2018-02-19 12:00:23 +03:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2018-02-19 12:00:23 +03:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
free(file->filename);
|
|
|
|
file->filename = _strdup(name);
|
2021-05-31 12:42:03 +03:00
|
|
|
fp = winpr_fopen(name, "r");
|
2014-06-29 02:33:46 +04:00
|
|
|
|
|
|
|
if (!fp)
|
2018-12-11 11:27:32 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to open ASSISTANCE file %s ", name);
|
2014-06-29 02:33:46 +04:00
|
|
|
return -1;
|
2018-12-11 11:27:32 +03:00
|
|
|
}
|
2014-06-29 02:33:46 +04:00
|
|
|
|
2017-08-11 11:07:46 +03:00
|
|
|
_fseeki64(fp, 0, SEEK_END);
|
2021-06-16 15:50:14 +03:00
|
|
|
fileSize.i64 = _ftelli64(fp);
|
2017-08-11 11:07:46 +03:00
|
|
|
_fseeki64(fp, 0, SEEK_SET);
|
2014-06-29 02:33:46 +04:00
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
if (fileSize.i64 < 1)
|
2014-06-29 02:33:46 +04:00
|
|
|
{
|
2018-12-11 11:27:32 +03:00
|
|
|
WLog_ERR(TAG, "Failed to read ASSISTANCE file %s ", name);
|
2014-06-29 02:33:46 +04:00
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
buffer = (BYTE*)malloc(fileSize.s + 2);
|
2015-05-06 23:32:45 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
2015-08-28 11:53:43 +03:00
|
|
|
{
|
|
|
|
fclose(fp);
|
2015-05-06 23:32:45 +03:00
|
|
|
return -1;
|
2015-08-28 11:53:43 +03:00
|
|
|
}
|
2015-05-06 23:32:45 +03:00
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
readSize = fread(buffer, fileSize.s, 1, fp);
|
2014-06-29 02:33:46 +04:00
|
|
|
|
|
|
|
if (!readSize)
|
|
|
|
{
|
|
|
|
if (!ferror(fp))
|
2021-06-16 15:50:14 +03:00
|
|
|
readSize = fileSize.s;
|
2014-06-29 02:33:46 +04:00
|
|
|
}
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2014-06-29 02:33:46 +04:00
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if (readSize < 1)
|
|
|
|
{
|
2018-12-11 11:27:32 +03:00
|
|
|
WLog_ERR(TAG, "Failed to read ASSISTANCE file %s ", name);
|
2014-06-29 02:33:46 +04:00
|
|
|
free(buffer);
|
|
|
|
buffer = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-06-16 15:50:14 +03:00
|
|
|
buffer[fileSize.s] = '\0';
|
|
|
|
buffer[fileSize.s + 1] = '\0';
|
|
|
|
status = freerdp_assistance_parse_file_buffer(file, (char*)buffer, fileSize.s, password);
|
2014-06-29 02:33:46 +04:00
|
|
|
free(buffer);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-11-12 15:40:40 +03:00
|
|
|
BOOL freerdp_assistance_populate_settings_from_assistance_file(rdpAssistanceFile* file,
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpSettings* settings)
|
2014-06-29 02:33:46 +04:00
|
|
|
{
|
2015-05-06 23:32:45 +03:00
|
|
|
UINT32 i;
|
2019-05-09 14:50:39 +03:00
|
|
|
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteAssistanceMode, TRUE))
|
|
|
|
return FALSE;
|
2014-06-29 02:33:46 +04:00
|
|
|
|
2018-11-09 16:42:10 +03:00
|
|
|
if (!file->RASessionId || !file->MachineAddresses)
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2014-06-29 02:33:46 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_RemoteAssistanceSessionId,
|
|
|
|
file->RASessionId))
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2014-06-29 02:33:46 +04:00
|
|
|
|
2018-11-12 15:40:40 +03:00
|
|
|
if (file->RCTicket)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_RemoteAssistanceRCTicket,
|
|
|
|
file->RCTicket))
|
2018-11-12 15:40:40 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_RemoteAssistanceRCTicket,
|
|
|
|
file->ConnectionString2))
|
2018-11-12 15:40:40 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-30 20:51:27 +04:00
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
if (file->PassStub)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_RemoteAssistancePassStub,
|
|
|
|
file->PassStub))
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-30 20:51:27 +04:00
|
|
|
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_ServerHostname, file->MachineAddresses[0]))
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_AssistanceFile, file->filename))
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2014-06-29 04:22:36 +04:00
|
|
|
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_RemoteAssistancePassword, file->password))
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-01-07 12:38:55 +03:00
|
|
|
if (file->Username)
|
|
|
|
{
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_string(settings, FreeRDP_Username, file->Username))
|
2019-01-07 12:38:55 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
settings->RemoteAssistanceMode = TRUE;
|
2019-05-06 10:51:42 +03:00
|
|
|
|
2019-05-08 15:35:25 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_ServerPort, file->MachinePorts[0]))
|
2019-05-06 10:51:42 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2015-05-06 23:32:45 +03:00
|
|
|
freerdp_target_net_addresses_free(settings);
|
|
|
|
settings->TargetNetAddressCount = file->MachineCount;
|
|
|
|
|
2015-05-22 21:14:57 +03:00
|
|
|
if (settings->TargetNetAddressCount)
|
2015-05-06 23:32:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
settings->TargetNetAddresses = (char**)calloc(file->MachineCount, sizeof(char*));
|
|
|
|
settings->TargetNetPorts = (UINT32*)calloc(file->MachineCount, sizeof(UINT32));
|
2015-05-22 21:14:57 +03:00
|
|
|
|
|
|
|
if (!settings->TargetNetAddresses || !settings->TargetNetPorts)
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2015-05-22 21:14:57 +03:00
|
|
|
|
|
|
|
for (i = 0; i < settings->TargetNetAddressCount; i++)
|
|
|
|
{
|
|
|
|
settings->TargetNetAddresses[i] = _strdup(file->MachineAddresses[i]);
|
|
|
|
settings->TargetNetPorts[i] = file->MachinePorts[i];
|
|
|
|
|
|
|
|
if (!settings->TargetNetAddresses[i])
|
2018-11-08 11:27:57 +03:00
|
|
|
return FALSE;
|
2015-05-22 21:14:57 +03:00
|
|
|
}
|
2015-05-06 23:32:45 +03:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
return TRUE;
|
2014-06-29 02:33:46 +04:00
|
|
|
}
|
|
|
|
|
2015-09-07 14:52:35 +03:00
|
|
|
rdpAssistanceFile* freerdp_assistance_file_new(void)
|
2014-06-29 00:04:49 +04:00
|
|
|
{
|
2019-02-25 12:37:30 +03:00
|
|
|
winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
|
2019-11-06 17:24:51 +03:00
|
|
|
return (rdpAssistanceFile*)calloc(1, sizeof(rdpAssistanceFile));
|
2014-06-29 00:04:49 +04:00
|
|
|
}
|
|
|
|
|
2014-06-30 20:51:27 +04:00
|
|
|
void freerdp_assistance_file_free(rdpAssistanceFile* file)
|
2014-06-29 00:04:49 +04:00
|
|
|
{
|
2015-05-06 23:32:45 +03:00
|
|
|
UINT32 i;
|
|
|
|
|
2014-06-29 00:04:49 +04:00
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
2018-11-08 11:27:57 +03:00
|
|
|
free(file->filename);
|
|
|
|
free(file->password);
|
2014-06-29 00:04:49 +04:00
|
|
|
free(file->Username);
|
|
|
|
free(file->LHTicket);
|
|
|
|
free(file->RCTicket);
|
|
|
|
free(file->PassStub);
|
2014-06-30 03:57:46 +04:00
|
|
|
free(file->ConnectionString1);
|
2014-06-29 01:03:16 +04:00
|
|
|
free(file->ConnectionString2);
|
|
|
|
free(file->EncryptedLHTicket);
|
2014-06-30 03:57:46 +04:00
|
|
|
free(file->RASessionId);
|
|
|
|
free(file->RASpecificParams);
|
|
|
|
free(file->EncryptedPassStub);
|
2014-06-29 00:04:49 +04:00
|
|
|
|
2015-05-06 23:32:45 +03:00
|
|
|
for (i = 0; i < file->MachineCount; i++)
|
|
|
|
{
|
|
|
|
free(file->MachineAddresses[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(file->MachineAddresses);
|
|
|
|
free(file->MachinePorts);
|
2014-06-29 00:04:49 +04:00
|
|
|
free(file);
|
|
|
|
}
|
2018-11-08 11:27:57 +03:00
|
|
|
|
|
|
|
void freerdp_assistance_print_file(rdpAssistanceFile* file, wLog* log, DWORD level)
|
|
|
|
{
|
2018-11-09 16:42:10 +03:00
|
|
|
size_t x;
|
2018-11-08 11:27:57 +03:00
|
|
|
WLog_Print(log, level, "Username: %s", file->Username);
|
|
|
|
WLog_Print(log, level, "LHTicket: %s", file->LHTicket);
|
|
|
|
WLog_Print(log, level, "RCTicket: %s", file->RCTicket);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(log, level, "RCTicketEncrypted: %" PRId32, file->RCTicketEncrypted);
|
2018-11-08 11:27:57 +03:00
|
|
|
WLog_Print(log, level, "PassStub: %s", file->PassStub);
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(log, level, "DtStart: %" PRIu32, file->DtStart);
|
|
|
|
WLog_Print(log, level, "DtLength: %" PRIu32, file->DtLength);
|
|
|
|
WLog_Print(log, level, "LowSpeed: %" PRId32, file->LowSpeed);
|
2018-11-08 11:27:57 +03:00
|
|
|
WLog_Print(log, level, "RASessionId: %s", file->RASessionId);
|
|
|
|
WLog_Print(log, level, "RASpecificParams: %s", file->RASpecificParams);
|
2018-11-09 16:42:10 +03:00
|
|
|
|
|
|
|
for (x = 0; x < file->MachineCount; x++)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(log, level, "MachineAddress [%" PRIdz ": %s", x, file->MachineAddresses[x]);
|
|
|
|
WLog_Print(log, level, "MachinePort [%" PRIdz ": %" PRIu32, x, file->MachinePorts[x]);
|
2018-11-09 16:42:10 +03:00
|
|
|
}
|
2018-11-08 11:27:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_assistance_get_encrypted_pass_stub(rdpAssistanceFile* file, const char** pwd,
|
2019-11-06 17:24:51 +03:00
|
|
|
size_t* size)
|
2018-11-08 11:27:57 +03:00
|
|
|
{
|
|
|
|
if (!file || !pwd || !size)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*pwd = (const char*)file->EncryptedPassStub;
|
|
|
|
*size = file->EncryptedPassStubLength;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-11-12 15:40:40 +03:00
|
|
|
|
|
|
|
int freerdp_assistance_set_connection_string2(rdpAssistanceFile* file, const char* string,
|
2019-11-06 17:24:51 +03:00
|
|
|
const char* password)
|
2018-11-12 15:40:40 +03:00
|
|
|
{
|
|
|
|
if (!file || !string || !password)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
free(file->ConnectionString2);
|
|
|
|
free(file->password);
|
|
|
|
file->ConnectionString2 = _strdup(string);
|
|
|
|
file->password = _strdup(password);
|
|
|
|
return freerdp_assistance_parse_connection_string2(file);
|
|
|
|
}
|