libfreerdp-core: TCP: obtain MAC address, LICENSE: generated HWID based on MAC

This commit is contained in:
Marc-André Moreau
2011-07-12 02:53:26 -04:00
parent f6de37d814
commit 30db2dc429
4 changed files with 61 additions and 3 deletions

View File

@@ -154,6 +154,24 @@ void license_generate_keys(rdpLicense* license)
license->encrypted_pre_master_secret->data = (uint8*) xzalloc(72);
}
/**
* Generate Unique Hardware Identifier (CLIENT_HARDWARE_ID).\n
* @param license license module
*/
void license_generate_hwid(rdpLicense* license)
{
CryptoMd5 md5;
uint8* mac_address;
memset(license->hwid, 0, 20);
mac_address = license->rdp->transport->tcp->mac_address;
md5 = crypto_md5_init();
crypto_md5_update(md5, mac_address, 6);
crypto_md5_final(md5, &license->hwid[4]);
}
/**
* Read Product Information (PRODUCT_INFO).\n
* @msdn{cc241915}
@@ -442,7 +460,7 @@ void license_write_platform_id(rdpLicense* license, STREAM* s)
{
stream_write_uint8(s, 0); /* Client Operating System Version */
stream_write_uint8(s, 0); /* Independent Software Vendor (ISV) */
stream_write_uint16(s, 0x0201); /* Client Software Build */
stream_write_uint16(s, 0); /* Client Software Build */
}
/**
@@ -503,6 +521,8 @@ void license_send_new_license_request_packet(rdpLicense* license)
void license_write_platform_challenge_response_packet(rdpLicense* license, STREAM* s)
{
license_generate_hwid(license);
/* EncryptedPlatformChallengeResponse */
/* EncryptedHWID */

View File

@@ -23,6 +23,7 @@
typedef struct rdp_license rdpLicense;
#include "rdp.h"
#include "crypto.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/debug.h>
@@ -90,6 +91,7 @@ typedef struct
struct rdp_license
{
uint8 hwid[20];
struct rdp_rdp* rdp;
uint8 client_random[32];
uint8 server_random[32];
@@ -107,6 +109,7 @@ void license_recv(rdpLicense* license, STREAM* s);
STREAM* license_send_stream_init(rdpLicense* license);
void license_generate_keys(rdpLicense* license);
void license_generate_hwid(rdpLicense* license);
PRODUCT_INFO* license_new_product_info();
void license_free_product_info(PRODUCT_INFO* productInfo);

View File

@@ -23,16 +23,18 @@
#include <string.h>
#include <time.h>
#include <errno.h>
#include <sys/socket.h>
#include <netdb.h>
#include <fcntl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <freerdp/utils/stream.h>
#include <freerdp/utils/memory.h>
#include "tcp.h"
static void tcp_get_ip_address(rdpTcp * tcp)
void tcp_get_ip_address(rdpTcp * tcp)
{
uint8* ip;
socklen_t length;
@@ -56,6 +58,37 @@ static void tcp_get_ip_address(rdpTcp * tcp)
tcp->settings->ip_address = tcp->ip_address;
}
void tcp_get_mac_address(rdpTcp * tcp)
{
uint8* mac;
struct ifreq if_req;
struct if_nameindex* ni;
ni = if_nameindex();
mac = tcp->mac_address;
while (ni->if_name != NULL)
{
if (strcmp(ni->if_name, "lo") != 0)
break;
ni++;
}
strncpy(if_req.ifr_name, ni->if_name, IF_NAMESIZE);
if (ioctl(tcp->sockfd, SIOCGIFHWADDR, &if_req) != 0)
{
printf("failed to obtain MAC address\n");
return;
}
memmove((void*) mac, (void*) &if_req.ifr_ifru.ifru_hwaddr.sa_data[0], 6);
/* printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); */
}
boolean tcp_connect(rdpTcp* tcp, const uint8* hostname, uint16 port)
{
int status;
@@ -101,6 +134,7 @@ boolean tcp_connect(rdpTcp* tcp, const uint8* hostname, uint16 port)
tcp->sockfd = sockfd;
tcp_get_ip_address(tcp);
tcp_get_mac_address(tcp);
return True;
}

View File

@@ -39,6 +39,7 @@ struct rdp_tcp
{
int sockfd;
uint8 ip_address[32];
uint8 mac_address[6];
struct rdp_settings* settings;
TcpConnect connect;
TcpDisconnect disconnect;