2012-09-20 07:51:34 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2014-02-20 12:41:53 +04:00
|
|
|
* Copyright (C) Jay Sorg 2004-2014
|
2012-09-20 07:51:34 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* secure layer
|
|
|
|
*/
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
#include "libxrdp.h"
|
2019-12-19 12:55:38 +03:00
|
|
|
#include "ms-rdpbcgr.h"
|
2013-02-01 13:00:39 +04:00
|
|
|
#include "log.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2007-09-15 12:14:49 +04:00
|
|
|
/* some compilers need unsigned char to avoid warnings */
|
|
|
|
static tui8 g_pad_54[40] =
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
|
|
|
|
54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
|
|
|
|
54, 54, 54, 54, 54, 54, 54, 54
|
|
|
|
};
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2007-09-15 12:14:49 +04:00
|
|
|
/* some compilers need unsigned char to avoid warnings */
|
|
|
|
static tui8 g_pad_92[48] =
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
|
|
|
|
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
|
|
|
|
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92
|
|
|
|
};
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2014-02-23 10:44:58 +04:00
|
|
|
static const tui8 g_fips_reverse_table[256] =
|
|
|
|
{
|
|
|
|
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
|
|
|
|
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
|
|
|
|
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
|
|
|
|
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
|
|
|
|
0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
|
|
|
|
0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
|
|
|
|
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
|
|
|
|
0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
|
|
|
|
0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
|
|
|
|
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
|
|
|
|
0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
|
|
|
|
0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
|
|
|
|
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
|
|
|
|
0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
|
|
|
|
0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
|
|
|
|
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
|
|
|
|
0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
|
|
|
|
0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
|
|
|
|
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
|
|
|
|
0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
|
|
|
|
0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
|
|
|
|
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
|
|
|
|
0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
|
|
|
|
0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
|
|
|
|
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
|
|
|
|
0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
|
|
|
|
0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
|
|
|
|
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
|
|
|
|
0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
|
|
|
|
0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
|
|
|
|
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
|
|
|
|
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
|
|
|
|
};
|
|
|
|
|
|
|
|
static const tui8 g_fips_oddparity_table[256] =
|
|
|
|
{
|
|
|
|
0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x07, 0x07,
|
|
|
|
0x08, 0x08, 0x0b, 0x0b, 0x0d, 0x0d, 0x0e, 0x0e,
|
|
|
|
0x10, 0x10, 0x13, 0x13, 0x15, 0x15, 0x16, 0x16,
|
|
|
|
0x19, 0x19, 0x1a, 0x1a, 0x1c, 0x1c, 0x1f, 0x1f,
|
|
|
|
0x20, 0x20, 0x23, 0x23, 0x25, 0x25, 0x26, 0x26,
|
|
|
|
0x29, 0x29, 0x2a, 0x2a, 0x2c, 0x2c, 0x2f, 0x2f,
|
|
|
|
0x31, 0x31, 0x32, 0x32, 0x34, 0x34, 0x37, 0x37,
|
|
|
|
0x38, 0x38, 0x3b, 0x3b, 0x3d, 0x3d, 0x3e, 0x3e,
|
|
|
|
0x40, 0x40, 0x43, 0x43, 0x45, 0x45, 0x46, 0x46,
|
|
|
|
0x49, 0x49, 0x4a, 0x4a, 0x4c, 0x4c, 0x4f, 0x4f,
|
|
|
|
0x51, 0x51, 0x52, 0x52, 0x54, 0x54, 0x57, 0x57,
|
|
|
|
0x58, 0x58, 0x5b, 0x5b, 0x5d, 0x5d, 0x5e, 0x5e,
|
|
|
|
0x61, 0x61, 0x62, 0x62, 0x64, 0x64, 0x67, 0x67,
|
|
|
|
0x68, 0x68, 0x6b, 0x6b, 0x6d, 0x6d, 0x6e, 0x6e,
|
|
|
|
0x70, 0x70, 0x73, 0x73, 0x75, 0x75, 0x76, 0x76,
|
|
|
|
0x79, 0x79, 0x7a, 0x7a, 0x7c, 0x7c, 0x7f, 0x7f,
|
|
|
|
0x80, 0x80, 0x83, 0x83, 0x85, 0x85, 0x86, 0x86,
|
|
|
|
0x89, 0x89, 0x8a, 0x8a, 0x8c, 0x8c, 0x8f, 0x8f,
|
|
|
|
0x91, 0x91, 0x92, 0x92, 0x94, 0x94, 0x97, 0x97,
|
|
|
|
0x98, 0x98, 0x9b, 0x9b, 0x9d, 0x9d, 0x9e, 0x9e,
|
|
|
|
0xa1, 0xa1, 0xa2, 0xa2, 0xa4, 0xa4, 0xa7, 0xa7,
|
|
|
|
0xa8, 0xa8, 0xab, 0xab, 0xad, 0xad, 0xae, 0xae,
|
|
|
|
0xb0, 0xb0, 0xb3, 0xb3, 0xb5, 0xb5, 0xb6, 0xb6,
|
|
|
|
0xb9, 0xb9, 0xba, 0xba, 0xbc, 0xbc, 0xbf, 0xbf,
|
|
|
|
0xc1, 0xc1, 0xc2, 0xc2, 0xc4, 0xc4, 0xc7, 0xc7,
|
|
|
|
0xc8, 0xc8, 0xcb, 0xcb, 0xcd, 0xcd, 0xce, 0xce,
|
|
|
|
0xd0, 0xd0, 0xd3, 0xd3, 0xd5, 0xd5, 0xd6, 0xd6,
|
|
|
|
0xd9, 0xd9, 0xda, 0xda, 0xdc, 0xdc, 0xdf, 0xdf,
|
|
|
|
0xe0, 0xe0, 0xe3, 0xe3, 0xe5, 0xe5, 0xe6, 0xe6,
|
|
|
|
0xe9, 0xe9, 0xea, 0xea, 0xec, 0xec, 0xef, 0xef,
|
|
|
|
0xf1, 0xf1, 0xf2, 0xf2, 0xf4, 0xf4, 0xf7, 0xf7,
|
|
|
|
0xf8, 0xf8, 0xfb, 0xfb, 0xfd, 0xfd, 0xfe, 0xfe
|
|
|
|
};
|
|
|
|
|
|
|
|
static const tui8 g_fips_ivec[8] =
|
|
|
|
{
|
|
|
|
0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF
|
|
|
|
};
|
|
|
|
|
2005-09-26 06:16:37 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
hex_str_to_bin(char *in, char *out, int out_len)
|
|
|
|
{
|
|
|
|
int in_index;
|
|
|
|
int in_len;
|
|
|
|
int out_index;
|
|
|
|
int val;
|
|
|
|
char hex[16];
|
|
|
|
|
|
|
|
in_len = g_strlen(in);
|
|
|
|
out_index = 0;
|
|
|
|
in_index = 0;
|
|
|
|
|
|
|
|
while (in_index <= (in_len - 4))
|
|
|
|
{
|
|
|
|
if ((in[in_index] == '0') && (in[in_index + 1] == 'x'))
|
|
|
|
{
|
|
|
|
hex[0] = in[in_index + 2];
|
|
|
|
hex[1] = in[in_index + 3];
|
|
|
|
hex[2] = 0;
|
|
|
|
|
|
|
|
if (out_index < out_len)
|
|
|
|
{
|
|
|
|
val = g_htoi(hex);
|
|
|
|
out[out_index] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
in_index++;
|
|
|
|
}
|
2005-09-26 06:16:37 +04:00
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
struct xrdp_sec *
|
2014-07-23 16:31:45 +04:00
|
|
|
xrdp_sec_create(struct xrdp_rdp *owner, struct trans *trans)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct xrdp_sec *self;
|
|
|
|
|
2014-11-07 03:51:39 +03:00
|
|
|
self = (struct xrdp_sec *) g_malloc(sizeof(struct xrdp_sec), 1);
|
|
|
|
self->rdp_layer = owner;
|
|
|
|
self->crypt_method = CRYPT_METHOD_NONE; /* set later */
|
|
|
|
self->crypt_level = CRYPT_LEVEL_NONE;
|
|
|
|
self->mcs_layer = xrdp_mcs_create(self, trans, &(self->client_mcs_data),
|
|
|
|
&(self->server_mcs_data));
|
|
|
|
self->fastpath_layer = xrdp_fastpath_create(self, trans);
|
|
|
|
self->chan_layer = xrdp_channel_create(self, self->mcs_layer);
|
|
|
|
self->is_security_header_present = 1;
|
|
|
|
|
|
|
|
return self;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
void
|
2014-11-07 03:51:39 +03:00
|
|
|
xrdp_sec_delete(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
if (self == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xrdp_channel_delete(self->chan_layer);
|
|
|
|
xrdp_mcs_delete(self->mcs_layer);
|
|
|
|
xrdp_fastpath_delete(self->fastpath_layer);
|
|
|
|
ssl_rc4_info_delete(self->decrypt_rc4_info); /* TODO clear all data */
|
|
|
|
ssl_rc4_info_delete(self->encrypt_rc4_info); /* TODO clear all data */
|
|
|
|
ssl_des3_info_delete(self->decrypt_fips_info);
|
|
|
|
ssl_des3_info_delete(self->encrypt_fips_info);
|
|
|
|
ssl_hmac_info_delete(self->sign_fips_info);
|
|
|
|
g_free(self->client_mcs_data.data);
|
|
|
|
g_free(self->server_mcs_data.data);
|
|
|
|
/* Crypto information must always be cleared */
|
|
|
|
g_memset(self, 0, sizeof(struct xrdp_sec));
|
|
|
|
g_free(self);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_init(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
|
|
|
if (xrdp_mcs_init(self->mcs_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_init: xrdp_mcs_init failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-16 03:26:32 +03:00
|
|
|
if (self->crypt_level > CRYPT_LEVEL_NONE) /* RDP encryption */
|
|
|
|
{
|
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 4 + 4 + 8);
|
|
|
|
}
|
|
|
|
else if (self->crypt_level > CRYPT_LEVEL_LOW)
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 4 + 8);
|
|
|
|
}
|
|
|
|
else if (self->crypt_level)
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 4);
|
|
|
|
}
|
|
|
|
}
|
2021-05-19 13:37:22 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 0);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* Reduce key entropy from 64 to 40 bits */
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_make_40bit(char *key)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
key[0] = 0xd1;
|
|
|
|
key[1] = 0x26;
|
|
|
|
key[2] = 0x9e;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
|
|
|
/* update an encryption key */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_update(char *key, char *update_key, int key_len)
|
|
|
|
{
|
|
|
|
char shasig[20];
|
|
|
|
void *sha1_info;
|
|
|
|
void *md5_info;
|
|
|
|
void *rc4_info;
|
|
|
|
|
|
|
|
sha1_info = ssl_sha1_info_create();
|
|
|
|
md5_info = ssl_md5_info_create();
|
|
|
|
rc4_info = ssl_rc4_info_create();
|
|
|
|
ssl_sha1_clear(sha1_info);
|
|
|
|
ssl_sha1_transform(sha1_info, update_key, key_len);
|
|
|
|
ssl_sha1_transform(sha1_info, (char *)g_pad_54, 40);
|
|
|
|
ssl_sha1_transform(sha1_info, key, key_len);
|
|
|
|
ssl_sha1_complete(sha1_info, shasig);
|
|
|
|
ssl_md5_clear(md5_info);
|
|
|
|
ssl_md5_transform(md5_info, update_key, key_len);
|
|
|
|
ssl_md5_transform(md5_info, (char *)g_pad_92, 48);
|
|
|
|
ssl_md5_transform(md5_info, shasig, 20);
|
|
|
|
ssl_md5_complete(md5_info, key);
|
|
|
|
ssl_rc4_set_key(rc4_info, key, key_len);
|
|
|
|
ssl_rc4_crypt(rc4_info, key, key_len);
|
|
|
|
|
|
|
|
if (key_len == 8)
|
|
|
|
{
|
|
|
|
xrdp_sec_make_40bit(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl_sha1_info_delete(sha1_info);
|
|
|
|
ssl_md5_info_delete(md5_info);
|
|
|
|
ssl_rc4_info_delete(rc4_info);
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 08:45:59 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2014-02-24 08:45:59 +04:00
|
|
|
xrdp_sec_fips_decrypt(struct xrdp_sec *self, char *data, int len)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_fips_decrypt:");
|
2014-02-24 08:45:59 +04:00
|
|
|
ssl_des3_decrypt(self->decrypt_fips_info, len, data, data);
|
|
|
|
self->decrypt_use_count++;
|
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_decrypt(struct xrdp_sec *self, char *data, int len)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_decrypt:");
|
2014-02-24 08:45:59 +04:00
|
|
|
if (self->decrypt_use_count == 4096)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-02-24 08:45:59 +04:00
|
|
|
xrdp_sec_update(self->decrypt_key, self->decrypt_update_key,
|
|
|
|
self->rc4_key_len);
|
|
|
|
ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key,
|
|
|
|
self->rc4_key_len);
|
|
|
|
self->decrypt_use_count = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2014-02-24 08:45:59 +04:00
|
|
|
ssl_rc4_crypt(self->decrypt_rc4_info, data, len);
|
|
|
|
self->decrypt_use_count++;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-02-24 08:45:59 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2014-02-24 08:45:59 +04:00
|
|
|
xrdp_sec_fips_encrypt(struct xrdp_sec *self, char *data, int len)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_fips_encrypt:");
|
2014-02-24 08:45:59 +04:00
|
|
|
ssl_des3_encrypt(self->encrypt_fips_info, len, data, data);
|
|
|
|
self->encrypt_use_count++;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2006-04-14 07:02:02 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_encrypt(struct xrdp_sec *self, char *data, int len)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_encrypt:");
|
2014-02-24 08:45:59 +04:00
|
|
|
if (self->encrypt_use_count == 4096)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2014-02-24 08:45:59 +04:00
|
|
|
xrdp_sec_update(self->encrypt_key, self->encrypt_update_key,
|
|
|
|
self->rc4_key_len);
|
|
|
|
ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key,
|
|
|
|
self->rc4_key_len);
|
|
|
|
self->encrypt_use_count = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 08:45:59 +04:00
|
|
|
ssl_rc4_crypt(self->encrypt_rc4_info, data, len);
|
|
|
|
self->encrypt_use_count++;
|
2006-04-14 07:02:02 +04:00
|
|
|
}
|
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/**
|
|
|
|
* Reads a null-terminated unicode string from a stream where the length
|
|
|
|
* of the string is known.
|
|
|
|
*
|
|
|
|
* Strings are part of one of the following from [MS-RDPBCGR] :-
|
|
|
|
* - TS_INFO_PACKET (2.2.1.11.1.1)
|
|
|
|
* - TS_EXTENDED_INFO_PACKET (2.2.1.11.1.1.1)
|
|
|
|
*
|
|
|
|
* @param s Stream
|
|
|
|
* @param src_bytes Size in bytes of the string, EXCLUDING the two-byte
|
|
|
|
* terminator
|
|
|
|
* @param dst Destination buffer
|
|
|
|
* @param dst_len Length of buffer, including terminator space
|
|
|
|
*
|
|
|
|
* @return 0 for success, != 0 for a buffer overflow or a missing terminator
|
2017-03-19 11:20:22 +03:00
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2023-09-20 18:14:55 +03:00
|
|
|
ts_info_utf16_in(struct stream *s, int src_bytes, char *dst, int dst_len)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-09-20 18:14:55 +03:00
|
|
|
int rv = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "ts_info_utf16_in: uni_len %d, dst_len %d", src_bytes, dst_len);
|
|
|
|
|
|
|
|
if (!s_check_rem_and_log(s, src_bytes + 2, "ts_info_utf16_in"))
|
|
|
|
{
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
else
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-09-20 18:14:55 +03:00
|
|
|
int term;
|
|
|
|
int num_chars = in_utf16_le_fixed_as_utf8(s, src_bytes / 2,
|
|
|
|
dst, dst_len);
|
|
|
|
if (num_chars > dst_len)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-09-20 18:14:55 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "ts_info_utf16_in: output buffer overflow");
|
|
|
|
rv = 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
// String should be null-terminated. We haven't read the terminator yet
|
|
|
|
in_uint16_le(s, term);
|
|
|
|
if (term != 0)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2023-09-20 18:14:55 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"ts_info_utf16_in: bad terminator. Expected 0, got %d", term);
|
|
|
|
rv = 1;
|
2013-09-11 10:17:18 +04:00
|
|
|
}
|
|
|
|
}
|
2017-03-19 11:20:22 +03:00
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
return rv;
|
2005-09-27 07:50:54 +04:00
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process TS_INFO_PACKET */
|
2005-06-28 07:11:35 +04:00
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_process_logon_info(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
2023-11-13 13:07:36 +03:00
|
|
|
unsigned int len_domain = 0;
|
|
|
|
unsigned int len_user = 0;
|
|
|
|
unsigned int len_password = 0;
|
|
|
|
unsigned int len_program = 0;
|
|
|
|
unsigned int len_directory = 0;
|
|
|
|
unsigned int len_clnt_addr = 0;
|
|
|
|
unsigned int len_clnt_dir = 0;
|
2020-08-17 09:52:17 +03:00
|
|
|
const char *sep;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 8, "Parsing [MS-RDPBCGR] TS_INFO_PACKET"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint8s(s, 4);
|
|
|
|
in_uint32_le(s, flags);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Parsing [MS-RDPBCGR] TS_INFO_PACKET");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* this is the first test that the decrypt is working */
|
|
|
|
if ((flags & RDP_LOGON_NORMAL) != RDP_LOGON_NORMAL) /* 0x33 */
|
|
|
|
{
|
|
|
|
/* must be or error */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "received wrong flags, likely decrypt not working");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & RDP_LOGON_LEAVE_AUDIO)
|
|
|
|
{
|
|
|
|
self->rdp_layer->client_info.sound_code = 1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "[MS-RDPBCGR] TS_INFO_PACKET flag INFO_REMOTECONSOLEAUDIO found");
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client requested that audio on the server be played on the server.");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2018-11-23 11:08:55 +03:00
|
|
|
if (flags & RDP_LOGON_RAIL)
|
|
|
|
{
|
|
|
|
self->rdp_layer->client_info.rail_enable = 1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "[MS-RDPBCGR] TS_INFO_PACKET flag INFO_RAIL found");
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client requested Remote Application Integrated Locally (RAIL).");
|
2018-11-23 11:08:55 +03:00
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (flags & RDP_LOGON_AUTO)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "[MS-RDPBCGR] TS_INFO_PACKET flag INFO_AUTOLOGON found");
|
|
|
|
/* todo, for now not allowing autologon and mce both */
|
|
|
|
if (!self->rdp_layer->client_info.is_mce)
|
|
|
|
{
|
|
|
|
self->rdp_layer->client_info.rdp_autologin = 1;
|
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client requested auto logon.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_WARNING, "Auto logon is not supported with MCE");
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & RDP_COMPRESSION)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "[MS-RDPBCGR] TS_INFO_PACKET flag INFO_COMPRESSION found, "
|
|
|
|
"CompressionType 0x%1.1x", (flags & 0x00001E00) >> 9);
|
|
|
|
/* TODO: check the client's supported compression type vs the server
|
|
|
|
compression used */
|
2013-01-07 11:56:40 +04:00
|
|
|
if (self->rdp_layer->client_info.use_bulk_comp)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2013-01-07 11:56:40 +04:00
|
|
|
self->rdp_layer->client_info.rdp_compression = 1;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client requested compression enabled.");
|
2013-01-07 11:56:40 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client requested compression, but server "
|
|
|
|
"compression is disabled.");
|
2013-01-07 11:56:40 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_INFO_PACKET cbDomain"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, len_domain);
|
|
|
|
|
2020-08-05 18:12:16 +03:00
|
|
|
if (len_domain >= INFO_CLIENT_MAX_CB_LEN)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Client supplied domain is too long. Max length %d, domain length %d",
|
|
|
|
INFO_CLIENT_MAX_CB_LEN, len_domain);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_INFO_PACKET cbUserName"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, len_user);
|
|
|
|
|
2014-03-01 07:28:31 +04:00
|
|
|
/*
|
|
|
|
* Microsoft's itap client running on Mac OS/Android
|
|
|
|
* always sends autologon credentials, even when user has not
|
|
|
|
* configured any
|
|
|
|
*/
|
2021-02-04 13:11:54 +03:00
|
|
|
if (len_user == 0 && self->rdp_layer->client_info.rdp_autologin)
|
2014-03-01 07:28:31 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied user name is empty, disabling autologin");
|
2014-03-01 07:28:31 +04:00
|
|
|
self->rdp_layer->client_info.rdp_autologin = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-05 18:12:16 +03:00
|
|
|
if (len_user >= INFO_CLIENT_MAX_CB_LEN)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Client supplied user name is too long. Max length %d, user name length %d",
|
|
|
|
INFO_CLIENT_MAX_CB_LEN, len_user);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_INFO_PACKET cbPassword"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, len_password);
|
|
|
|
|
2022-12-30 13:28:57 +03:00
|
|
|
/*
|
|
|
|
* Ignore autologin requests if the password is empty. System managers
|
|
|
|
* who really want to allow empty passwords can do this with a
|
|
|
|
* special session type */
|
|
|
|
if (len_password == 0 && self->rdp_layer->client_info.rdp_autologin)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client supplied password is empty, disabling autologin");
|
|
|
|
self->rdp_layer->client_info.rdp_autologin = 0;
|
|
|
|
}
|
|
|
|
|
2020-08-05 18:12:16 +03:00
|
|
|
if (len_password >= INFO_CLIENT_MAX_CB_LEN)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Client supplied password is too long. Max length %d, password length %d",
|
|
|
|
INFO_CLIENT_MAX_CB_LEN, len_password);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_INFO_PACKET cbAlternateShell"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, len_program);
|
|
|
|
|
2020-08-05 18:12:16 +03:00
|
|
|
if (len_program >= INFO_CLIENT_MAX_CB_LEN)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Client supplied program name is too long. Max length %d, program name length %d",
|
|
|
|
INFO_CLIENT_MAX_CB_LEN, len_program);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_INFO_PACKET cbWorkingDir"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint16_le(s, len_directory);
|
|
|
|
|
2020-08-05 18:12:16 +03:00
|
|
|
if (len_directory >= INFO_CLIENT_MAX_CB_LEN)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Client supplied directory name is too long. Max length %d, directory name length %d",
|
|
|
|
INFO_CLIENT_MAX_CB_LEN, len_directory);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
if (ts_info_utf16_in(s, len_domain, self->rdp_layer->client_info.domain, sizeof(self->rdp_layer->client_info.domain)) != 0)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "ERROR reading domain");
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
if (ts_info_utf16_in(s, len_user, self->rdp_layer->client_info.username, sizeof(self->rdp_layer->client_info.username)) != 0)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "ERROR reading user name");
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2024-06-27 13:39:21 +03:00
|
|
|
// If we require credentials, don't continue if they're not provided
|
|
|
|
if (self->rdp_layer->client_info.require_credentials)
|
|
|
|
{
|
|
|
|
if ((flags & RDP_LOGON_AUTO) == 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "Server is configured to require that the "
|
|
|
|
"client enable auto logon with credentials, but the client did "
|
|
|
|
"not request auto logon.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (len_user == 0 || len_password == 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "Server is configured to require that the "
|
|
|
|
"client enable auto logon with credentials, but the client did "
|
|
|
|
"not supply both a username and password.");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (flags & RDP_LOGON_AUTO)
|
|
|
|
{
|
2023-09-20 18:14:55 +03:00
|
|
|
if (ts_info_utf16_in(s, len_password, self->rdp_layer->client_info.password, sizeof(self->rdp_layer->client_info.password)) != 0)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "ERROR reading password");
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2020-08-17 09:52:17 +03:00
|
|
|
else if (self->rdp_layer->client_info.enable_token_login
|
|
|
|
&& len_user > 0
|
|
|
|
&& len_password == 0
|
|
|
|
&& (sep = g_strchr(self->rdp_layer->client_info.username, '\x1f')) != NULL)
|
|
|
|
{
|
2022-09-03 02:48:01 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied a Logon token. Overwriting password with logon token.");
|
2020-08-17 09:52:17 +03:00
|
|
|
g_strncpy(self->rdp_layer->client_info.password, sep + 1,
|
|
|
|
sizeof(self->rdp_layer->client_info.password) - 1);
|
|
|
|
self->rdp_layer->client_info.username[sep - self->rdp_layer->client_info.username] = '\0';
|
|
|
|
self->rdp_layer->client_info.rdp_autologin = 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
|
|
|
{
|
2024-06-27 13:39:21 +03:00
|
|
|
// Skip the password
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, len_password + 2, "Parsing [MS-RDPBCGR] TS_INFO_PACKET Password"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint8s(s, len_password + 2);
|
|
|
|
}
|
2020-08-30 22:20:21 +03:00
|
|
|
if (self->rdp_layer->client_info.domain_user_separator[0] != '\0'
|
2020-11-30 06:29:57 +03:00
|
|
|
&& self->rdp_layer->client_info.domain[0] != '\0')
|
2020-08-30 22:20:21 +03:00
|
|
|
{
|
2022-09-03 02:48:01 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied domain with user name. Overwriting user name with user name parsed from domain.");
|
2020-08-30 22:20:21 +03:00
|
|
|
int size = sizeof(self->rdp_layer->client_info.username);
|
|
|
|
g_strncat(self->rdp_layer->client_info.username, self->rdp_layer->client_info.domain_user_separator, size - 1 - g_strlen(self->rdp_layer->client_info.domain_user_separator));
|
|
|
|
g_strncat(self->rdp_layer->client_info.username, self->rdp_layer->client_info.domain, size - 1 - g_strlen(self->rdp_layer->client_info.domain));
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
if (ts_info_utf16_in(s, len_program, self->rdp_layer->client_info.program, sizeof(self->rdp_layer->client_info.program)) != 0)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "ERROR reading program");
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2023-09-20 18:14:55 +03:00
|
|
|
if (ts_info_utf16_in(s, len_directory, self->rdp_layer->client_info.directory, sizeof(self->rdp_layer->client_info.directory)) != 0)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "ERROR reading directory");
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_INFO_PACKET "
|
|
|
|
"CodePage (ignored), flags 0x%8.8x, cbDomain %d, cbUserName %d, "
|
|
|
|
"cbPassword %d, cbAlternateShell %d, cbWorkingDir %d, Domain %s, "
|
|
|
|
"UserName %s, Password (omitted from log), AlternateShell %s, "
|
|
|
|
"WorkingDir %s", flags, len_domain,
|
|
|
|
len_user, len_password, len_program, len_directory,
|
|
|
|
self->rdp_layer->client_info.domain,
|
|
|
|
self->rdp_layer->client_info.username,
|
|
|
|
self->rdp_layer->client_info.program,
|
|
|
|
self->rdp_layer->client_info.directory);
|
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied domain: %s", self->rdp_layer->client_info.domain);
|
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied username: %s", self->rdp_layer->client_info.username);
|
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied password: <omitted from log>");
|
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied program: %s", self->rdp_layer->client_info.program);
|
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supplied directory: %s", self->rdp_layer->client_info.directory);
|
|
|
|
|
|
|
|
/* TODO: explain why the windows key flag is used to determine if the
|
|
|
|
TS_EXTENDED_INFO_PACKET should be parsed */
|
|
|
|
if (flags & RDP_LOGON_BLOB) /* INFO_ENABLEWINDOWSKEY */
|
|
|
|
{
|
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET "
|
|
|
|
"clientAddressFamily and cbClientAddress"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2022-09-03 02:48:01 +03:00
|
|
|
/* TS_EXTENDED_INFO_PACKET required fields */
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint8s(s, 2); /* clientAddressFamily */
|
2023-11-13 13:07:36 +03:00
|
|
|
in_uint16_le(s, len_clnt_addr);
|
|
|
|
if (len_clnt_addr > EXTENDED_INFO_MAX_CLIENT_ADDR_LENGTH ||
|
|
|
|
!s_check_rem(s, len_clnt_addr))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2023-11-13 13:07:36 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "clientAddress is too long (%u bytes)",
|
|
|
|
len_clnt_addr);
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2023-11-13 13:07:36 +03:00
|
|
|
// The clientAddress is currently unused. [MS-RDPBCGR] requires
|
|
|
|
// a mandatory null terminator, but some clients set
|
|
|
|
// len_clnt_addr == 0 if this field is missing. Allow for this
|
|
|
|
// in any future implementation.
|
|
|
|
in_uint8s(s, len_clnt_addr); // Skip Unicode clientAddress
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 2, "Parsing [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET clientDir"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2023-11-13 13:07:36 +03:00
|
|
|
in_uint16_le(s, len_clnt_dir);
|
|
|
|
if (len_clnt_dir > INFO_CLIENT_MAX_CB_LEN ||
|
|
|
|
!s_check_rem(s, len_clnt_dir))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2023-11-13 13:07:36 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "clientDir is too long (%u bytes)", len_clnt_dir);
|
2013-09-11 10:17:18 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2023-11-13 13:07:36 +03:00
|
|
|
in_uint8s(s, len_clnt_dir); // Skip Unicode clientDir
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET "
|
2022-09-03 02:48:01 +03:00
|
|
|
"<Required Fields> clientAddressFamily (ignored), "
|
2021-02-04 13:11:54 +03:00
|
|
|
"cbClientAddress (ignored), clientAddress (ignored), "
|
|
|
|
"cbClientDir (ignored), clientDir (ignored)");
|
|
|
|
|
|
|
|
/* TODO: MS-BCGR 2.2.1.11.1.1.1 says that all fields after the
|
|
|
|
client directory are optional. */
|
|
|
|
if (!s_check_rem_and_log(s, 4 + 64 + 20 + 64 + 20 + 4 + 4,
|
|
|
|
"Parsing [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET "
|
|
|
|
"clientTimeZone, clientSessionId, and performanceFlags"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TS_TIME_ZONE_INFORMATION */
|
|
|
|
in_uint8s(s, 4); /* Bias (4) */
|
|
|
|
in_uint8s(s, 64); /* StandardName (64) */
|
|
|
|
in_uint8s(s, 20); /* StandardDate (16), StandardBias (4) */
|
|
|
|
in_uint8s(s, 64); /* DaylightName (64) */
|
|
|
|
in_uint8s(s, 20); /* DaylightDate (16), DaylightBias (4) */
|
|
|
|
in_uint8s(s, 4); /* TS_EXTENDED_INFO_PACKET clientSessionId (4) */
|
|
|
|
|
|
|
|
/* TS_EXTENDED_INFO_PACKET optional fields */
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint32_le(s, self->rdp_layer->client_info.rdp5_performanceflags);
|
2021-02-04 13:11:54 +03:00
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_EXTENDED_INFO_PACKET "
|
|
|
|
"<Optional Fields> clientTimeZone (ignored), "
|
|
|
|
"clientSessionId (ignored), performanceFlags 0x%8.8x, "
|
|
|
|
"cbAutoReconnectCookie (ignored), autoReconnectCookie (ignored), "
|
|
|
|
"reserved1 (ignored), reserved2 (ignored), "
|
|
|
|
"cbDynamicDSTTimeZoneKeyName (ignored), "
|
|
|
|
"dynamicDSTTimeZoneKeyName (ignored), "
|
|
|
|
"dynamicDaylightTimeDisabled (ignored)",
|
|
|
|
self->rdp_layer->client_info.rdp5_performanceflags);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/*
|
2024-07-02 13:23:49 +03:00
|
|
|
* Send a [MS-RDPBCGR] Server License Error PDU (2.2.1.12) with
|
|
|
|
* STATUS_VALID_CLIENT
|
2021-02-04 13:11:54 +03:00
|
|
|
*/
|
2005-06-28 07:11:35 +04:00
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_send_lic_response(struct xrdp_sec *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
|
|
|
|
|
|
|
if (xrdp_mcs_init(self->mcs_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_send_lic_response: xrdp_mcs_init failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-07-02 13:23:49 +03:00
|
|
|
/* [MS-RDPBCGR] TS_SECURITY_HEADER */
|
|
|
|
/* A careful reading of [MS-RDPBCGR] 2.2.1.12 shows that a securityHeader
|
|
|
|
* MUST be included, and provided the flag fields of the header does
|
|
|
|
* not contain SEC_ENCRYPT, it is always possible to send a basic
|
|
|
|
* security header */
|
|
|
|
out_uint16_le(s, SEC_LICENSE_PKT | SEC_LICENSE_ENCRYPT_CS); /* flags */
|
|
|
|
out_uint16_le(s, 0); /* flagsHi */
|
|
|
|
|
|
|
|
/* [MS-RDPBCGR] LICENSE_VALID_CLIENT_DATA */
|
|
|
|
/* preamble (LICENSE_PREAMBLE) */
|
|
|
|
out_uint8(s, ERROR_ALERT);
|
|
|
|
out_uint8(s, PREAMBLE_VERSION_3_0);
|
|
|
|
out_uint16_le(s, 16); /* Message size, including pre-amble */
|
|
|
|
|
|
|
|
/* validClientMessage */
|
|
|
|
/* From [MS-RDPBCGR] 2.2.12.1, dwStateTransition must be ST_NO_TRANSITION,
|
|
|
|
* and the bbErrorInfo field must contain an empty blob of type
|
|
|
|
* BB_ERROR_BLOB */
|
|
|
|
out_uint32_le(s, STATUS_VALID_CLIENT); /* dwErrorCode */
|
|
|
|
out_uint32_le(s, ST_NO_TRANSITION); /* dwStateTransition */
|
|
|
|
out_uint16_le(s, BB_ERROR_BLOB); /* wBlobType */
|
|
|
|
out_uint16_le(s, 0); /* wBlobLen */
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(s);
|
|
|
|
|
2024-07-02 13:23:49 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] Server License Error PDU with STATUS_VALID_CLIENT");
|
2012-09-20 07:51:34 +04:00
|
|
|
if (xrdp_mcs_send(self->mcs_layer, s, MCS_GLOBAL_CHANNEL) != 0)
|
|
|
|
{
|
2024-07-02 13:23:49 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Sending [MS-RDPBCGR] Server License Error PDU with STATUS_VALID_CLIENT failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(s);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-01-16 08:57:37 +03:00
|
|
|
|
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2007-01-16 08:57:37 +03:00
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2014-07-19 22:56:00 +04:00
|
|
|
xrdp_sec_rsa_op(struct xrdp_sec *self, char *out, char *in, int in_bytes,
|
2014-06-19 09:02:58 +04:00
|
|
|
char *mod, char *exp)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2014-06-19 09:02:58 +04:00
|
|
|
ssl_mod_exp(out, self->rsa_key_bytes, in, in_bytes,
|
|
|
|
mod, self->rsa_key_bytes,
|
|
|
|
exp, self->rsa_key_bytes);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_hash_48(char *out, char *in, char *salt1, char *salt2, int salt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
void *sha1_info;
|
|
|
|
void *md5_info;
|
|
|
|
char pad[4];
|
|
|
|
char sha1_sig[20];
|
|
|
|
char md5_sig[16];
|
|
|
|
|
|
|
|
sha1_info = ssl_sha1_info_create();
|
|
|
|
md5_info = ssl_md5_info_create();
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
g_memset(pad, salt + i, 4);
|
|
|
|
ssl_sha1_clear(sha1_info);
|
|
|
|
ssl_sha1_transform(sha1_info, pad, i + 1);
|
|
|
|
ssl_sha1_transform(sha1_info, in, 48);
|
|
|
|
ssl_sha1_transform(sha1_info, salt1, 32);
|
|
|
|
ssl_sha1_transform(sha1_info, salt2, 32);
|
|
|
|
ssl_sha1_complete(sha1_info, sha1_sig);
|
|
|
|
ssl_md5_clear(md5_info);
|
|
|
|
ssl_md5_transform(md5_info, in, 48);
|
|
|
|
ssl_md5_transform(md5_info, sha1_sig, 20);
|
|
|
|
ssl_md5_complete(md5_info, md5_sig);
|
|
|
|
g_memcpy(out + i * 16, md5_sig, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl_sha1_info_delete(sha1_info);
|
|
|
|
ssl_md5_info_delete(md5_info);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_hash_16(char *out, char *in, char *salt1, char *salt2)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
void *md5_info;
|
2005-06-28 07:11:35 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
md5_info = ssl_md5_info_create();
|
|
|
|
ssl_md5_clear(md5_info);
|
|
|
|
ssl_md5_transform(md5_info, in, 16);
|
|
|
|
ssl_md5_transform(md5_info, salt1, 32);
|
|
|
|
ssl_md5_transform(md5_info, salt2, 32);
|
|
|
|
ssl_md5_complete(md5_info, out);
|
|
|
|
ssl_md5_info_delete(md5_info);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2014-02-23 10:44:58 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2014-02-23 10:44:58 +04:00
|
|
|
fips_expand_key_bits(const char *in, char *out)
|
|
|
|
{
|
|
|
|
tui8 buf[32];
|
|
|
|
tui8 c;
|
|
|
|
int i;
|
|
|
|
int b;
|
|
|
|
int p;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* reverse every byte in the key */
|
|
|
|
for (i = 0; i < 21; i++)
|
|
|
|
{
|
|
|
|
c = in[i];
|
|
|
|
buf[i] = g_fips_reverse_table[c];
|
|
|
|
}
|
|
|
|
/* insert a zero-bit after every 7th bit */
|
|
|
|
for (i = 0, b = 0; i < 24; i++, b += 7)
|
|
|
|
{
|
|
|
|
p = b / 8;
|
|
|
|
r = b % 8;
|
|
|
|
if (r == 0)
|
|
|
|
{
|
|
|
|
out[i] = buf[p] & 0xfe;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* c is accumulator */
|
|
|
|
c = buf[p] << r;
|
|
|
|
c |= buf[p + 1] >> (8 - r);
|
|
|
|
out[i] = c & 0xfe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* reverse every byte */
|
|
|
|
/* alter lsb so the byte has odd parity */
|
|
|
|
for (i = 0; i < 24; i++)
|
|
|
|
{
|
|
|
|
c = out[i];
|
|
|
|
c = g_fips_reverse_table[c];
|
|
|
|
out[i] = g_fips_oddparity_table[c];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-24 08:45:59 +04:00
|
|
|
/****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2014-02-24 08:45:59 +04:00
|
|
|
xrdp_sec_fips_establish_keys(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
char server_encrypt_key[32];
|
|
|
|
char server_decrypt_key[32];
|
|
|
|
const char *fips_ivec;
|
|
|
|
void *sha1;
|
|
|
|
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "xrdp_sec_fips_establish_keys:");
|
2014-02-24 08:45:59 +04:00
|
|
|
|
|
|
|
sha1 = ssl_sha1_info_create();
|
|
|
|
ssl_sha1_clear(sha1);
|
|
|
|
ssl_sha1_transform(sha1, self->client_random + 16, 16);
|
|
|
|
ssl_sha1_transform(sha1, self->server_random + 16, 16);
|
|
|
|
ssl_sha1_complete(sha1, server_decrypt_key);
|
|
|
|
|
|
|
|
server_decrypt_key[20] = server_decrypt_key[0];
|
|
|
|
fips_expand_key_bits(server_decrypt_key, self->fips_decrypt_key);
|
|
|
|
ssl_sha1_info_delete(sha1);
|
|
|
|
|
|
|
|
sha1 = ssl_sha1_info_create();
|
|
|
|
ssl_sha1_clear(sha1);
|
|
|
|
ssl_sha1_transform(sha1, self->client_random, 16);
|
|
|
|
ssl_sha1_transform(sha1, self->server_random, 16);
|
|
|
|
ssl_sha1_complete(sha1, server_encrypt_key);
|
|
|
|
server_encrypt_key[20] = server_encrypt_key[0];
|
|
|
|
fips_expand_key_bits(server_encrypt_key, self->fips_encrypt_key);
|
|
|
|
ssl_sha1_info_delete(sha1);
|
|
|
|
|
|
|
|
sha1 = ssl_sha1_info_create();
|
|
|
|
ssl_sha1_clear(sha1);
|
|
|
|
ssl_sha1_transform(sha1, server_encrypt_key, 20);
|
|
|
|
ssl_sha1_transform(sha1, server_decrypt_key, 20);
|
|
|
|
ssl_sha1_complete(sha1, self->fips_sign_key);
|
|
|
|
ssl_sha1_info_delete(sha1);
|
|
|
|
|
|
|
|
fips_ivec = (const char *) g_fips_ivec;
|
|
|
|
self->encrypt_fips_info =
|
2020-11-30 06:29:57 +03:00
|
|
|
ssl_des3_encrypt_info_create(self->fips_encrypt_key, fips_ivec);
|
2014-02-24 08:45:59 +04:00
|
|
|
self->decrypt_fips_info =
|
2020-11-30 06:29:57 +03:00
|
|
|
ssl_des3_decrypt_info_create(self->fips_decrypt_key, fips_ivec);
|
2014-02-24 08:45:59 +04:00
|
|
|
self->sign_fips_info = ssl_hmac_info_create();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_establish_keys(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
char session_key[48];
|
|
|
|
char temp_hash[48];
|
|
|
|
char input[48];
|
2014-02-23 10:44:58 +04:00
|
|
|
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "xrdp_sec_establish_keys:");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
g_memcpy(input, self->client_random, 24);
|
|
|
|
g_memcpy(input + 24, self->server_random, 24);
|
|
|
|
xrdp_sec_hash_48(temp_hash, input, self->client_random,
|
|
|
|
self->server_random, 65);
|
|
|
|
xrdp_sec_hash_48(session_key, temp_hash, self->client_random,
|
|
|
|
self->server_random, 88);
|
|
|
|
g_memcpy(self->sign_key, session_key, 16);
|
|
|
|
xrdp_sec_hash_16(self->encrypt_key, session_key + 16, self->client_random,
|
|
|
|
self->server_random);
|
|
|
|
xrdp_sec_hash_16(self->decrypt_key, session_key + 32, self->client_random,
|
|
|
|
self->server_random);
|
|
|
|
|
2014-02-20 12:41:53 +04:00
|
|
|
if (self->crypt_method == CRYPT_METHOD_40BIT)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
xrdp_sec_make_40bit(self->sign_key);
|
|
|
|
xrdp_sec_make_40bit(self->encrypt_key);
|
|
|
|
xrdp_sec_make_40bit(self->decrypt_key);
|
|
|
|
self->rc4_key_len = 8;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->rc4_key_len = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_memcpy(self->decrypt_update_key, self->decrypt_key, 16);
|
|
|
|
g_memcpy(self->encrypt_update_key, self->encrypt_key, 16);
|
|
|
|
ssl_rc4_set_key(self->decrypt_rc4_info, self->decrypt_key, self->rc4_key_len);
|
|
|
|
ssl_rc4_set_key(self->encrypt_rc4_info, self->encrypt_key, self->rc4_key_len);
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2014-03-10 08:07:08 +04:00
|
|
|
|
2014-02-09 03:42:04 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-02-09 03:42:04 +04:00
|
|
|
xrdp_sec_recv_fastpath(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
2014-03-07 05:51:35 +04:00
|
|
|
int ver;
|
|
|
|
int len;
|
|
|
|
int pad;
|
|
|
|
|
2021-05-19 13:19:43 +03:00
|
|
|
#ifndef USE_DEVEL_LOGGING
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TODO: remove UNUSED_VAR once the `ver` variable is used for more than
|
2020-08-02 07:04:12 +03:00
|
|
|
logging in debug mode */
|
|
|
|
UNUSED_VAR(ver);
|
|
|
|
#endif
|
|
|
|
|
2014-03-07 05:51:35 +04:00
|
|
|
if (xrdp_fastpath_recv(self->fastpath_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_recv_fastpath: xrdp_fastpath_recv failed");
|
2014-03-07 05:51:35 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED)
|
|
|
|
{
|
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 12, "Parsing [MS-RDPBCGR] TS_FP_FIPS_INFO"))
|
2014-03-07 05:51:35 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TS_FP_FIPS_INFO */
|
2014-03-07 05:51:35 +04:00
|
|
|
in_uint16_le(s, len);
|
|
|
|
in_uint8(s, ver); /* length (2 bytes) */
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint8(s, pad);
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received header [MS-RDPBCGR] TS_FP_FIPS_INFO "
|
|
|
|
"length %d, version %d, padlen %d", len, ver, pad);
|
2014-03-07 05:51:35 +04:00
|
|
|
if (len != 0x10) /* length MUST set to 0x10 */
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Received header [MS-RDPBCGR] TS_FP_FIPS_INFO "
|
|
|
|
"invalid fastpath length. Expected 16, received %d", len);
|
2014-03-07 05:51:35 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
|
|
|
|
/* remainder of TS_FP_INPUT_PDU */
|
2014-03-07 05:51:35 +04:00
|
|
|
in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "CRYPT_LEVEL_FIPS - data len %d",
|
|
|
|
(int)(s->end - s->p));
|
2014-03-07 05:51:35 +04:00
|
|
|
xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p));
|
|
|
|
s->end -= pad;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 8,
|
|
|
|
"Parsing [MS-RDPBCGR] TS_FP_INPUT_PDU dataSignature"))
|
2014-03-07 05:51:35 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
/* remainder of TS_FP_INPUT_PDU */
|
2014-03-07 05:51:35 +04:00
|
|
|
in_uint8s(s, 8); /* dataSignature (8 bytes), skip for now */
|
|
|
|
xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (self->fastpath_layer->numEvents == 0) /* set by xrdp_fastpath_recv() */
|
2014-03-07 05:51:35 +04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If numberEvents is not provided in fpInputHeader, it will be provided
|
|
|
|
* as one additional byte here.
|
|
|
|
*/
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 8, "Parsing [MS-RDPBCGR] TS_FP_INPUT_PDU numEvents"))
|
2014-03-07 05:51:35 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8(s, self->fastpath_layer->numEvents); /* numEvents (1 byte) (optional) */
|
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_FP_INPUT_PDU "
|
|
|
|
"fpInputHeader.action (ignored), "
|
|
|
|
"fpInputHeader.numEvents (see final numEvents), "
|
|
|
|
"fpInputHeader.flags %d, length1 (ToDo), length2 (ToDo), "
|
|
|
|
"fipsInformation %s, dataSignature (ignored), numEvents %d",
|
|
|
|
self->fastpath_layer->secFlags,
|
|
|
|
(self->fastpath_layer->secFlags & FASTPATH_INPUT_ENCRYPTED) ? "(see above)" : "(not present)",
|
|
|
|
self->fastpath_layer->numEvents);
|
|
|
|
|
2014-03-07 05:51:35 +04:00
|
|
|
return 0;
|
2014-02-09 03:42:04 +04:00
|
|
|
}
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int len;
|
2014-02-24 08:45:59 +04:00
|
|
|
int ver;
|
|
|
|
int pad;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0)
|
2007-01-16 08:57:37 +03:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_recv: xrdp_mcs_recv failed");
|
2007-01-16 08:57:37 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TODO: check if moving this check until after the is_security_header_present
|
|
|
|
causes any issues.
|
|
|
|
the security header is optional (eg. TLS connections), so this
|
|
|
|
check should really be after the check if the security header is present,
|
|
|
|
this currently seems to be working by coincidence at the moment. */
|
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPBCGR] TS_SECURITY_HEADER"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
|
2014-11-07 03:51:39 +03:00
|
|
|
if (!(self->is_security_header_present))
|
2014-07-23 16:31:45 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
/* noisy log statement with no real info since this is an
|
|
|
|
expected state for TLS connections
|
|
|
|
*/
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_sec_recv: security header NOT present");
|
2014-08-05 22:59:52 +04:00
|
|
|
return 0;
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TS_SECURITY_HEADER */
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint32_le(s, flags);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received header [MS-RDPBCGR] TS_SECURITY_HEADER "
|
|
|
|
"flags 0x%8.8x, flagsHi (merged with flags)", flags);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (flags & SEC_ENCRYPT) /* 0x08 */
|
|
|
|
{
|
2014-02-24 23:37:32 +04:00
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 12, "Parsing [MS-RDPBCGR] TS_SECURITY_HEADER2"))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TS_SECURITY_HEADER2 */
|
|
|
|
in_uint16_le(s, len); /* length */
|
|
|
|
in_uint8(s, ver); /* version */
|
|
|
|
in_uint8(s, pad); /* padlen */
|
|
|
|
in_uint8s(s, 8); /* signature(8) */
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received header [MS-RDPBCGR] TS_SECURITY_HEADER2 "
|
|
|
|
"length %d, version %d, padlen %d, dataSignature (ignored)",
|
|
|
|
len, ver, pad);
|
|
|
|
if (len != 16)
|
2014-02-24 23:37:32 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Received header [MS-RDPBCGR] TS_SECURITY_HEADER2 "
|
|
|
|
"has unexpected length. Expected 16, actual %d", len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (ver != 1)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "Received header [MS-RDPBCGR] TS_SECURITY_HEADER2 "
|
|
|
|
"has unexpected version. Expected 1, actual %d", ver);
|
2014-02-24 23:37:32 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-02-24 08:45:59 +04:00
|
|
|
xrdp_sec_fips_decrypt(self, s->p, (int)(s->end - s->p));
|
|
|
|
s->end -= pad;
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
else if (self->crypt_level > CRYPT_LEVEL_NONE)
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 8, "Parsing [MS-RDPBCGR] TS_SECURITY_HEADER1"))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TS_SECURITY_HEADER1 */
|
2014-02-23 10:44:58 +04:00
|
|
|
in_uint8s(s, 8); /* signature(8) */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received header [MS-RDPBCGR] TS_SECURITY_HEADER1 "
|
|
|
|
"dataSignature (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
xrdp_sec_decrypt(self, s->p, (int)(s->end - s->p));
|
2013-09-11 10:17:18 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2024-07-02 13:23:49 +03:00
|
|
|
if (flags & SEC_EXCHANGE_PKT) /* 0x01 TS_SECURITY_PACKET */
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPBCGR] TS_SECURITY_PACKET"))
|
2013-09-11 10:17:18 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint32_le(s, len);
|
2014-06-19 09:02:58 +04:00
|
|
|
/* 512, 2048 bit */
|
|
|
|
if ((len != 64 + 8) && (len != 256 + 8))
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_recv : error - unexpected length %d", len);
|
2014-06-19 09:02:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, len - 8,
|
|
|
|
"Parsing [MS-RDPBCGR] TS_SECURITY_PACKET encryptedClientRandom"))
|
2014-06-19 09:02:58 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8a(s, self->client_crypt_random, len - 8);
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2014-06-19 09:02:58 +04:00
|
|
|
xrdp_sec_rsa_op(self, self->client_random, self->client_crypt_random,
|
|
|
|
len - 8, self->pub_mod, self->pri_exp);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_SECURITY_PACKET "
|
|
|
|
"length %d, encryptedClientRandom (see below)", len);
|
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "encryptedClientRandom", self->client_crypt_random, len - 8);
|
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "decrypted encryptedClientRandom", self->client_random, 256);
|
2014-02-24 23:37:32 +04:00
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
2014-02-24 08:45:59 +04:00
|
|
|
{
|
|
|
|
xrdp_sec_fips_establish_keys(self);
|
|
|
|
}
|
2014-08-06 01:41:59 +04:00
|
|
|
else if (self->crypt_method != CRYPT_METHOD_NONE)
|
2014-02-24 08:45:59 +04:00
|
|
|
{
|
|
|
|
xrdp_sec_establish_keys(self);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
*chan = 1; /* just set a non existing channel and exit */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_recv: out channel 1 (non-existing channel)");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2024-07-02 13:23:49 +03:00
|
|
|
if (flags & SEC_INFO_PKT)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (xrdp_sec_process_logon_info(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_recv: xrdp_sec_process_logon_info failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xrdp_sec_send_lic_response(self) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_recv: xrdp_sec_send_lic_response failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-22 10:13:33 +04:00
|
|
|
if (self->crypt_level == CRYPT_LEVEL_NONE
|
|
|
|
&& self->crypt_method == CRYPT_METHOD_NONE)
|
|
|
|
{
|
2014-11-07 03:51:39 +03:00
|
|
|
/* in tls mode, no more security header from now on */
|
|
|
|
self->is_security_header_present = 0;
|
2014-08-22 10:13:33 +04:00
|
|
|
}
|
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_recv: out 'send demand active'");
|
2012-09-20 07:51:34 +04:00
|
|
|
return -1; /* special error that means send demand active */
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
2006-04-12 06:45:26 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Output a uint32 into a buffer (little-endian) */
|
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
buf_out_uint32(char *buffer, int value)
|
2006-04-12 06:45:26 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
buffer[0] = (value) & 0xff;
|
|
|
|
buffer[1] = (value >> 8) & 0xff;
|
|
|
|
buffer[2] = (value >> 16) & 0xff;
|
|
|
|
buffer[3] = (value >> 24) & 0xff;
|
2006-04-12 06:45:26 +04:00
|
|
|
}
|
|
|
|
|
2014-02-24 23:37:32 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Generate a MAC hash (5.2.3.1), using a combination of SHA1 and MD5 */
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2014-02-24 23:37:32 +04:00
|
|
|
xrdp_sec_fips_sign(struct xrdp_sec *self, char *out, int out_len,
|
|
|
|
char *data, int data_len)
|
|
|
|
{
|
|
|
|
char buf[20];
|
|
|
|
char lenhdr[4];
|
|
|
|
|
|
|
|
buf_out_uint32(lenhdr, self->encrypt_use_count);
|
|
|
|
ssl_hmac_sha1_init(self->sign_fips_info, self->fips_sign_key, 20);
|
|
|
|
ssl_hmac_transform(self->sign_fips_info, data, data_len);
|
|
|
|
ssl_hmac_transform(self->sign_fips_info, lenhdr, 4);
|
|
|
|
ssl_hmac_complete(self->sign_fips_info, buf, 20);
|
|
|
|
g_memcpy(out, buf, out_len);
|
|
|
|
}
|
|
|
|
|
2006-04-12 06:45:26 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Generate a MAC hash (5.2.3.1), using a combination of SHA1 and MD5 */
|
2017-03-12 19:35:00 +03:00
|
|
|
static void
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_sign(struct xrdp_sec *self, char *out, int out_len,
|
|
|
|
char *data, int data_len)
|
|
|
|
{
|
|
|
|
char shasig[20];
|
|
|
|
char md5sig[16];
|
|
|
|
char lenhdr[4];
|
|
|
|
void *sha1_info;
|
|
|
|
void *md5_info;
|
|
|
|
|
|
|
|
buf_out_uint32(lenhdr, data_len);
|
|
|
|
sha1_info = ssl_sha1_info_create();
|
|
|
|
md5_info = ssl_md5_info_create();
|
|
|
|
ssl_sha1_clear(sha1_info);
|
|
|
|
ssl_sha1_transform(sha1_info, self->sign_key, self->rc4_key_len);
|
|
|
|
ssl_sha1_transform(sha1_info, (char *)g_pad_54, 40);
|
|
|
|
ssl_sha1_transform(sha1_info, lenhdr, 4);
|
|
|
|
ssl_sha1_transform(sha1_info, data, data_len);
|
|
|
|
ssl_sha1_complete(sha1_info, shasig);
|
|
|
|
ssl_md5_clear(md5_info);
|
|
|
|
ssl_md5_transform(md5_info, self->sign_key, self->rc4_key_len);
|
|
|
|
ssl_md5_transform(md5_info, (char *)g_pad_92, 48);
|
|
|
|
ssl_md5_transform(md5_info, shasig, 20);
|
|
|
|
ssl_md5_complete(md5_info, md5sig);
|
|
|
|
g_memcpy(out, md5sig, out_len);
|
|
|
|
ssl_sha1_info_delete(sha1_info);
|
|
|
|
ssl_md5_info_delete(md5_info);
|
2006-04-12 06:45:26 +04:00
|
|
|
}
|
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_send(struct xrdp_sec *self, struct stream *s, int chan)
|
|
|
|
{
|
|
|
|
int datalen;
|
2014-02-24 08:45:59 +04:00
|
|
|
int pad;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
s_pop_layer(s, sec_hdr);
|
|
|
|
|
2014-12-15 23:12:16 +03:00
|
|
|
if (self->crypt_level > CRYPT_LEVEL_NONE)
|
|
|
|
{
|
2014-12-16 03:26:32 +03:00
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
|
|
|
{
|
|
|
|
out_uint32_le(s, SEC_ENCRYPT);
|
|
|
|
datalen = (int)((s->end - s->p) - 12);
|
|
|
|
out_uint16_le(s, 16); /* crypto header size */
|
|
|
|
out_uint8(s, 1); /* fips version */
|
|
|
|
pad = (8 - (datalen % 8)) & 7;
|
|
|
|
g_memset(s->end, 0, pad);
|
|
|
|
s->end += pad;
|
|
|
|
out_uint8(s, pad); /* fips pad */
|
|
|
|
xrdp_sec_fips_sign(self, s->p, 8, s->p + 8, datalen);
|
|
|
|
xrdp_sec_fips_encrypt(self, s->p + 8, datalen + pad);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_SECURITY_HEADER2 "
|
|
|
|
"flags 0x%4.4x, flagsHi 0x%4.4x, length 16, version 1, "
|
|
|
|
"padlen %d, dataSignature 0x%8.8x 0x%8.8x",
|
|
|
|
SEC_ENCRYPT & 0xffff, (SEC_ENCRYPT & 0xffff0000) >> 16,
|
|
|
|
pad, *((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));
|
2014-12-16 03:26:32 +03:00
|
|
|
}
|
|
|
|
else if (self->crypt_level > CRYPT_LEVEL_LOW)
|
|
|
|
{
|
|
|
|
out_uint32_le(s, SEC_ENCRYPT);
|
|
|
|
datalen = (int)((s->end - s->p) - 8);
|
|
|
|
xrdp_sec_sign(self, s->p, 8, s->p + 8, datalen);
|
|
|
|
xrdp_sec_encrypt(self, s->p + 8, datalen);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_SECURITY_HEADER1 "
|
|
|
|
"flags 0x%4.4x, flagsHi 0x%4.4x, dataSignature 0x%8.8x 0x%8.8x",
|
|
|
|
SEC_ENCRYPT & 0xffff, (SEC_ENCRYPT & 0xffff0000) >> 16,
|
|
|
|
*((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));
|
2014-12-16 03:26:32 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out_uint32_le(s, 0);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Adding header [MS-RDPBCGR] TS_SECURITY_HEADER "
|
|
|
|
"flags 0x0000, flagsHi 0x0000");
|
2014-12-16 03:26:32 +03:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xrdp_mcs_send(self->mcs_layer, s, chan) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_send: xrdp_mcs_send failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
2014-03-08 00:45:33 +04:00
|
|
|
|
2014-03-09 23:11:36 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns the fastpath sec byte count */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-03-09 23:11:36 +04:00
|
|
|
xrdp_sec_get_fastpath_bytes(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
|
|
|
{
|
|
|
|
return 3 + 4 + 8;
|
|
|
|
}
|
|
|
|
else if (self->crypt_level > CRYPT_LEVEL_LOW)
|
|
|
|
{
|
|
|
|
return 3 + 8;
|
|
|
|
}
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2014-03-08 00:45:33 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-03-08 00:45:33 +04:00
|
|
|
xrdp_sec_init_fastpath(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
|
|
|
if (xrdp_fastpath_init(self->fastpath_layer, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"xrdp_sec_init_fastpath: xrdp_fastpath_init failed");
|
2014-03-08 00:45:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 3 + 4 + 8);
|
|
|
|
}
|
|
|
|
else if (self->crypt_level > CRYPT_LEVEL_LOW)
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 3 + 8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s_push_layer(s, sec_hdr, 3);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2014-03-09 23:11:36 +04:00
|
|
|
/* 2.2.9.1.2 Server Fast-Path Update PDU (TS_FP_UPDATE_PDU)
|
|
|
|
* http://msdn.microsoft.com/en-us/library/cc240621.aspx */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-03-08 00:45:33 +04:00
|
|
|
xrdp_sec_send_fastpath(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
|
|
|
int secFlags;
|
|
|
|
int fpOutputHeader;
|
|
|
|
int datalen;
|
|
|
|
int pdulen;
|
|
|
|
int pad;
|
2014-03-22 11:24:06 +04:00
|
|
|
int error;
|
|
|
|
char save[8];
|
2014-03-08 00:45:33 +04:00
|
|
|
|
2014-03-22 11:24:06 +04:00
|
|
|
error = 0;
|
2014-03-08 00:45:33 +04:00
|
|
|
s_pop_layer(s, sec_hdr);
|
|
|
|
if (self->crypt_level == CRYPT_LEVEL_FIPS)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_send_fastpath: fips");
|
2014-03-08 00:45:33 +04:00
|
|
|
pdulen = (int)(s->end - s->p);
|
|
|
|
datalen = pdulen - 15;
|
2014-03-08 03:18:17 +04:00
|
|
|
pad = (8 - (datalen % 8)) & 7;
|
2014-03-08 00:45:33 +04:00
|
|
|
secFlags = 0x2;
|
|
|
|
fpOutputHeader = secFlags << 6;
|
|
|
|
out_uint8(s, fpOutputHeader);
|
2014-03-08 03:18:17 +04:00
|
|
|
pdulen += pad;
|
2014-03-08 00:45:33 +04:00
|
|
|
pdulen |= 0x8000;
|
|
|
|
out_uint16_be(s, pdulen);
|
|
|
|
out_uint16_le(s, 16); /* crypto header size */
|
|
|
|
out_uint8(s, 1); /* fips version */
|
|
|
|
s->end += pad;
|
|
|
|
out_uint8(s, pad); /* fips pad */
|
|
|
|
xrdp_sec_fips_sign(self, s->p, 8, s->p + 8, datalen);
|
2014-03-22 11:24:06 +04:00
|
|
|
g_memcpy(save, s->p + 8 + datalen, pad);
|
|
|
|
g_memset(s->p + 8 + datalen, 0, pad);
|
2014-03-08 00:45:33 +04:00
|
|
|
xrdp_sec_fips_encrypt(self, s->p + 8, datalen + pad);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_FP_UPDATE_PDU "
|
|
|
|
"fpOutputHeader.action 0, fpOutputHeader.reserved 0, "
|
|
|
|
"fpOutputHeader.flags 0x2, length1 0x%2.2x, length2 0x%2.2x, "
|
|
|
|
"fipsInformation.length 16, fipsInformation.version 1, "
|
|
|
|
"fipsInformation.padlen %d, dataSignature 0x%8.8x 0x%8.8x, ",
|
|
|
|
pdulen >> 4, pdulen & 0xff, pad,
|
|
|
|
*((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));
|
2014-03-22 11:24:06 +04:00
|
|
|
error = xrdp_fastpath_send(self->fastpath_layer, s);
|
|
|
|
g_memcpy(s->p + 8 + datalen, save, pad);
|
2014-03-08 00:45:33 +04:00
|
|
|
}
|
|
|
|
else if (self->crypt_level > CRYPT_LEVEL_LOW)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_send_fastpath: crypt");
|
2014-03-08 00:45:33 +04:00
|
|
|
pdulen = (int)(s->end - s->p);
|
|
|
|
datalen = pdulen - 11;
|
|
|
|
secFlags = 0x2;
|
|
|
|
fpOutputHeader = secFlags << 6;
|
|
|
|
out_uint8(s, fpOutputHeader);
|
|
|
|
pdulen |= 0x8000;
|
|
|
|
out_uint16_be(s, pdulen);
|
|
|
|
xrdp_sec_sign(self, s->p, 8, s->p + 8, datalen);
|
|
|
|
xrdp_sec_encrypt(self, s->p + 8, datalen);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_FP_UPDATE_PDU "
|
|
|
|
"fpOutputHeader.action 0, fpOutputHeader.reserved 0, "
|
|
|
|
"fpOutputHeader.flags 0x2, length1 0x%2.2x, length2 0x%2.2x, "
|
|
|
|
"dataSignature 0x%8.8x 0x%8.8x, ",
|
|
|
|
pdulen >> 4, pdulen & 0xff,
|
|
|
|
*((uint32_t *) s->p), *((uint32_t *) (s->p + 4)));
|
2014-03-22 11:24:06 +04:00
|
|
|
error = xrdp_fastpath_send(self->fastpath_layer, s);
|
2014-03-08 00:45:33 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xrdp_sec_send_fastpath: no crypt");
|
2014-03-08 00:45:33 +04:00
|
|
|
pdulen = (int)(s->end - s->p);
|
|
|
|
secFlags = 0x0;
|
|
|
|
fpOutputHeader = secFlags << 6;
|
|
|
|
out_uint8(s, fpOutputHeader);
|
|
|
|
pdulen |= 0x8000;
|
|
|
|
out_uint16_be(s, pdulen);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Sending [MS-RDPBCGR] TS_FP_UPDATE_PDU "
|
|
|
|
"fpOutputHeader.action 0, fpOutputHeader.reserved 0, "
|
|
|
|
"fpOutputHeader.flags 0, length1 0x%2.2x, length2 0x%2.2x",
|
|
|
|
pdulen >> 4, pdulen & 0xff);
|
2014-03-22 11:24:06 +04:00
|
|
|
error = xrdp_fastpath_send(self->fastpath_layer, s);
|
2014-03-08 00:45:33 +04:00
|
|
|
}
|
2014-03-22 11:24:06 +04:00
|
|
|
if (error != 0)
|
2014-03-08 00:45:33 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"xrdp_sec_send_fastpath: xrdp_fastpath_send failed");
|
2014-03-08 00:45:33 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-23 10:44:58 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc240510.aspx
|
|
|
|
2.2.1.3.2 Client Core Data (TS_UD_CS_CORE) */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2020-11-30 06:29:57 +03:00
|
|
|
xrdp_sec_process_mcs_data_CS_CORE(struct xrdp_sec *self, struct stream *s)
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
2022-12-07 14:05:46 +03:00
|
|
|
#define CS_CORE_MIN_LENGTH \
|
|
|
|
(\
|
|
|
|
4 + /* Version */ \
|
|
|
|
2 + 2 + /* desktopWidth + desktopHeight */ \
|
|
|
|
2 + 2 + /* colorDepth + SASSequence */ \
|
|
|
|
4 + /* keyboardLayout */ \
|
2023-09-20 18:14:55 +03:00
|
|
|
4 + INFO_CLIENT_NAME_BYTES + /* clientBuild + clientName */ \
|
2022-12-07 14:05:46 +03:00
|
|
|
4 + 4 + 4 + /* keyboardType + keyboardSubType + keyboardFunctionKey */ \
|
|
|
|
64 + /* imeFileName */ \
|
|
|
|
0)
|
|
|
|
|
2022-05-11 15:39:41 +03:00
|
|
|
int version;
|
2014-02-23 10:44:58 +04:00
|
|
|
int colorDepth;
|
|
|
|
int postBeta2ColorDepth;
|
|
|
|
int highColorDepth;
|
|
|
|
int supportedColorDepths;
|
|
|
|
int earlyCapabilityFlags;
|
2017-03-19 12:03:36 +03:00
|
|
|
char clientName[INFO_CLIENT_NAME_BYTES / 2] = { '\0' };
|
2014-02-23 10:44:58 +04:00
|
|
|
|
2022-05-11 15:39:41 +03:00
|
|
|
UNUSED_VAR(version);
|
2022-07-06 13:04:44 +03:00
|
|
|
struct xrdp_client_info *client_info = &self->rdp_layer->client_info;
|
|
|
|
/* Clear physical sizes. These are optional and may not be read later */
|
|
|
|
client_info->session_physical_width = 0;
|
|
|
|
client_info->session_physical_height = 0;
|
2022-05-11 15:39:41 +03:00
|
|
|
|
2022-07-06 13:04:44 +03:00
|
|
|
/* TS_UD_CS_CORE required fields */
|
2022-12-07 14:05:46 +03:00
|
|
|
if (!s_check_rem_and_log(s, CS_CORE_MIN_LENGTH,
|
|
|
|
"Parsing [MS-RDPBCGR] TS_UD_CS_CORE"))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2022-05-11 15:39:41 +03:00
|
|
|
in_uint32_le(s, version);
|
2022-07-06 13:04:44 +03:00
|
|
|
in_uint16_le(s, client_info->display_sizes.session_width);
|
|
|
|
in_uint16_le(s, client_info->display_sizes.session_height);
|
2014-02-23 10:44:58 +04:00
|
|
|
in_uint16_le(s, colorDepth);
|
|
|
|
switch (colorDepth)
|
|
|
|
{
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_4BPP:
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 4;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_8BPP:
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 8;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 2); /* SASSequence */
|
|
|
|
in_uint8s(s, 4); /* keyboardLayout */
|
|
|
|
in_uint8s(s, 4); /* clientBuild */
|
2023-09-20 18:14:55 +03:00
|
|
|
|
|
|
|
/* clientName
|
|
|
|
*
|
|
|
|
* This should be null-terminated. Allow for the possibility it
|
|
|
|
* isn't by ignoring the last two bytes and treating them as a
|
|
|
|
* terminator anyway */
|
|
|
|
in_utf16_le_fixed_as_utf8(s, (INFO_CLIENT_NAME_BYTES - 2) / 2,
|
|
|
|
clientName, sizeof(clientName));
|
|
|
|
in_uint8s(s, 2); /* See above */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_INFO, "Connected client computer name: %s", clientName);
|
2014-02-23 10:44:58 +04:00
|
|
|
in_uint8s(s, 4); /* keyboardType */
|
|
|
|
in_uint8s(s, 4); /* keyboardSubType */
|
|
|
|
in_uint8s(s, 4); /* keyboardFunctionKey */
|
|
|
|
in_uint8s(s, 64); /* imeFileName */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
2022-05-11 15:39:41 +03:00
|
|
|
"<Required fields> version %08x, desktopWidth %d, "
|
2022-09-03 02:48:01 +03:00
|
|
|
"desktopHeight %d, colorDepth %s, SASSequence (ignored), "
|
2021-02-04 13:11:54 +03:00
|
|
|
"keyboardLayout (ignored), clientBuild (ignored), "
|
|
|
|
"clientName %s, keyboardType (ignored), "
|
|
|
|
"keyboardSubType (ignored), keyboardFunctionKey (ignored), "
|
2022-05-11 15:39:41 +03:00
|
|
|
"imeFileName (ignored)",
|
|
|
|
version,
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->display_sizes.session_width,
|
|
|
|
client_info->display_sizes.session_height,
|
2021-02-04 13:11:54 +03:00
|
|
|
(colorDepth == 0xca00 ? "RNS_UD_COLOR_4BPP" :
|
|
|
|
colorDepth == 0xca01 ? "RNS_UD_COLOR_8BPP" : "unknown"),
|
|
|
|
clientName);
|
|
|
|
|
|
|
|
/* TS_UD_CS_CORE optional fields */
|
2022-12-07 14:05:46 +03:00
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-23 10:44:58 +04:00
|
|
|
in_uint16_le(s, postBeta2ColorDepth);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> postBeta2ColorDepth %s",
|
|
|
|
postBeta2ColorDepth == 0xca00 ? "RNS_UD_COLOR_4BPP" :
|
|
|
|
postBeta2ColorDepth == 0xca01 ? "RNS_UD_COLOR_8BPP" :
|
|
|
|
postBeta2ColorDepth == 0xca02 ? "RNS_UD_COLOR_16BPP_555" :
|
|
|
|
postBeta2ColorDepth == 0xca03 ? "RNS_UD_COLOR_16BPP_565" :
|
|
|
|
postBeta2ColorDepth == 0xca04 ? "RNS_UD_COLOR_24BPP" :
|
|
|
|
"unknown");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
switch (postBeta2ColorDepth)
|
|
|
|
{
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_4BPP:
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 4;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_8BPP :
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 8;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_16BPP_555:
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 15;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_16BPP_565:
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 16;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
2017-11-24 17:35:50 +03:00
|
|
|
case RNS_UD_COLOR_24BPP:
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 24;
|
2014-02-23 10:44:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 2); /* clientProductId */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> clientProductId (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 4))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 4); /* serialNumber */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> serialNumber (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint16_le(s, highColorDepth);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> highColorDepth %s",
|
|
|
|
highColorDepth == 0x0004 ? "HIGH_COLOR_4BPP" :
|
|
|
|
highColorDepth == 0x0008 ? "HIGH_COLOR_8BPP" :
|
|
|
|
highColorDepth == 0x000F ? "HIGH_COLOR_15BPP" :
|
|
|
|
highColorDepth == 0x0010 ? "HIGH_COLOR_16BPP" :
|
|
|
|
highColorDepth == 0x0018 ? "HIGH_COLOR_24BPP" :
|
|
|
|
"unknown");
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = highColorDepth;
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint16_le(s, supportedColorDepths);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> supportedColorDepths %s",
|
2023-12-16 20:49:56 +03:00
|
|
|
supportedColorDepths == RNS_UD_24BPP_SUPPORT
|
|
|
|
? "RNS_UD_24BPP_SUPPORT" :
|
|
|
|
supportedColorDepths == RNS_UD_16BPP_SUPPORT
|
|
|
|
? "RNS_UD_16BPP_SUPPORT" :
|
|
|
|
supportedColorDepths == RNS_UD_15BPP_SUPPORT
|
|
|
|
? "RNS_UD_15BPP_SUPPORT" :
|
|
|
|
supportedColorDepths == RNS_UD_32BPP_SUPPORT
|
|
|
|
? "RNS_UD_32BPP_SUPPORT" :
|
2021-02-04 13:11:54 +03:00
|
|
|
"unknown");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint16_le(s, earlyCapabilityFlags);
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->mcs_early_capability_flags = earlyCapabilityFlags;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> earlyCapabilityFlags 0x%4.4x",
|
2014-02-23 10:44:58 +04:00
|
|
|
earlyCapabilityFlags);
|
2023-12-16 20:49:56 +03:00
|
|
|
if ((earlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION)
|
|
|
|
&& (supportedColorDepths & RNS_UD_32BPP_SUPPORT))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp = 32;
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
2024-01-23 19:55:48 +03:00
|
|
|
#ifdef XRDP_RFXCODEC
|
2023-12-16 20:49:56 +03:00
|
|
|
if (earlyCapabilityFlags & RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL)
|
|
|
|
{
|
2024-01-23 19:55:48 +03:00
|
|
|
if (client_info->bpp < 32)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_WARNING,
|
|
|
|
"client requested gfx protocol with insufficient color depth");
|
|
|
|
}
|
2024-06-17 13:53:47 +03:00
|
|
|
else if (client_info->max_bpp > 0 && client_info->max_bpp < 32)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_WARNING, "Client requested gfx protocol "
|
|
|
|
"but the server configuration is limited to %d bpp.",
|
|
|
|
client_info->max_bpp);
|
|
|
|
}
|
2024-01-23 19:55:48 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_INFO, "client supports gfx protocol");
|
|
|
|
self->rdp_layer->client_info.gfx = 1;
|
|
|
|
}
|
2023-12-16 20:49:56 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "client DOES NOT support gfx");
|
|
|
|
}
|
2024-01-23 19:55:48 +03:00
|
|
|
#endif
|
2014-02-23 10:44:58 +04:00
|
|
|
if (!s_check_rem(s, 64))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 64); /* clientDigProductId */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> clientDigProductId (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 1))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-06 13:04:44 +03:00
|
|
|
in_uint8(s, client_info->mcs_connection_type); /* connectionType */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> connectionType 0x%2.2x",
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->mcs_connection_type);
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 1))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 1); /* pad1octet */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> pad1octet (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 4))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 4); /* serverSelectedProtocol */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> serverSelectedProtocol (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
2022-07-06 13:04:44 +03:00
|
|
|
/*
|
|
|
|
* Non-zero values for the desktop physical width and height values
|
|
|
|
* are only sent if the client has a single monitor. For multiple
|
|
|
|
* monitors, the physical size of each monitor is sent in the
|
|
|
|
* TS_UD_CS_MONITOR_EX PDU */
|
2014-02-23 10:44:58 +04:00
|
|
|
if (!s_check_rem(s, 4))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2022-07-06 13:04:44 +03:00
|
|
|
in_uint32_le(s, client_info->session_physical_width);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
2022-07-06 13:04:44 +03:00
|
|
|
"<Optional Field> desktopPhysicalWidth %u",
|
|
|
|
client_info->session_physical_width);
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
if (!s_check_rem(s, 4))
|
|
|
|
{
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->session_physical_width = 0;
|
2014-02-23 10:44:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2022-07-06 13:04:44 +03:00
|
|
|
in_uint32_le(s, client_info->session_physical_height);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
2022-07-06 13:04:44 +03:00
|
|
|
"<Optional Field> desktopPhysicalHeight %u",
|
|
|
|
client_info->session_physical_height);
|
2014-02-23 10:44:58 +04:00
|
|
|
|
2022-07-06 13:04:44 +03:00
|
|
|
/* MS-RDPBCGR 2.2.1.3.2 */
|
|
|
|
if (client_info->session_physical_width < 10 ||
|
|
|
|
client_info->session_physical_width > 10000 ||
|
|
|
|
client_info->session_physical_height < 10 ||
|
|
|
|
client_info->session_physical_height > 10000)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_WARNING,
|
|
|
|
"Physical desktop dimensions (%ux%u) are invalid",
|
|
|
|
client_info->session_physical_width,
|
|
|
|
client_info->session_physical_height);
|
|
|
|
client_info->session_physical_width = 0;
|
|
|
|
client_info->session_physical_height = 0;
|
|
|
|
}
|
2014-02-23 10:44:58 +04:00
|
|
|
if (!s_check_rem(s, 2))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 2); /* reserved */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
|
|
|
"<Optional Field> desktopOrientation (ignored)");
|
2014-02-23 10:44:58 +04:00
|
|
|
|
|
|
|
return 0;
|
2022-12-07 14:05:46 +03:00
|
|
|
#undef CS_CORE_MIN_LENGTH
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_UD_CS_SEC message */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2020-11-30 06:29:57 +03:00
|
|
|
xrdp_sec_process_mcs_data_CS_SECURITY(struct xrdp_sec *self, struct stream *s)
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
int crypt_method;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
in_uint32_le(s, crypt_method);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_SEC "
|
|
|
|
"encryptionMethods 0x%8.8x, extEncryptionMethods (ignored)",
|
|
|
|
crypt_method);
|
2014-02-23 10:44:58 +04:00
|
|
|
if (crypt_method & CRYPT_METHOD_40BIT)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supports 40 bit encryption");
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
|
|
|
if (crypt_method & CRYPT_METHOD_128BIT)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supports 128 bit encryption");
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
|
|
|
if (crypt_method & CRYPT_METHOD_56BIT)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supports 56 bit encryption");
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
|
|
|
if (crypt_method & CRYPT_METHOD_FIPS)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Client supports fips encryption");
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
|
|
|
found = 0;
|
2021-02-04 13:11:54 +03:00
|
|
|
if ((found == 0) &&
|
|
|
|
(self->mcs_layer->iso_layer->selectedProtocol == PROTOCOL_SSL))
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"The connection is using TLS, skipping RDP crypto negotiation");
|
|
|
|
found = 1;
|
|
|
|
}
|
2014-02-23 10:44:58 +04:00
|
|
|
if ((found == 0) &&
|
2020-11-30 06:29:57 +03:00
|
|
|
(self->crypt_method & CRYPT_METHOD_FIPS) &&
|
|
|
|
(self->crypt_level == CRYPT_LEVEL_FIPS))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
if (crypt_method & CRYPT_METHOD_FIPS)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client and server both support fips encryption, "
|
|
|
|
"using RDP fips encryption.");
|
2014-02-23 10:44:58 +04:00
|
|
|
self->crypt_method = CRYPT_METHOD_FIPS;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_FIPS;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((found == 0) &&
|
2020-11-30 06:29:57 +03:00
|
|
|
(self->crypt_method & CRYPT_METHOD_128BIT) &&
|
|
|
|
(self->crypt_level == CRYPT_LEVEL_HIGH))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
if (crypt_method & CRYPT_METHOD_128BIT)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client and server both support high encryption, "
|
|
|
|
"using RDP 128-bit encryption.");
|
2014-02-23 10:44:58 +04:00
|
|
|
self->crypt_method = CRYPT_METHOD_128BIT;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_HIGH;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
/* TODO: figure out why both "COMPATIBLE" and "LOW" crypto level both use
|
|
|
|
40-bit encryption, and why there is no cypto method for 56-bit
|
|
|
|
encryption even though there is code for checking for 56-bit
|
|
|
|
encryption */
|
2014-02-24 08:45:59 +04:00
|
|
|
if ((found == 0) &&
|
2020-11-30 06:29:57 +03:00
|
|
|
(self->crypt_method & CRYPT_METHOD_40BIT) &&
|
|
|
|
(self->crypt_level == CRYPT_LEVEL_CLIENT_COMPATIBLE))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
if (crypt_method & CRYPT_METHOD_40BIT)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client and server both support medium encryption, "
|
|
|
|
"using RDP 40-bit encryption.");
|
2014-02-23 10:44:58 +04:00
|
|
|
self->crypt_method = CRYPT_METHOD_40BIT;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_CLIENT_COMPATIBLE;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
2014-02-24 08:45:59 +04:00
|
|
|
if ((found == 0) &&
|
2020-11-30 06:29:57 +03:00
|
|
|
(self->crypt_method & CRYPT_METHOD_40BIT) &&
|
|
|
|
(self->crypt_level == CRYPT_LEVEL_LOW))
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
|
|
|
if (crypt_method & CRYPT_METHOD_40BIT)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client and server both support low encryption, "
|
|
|
|
"using RDP 40-bit encryption.");
|
2014-02-23 10:44:58 +04:00
|
|
|
self->crypt_method = CRYPT_METHOD_40BIT;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_LOW;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
2014-08-05 23:28:54 +04:00
|
|
|
if ((found == 0) &&
|
2020-11-30 06:29:57 +03:00
|
|
|
(self->crypt_level == CRYPT_LEVEL_NONE))
|
2014-08-05 23:28:54 +04:00
|
|
|
{
|
|
|
|
if (crypt_method == CRYPT_METHOD_NONE)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Client and server both support no encryption, "
|
|
|
|
"RDP encryption is disabled.");
|
2014-08-05 23:28:54 +04:00
|
|
|
self->crypt_method = CRYPT_METHOD_NONE;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_NONE;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
if (found == 0)
|
|
|
|
{
|
|
|
|
/* TODO: figure out why failing to find a shared encryption level
|
|
|
|
does not return an error? */
|
|
|
|
/* TODO: does the connection fail now or is the default server
|
|
|
|
encryption used? */
|
|
|
|
LOG(LOG_LEVEL_WARNING,
|
|
|
|
"Client and server do not both support the same encryption.");
|
|
|
|
// return 1;
|
|
|
|
}
|
2014-02-23 10:44:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-28 09:15:13 +03:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_UD_CS_NET message.
|
|
|
|
This adds the mcs channels in the list of channels to be used when
|
2006-12-28 09:15:13 +03:00
|
|
|
creating the server mcs data */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_process_mcs_data_channels(struct xrdp_sec *self, struct stream *s)
|
2006-12-28 09:15:13 +03:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int num_channels;
|
|
|
|
int index;
|
2018-10-12 08:09:20 +03:00
|
|
|
struct xrdp_client_info *client_info;
|
|
|
|
struct mcs_channel_item *channel_item;
|
2022-05-12 18:10:53 +03:00
|
|
|
int next_mcs_channel_id;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-07-23 16:31:45 +04:00
|
|
|
client_info = &(self->rdp_layer->client_info);
|
2012-09-20 07:51:34 +04:00
|
|
|
/* this is an option set in xrdp.ini */
|
2018-10-12 08:09:20 +03:00
|
|
|
if (client_info->channels_allowed == 0) /* are channels on? */
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "All channels are disabled by configuration");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4, "Parsing [MS-RDPBCGR] TS_UD_CS_NET"))
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint32_le(s, num_channels);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_NET "
|
|
|
|
"channelCount %d", num_channels);
|
2024-01-25 18:22:45 +03:00
|
|
|
if (num_channels > MAX_STATIC_CHANNELS)
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "[MS-RDPBCGR] Protocol error: too many channels requested. "
|
2024-01-25 18:22:45 +03:00
|
|
|
"max %d, received %d", MAX_STATIC_CHANNELS, num_channels);
|
2013-09-11 03:00:30 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2022-05-12 18:10:53 +03:00
|
|
|
|
|
|
|
/* GOTCHA: When adding a channel the MCS channel ID is set to
|
|
|
|
* MCS_GLOBAL_CHANNEL + (index + 1). This is assumed by
|
|
|
|
* xrdp_channel_process(), when mapping an incoming PDU into an
|
|
|
|
* entry in this array */
|
|
|
|
next_mcs_channel_id = MCS_GLOBAL_CHANNEL + 1;
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
for (index = 0; index < num_channels; index++)
|
|
|
|
{
|
2018-10-12 08:09:20 +03:00
|
|
|
channel_item = g_new0(struct mcs_channel_item, 1);
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 12, "Parsing [MS-RDPBCGR] TS_UD_CS_NET.CHANNEL_DEF"))
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
2014-07-19 22:56:00 +04:00
|
|
|
g_free(channel_item);
|
2013-09-11 03:00:30 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint8a(s, channel_item->name, 8);
|
2018-10-12 08:09:20 +03:00
|
|
|
in_uint32_le(s, channel_item->flags);
|
2021-02-04 13:11:54 +03:00
|
|
|
|
|
|
|
if (g_strlen(channel_item->name) > 0 && g_strlen(channel_item->name) < 8)
|
2018-10-12 08:09:20 +03:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] "
|
|
|
|
"TS_UD_CS_NET.CHANNEL_DEF %d, name %s, options 0x%8.8x",
|
|
|
|
index, channel_item->name, channel_item->flags);
|
2022-05-12 18:10:53 +03:00
|
|
|
channel_item->chanid = next_mcs_channel_id++;
|
2018-10-12 08:09:20 +03:00
|
|
|
list_add_item(self->mcs_layer->channel_list,
|
|
|
|
(intptr_t) channel_item);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"Adding channel: name %s, channel id %d, flags 0x%8.8x",
|
|
|
|
channel_item->name, channel_item->chanid, channel_item->flags);
|
2018-10-12 08:09:20 +03:00
|
|
|
}
|
|
|
|
else
|
2017-01-06 09:01:33 +03:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING, "Received [MS-RDPBCGR] "
|
|
|
|
"TS_UD_CS_NET.CHANNEL_DEF %d, skipped because of "
|
|
|
|
"malformed channel name.", index);
|
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_WARNING,
|
|
|
|
"[MS-RDPBCGR] TS_UD_CS_NET.CHANNEL_DEF name",
|
|
|
|
channel_item->name, 8);
|
2017-01-06 09:01:33 +03:00
|
|
|
g_free(channel_item);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2022-05-12 18:10:53 +03:00
|
|
|
|
|
|
|
/* Set the user channel as well */
|
|
|
|
self->mcs_layer->chanid = next_mcs_channel_id++;
|
|
|
|
self->mcs_layer->userid = self->mcs_layer->chanid - MCS_USERCHANNEL_BASE;
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "MCS user is %d, channel id is %d",
|
|
|
|
self->mcs_layer->userid, self->mcs_layer->chanid);
|
|
|
|
|
2006-12-28 09:15:13 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-23 10:44:58 +04:00
|
|
|
|
2013-07-15 11:13:03 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a [MS-RDPBCGR] TS_UD_CS_MONITOR message.
|
|
|
|
reads the client monitors data */
|
2021-06-27 05:37:58 +03:00
|
|
|
int
|
2013-07-15 11:13:03 +04:00
|
|
|
xrdp_sec_process_mcs_data_monitors(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
2013-10-10 06:24:04 +04:00
|
|
|
int flags;
|
2021-05-25 07:05:54 +03:00
|
|
|
int error = 0;
|
|
|
|
struct xrdp_client_info *client_info = &(self->rdp_layer->client_info);
|
2013-10-30 21:41:59 +04:00
|
|
|
|
2021-05-25 07:05:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_sec_process_mcs_data_monitors:");
|
2013-07-15 11:13:03 +04:00
|
|
|
|
|
|
|
/* this is an option set in xrdp.ini */
|
2014-07-23 16:31:45 +04:00
|
|
|
if (client_info->multimon != 1) /* are multi-monitors allowed ? */
|
2013-07-15 11:13:03 +04:00
|
|
|
{
|
2021-05-25 07:05:54 +03:00
|
|
|
LOG(LOG_LEVEL_INFO,
|
|
|
|
"xrdp_sec_process_mcs_data_monitors:"
|
|
|
|
" Multi-monitor is disabled by server config");
|
2013-07-15 11:13:03 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2021-05-25 07:05:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 4,
|
|
|
|
"xrdp_sec_process_mcs_data_monitors:"
|
|
|
|
" Parsing [MS-RDPBCGR] TS_UD_CS_MONITOR"))
|
2021-02-04 13:11:54 +03:00
|
|
|
{
|
2021-05-25 07:05:54 +03:00
|
|
|
return SEC_PROCESS_MONITORS_ERR;
|
2021-02-04 13:11:54 +03:00
|
|
|
}
|
2013-07-15 11:13:03 +04:00
|
|
|
in_uint32_le(s, flags); /* flags */
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2013-10-05 13:03:15 +04:00
|
|
|
//verify flags - must be 0x0
|
2013-10-10 06:24:04 +04:00
|
|
|
if (flags != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
2021-05-25 07:05:54 +03:00
|
|
|
"xrdp_sec_process_mcs_data_monitors: [MS-RDPBCGR]"
|
|
|
|
" Protocol error: TS_UD_CS_MONITOR flags MUST be zero,"
|
|
|
|
" received: 0x%8.8x", flags);
|
|
|
|
return SEC_PROCESS_MONITORS_ERR;
|
2013-10-05 13:03:15 +04:00
|
|
|
}
|
2013-10-30 21:41:59 +04:00
|
|
|
|
2021-05-25 07:05:54 +03:00
|
|
|
struct display_size_description *description =
|
|
|
|
(struct display_size_description *)
|
|
|
|
g_malloc(sizeof(struct display_size_description), 1);
|
2013-11-05 23:36:18 +04:00
|
|
|
|
2021-05-25 07:05:54 +03:00
|
|
|
error = libxrdp_process_monitor_stream(s, description, 0);
|
|
|
|
if (error == 0)
|
2013-07-15 11:13:03 +04:00
|
|
|
{
|
2022-03-20 09:55:09 +03:00
|
|
|
client_info->display_sizes.monitorCount = description->monitorCount;
|
2013-11-04 10:13:46 +04:00
|
|
|
|
2021-05-25 07:05:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_sec_process_mcs_data_monitors:"
|
|
|
|
" Received [MS-RDPBCGR] TS_UD_CS_MONITOR"
|
|
|
|
" flags 0x%8.8x, monitorCount %d",
|
|
|
|
flags, description->monitorCount);
|
2016-05-18 03:11:49 +03:00
|
|
|
|
2022-03-20 09:55:09 +03:00
|
|
|
client_info->display_sizes.session_width = description->session_width;
|
|
|
|
client_info->display_sizes.session_height = description->session_height;
|
|
|
|
g_memcpy(client_info->display_sizes.minfo, description->minfo, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);
|
|
|
|
g_memcpy(client_info->display_sizes.minfo_wm, description->minfo_wm, sizeof(struct monitor_info) * CLIENT_MONITOR_DATA_MAXIMUM_MONITORS);
|
2016-05-18 03:11:49 +03:00
|
|
|
}
|
|
|
|
|
2021-05-25 07:05:54 +03:00
|
|
|
g_free(description);
|
2015-08-04 03:12:46 +03:00
|
|
|
|
2021-05-25 07:05:54 +03:00
|
|
|
return error;
|
2013-07-15 11:13:03 +04:00
|
|
|
}
|
2014-02-23 10:44:58 +04:00
|
|
|
|
2022-07-06 13:04:44 +03:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Process a [MS-RDPBCGR] TS_UD_CS_MONITOR_EX message.
|
|
|
|
reads the client monitor's extended data */
|
2023-10-20 18:14:47 +03:00
|
|
|
static int
|
2022-07-06 13:04:44 +03:00
|
|
|
xrdp_sec_process_mcs_data_monitors_ex(struct xrdp_sec *self, struct stream *s)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
struct xrdp_client_info *client_info = &(self->rdp_layer->client_info);
|
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "xrdp_sec_process_mcs_data_monitors_ex:");
|
|
|
|
|
|
|
|
/* this is an option set in xrdp.ini */
|
|
|
|
if (client_info->multimon != 1) /* are multi-monitors allowed ? */
|
|
|
|
{
|
|
|
|
/* This should already be logged in
|
|
|
|
xrdp_sec_process_mcs_data_monitors() */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!s_check_rem_and_log(s, 4,
|
|
|
|
"xrdp_sec_process_mcs_data_monitors_ex:"
|
|
|
|
" Parsing [MS-RDPBCGR] TS_UD_CS_MONITOR_EX"))
|
|
|
|
{
|
|
|
|
return SEC_PROCESS_MONITORS_ERR;
|
|
|
|
}
|
|
|
|
in_uint32_le(s, flags); /* flags */
|
|
|
|
|
|
|
|
//verify flags - must be 0x0
|
|
|
|
if (flags != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"xrdp_sec_process_mcs_data_monitors_ex: [MS-RDPBCGR]"
|
|
|
|
" Protocol error: TS_UD_CS_MONITOR_EX flags MUST be zero,"
|
|
|
|
" received: 0x%8.8x", flags);
|
|
|
|
return SEC_PROCESS_MONITORS_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return libxrdp_process_monitor_ex_stream(s, &client_info->display_sizes);
|
|
|
|
}
|
|
|
|
|
2006-12-28 09:15:13 +03:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process a Client MCS Connect Initial PDU with GCC Conference Create Request.
|
|
|
|
process client mcs data, we need some things in here to create the server
|
2006-12-28 09:15:13 +03:00
|
|
|
mcs data */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_process_mcs_data(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
struct stream *s = (struct stream *)NULL;
|
|
|
|
char *hold_p = (char *)NULL;
|
|
|
|
int tag = 0;
|
|
|
|
int size = 0;
|
2022-07-06 13:04:44 +03:00
|
|
|
struct xrdp_client_info *client_info = &self->rdp_layer->client_info;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2013-09-11 03:00:30 +04:00
|
|
|
s = &(self->client_mcs_data);
|
2012-09-20 07:51:34 +04:00
|
|
|
/* set p to beginning */
|
|
|
|
s->p = s->data;
|
|
|
|
/* skip header */
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 23, "Parsing [ITU T.124] ConferenceCreateRequest"))
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint8s(s, 23); /* skip [ITU T.124] ConferenceCreateRequest fields until userData */
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
while (s_check_rem(s, 4))
|
|
|
|
{
|
|
|
|
hold_p = s->p;
|
|
|
|
in_uint16_le(s, tag);
|
|
|
|
in_uint16_le(s, size);
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received header [MS-RDPBCGR] TS_UD_HEADER "
|
|
|
|
"type 0x%4.4x, length %d", tag, size);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
if (size < 4)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_WARNING, "[MS-RDPBCGR] Protocol error: Invalid TS_UD_HEADER length value. "
|
|
|
|
"expected >= 4, actual %d", size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!s_check_rem_and_log(s, size - 4,
|
|
|
|
"Parsing [MS-RDPBCGR] GCC Conference Create Request client data field"))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-02-23 10:44:58 +04:00
|
|
|
case SEC_TAG_CLI_INFO: /* CS_CORE 0xC001 */
|
|
|
|
if (xrdp_sec_process_mcs_data_CS_CORE(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Processing [MS-RDPBCGR] TS_UD_CS_CORE failed");
|
2014-02-23 10:44:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
2014-02-23 10:44:58 +04:00
|
|
|
case SEC_TAG_CLI_CRYPT: /* CS_SECURITY 0xC002 */
|
|
|
|
if (xrdp_sec_process_mcs_data_CS_SECURITY(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Processing [MS-RDPBCGR] TS_UD_CS_SEC failed");
|
2014-02-23 10:44:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
2014-02-23 10:44:58 +04:00
|
|
|
case SEC_TAG_CLI_CHANNELS: /* CS_NET 0xC003 */
|
2013-09-11 03:05:17 +04:00
|
|
|
if (xrdp_sec_process_mcs_data_channels(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Processing [MS-RDPBCGR] TS_UD_CS_NET failed");
|
2013-09-11 03:05:17 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
2014-02-23 10:44:58 +04:00
|
|
|
case SEC_TAG_CLI_4: /* CS_CLUSTER 0xC004 */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Received [MS-RDPBCGR] TS_UD_CS_CLUSTER - no-op");
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
2014-02-23 10:44:58 +04:00
|
|
|
case SEC_TAG_CLI_MONITOR: /* CS_MONITOR 0xC005 */
|
2013-10-30 21:41:59 +04:00
|
|
|
if (xrdp_sec_process_mcs_data_monitors(self, s) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Processing [MS-RDPBCGR] TS_UD_CS_MONITOR failed");
|
2013-10-30 21:41:59 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2013-07-15 11:13:03 +04:00
|
|
|
break;
|
2022-07-06 13:04:44 +03:00
|
|
|
case SEC_TAG_CLI_MONITOR_EX: /* CS_MONITOR_EX 0xC008 */
|
|
|
|
if (xrdp_sec_process_mcs_data_monitors_ex(self, s) != 0)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR,
|
|
|
|
"Processing [MS-RDPBCGR] TS_UD_CS_MONITOR_EX failed");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
2020-11-30 06:29:57 +03:00
|
|
|
/* CS_MCS_MSGCHANNEL 0xC006
|
|
|
|
CS_MULTITRANSPORT 0xC00A
|
|
|
|
SC_CORE 0x0C01
|
|
|
|
SC_SECURITY 0x0C02
|
|
|
|
SC_NET 0x0C03
|
|
|
|
SC_MCS_MSGCHANNEL 0x0C04
|
|
|
|
SC_MULTITRANSPORT 0x0C08 */
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING,
|
|
|
|
"Received [MS-RDPBCGR] TS_UD_HEADER type 0x%4.4x "
|
|
|
|
"is unknown (ignored)", tag);
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->p = hold_p + size;
|
|
|
|
}
|
2014-02-24 08:45:59 +04:00
|
|
|
|
2022-07-06 13:04:44 +03:00
|
|
|
if (client_info->max_bpp > 0)
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
2022-07-06 13:04:44 +03:00
|
|
|
if (client_info->bpp > client_info->max_bpp)
|
2014-02-23 10:44:58 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "Client requested %d bpp color depth, "
|
|
|
|
"but the server configuration is limited to %d bpp. "
|
|
|
|
"Downgrading the color depth to %d bits-per-pixel.",
|
2022-07-06 13:04:44 +03:00
|
|
|
client_info->bpp,
|
|
|
|
client_info->max_bpp,
|
|
|
|
client_info->max_bpp);
|
|
|
|
client_info->bpp = client_info->max_bpp;
|
2014-02-23 10:44:58 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* set p to beginning */
|
|
|
|
s->p = s->data;
|
|
|
|
return 0;
|
2006-12-28 09:15:13 +03:00
|
|
|
}
|
|
|
|
|
2005-08-18 06:49:35 +04:00
|
|
|
/*****************************************************************************/
|
2021-02-04 13:11:54 +03:00
|
|
|
/* Process the mcs client data [ITU T.124] ConferenceCreateRequest userData field
|
|
|
|
as a [MS-RDPBCGR] TS_UD_CS_CORE struct */
|
|
|
|
/* TODO: why does this method parse the strust from back to front (resetting
|
|
|
|
after each field) instead of from front to back like the rest of the parsing
|
|
|
|
code? */
|
|
|
|
/* TODO: why does this method exist when the same struct is parsed in
|
|
|
|
xrdp_sec_process_mcs_data_CS_CORE and there does not seem to be any
|
|
|
|
dependencies preventing a call to that function. */
|
|
|
|
/* TODO: this is a brittle function that assumes field offsets in the stream
|
|
|
|
instead of parsing the variable length fields of [ITU T.124] ConferenceCreateRequest */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_in_mcs_data(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
struct stream *s = (struct stream *)NULL;
|
|
|
|
struct xrdp_client_info *client_info = (struct xrdp_client_info *)NULL;
|
|
|
|
|
|
|
|
client_info = &(self->rdp_layer->client_info);
|
|
|
|
s = &(self->client_mcs_data);
|
2016-06-22 02:30:15 +03:00
|
|
|
/* get hostname, it's unicode */
|
2012-09-20 07:51:34 +04:00
|
|
|
s->p = s->data;
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 47, "Parsing [ITU T.124] ConferenceCreateRequest"))
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint8s(s, 47); /* skip [ITU T.124] ConferenceCreateRequest up to the
|
|
|
|
userData field, and skip [MS-RDPBCGR] TS_UD_CS_CORE
|
|
|
|
up to the clientName field */
|
2023-09-20 18:14:55 +03:00
|
|
|
if (!s_check_rem_and_log(s, INFO_CLIENT_NAME_BYTES,
|
|
|
|
"Parsing [MS-RDPBCGR] TS_UD_CS_CORE clientName"))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-09-20 18:14:55 +03:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2023-09-20 18:14:55 +03:00
|
|
|
in_utf16_le_fixed_as_utf8(s, (INFO_CLIENT_NAME_BYTES - 2) / 2,
|
|
|
|
client_info->hostname,
|
|
|
|
sizeof(client_info->hostname));
|
|
|
|
in_uint8s(s, 2); /* Ignored - terminator for full-size clientName */
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
/* get build */
|
|
|
|
s->p = s->data;
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 43 + 4, "Parsing [MS-RDPBCGR] TS_UD_CS_CORE clientBuild"))
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint8s(s, 43);
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint32_le(s, client_info->build); /* [MS-RDPBCGR] TS_UD_CS_CORE clientBuild */
|
2012-09-20 07:51:34 +04:00
|
|
|
/* get keylayout */
|
|
|
|
s->p = s->data;
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 39 + 4, "Parsing [MS-RDPBCGR] TS_UD_CS_CORE keyboardLayout"))
|
2013-09-11 03:00:30 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
in_uint8s(s, 39);
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint32_le(s, client_info->keylayout); /* [MS-RDPBCGR] TS_UD_CS_CORE keyboardLayout */
|
2014-01-13 06:24:07 +04:00
|
|
|
/* get keyboard type / subtype */
|
|
|
|
s->p = s->data;
|
2021-02-04 13:11:54 +03:00
|
|
|
if (!s_check_rem_and_log(s, 79 + 8, "Parsing [MS-RDPBCGR] TS_UD_CS_CORE keyboardType"))
|
2014-01-13 06:24:07 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
in_uint8s(s, 79);
|
2021-02-04 13:11:54 +03:00
|
|
|
in_uint32_le(s, client_info->keyboard_type); /* [MS-RDPBCGR] TS_UD_CS_CORE keyboardType */
|
|
|
|
in_uint32_le(s, client_info->keyboard_subtype); /* [MS-RDPBCGR] TS_UD_CS_CORE keyboardSubType */
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "Received [MS-RDPBCGR] TS_UD_CS_CORE "
|
2022-09-03 02:48:01 +03:00
|
|
|
"<Required fields> version (ignored), desktopWidth (ignored), "
|
|
|
|
"desktopHeight (ignored), colorDepth (ignored), SASSequence (ignored), "
|
2021-02-04 13:11:54 +03:00
|
|
|
"keyboardLayout 0x%8.8x, clientBuild %d, "
|
|
|
|
"clientName %s, keyboardType 0x%8.8x, "
|
|
|
|
"keyboardSubType 0x%8.8x, keyboardFunctionKey (ignored), "
|
2022-09-03 02:48:01 +03:00
|
|
|
"imeFileName (ignored)",
|
2021-02-04 13:11:54 +03:00
|
|
|
client_info->keylayout,
|
|
|
|
client_info->build,
|
|
|
|
client_info->hostname,
|
|
|
|
client_info->keyboard_type,
|
|
|
|
client_info->keyboard_subtype);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
s->p = s->data;
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2013-09-11 03:00:30 +04:00
|
|
|
return 0;
|
2005-08-18 06:49:35 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 16:31:45 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2023-10-20 18:14:47 +03:00
|
|
|
static int
|
2014-07-23 16:31:45 +04:00
|
|
|
xrdp_sec_init_rdp_security(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
switch (self->rdp_layer->client_info.crypt_level)
|
|
|
|
{
|
2014-08-05 23:28:54 +04:00
|
|
|
case 0: /* none */
|
|
|
|
self->crypt_method = CRYPT_METHOD_NONE;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_NONE;
|
|
|
|
break;
|
2014-07-23 16:31:45 +04:00
|
|
|
case 1: /* low */
|
|
|
|
self->crypt_method = CRYPT_METHOD_40BIT;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_LOW;
|
|
|
|
break;
|
|
|
|
case 2: /* medium */
|
|
|
|
self->crypt_method = CRYPT_METHOD_40BIT;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_CLIENT_COMPATIBLE;
|
|
|
|
break;
|
|
|
|
case 3: /* high */
|
|
|
|
self->crypt_method = CRYPT_METHOD_128BIT;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_HIGH;
|
|
|
|
break;
|
|
|
|
case 4: /* fips */
|
|
|
|
self->crypt_method = CRYPT_METHOD_FIPS;
|
|
|
|
self->crypt_level = CRYPT_LEVEL_FIPS;
|
|
|
|
break;
|
|
|
|
default:
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING, "Fatal : Illegal crypt_level %d",
|
|
|
|
self->rdp_layer->client_info.crypt_level);
|
2014-07-23 16:31:45 +04:00
|
|
|
break ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->decrypt_rc4_info != NULL)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"xrdp_sec_init_rdp_security: decrypt_rc4_info already created !!!");
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-05 22:59:52 +04:00
|
|
|
self->decrypt_rc4_info = ssl_rc4_info_create();
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (self->encrypt_rc4_info != NULL)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_WARNING,
|
|
|
|
"xrdp_sec_init_rdp_security: encrypt_rc4_info already created !!!");
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-05 22:59:52 +04:00
|
|
|
self->encrypt_rc4_info = ssl_rc4_info_create();
|
2014-12-16 03:26:32 +03:00
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
|
2014-08-05 22:59:52 +04:00
|
|
|
return 0;
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2014-08-05 22:59:52 +04:00
|
|
|
|
2005-06-28 07:11:35 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_incoming(struct xrdp_sec *self)
|
|
|
|
{
|
|
|
|
struct list *items = NULL;
|
|
|
|
struct list *values = NULL;
|
2014-07-23 16:31:45 +04:00
|
|
|
struct xrdp_iso *iso;
|
2012-09-20 07:51:34 +04:00
|
|
|
int index = 0;
|
|
|
|
char *item = NULL;
|
|
|
|
char *value = NULL;
|
|
|
|
char key_file[256];
|
|
|
|
|
2014-07-23 16:31:45 +04:00
|
|
|
iso = self->mcs_layer->iso_layer;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-07-23 16:31:45 +04:00
|
|
|
/* negotiate security layer */
|
|
|
|
if (xrdp_iso_incoming(iso) != 0)
|
2008-05-11 10:23:20 +04:00
|
|
|
{
|
2020-12-05 21:28:34 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_incoming: xrdp_iso_incoming failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
2008-05-11 10:23:20 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-07-23 16:31:45 +04:00
|
|
|
/* initialize selected security layer */
|
2014-12-13 17:24:07 +03:00
|
|
|
if (iso->selectedProtocol > PROTOCOL_RDP)
|
2008-05-11 10:23:20 +04:00
|
|
|
{
|
2014-07-23 17:44:59 +04:00
|
|
|
/* init tls security */
|
2014-07-23 16:31:45 +04:00
|
|
|
|
2014-07-23 17:44:59 +04:00
|
|
|
if (trans_set_tls_mode(self->mcs_layer->iso_layer->trans,
|
2020-11-30 06:29:57 +03:00
|
|
|
self->rdp_layer->client_info.key_file,
|
|
|
|
self->rdp_layer->client_info.certificate,
|
|
|
|
self->rdp_layer->client_info.ssl_protocols,
|
|
|
|
self->rdp_layer->client_info.tls_ciphers) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_incoming: trans_set_tls_mode failed");
|
2014-07-23 17:44:59 +04:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Using TLS security, and "
|
|
|
|
"setting RDP security crypto to LEVEL_NONE and METHOD_NONE");
|
2014-07-23 17:44:59 +04:00
|
|
|
self->crypt_level = CRYPT_LEVEL_NONE;
|
|
|
|
self->crypt_method = CRYPT_METHOD_NONE;
|
|
|
|
self->rsa_key_bytes = 0;
|
2014-07-23 16:31:45 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-05 22:59:52 +04:00
|
|
|
/* init rdp security */
|
2014-07-23 16:31:45 +04:00
|
|
|
if (xrdp_sec_init_rdp_security(self) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_incoming: xrdp_sec_init_rdp_security failed");
|
2014-07-23 16:31:45 +04:00
|
|
|
return 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2014-08-06 01:41:59 +04:00
|
|
|
if (self->crypt_method != CRYPT_METHOD_NONE)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "Using RDP security, and "
|
|
|
|
"reading the server configuration");
|
|
|
|
|
2014-08-06 01:41:59 +04:00
|
|
|
g_memset(key_file, 0, sizeof(char) * 256);
|
|
|
|
g_random(self->server_random, 32);
|
|
|
|
items = list_create();
|
|
|
|
items->auto_free = 1;
|
|
|
|
values = list_create();
|
|
|
|
values->auto_free = 1;
|
|
|
|
g_snprintf(key_file, 255, "%s/rsakeys.ini", XRDP_CFG_PATH);
|
|
|
|
|
|
|
|
if (file_by_name_read_section(key_file, "keys", items, values) != 0)
|
2014-07-23 16:31:45 +04:00
|
|
|
{
|
2014-08-06 01:41:59 +04:00
|
|
|
/* this is a show stopper */
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "XRDP cannot read file: %s "
|
2020-11-30 06:29:57 +03:00
|
|
|
"(check permissions)", key_file);
|
2014-08-06 01:41:59 +04:00
|
|
|
list_delete(items);
|
|
|
|
list_delete(values);
|
|
|
|
return 1;
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2014-08-06 01:41:59 +04:00
|
|
|
|
|
|
|
for (index = 0; index < items->count; index++)
|
2014-07-23 16:31:45 +04:00
|
|
|
{
|
2014-08-06 01:41:59 +04:00
|
|
|
item = (char *)list_get_item(items, index);
|
|
|
|
value = (char *)list_get_item(values, index);
|
|
|
|
|
|
|
|
if (g_strcasecmp(item, "pub_exp") == 0)
|
|
|
|
{
|
|
|
|
hex_str_to_bin(value, self->pub_exp, 4);
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "pub_mod") == 0)
|
|
|
|
{
|
|
|
|
self->rsa_key_bytes = (g_strlen(value) + 1) / 5;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Server config: pub_mod bytes %d",
|
|
|
|
self->rsa_key_bytes);
|
2014-08-06 01:41:59 +04:00
|
|
|
hex_str_to_bin(value, self->pub_mod, self->rsa_key_bytes);
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "pub_sig") == 0)
|
|
|
|
{
|
|
|
|
hex_str_to_bin(value, self->pub_sig, 64);
|
|
|
|
}
|
|
|
|
else if (g_strcasecmp(item, "pri_exp") == 0)
|
|
|
|
{
|
|
|
|
self->rsa_key_bytes = (g_strlen(value) + 1) / 5;
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Server config: pri_exp %d",
|
|
|
|
self->rsa_key_bytes);
|
2014-08-06 01:41:59 +04:00
|
|
|
hex_str_to_bin(value, self->pri_exp, self->rsa_key_bytes);
|
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2016-11-12 09:29:54 +03:00
|
|
|
|
|
|
|
if (self->rsa_key_bytes <= 64)
|
|
|
|
{
|
2020-08-02 07:04:12 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "warning, RSA key len 512 "
|
2020-11-30 06:29:57 +03:00
|
|
|
"bits or less, consider creating a 2048 bit key");
|
2016-11-12 09:29:54 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 01:41:59 +04:00
|
|
|
list_delete(items);
|
|
|
|
list_delete(values);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-07-23 16:31:45 +04:00
|
|
|
/* negotiate mcs layer */
|
2012-09-20 07:51:34 +04:00
|
|
|
if (xrdp_mcs_incoming(self->mcs_layer) != 0)
|
2008-05-11 10:23:20 +04:00
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_incoming: xrdp_mcs_incoming failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
2008-05-11 10:23:20 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "client mcs data received",
|
|
|
|
self->client_mcs_data.data,
|
2020-11-30 06:29:57 +03:00
|
|
|
(int)(self->client_mcs_data.end - self->client_mcs_data.data));
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "server mcs data sent",
|
|
|
|
self->server_mcs_data.data,
|
2020-11-30 06:29:57 +03:00
|
|
|
(int)(self->server_mcs_data.end - self->server_mcs_data.data));
|
2021-02-04 13:11:54 +03:00
|
|
|
|
2013-09-11 03:00:30 +04:00
|
|
|
if (xrdp_sec_in_mcs_data(self) != 0)
|
|
|
|
{
|
2021-02-04 13:11:54 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "xrdp_sec_incoming: xrdp_sec_in_mcs_data failed");
|
2013-09-11 03:00:30 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-07-23 16:31:45 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
xrdp_sec_disconnect(struct xrdp_sec *self)
|
2005-06-28 07:11:35 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int rv;
|
2007-01-16 08:57:37 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = xrdp_mcs_disconnect(self->mcs_layer);
|
|
|
|
return rv;
|
2005-06-28 07:11:35 +04:00
|
|
|
}
|