diff --git a/libfreerdp-core/CMakeLists.txt b/libfreerdp-core/CMakeLists.txt index c9972ac36..d8c0dc951 100644 --- a/libfreerdp-core/CMakeLists.txt +++ b/libfreerdp-core/CMakeLists.txt @@ -36,11 +36,15 @@ set(LIBFREERDP_CORE_SRCS credssp.h ntlmssp.c ntlmssp.h + license.c + license.h security.c security.h settings.c connection.c connection.h + redirection.c + redirection.h rdp.c rdp.h per.c diff --git a/libfreerdp-core/license.c b/libfreerdp-core/license.c new file mode 100644 index 000000000..b16d171ed --- /dev/null +++ b/libfreerdp-core/license.c @@ -0,0 +1,240 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * RDP Licensing + * + * Copyright 2011 Marc-Andre Moreau + * + * 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. + */ + +#include "license.h" + +/** + * Receive an RDP licensing packet.\n + * @msdn{cc240479} + * @param rdp RDP module + * @param s stream + * @param sec_flags security flags + */ + +void license_recv(rdpLicense* license, STREAM* s, uint16 sec_flags) +{ + uint8 flags; + uint8 bMsgType; + uint16 wMsgSize; + + printf("SEC_LICENSE_PKT\n"); + + /* preamble (4 bytes) */ + stream_read_uint8(s, bMsgType); /* bMsgType (1 byte) */ + stream_read_uint8(s, flags); /* flags (1 byte) */ + stream_read_uint16(s, wMsgSize); /* wMsgSize (2 bytes) */ + + printf("bMsgType:%X, flags:%X, wMsgSize:%02x\n", bMsgType, flags, wMsgSize); + + switch (bMsgType) + { + case LICENSE_REQUEST: + license_read_license_request_packet(license, s); + break; + + case PLATFORM_CHALLENGE: + license_read_platform_challenge_packet(license, s); + break; + + case NEW_LICENSE: + license_read_new_license_packet(license, s); + break; + + case UPGRADE_LICENSE: + license_read_upgrade_license_packet(license, s); + break; + + case ERROR_ALERT: + license_read_error_alert_packet(license, s); + break; + + default: + printf("invalid bMsgType:%d\n", bMsgType); + break; + } +} + +/** + * Read PRODUCT_INFO.\n + * @param s stream + * @param productInfo product information + */ + +void license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo) +{ + stream_read_uint32(s, productInfo->dwVersion); /* dwVersion (4 bytes) */ + + stream_read_uint32(s, productInfo->cbCompanyName); /* cbCompanyName (4 bytes) */ + + productInfo->pbCompanyName = (uint8*) xmalloc(productInfo->cbCompanyName); + stream_read(s, productInfo->pbCompanyName, productInfo->cbCompanyName); + + stream_read_uint32(s, productInfo->cbProductId); /* cbProductId (4 bytes) */ + + productInfo->pbProductId = (uint8*) xmalloc(productInfo->cbProductId); + stream_read(s, productInfo->pbProductId, productInfo->cbProductId); +} + +void license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob) +{ + uint16 wBlobType; + + stream_read_uint16(s, wBlobType); /* wBlobType (2 bytes) */ + + if (blob->type != wBlobType && blob->type != 0) + { + printf("license binary blob type does not match expected type.\n"); + return; + } + + blob->type = wBlobType; + + stream_read_uint16(s, blob->length); /* wBlobLen (2 bytes) */ + + blob->data = (uint8*) xmalloc(blob->length); + + stream_read(s, blob->data, blob->length); /* blobData */ +} + +void license_read_scope_list(STREAM* s, SCOPE_LIST* scopeList) +{ + int i; + uint32 scopeCount; + + stream_read_uint32(s, scopeCount); /* ScopeCount (4 bytes) */ + + scopeList->count = scopeCount; + scopeList->array = (LICENSE_BLOB*) xmalloc(sizeof(LICENSE_BLOB) * scopeCount); + + /* ScopeArray */ + for (i = 0; i < scopeCount; i++) + { + scopeList->array[i].type = BB_SCOPE_BLOB; + license_read_binary_blob(s, &scopeList->array[i]); + } +} + +/** + * Read a LICENSE_REQUEST packet.\n + * @msdn{cc241914} + * @param rdp RDP module + * @param s stream + */ + +void license_read_license_request_packet(rdpLicense* license, STREAM* s) +{ + printf("LICENSE_REQUEST\n"); + + /* ServerRandom (32 bytes) */ + stream_read(s, license->server_random, 32); + + /* ProductInfo */ + license_read_product_info(s, &(license->product_info)); + + /* KeyExchangeList */ + license_read_binary_blob(s, &(license->key_exchange_list)); + + /* ServerCertificate */ + license_read_binary_blob(s, &(license->server_certificate)); + + /* ScopeList */ + license_read_scope_list(s, &(license->scope_list)); +} + +/** + * Read a PLATFORM_CHALLENGE packet.\n + * @msdn{cc241921} + * @param rdp RDP module + * @param s stream + */ + +void license_read_platform_challenge_packet(rdpLicense* license, STREAM* s) +{ + +} + +/** + * Read a NEW_LICENSE packet.\n + * @msdn{cc241926} + * @param rdp RDP module + * @param s stream + */ + +void license_read_new_license_packet(rdpLicense* license, STREAM* s) +{ + +} + +/** + * Read an UPGRADE_LICENSE packet.\n + * @msdn{cc241924} + * @param rdp RDP module + * @param s stream + */ + +void license_read_upgrade_license_packet(rdpLicense* license, STREAM* s) +{ + +} + +/** + * Read an ERROR_ALERT packet.\n + * @msdn{cc240482} + * @param rdp RDP module + * @param s stream + */ + +void license_read_error_alert_packet(rdpLicense* license, STREAM* s) +{ + +} + +/** + * Instantiate new license module. + * @return new license module + */ + +rdpLicense* license_new() +{ + rdpLicense* license; + + license = (rdpLicense*) xzalloc(sizeof(rdpLicense)); + + if (license != NULL) + { + license->key_exchange_list.type = BB_KEY_EXCHG_ALG_BLOB; + license->server_certificate.type = BB_CERTIFICATE_BLOB; + } + + return license; +} + +/** + * Free license module. + * @param license license module to be freed + */ + +void license_free(rdpLicense* license) +{ + if (license != NULL) + { + xfree(license); + } +} + diff --git a/libfreerdp-core/license.h b/libfreerdp-core/license.h new file mode 100644 index 000000000..5364225f3 --- /dev/null +++ b/libfreerdp-core/license.h @@ -0,0 +1,108 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * RDP Licensing + * + * Copyright 2011 Marc-Andre Moreau + * + * 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. + */ + +#ifndef __LICENSE_H +#define __LICENSE_H + +typedef struct rdp_license rdpLicense; + +#include "rdp.h" + +#include +#include + +/* Licensing Packet Types */ +#define LICENSE_REQUEST 0x01 +#define PLATFORM_CHALLENGE 0x02 +#define NEW_LICENSE 0x03 +#define UPGRADE_LICENSE 0x04 +#define LICENSE_INFO 0x12 +#define NEW_LICENSE_REQUEST 0x13 +#define PLATFORM_CHALLENGE_RESPONSE 0x15 +#define ERROR_ALERT 0xFF + +#define LICENSE_PKT_CS_MASK (LICENSE_INFO | NEW_LICENSE_REQUEST | PLATFORM_CHALLENGE_RESPONSE | ERROR_ALERT) +#define LICENSE_PKT_SC_MASK (LICENSE_REQUEST | PLATFORM_CHALLENGE | NEW_LICENSE | UPGRADE_LICENSE | ERROR_ALERT) +#define LICENSE_PKT_MASK (LICENSE_PKT_CS_MASK | LICENSE_PKT_SC_MASK) + +/* Licensing Preamble Flags */ +#define PREAMBLE_VERSION_2_0 0x02 +#define PREAMBLE_VERSION_3_0 0x03 +#define LicenseProtocolVersionMask 0x0F +#define EXTENDED_ERROR_MSG_SUPPORTED 0x80 + +/* Licensing Binary Blob Types */ +#define BB_DATA_BLOB 0x0001 +#define BB_RANDOM_BLOB 0x0002 +#define BB_CERTIFICATE_BLOB 0x0003 +#define BB_ERROR_BLOB 0x0004 +#define BB_ENCRYPTED_DATA_BLOB 0x0009 +#define BB_KEY_EXCHG_ALG_BLOB 0x000D +#define BB_SCOPE_BLOB 0x000E +#define BB_CLIENT_USER_NAME_BLOB 0x000F +#define BB_CLIENT_MACHINE_NAME_BLOB 0x0010 + +#define KEY_EXCHANGE_ALG_RSA 0x00000001 + +typedef struct +{ + uint32 dwVersion; + uint32 cbCompanyName; + uint8* pbCompanyName; + uint32 cbProductId; + uint8* pbProductId; +} PRODUCT_INFO; + +typedef struct +{ + uint16 type; + uint16 length; + uint8* data; +} LICENSE_BLOB; + +typedef struct +{ + uint32 count; + LICENSE_BLOB* array; +} SCOPE_LIST; + +struct rdp_license +{ + uint8 server_random[32]; + PRODUCT_INFO product_info; + LICENSE_BLOB key_exchange_list; + LICENSE_BLOB server_certificate; + SCOPE_LIST scope_list; +}; + +void license_recv(rdpLicense* license, STREAM* s, uint16 sec_flags); + +void license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo); +void license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob); + +void license_read_license_request_packet(rdpLicense* license, STREAM* s); +void license_read_platform_challenge_packet(rdpLicense* license, STREAM* s); +void license_read_new_license_packet(rdpLicense* license, STREAM* s); +void license_read_upgrade_license_packet(rdpLicense* license, STREAM* s); +void license_read_error_alert_packet(rdpLicense* license, STREAM* s); + +rdpLicense* license_new(); +void license_free(rdpLicense* license); + +#endif /* __LICENSE_H */ diff --git a/libfreerdp-core/rdp.c b/libfreerdp-core/rdp.c index 0f5f5ac2b..18f9d1f2f 100644 --- a/libfreerdp-core/rdp.c +++ b/libfreerdp-core/rdp.c @@ -47,6 +47,12 @@ void rdp_write_security_header(STREAM* s, uint16 flags) stream_write_uint16(s, 0); /* flagsHi (unused) */ } +/** + * Initialize an RDP packet stream.\n + * @param rdp rdp module + * @return + */ + STREAM* rdp_send_stream_init(rdpRdp* rdp) { STREAM* s; @@ -55,6 +61,12 @@ STREAM* rdp_send_stream_init(rdpRdp* rdp) return s; } +/** + * Send an RDP packet.\n + * @param rdp RDP module + * @param s stream + */ + void rdp_send(rdpRdp* rdp, STREAM* s) { int length; @@ -73,6 +85,11 @@ void rdp_send(rdpRdp* rdp, STREAM* s) transport_write(rdp->transport, s); } +/** + * Receive an RDP packet.\n + * @param rdp RDP module + */ + void rdp_recv(rdpRdp* rdp) { STREAM* s; @@ -101,11 +118,11 @@ void rdp_recv(rdpRdp* rdp) switch (sec_flags & SEC_PKT_MASK) { case SEC_LICENSE_PKT: - security_read_license_packet(s, sec_flags); + license_recv(rdp->license, s, sec_flags); break; case SEC_REDIRECTION_PKT: - security_read_redirection_packet(s, sec_flags); + rdp_read_redirection_packet(rdp, s, sec_flags); break; default: @@ -130,6 +147,7 @@ rdpRdp* rdp_new() { rdp->settings = settings_new(); rdp->transport = transport_new(rdp->settings); + rdp->license = license_new(rdp->license); rdp->nego = nego_new(rdp->transport); rdp->mcs = mcs_new(rdp->transport); } @@ -139,7 +157,7 @@ rdpRdp* rdp_new() /** * Free RDP module. - * @param RDP connect module to be freed + * @param rdp RDP module to be freed */ void rdp_free(rdpRdp* rdp) @@ -147,6 +165,9 @@ void rdp_free(rdpRdp* rdp) if (rdp != NULL) { settings_free(rdp->settings); + transport_free(rdp->transport); + license_free(rdp->license); + mcs_free(rdp->mcs); xfree(rdp); } } diff --git a/libfreerdp-core/rdp.h b/libfreerdp-core/rdp.h index e97714316..9400b4caa 100644 --- a/libfreerdp-core/rdp.h +++ b/libfreerdp-core/rdp.h @@ -26,6 +26,7 @@ typedef struct rdp_rdp rdpRdp; #include "tpkt.h" #include "tpdu.h" #include "nego.h" +#include "license.h" #include "security.h" #include "transport.h" #include "connection.h" @@ -56,6 +57,7 @@ struct rdp_rdp { struct rdp_mcs* mcs; struct rdp_nego* nego; + struct rdp_license* license; struct rdp_settings* settings; struct rdp_transport* transport; }; diff --git a/libfreerdp-core/redirection.c b/libfreerdp-core/redirection.c new file mode 100644 index 000000000..215cf4c54 --- /dev/null +++ b/libfreerdp-core/redirection.c @@ -0,0 +1,33 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * RDP Server Redirection + * + * Copyright 2011 Marc-Andre Moreau + * + * 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. + */ + +#include "redirection.h" + +/** + * Read an RDP Server Redirection Packet.\n + * @msdn{ee441959} + * @param rdp RDP module + * @param s stream + * @param sec_flags security flags + */ + +void rdp_read_redirection_packet(rdpRdp* rdp, STREAM* s, uint16 sec_flags) +{ + printf("SEC_REDIRECTION_PKT\n"); +} diff --git a/libfreerdp-core/redirection.h b/libfreerdp-core/redirection.h new file mode 100644 index 000000000..b7a83fa6e --- /dev/null +++ b/libfreerdp-core/redirection.h @@ -0,0 +1,30 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * RDP Server Redirection + * + * Copyright 2011 Marc-Andre Moreau + * + * 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. + */ + +#ifndef __REDIRECTION_H +#define __REDIRECTION_H + +#include "rdp.h" + +#include +#include + +void rdp_read_redirection_packet(rdpRdp* rdp, STREAM* s, uint16 sec_flags); + +#endif /* __REDIRECTION_H */ diff --git a/libfreerdp-core/security.c b/libfreerdp-core/security.c index e93c2640d..b0c57ab44 100644 --- a/libfreerdp-core/security.c +++ b/libfreerdp-core/security.c @@ -19,12 +19,4 @@ #include "security.h" -void security_read_license_packet(STREAM* s, uint16 sec_flags) -{ - printf("SEC_LICENSE_PKT\n"); -} -void security_read_redirection_packet(STREAM* s, uint16 sec_flags) -{ - printf("SEC_REDIRECTION_PKT\n"); -} diff --git a/libfreerdp-core/security.h b/libfreerdp-core/security.h index 403af7d20..2d36fe3e2 100644 --- a/libfreerdp-core/security.h +++ b/libfreerdp-core/security.h @@ -20,10 +20,11 @@ #ifndef __SECURITY_H #define __SECURITY_H +#include "rdp.h" + #include #include -void security_read_license_packet(STREAM* s, uint16 sec_flags); -void security_read_redirection_packet(STREAM* s, uint16 sec_flags); + #endif /* __SECURITY_H */