Example #1
0
        public void S1_ELE_NewLicenseRequest()
        {
            Site.Log.Add(LogEntryKind.TestStep, "Set up a RDPBCGR connection with server.");
            StartRDPConnect();

            TS_LICENSE_PDU licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);

            Site.Log.Add(LogEntryKind.TestStep, "Start a RDPELE New license procedure");
            Site.Assert.AreEqual(bMsgType_Values.LICENSE_REQUEST, licensePdu.preamble.bMsgType, $"A LICENSE_REQUEST message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");

            Site.Log.Add(LogEntryKind.TestStep, "Send Client New License Request to the server.");
            rdpbcgrAdapter.rdpeleClient.SendClientNewLicenseRequest(
                KeyExchangeAlg.KEY_EXCHANGE_ALG_RSA, (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT, testConfig.userName, testConfig.localAddress);
            licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);
            Site.Assert.AreEqual(bMsgType_Values.PLATFORM_CHALLENGE, licensePdu.preamble.bMsgType, $"A PLATFORM_CHALLENGE message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");

            Site.Log.Add(LogEntryKind.TestStep, "Send Client Platform Challenge Response to the server.");
            Random random = new Random();

            rdpbcgrAdapter.rdpeleClient.SendClientPlatformChallengeResponse(
                new CLIENT_HARDWARE_ID {
                PlatformId = (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT,
                Data1      = (uint)random.Next(),
                Data2      = (uint)random.Next(),
                Data3      = (uint)random.Next(),
                Data4      = (uint)random.Next()
            });
            licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);
            Site.Assert.AreEqual(bMsgType_Values.NEW_LICENSE, licensePdu.preamble.bMsgType, $"A NEW_LICENSE message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");
        }
        private bool ProcessLicenseSequence(Configs config, TimeSpan timeout)
        {
            try
            {
                TS_LICENSE_PDU licensePdu = rdpeleClient.ExpectPdu(timeout);

                if (licensePdu.preamble.bMsgType == bMsgType_Values.ERROR_ALERT)
                {
                    // If the target machine is a personal terminal server, whether the client sends the license or not,
                    // the server always sends a license error message with the error code STATUS_VALID_CLIENT and the state transition code ST_NO_TRANSITION.
                    if (dwErrorCode_Values.STATUS_VALID_CLIENT != licensePdu.LicensingMessage.LicenseError.Value.dwErrorCode)
                    {
                        DetectorUtil.WriteLog($"A license error message with the error code STATUS_VALID_CLIENT should be received, but the real error code is {licensePdu.LicensingMessage.LicenseError.Value.dwErrorCode}.");
                    }
                    return(false);
                }

                DetectorUtil.WriteLog("Start RDP license procedure");
                if (bMsgType_Values.LICENSE_REQUEST != licensePdu.preamble.bMsgType)
                {
                    DetectorUtil.WriteLog($"A LICENSE_REQUEST message should be received from server, but the real message type is {licensePdu.preamble.bMsgType}");
                }

                rdpeleClient.SendClientNewLicenseRequest(
                    KeyExchangeAlg.KEY_EXCHANGE_ALG_RSA, (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT, config.ServerUserName, config.ClientName);
                licensePdu = rdpeleClient.ExpectPdu(timeout);
                if (bMsgType_Values.PLATFORM_CHALLENGE != licensePdu.preamble.bMsgType)
                {
                    DetectorUtil.WriteLog($"A PLATFORM_CHALLENGE message should be received from server, but the real message type is {licensePdu.preamble.bMsgType}");
                    return(false);
                }

                Random             random     = new Random();
                CLIENT_HARDWARE_ID clientHWID = new CLIENT_HARDWARE_ID
                {
                    PlatformId = (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT,
                    Data1      = (uint)random.Next(),
                    Data2      = (uint)random.Next(),
                    Data3      = (uint)random.Next(),
                    Data4      = (uint)random.Next()
                };
                rdpeleClient.SendClientPlatformChallengeResponse(clientHWID);
                licensePdu = rdpeleClient.ExpectPdu(timeout);
                if (bMsgType_Values.NEW_LICENSE != licensePdu.preamble.bMsgType)
                {
                    DetectorUtil.WriteLog($"A NEW_LICENSE message should be received from server, but the real message type is {licensePdu.preamble.bMsgType}");
                    return(false);
                }
                DetectorUtil.WriteLog("End RDP license procedure");
                return(true);
            }
            catch (Exception e)
            {
                DetectorUtil.WriteLog("RDP license procedure throws exception: " + e.Message);
                return(false);
            }
        }
        public void S2_ELE_LicenseInfo()
        {
            Site.Log.Add(LogEntryKind.TestStep, "Set up a RDPBCGR connection with server.");
            StartRDPConnect();

            TS_LICENSE_PDU licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);

            Site.Log.Add(LogEntryKind.TestStep, "Start a RDPELE New license procedure.");
            Site.Assert.AreEqual(bMsgType_Values.LICENSE_REQUEST, licensePdu.preamble.bMsgType, $"A LICENSE_REQUEST message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");

            Site.Log.Add(LogEntryKind.TestStep, "Send Client New License Request to the server.");
            rdpbcgrAdapter.rdpeleClient.SendClientNewLicenseRequest(
                KeyExchangeAlg.KEY_EXCHANGE_ALG_RSA, (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT, testConfig.userName, testConfig.localAddress);
            licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);
            Site.Assert.AreEqual(bMsgType_Values.PLATFORM_CHALLENGE, licensePdu.preamble.bMsgType, $"A PLATFORM_CHALLENGE message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");

            Site.Log.Add(LogEntryKind.TestStep, "Send Client Platform Challenge Response to the server.");
            uint               platformId = (uint)Client_OS_ID.CLIENT_OS_ID_WINNT_POST_52 | (uint)Client_Image_ID.CLIENT_IMAGE_ID_MICROSOFT;
            Random             random     = new Random();
            CLIENT_HARDWARE_ID clientHWID = new CLIENT_HARDWARE_ID {
                PlatformId = platformId,
                Data1      = (uint)random.Next(),
                Data2      = (uint)random.Next(),
                Data3      = (uint)random.Next(),
                Data4      = (uint)random.Next()
            };

            rdpbcgrAdapter.rdpeleClient.SendClientPlatformChallengeResponse(clientHWID);
            licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);
            Site.Assert.AreEqual(bMsgType_Values.NEW_LICENSE, licensePdu.preamble.bMsgType, $"A NEW_LICENSE message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");
            byte[] licenseInfo = rdpbcgrAdapter.rdpeleClient.GetNewLicenseInfo().Value.pbLicenseInfo; // Get the license info for the next step
            rdpbcgrAdapter.Disconnect();

            Site.Log.Add(LogEntryKind.TestStep, "Set up a second RDPBCGR connection with server.");
            rdpbcgrAdapter = new RdpbcgrAdapter(testConfig);
            rdpbcgrAdapter.Initialize(Site);
            StartRDPConnect();

            Site.Log.Add(LogEntryKind.TestStep, "Start a RDPELE license info procedure.");
            licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);
            Site.Assert.AreEqual(bMsgType_Values.LICENSE_REQUEST, licensePdu.preamble.bMsgType, $"A LICENSE_REQUEST message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");
            Site.Log.Add(LogEntryKind.TestStep, "Send Client License Information to the server.");
            rdpbcgrAdapter.rdpeleClient.SendClientLicenseInformation(
                KeyExchangeAlg.KEY_EXCHANGE_ALG_RSA,
                platformId,  // same platformId as the first procedure (new license).
                licenseInfo, // the license info retreived from the server in the first procedure.
                clientHWID); // same clientHWID as the first procedure.
            licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);

            if (testConfig.issueTemporaryLicenseForTheFirstTime)
            {
                Site.Log.Add(LogEntryKind.Comment, "If the client presents a license that requires upgrading, that is a valid temporary license. " +
                             "The server MUST respond back with Server Platform Challenge message to the client.");
                Site.Assert.AreEqual(bMsgType_Values.PLATFORM_CHALLENGE, licensePdu.preamble.bMsgType, $"A PLATFORM_CHALLENGE message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");
                Site.Log.Add(LogEntryKind.TestStep, "Send Client Platform Challenge Response to the server.");
                rdpbcgrAdapter.rdpeleClient.SendClientPlatformChallengeResponse(clientHWID);
                licensePdu = rdpbcgrAdapter.rdpeleClient.ExpectPdu(testConfig.timeout);
                Site.Assert.AreEqual(bMsgType_Values.UPGRADE_LICENSE, licensePdu.preamble.bMsgType, $"An UPGRADE_LICENSE message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");
            }
            else
            {
                Site.Log.Add(LogEntryKind.Comment, "The client presents a valid permanent license that does not require an upgrade. " +
                             "The server MUST send a license error message with the error code STATUS_VALID_CLIENT and the state transition code ST_NO_TRANSITION.The licensing protocol is complete at this point.");
                Site.Assert.AreEqual(bMsgType_Values.ERROR_ALERT, licensePdu.preamble.bMsgType, $"An ERROR_ALERT message should be received from server, the real message type is {licensePdu.preamble.bMsgType}");
                Site.Assert.AreEqual(dwErrorCode_Values.STATUS_VALID_CLIENT,
                                     licensePdu.LicensingMessage.LicenseError.Value.dwErrorCode,
                                     $"The error code of the ERROR_ALERT message should be STATUS_VALID_CLIENT, the real error code is {licensePdu.LicensingMessage.LicenseError.Value.dwErrorCode}");
            }
        }