Beispiel #1
0
boolean rpc_ntlm_http_in_connect(rdpRpc* rpc)
{
	STREAM* s;
	int ntlm_token_length;
	uint8* ntlm_token_data;
	HttpResponse* http_response;
	rdpNtlm* ntlm = rpc->ntlm_http_in->ntlm;

	ntlm_client_init(ntlm, true, rpc->settings->username,
			rpc->settings->domain, rpc->settings->password);

	ntlm_authenticate(ntlm);

	s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer, 0, TSG_CHANNEL_IN);

	/* Send IN Channel Request */

	DEBUG_RPC("\n%s", s->data);
	tls_write_all(rpc->tls_in, s->data, s->size);
	stream_free(s);

	/* Receive IN Channel Response */

	http_response = http_response_recv(rpc->tls_in);

	ntlm_token_data = NULL;
	crypto_base64_decode((uint8*) http_response->AuthParam, strlen(http_response->AuthParam),
			&ntlm_token_data, &ntlm_token_length);

	ntlm->inputBuffer.pvBuffer = ntlm_token_data;
	ntlm->inputBuffer.cbBuffer = ntlm_token_length;

	ntlm_authenticate(ntlm);

	http_response_free(http_response);

	s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer, 0x40000000, TSG_CHANNEL_IN);

	/* Send IN Channel Request */

	DEBUG_RPC("\n%s", s->data);
	tls_write_all(rpc->tls_in, s->data, s->size);
	stream_free(s);

	ntlm_client_uninit(ntlm);
	ntlm_free(ntlm);

	return true;
}
Beispiel #2
0
static int rdg_write_data_packet(rdpRdg* rdg, BYTE* buf, int size)
{
	int status;
	wStream* sChunk;
	int packetSize = size + 10;
	char chunkSize[11];

	if (size < 1)
		return 0;

	sprintf_s(chunkSize, sizeof(chunkSize), "%X\r\n", packetSize);
	sChunk = Stream_New(NULL, strlen(chunkSize) + packetSize + 2);

	if (!sChunk)
		return -1;

	Stream_Write(sChunk, chunkSize, strlen(chunkSize));
	Stream_Write_UINT16(sChunk, PKT_TYPE_DATA);   /* Type */
	Stream_Write_UINT16(sChunk, 0);   /* Reserved */
	Stream_Write_UINT32(sChunk, packetSize);   /* Packet length */
	Stream_Write_UINT16(sChunk, size);   /* Data size */
	Stream_Write(sChunk, buf, size);   /* Data */
	Stream_Write(sChunk, "\r\n", 2);
	Stream_SealLength(sChunk);
	status = tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), Stream_Length(sChunk));
	Stream_Free(sChunk, TRUE);

	if (status < 0)
		return -1;

	return size;
}
Beispiel #3
0
BOOL rdg_process_in_channel_authorization(rdpRdg* rdg, HttpResponse* response)
{
	wStream* s;
	int status;

	if (response->StatusCode != HTTP_STATUS_OK)
	{
		rdg->state = RDG_CLIENT_STATE_CLOSED;
		return FALSE;
	}

	WLog_DBG(TAG, "In Channel authorization complete");
	rdg->state = RDG_CLIENT_STATE_IN_CHANNEL_AUTHORIZED;

	s = rdg_build_http_request(rdg, "RDG_IN_DATA");

	if (!s)
		return FALSE;

	status = tls_write_all(rdg->tlsIn, Stream_Buffer(s), Stream_Length(s));
	
	Stream_Free(s, TRUE);

	if (status <= 0)
		return FALSE;

	return TRUE;
}
Beispiel #4
0
BOOL rdg_write_packet(rdpRdg* rdg, wStream* sPacket)
{
	int status;
	wStream* sChunk;
	char chunkSize[11];

	sprintf_s(chunkSize, sizeof(chunkSize), "%X\r\n", (unsigned int) Stream_Length(sPacket));
	sChunk = Stream_New(NULL, strlen(chunkSize) + Stream_Length(sPacket) + 2);

	if (!sChunk)
		return FALSE;

	Stream_Write(sChunk, chunkSize, strlen(chunkSize));
	Stream_Write(sChunk, Stream_Buffer(sPacket), Stream_Length(sPacket));
	Stream_Write(sChunk, "\r\n", 2);
	Stream_SealLength(sChunk);

	status = tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), Stream_Length(sChunk));
	Stream_Free(sChunk, TRUE);

	if (status < 0)
		return FALSE;

	return TRUE;
}
Beispiel #5
0
BOOL rdg_process_keep_alive_packet(rdpRdg* rdg)
{
	int status;
	wStream* sChunk;
	int packetSize = 8;
	char chunkSize[11];
    
	sprintf_s(chunkSize, sizeof(chunkSize), "%X\r\n", packetSize);
    
	sChunk = Stream_New(NULL, strlen(chunkSize) + packetSize + 2);
    
	if (!sChunk)
		return FALSE;
    
	Stream_Write(sChunk, chunkSize, strlen(chunkSize));
    
	Stream_Write_UINT16(sChunk, PKT_TYPE_KEEPALIVE);   /* Type */
	Stream_Write_UINT16(sChunk, 0);   /* Reserved */
	Stream_Write_UINT32(sChunk, packetSize);   /* Packet length */
    
	Stream_Write(sChunk, "\r\n", 2);
	Stream_SealLength(sChunk);
    
	status = tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), Stream_Length(sChunk));
	Stream_Free(sChunk, TRUE);
    
	return (status < 0 ? FALSE : TRUE);
}
Beispiel #6
0
BOOL rdg_process_out_channel_response(rdpRdg* rdg, HttpResponse* response)
{
	int status;
	wStream* s;
	char* token64 = NULL;
	int ntlmTokenLength = 0;
	BYTE* ntlmTokenData = NULL;
	rdpNtlm* ntlm = rdg->ntlm;

	if (response->StatusCode != HTTP_STATUS_DENIED)
	{
		WLog_DBG(TAG, "RDG not supported");
		rdg->state = RDG_CLIENT_STATE_NOT_FOUND;
		return FALSE;
	}

	WLog_DBG(TAG, "Out Channel authorization required");

	if (ListDictionary_Contains(response->Authenticates, "NTLM"))
	{
		token64 = ListDictionary_GetItemValue(response->Authenticates, "NTLM");

		if (!token64)
		{
			return FALSE;
		}

		crypto_base64_decode(token64, strlen(token64), &ntlmTokenData, &ntlmTokenLength);
	}

	if (ntlmTokenData && ntlmTokenLength)
	{
		ntlm->inputBuffer[0].pvBuffer = ntlmTokenData;
		ntlm->inputBuffer[0].cbBuffer = ntlmTokenLength;
	}

	ntlm_authenticate(ntlm);

	s = rdg_build_http_request(rdg, "RDG_OUT_DATA");

	if (!s)
		return FALSE;

	status = tls_write_all(rdg->tlsOut, Stream_Buffer(s), Stream_Length(s));

	Stream_Free(s, TRUE);

	ntlm_free(rdg->ntlm);
	rdg->ntlm = NULL;

	if (status < 0)
	{
		return FALSE;
	}

	rdg->state = RDG_CLIENT_STATE_OUT_CHANNEL_AUTHORIZE;

	return TRUE;
}
Beispiel #7
0
int rpc_out_write(rdpRpc* rpc, BYTE* data, int length)
{
	int status;

	status = tls_write_all(rpc->TlsOut, data, length);

	return status;
}
Beispiel #8
0
int rpc_in_write(rdpRpc* rpc, BYTE* data, int length)
{
	int status;

#ifdef WITH_DEBUG_TSG
	rpc_pdu_header_print((rpcconn_hdr_t*) data);
	printf("Sending PDU (length: %d)\n", length);
	winpr_HexDump(data, length);
#endif
	
	status = tls_write_all(rpc->TlsIn, data, length);

	return status;
}
Beispiel #9
0
static BOOL rdg_send_http_request(rdpRdg* rdg, rdpTls* tls, const char* method,
                                  const char* transferEncoding)
{
	wStream* s = NULL;
	int status;
	s = rdg_build_http_request(rdg, method, transferEncoding);

	if (!s)
		return FALSE;

	status = tls_write_all(tls, Stream_Buffer(s), Stream_Length(s));
	Stream_Free(s, TRUE);
	return (status >= 0);
}
Beispiel #10
0
int rpc_out_write(rdpRpc* rpc, uint8* data, int length)
{
	int status;

#ifdef WITH_DEBUG_RPC
	printf("rpc_out_write(): length: %d\n", length);
	freerdp_hexdump(data, length);
	printf("\n");
#endif

	status = tls_write_all(rpc->tls_out, data, length);

	return status;
}
Beispiel #11
0
int rpc_in_write(rdpRpc* rpc, uint8* data, int length)
{
	int status;

#ifdef WITH_DEBUG_RPC
	printf("rpc_in_write() length: %d\n", length);
	freerdp_hexdump(data, length);
	printf("\n");
#endif

	status = tls_write_all(rpc->tls_in, data, length);

	if (status > 0)
		rpc->VirtualConnection->DefaultInChannel->BytesSent += status;

	return status;
}
Beispiel #12
0
BOOL rdg_send_in_channel_request(rdpRdg*rdg)
{
	int status;
	wStream* s = NULL;

	rdg->ntlm = ntlm_new();

	if (!rdg->ntlm)
		return FALSE;

	status = rdg_ncacn_http_ntlm_init(rdg, rdg->tlsIn);

	if (!status)
		return FALSE;

	status = ntlm_authenticate(rdg->ntlm);

	if (!status)
		return FALSE;

	s = rdg_build_http_request(rdg, "RDG_IN_DATA");

	if (!s)
		return FALSE;

	status = tls_write_all(rdg->tlsIn, Stream_Buffer(s), Stream_Length(s));

	Stream_Free(s, TRUE);

	if (status < 0)
		return FALSE;

	rdg->state = RDG_CLIENT_STATE_IN_CHANNEL_REQUEST;

	return TRUE;
}
Beispiel #13
0
int rpc_out_channel_write(RpcOutChannel* outChannel, const BYTE* data, int length)
{
	int status;
	status = tls_write_all(outChannel->tls, data, length);
	return status;
}
Beispiel #14
0
int rpc_in_channel_write(RpcInChannel* inChannel, const BYTE* data, int length)
{
	int status;
	status = tls_write_all(inChannel->tls, data, length);
	return status;
}
Beispiel #15
0
BOOL rpc_ntlm_http_in_connect(rdpRpc* rpc)
{
    STREAM* s;
    rdpSettings* settings;
    int ntlm_token_length;
    BYTE* ntlm_token_data;
    HttpResponse* http_response;
    rdpNtlm* ntlm = rpc->ntlm_http_in->ntlm;

    settings = rpc->settings;

    if (settings->tsg_same_credentials)
    {
        ntlm_client_init(ntlm, TRUE, settings->username,
                         settings->domain, settings->password);
        ntlm_client_make_spn(ntlm, _T("HTTP"), settings->tsg_hostname);
    }
    else
    {
        ntlm_client_init(ntlm, TRUE, settings->tsg_username,
                         settings->tsg_domain, settings->tsg_password);
        ntlm_client_make_spn(ntlm, _T("HTTP"), settings->tsg_hostname);
    }

    ntlm_authenticate(ntlm);

    s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer, 0, TSG_CHANNEL_IN);

    /* Send IN Channel Request */

    DEBUG_RPC("\n%s", s->data);
    tls_write_all(rpc->tls_in, s->data, s->size);
    stream_free(s);

    /* Receive IN Channel Response */

    http_response = http_response_recv(rpc->tls_in);

    ntlm_token_data = NULL;
    crypto_base64_decode((BYTE*) http_response->AuthParam, strlen(http_response->AuthParam),
                         &ntlm_token_data, &ntlm_token_length);

    ntlm->inputBuffer.pvBuffer = ntlm_token_data;
    ntlm->inputBuffer.cbBuffer = ntlm_token_length;

    ntlm_authenticate(ntlm);

    http_response_free(http_response);

    s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer, 0x40000000, TSG_CHANNEL_IN);

    /* Send IN Channel Request */

    DEBUG_RPC("\n%s", s->data);
    tls_write_all(rpc->tls_in, s->data, s->size);
    stream_free(s);

    ntlm_client_uninit(ntlm);
    ntlm_free(ntlm);

    return TRUE;
}