From: Marc-André Moreau Date: Tue, 12 Jul 2011 06:53:26 +0000 (-0400) Subject: libfreerdp-core: TCP: obtain MAC address, LICENSE: generated HWID based on MAC X-Git-Tag: 1.0-beta1~441 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30db2dc42959d64a3669ede104510eb231c12fde;p=platform%2Fupstream%2Ffreerdp.git libfreerdp-core: TCP: obtain MAC address, LICENSE: generated HWID based on MAC --- diff --git a/libfreerdp-core/license.c b/libfreerdp-core/license.c index e7eb3ea..0292e02 100644 --- a/libfreerdp-core/license.c +++ b/libfreerdp-core/license.c @@ -155,6 +155,24 @@ void license_generate_keys(rdpLicense* license) } /** + * 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} * @param s stream @@ -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 */ diff --git a/libfreerdp-core/license.h b/libfreerdp-core/license.h index 0e31d45..a7f312c 100644 --- a/libfreerdp-core/license.h +++ b/libfreerdp-core/license.h @@ -23,6 +23,7 @@ typedef struct rdp_license rdpLicense; #include "rdp.h" +#include "crypto.h" #include #include @@ -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); diff --git a/libfreerdp-core/tcp.c b/libfreerdp-core/tcp.c index f59dc8e..afe9892 100644 --- a/libfreerdp-core/tcp.c +++ b/libfreerdp-core/tcp.c @@ -23,16 +23,18 @@ #include #include #include -#include #include #include +#include +#include +#include #include #include #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; } diff --git a/libfreerdp-core/tcp.h b/libfreerdp-core/tcp.h index 3a45d9f..bb0538b 100644 --- a/libfreerdp-core/tcp.h +++ b/libfreerdp-core/tcp.h @@ -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;