Exemple #1
0
static int peer_recv_tpkt_pdu(freerdp_peer* client, wStream* s)
{
	rdpRdp* rdp;
	UINT16 length;
	UINT16 pduType;
	UINT16 pduLength;
	UINT16 pduSource;
	UINT16 channelId;
	UINT16 securityFlags;

	rdp = client->context->rdp;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		fprintf(stderr, "Incorrect RDP header.\n");
		return -1;
	}

	if (rdp->settings->DisableEncryption)
	{
		if (!rdp_read_security_header(s, &securityFlags))
			return -1;

		if (securityFlags & SEC_ENCRYPT)
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				fprintf(stderr, "rdp_decrypt failed\n");
				return -1;
			}
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		if(!freerdp_channel_peer_process(client, s, channelId))
			return -1;
	}
	else
	{
		if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
			return -1;

		client->settings->PduSource = pduSource;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				if (!peer_recv_data_pdu(client, s))
					return -1;
				break;

			default:
				fprintf(stderr, "Client sent pduType %d\n", pduType);
				return -1;
		}
	}

	return 0;
}
Exemple #2
0
boolean rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 type;
	uint16 length;
	uint16 channelId;

	//freerdp_hexdump(s->p, stream_get_left(s));

	rdp_read_share_control_header(s, &length, &type, &channelId);

	if (type == PDU_TYPE_DATA)
	{
		rdp_recv_data_pdu(rdp, s);
		return True;
	}
	else if (type == PDU_TYPE_SERVER_REDIRECTION)
	{
		rdp_recv_enhanced_security_redirection_packet(rdp, s);
		return True;
	}
	else
	{
		return False;
	}
}
Exemple #3
0
void update_recv(rdpUpdate* update, STREAM* s)
{
	uint16 updateType;

	stream_read_uint16(s, updateType); /* updateType (2 bytes) */

	//printf("%s Update Data PDU\n", UPDATE_TYPE_STRINGS[updateType]);

	IFCALL(update->BeginPaint, update);

	switch (updateType)
	{
		case UPDATE_TYPE_ORDERS:
			update_recv_orders(update, s);
			break;

		case UPDATE_TYPE_BITMAP:
			update_read_bitmap(update, s, &update->bitmap_update);
			IFCALL(update->Bitmap, update, &update->bitmap_update);
			break;

		case UPDATE_TYPE_PALETTE:
			update_read_palette(update, s, &update->palette_update);
			IFCALL(update->Palette, update, &update->palette_update);
			break;

		case UPDATE_TYPE_SYNCHRONIZE:
			update_read_synchronize(update, s);
			IFCALL(update->Synchronize, update);
			break;
	}

	IFCALL(update->EndPaint, update);

	if (stream_get_left(s) > RDP_SHARE_DATA_HEADER_LENGTH)
	{
		uint8 type;
		uint16 pduType;
		uint16 length;
		uint16 source;
		uint32 shareId;
		uint8 compressed_type;
		uint16 compressed_len;

		rdp_read_share_control_header(s, &length, &pduType, &source);

		if (pduType != PDU_TYPE_DATA)
			return;

		rdp_read_share_data_header(s, &length, &type, &shareId, &compressed_type, &compressed_len);

		if (type == DATA_PDU_TYPE_UPDATE)
			update_recv(update, s);
	}
}
Exemple #4
0
int rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s)
{
    UINT16 type;
    UINT16 length;
    UINT16 channelId;

    if (!rdp_read_share_control_header(s, &length, &type, &channelId))
        return -1;

    if (type == PDU_TYPE_DATA)
    {
        return rdp_recv_data_pdu(rdp, s);
    }
    else if (type == PDU_TYPE_SERVER_REDIRECTION)
    {
        return rdp_recv_enhanced_security_redirection_packet(rdp, s);
    }
    else
    {
        return -1;
    }
}
Exemple #5
0
tbool rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 type;
	uint16 length;
	uint16 channelId;

	rdp_read_share_control_header(s, &length, &type, &channelId);

	if (type == PDU_TYPE_DATA)
	{
		return rdp_recv_data_pdu(rdp, s);
	}
	else if (type == PDU_TYPE_SERVER_REDIRECTION)
	{
		rdp_recv_enhanced_security_redirection_packet(rdp, s);
		return true;
	}
	else
	{
		return false;
	}
}
Exemple #6
0
static boolean peer_recv_tpkt_pdu(rdpPeer* peer, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 channelId;

	if (!rdp_read_header(peer->rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return False;
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		/* TODO: process channel data from client */
	}
	else
	{
		if (!rdp_read_share_control_header(s, &pduLength, &pduType, &peer->rdp->settings->pdu_source))
			return False;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				if (!peer_recv_data_pdu(peer, s))
					return False;
				break;

			default:
				printf("Client sent pduType %d\n", pduType);
				return False;
		}
	}

	return True;
}
Exemple #7
0
static int peer_recv_tpkt_pdu(freerdp_peer* client, wStream* s)
{
	rdpRdp* rdp;
	UINT16 length;
	UINT16 pduType;
	UINT16 pduLength;
	UINT16 pduSource;
	UINT16 channelId;
	UINT16 securityFlags = 0;
	rdp = client->context->rdp;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		WLog_ERR(TAG, "Incorrect RDP header.");
		return -1;
	}

	if (freerdp_shall_disconnect(rdp->instance))
		return 0;

	if (rdp->settings->UseRdpSecurityLayer)
	{
		if (!rdp_read_security_header(s, &securityFlags))
			return -1;

		if (securityFlags & SEC_ENCRYPT)
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				WLog_ERR(TAG, "rdp_decrypt failed");
				return -1;
			}
		}
	}

	if (channelId == MCS_GLOBAL_CHANNEL_ID)
	{
		if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
			return -1;

		client->settings->PduSource = pduSource;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				if (!peer_recv_data_pdu(client, s))
					return -1;

				break;

			case PDU_TYPE_CONFIRM_ACTIVE:
				if (!rdp_server_accept_confirm_active(rdp, s))
					return -1;

				break;

			case PDU_TYPE_FLOW_RESPONSE:
			case PDU_TYPE_FLOW_STOP:
			case PDU_TYPE_FLOW_TEST:
				break;

			default:
				WLog_ERR(TAG, "Client sent pduType %"PRIu16"", pduType);
				return -1;
		}
	}
	else if (rdp->mcs->messageChannelId && channelId == rdp->mcs->messageChannelId)
	{
		if (!rdp->settings->UseRdpSecurityLayer)
			if (!rdp_read_security_header(s, &securityFlags))
				return -1;

		return rdp_recv_message_channel_pdu(rdp, s, securityFlags);
	}
	else
	{
		if (!freerdp_channel_peer_process(client, s, channelId))
			return -1;
	}

	return 0;
}
Exemple #8
0
static boolean rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 pduSource;
	uint16 channelId;
	uint16 securityFlags;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return false;
	}

	if (rdp->settings->encryption)
	{
		rdp_read_security_header(s, &securityFlags);
		if (securityFlags & (SEC_ENCRYPT|SEC_REDIRECTION_PKT))
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				printf("rdp_decrypt failed\n");
				return false;
			}
		}
		if (securityFlags & SEC_REDIRECTION_PKT)
		{
			/*
			 * [MS-RDPBCGR] 2.2.13.2.1
			 *  - no share control header, nor the 2 byte pad
			 */
			s->p -= 2;
			rdp_recv_enhanced_security_redirection_packet(rdp, s);
			return true;
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		freerdp_channel_process(rdp->instance, s, channelId);
	}
	else
	{
		rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);

		rdp->settings->pdu_source = pduSource;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				rdp_recv_data_pdu(rdp, s);
				break;

			case PDU_TYPE_DEACTIVATE_ALL:
				if (!rdp_recv_deactivate_all(rdp, s))
					return false;
				break;

			case PDU_TYPE_SERVER_REDIRECTION:
				rdp_recv_enhanced_security_redirection_packet(rdp, s);
				break;

			default:
				printf("incorrect PDU type: 0x%04X\n", pduType);
				break;
		}
	}

	return true;
}
Exemple #9
0
void rdp_recv(rdpRdp* rdp)
{
	STREAM* s;
	int length;
	uint16 pduType;
	uint16 pduLength;
	uint16 initiator;
	uint16 channelId;
	uint16 sec_flags;
	enum DomainMCSPDU MCSPDU;

	s = transport_recv_stream_init(rdp->transport, 4096);
	transport_read(rdp->transport, s);

	MCSPDU = DomainMCSPDU_SendDataIndication;
	mcs_read_domain_mcspdu_header(s, &MCSPDU, &length);

	per_read_integer16(s, &initiator, MCS_BASE_CHANNEL_ID); /* initiator (UserId) */
	per_read_integer16(s, &channelId, 0); /* channelId */
	stream_seek(s, 1); /* dataPriority + Segmentation (0x70) */
	per_read_length(s, &pduLength); /* userData (OCTET_STRING) */

	if (rdp->connected != True)
	{
		rdp_read_security_header(s, &sec_flags);

		if (sec_flags & SEC_PKT_MASK)
		{
			switch (sec_flags & SEC_PKT_MASK)
			{
				case SEC_LICENSE_PKT:
					license_recv(rdp->license, s);
					break;

				case SEC_REDIRECTION_PKT:
					rdp_read_redirection_packet(rdp, s);
					break;

				default:
					printf("incorrect security flags: 0x%04X\n", sec_flags);
					break;
			}
		}
	}
	else
	{
		rdp_read_share_control_header(s, &pduLength, &pduType, &rdp->settings->pdu_source);

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				rdp_read_data_pdu(rdp, s);
				break;

			case PDU_TYPE_DEMAND_ACTIVE:
				rdp_recv_demand_active(rdp, s, rdp->settings);
				break;

			case PDU_TYPE_DEACTIVATE_ALL:
				rdp_read_deactivate_all(s, rdp->settings);
				break;

			case PDU_TYPE_SERVER_REDIRECTION:
				rdp_read_enhanced_security_redirection_packet(rdp, s);
				break;

			default:
				printf("incorrect PDU type: 0x%04X\n", pduType);
				break;
		}
	}
}
Exemple #10
0
static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s)
{
    UINT16 length;
    UINT16 pduType;
    UINT16 pduLength;
    UINT16 pduSource;
    UINT16 channelId = 0;
    UINT16 securityFlags;
    int nextPosition;

    if (!rdp_read_header(rdp, s, &length, &channelId))
    {
        DEBUG_WARN( "Incorrect RDP header.\n");
        return -1;
    }

    if (rdp->settings->DisableEncryption)
    {
        if (!rdp_read_security_header(s, &securityFlags))
            return -1;

        if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
        {
            if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
            {
                DEBUG_WARN( "rdp_decrypt failed\n");
                return -1;
            }
        }

        if (securityFlags & SEC_REDIRECTION_PKT)
        {
            /*
             * [MS-RDPBCGR] 2.2.13.2.1
             *  - no share control header, nor the 2 byte pad
             */
            Stream_Rewind(s, 2);

            return rdp_recv_enhanced_security_redirection_packet(rdp, s);
        }
    }

    if (channelId == MCS_GLOBAL_CHANNEL_ID)
    {
        while (Stream_GetRemainingLength(s) > 3)
        {
            nextPosition = Stream_GetPosition(s);

            if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
                return -1;

            nextPosition += pduLength;

            rdp->settings->PduSource = pduSource;

            switch (pduType)
            {
            case PDU_TYPE_DATA:
                if (rdp_recv_data_pdu(rdp, s) < 0)
                {
                    DEBUG_WARN( "rdp_recv_data_pdu failed\n");
                    return -1;
                }
                break;

            case PDU_TYPE_DEACTIVATE_ALL:
                if (!rdp_recv_deactivate_all(rdp, s))
                    return -1;
                break;

            case PDU_TYPE_SERVER_REDIRECTION:
                return rdp_recv_enhanced_security_redirection_packet(rdp, s);
                break;

            default:
                DEBUG_WARN( "incorrect PDU type: 0x%04X\n", pduType);
                break;
            }

            Stream_SetPosition(s, nextPosition);
        }
    }
    else if (rdp->mcs->messageChannelId && channelId == rdp->mcs->messageChannelId)
    {
        return rdp_recv_message_channel_pdu(rdp, s);
    }
    else
    {
        if (!freerdp_channel_process(rdp->instance, s, channelId))
            return -1;
    }

    return 0;
}
Exemple #11
0
static boolean rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 pduSource;
	uint16 channelId;
	uint32 securityHeader;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return false;
	}

	if (rdp->settings->encryption)
	{
		stream_read_uint32(s, securityHeader);
		if (securityHeader & SEC_SECURE_CHECKSUM)
		{
			printf("Error: TODO\n");
			return false;
		}
		if (securityHeader & SEC_ENCRYPT)
		{
			if (!rdp_decrypt(rdp, s, length - 4))
			{
				printf("rdp_decrypt failed\n");
				return false;
			}
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		freerdp_channel_process(rdp->instance, s, channelId);
	}
	else
	{
		rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);

		rdp->settings->pdu_source = pduSource;

		switch (pduType)
		{
			case PDU_TYPE_DATA:
				rdp_recv_data_pdu(rdp, s);
				break;

			case PDU_TYPE_DEACTIVATE_ALL:
				if (!rdp_recv_deactivate_all(rdp, s))
					return false;
				break;

			case PDU_TYPE_SERVER_REDIRECTION:
				rdp_recv_enhanced_security_redirection_packet(rdp, s);
				break;

			default:
				printf("incorrect PDU type: 0x%04X\n", pduType);
				break;
		}
	}

	return true;
}
Exemple #12
0
static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	UINT16 length;
	UINT16 pduType;
	UINT16 pduLength;
	UINT16 pduSource;
	UINT16 channelId;
	UINT16 securityFlags;
	BYTE* nextp;

	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		printf("Incorrect RDP header.\n");
		return -1;
	}

	if (rdp->settings->DisableEncryption)
	{
		if (!rdp_read_security_header(s, &securityFlags))
			return -1;

		if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				printf("rdp_decrypt failed\n");
				return -1;
			}
		}

		if (securityFlags & SEC_REDIRECTION_PKT)
		{
			/*
			 * [MS-RDPBCGR] 2.2.13.2.1
			 *  - no share control header, nor the 2 byte pad
			 */
			s->p -= 2;
			rdp_recv_enhanced_security_redirection_packet(rdp, s);
			return -1;
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		if (!freerdp_channel_process(rdp->instance, s, channelId))
			return -1;
	}
	else
	{
		while (stream_get_left(s) > 3)
		{
			stream_get_mark(s, nextp);

			if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource))
				return -1;

			nextp += pduLength;

			rdp->settings->PduSource = pduSource;

			switch (pduType)
			{
				case PDU_TYPE_DATA:
					if (rdp_recv_data_pdu(rdp, s) < 0)
					{
						printf("rdp_recv_data_pdu failed\n");
						return -1;
					}
					break;

				case PDU_TYPE_DEACTIVATE_ALL:
					if (!rdp_recv_deactivate_all(rdp, s))
						return -1;
					break;

				case PDU_TYPE_SERVER_REDIRECTION:
					if (!rdp_recv_enhanced_security_redirection_packet(rdp, s))
						return -1;
					break;

				default:
					printf("incorrect PDU type: 0x%04X\n", pduType);
					break;
			}
			stream_set_mark(s, nextp);
		}
	}

	return 0;
}
Exemple #13
0
static tbool rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s)
{
	uint16 length;
	uint16 pduType;
	uint16 pduLength;
	uint16 pduSource;
	uint16 channelId;
	uint16 securityFlags;
	uint8* nextp;

	LLOGLN(10, ("rdp_recv_tpkt_pdu:"));
	if (!rdp_read_header(rdp, s, &length, &channelId))
	{
		LLOGLN(0, ("Incorrect RDP header."));
		return false;
	}
	LLOGLN(10, ("rdp_recv_tpkt_pdu: length %d", length));
	if (rdp->disconnect)
	{
		LLOGLN(0, ("rdp_recv_tpkt_pdu: disconnect"));
		return false;
	}

	if (rdp->settings->encryption)
	{
		rdp_read_security_header(s, &securityFlags);
		LLOGLN(10, ("rdp_recv_tpkt_pdu: securityFlags 0x%8.8x", securityFlags));
		if (securityFlags & (SEC_ENCRYPT | SEC_REDIRECTION_PKT))
		{
			if (!rdp_decrypt(rdp, s, length - 4, securityFlags))
			{
				LLOGLN(0, ("rdp_decrypt failed"));
				return false;
			}
		}
		if (securityFlags & SEC_REDIRECTION_PKT)
		{
			LLOGLN(0, ("rdp_recv_tpkt_pdu: got SEC_REDIRECTION_PKT securityFlags 0x%8.8x", securityFlags));
			/*
			 * [MS-RDPBCGR] 2.2.13.2.1
			 *  - no share control header, nor the 2 byte pad
			 */
			s->p -= 2;
			rdp_recv_enhanced_security_redirection_packet(rdp, s);
			return true;
		}
	}

	if (channelId != MCS_GLOBAL_CHANNEL_ID)
	{
		freerdp_channel_process(rdp->instance, s, channelId);
	}
	else
	{
		while (stream_get_left(s) > 3)
		{
			stream_get_mark(s, nextp);
			rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource);
			nextp += pduLength;

			rdp->settings->pdu_source = pduSource;

			switch (pduType)
			{
				case PDU_TYPE_DATA:
					if (!rdp_recv_data_pdu(rdp, s))
					{
						LLOGLN(0, ("rdp_recv_data_pdu failed"));
						return false;
					}
					break;

				case PDU_TYPE_DEACTIVATE_ALL:
					if (!rdp_recv_deactivate_all(rdp, s))
						return false;
					break;

				case PDU_TYPE_SERVER_REDIRECTION:
					rdp_recv_enhanced_security_redirection_packet(rdp, s);
					break;

				default:
					LLOGLN(0, ("incorrect PDU type: 0x%04X", pduType));
					break;
			}
			stream_set_mark(s, nextp);
		}
	}

	return true;
}