From 30dbaf29f1f6ec9ff8b240721bf2cdf0b9c45474 Mon Sep 17 00:00:00 2001 From: Dmitriy Boltovskiy Date: Mon, 16 Sep 2019 01:11:21 -0400 Subject: [PATCH] Add script to check PTU in protected mode --- .../002_PTU_all_flows_Protected_Mode.lua | 153 ++++++++++++++++++ test_sets/smoke_tests.txt | 1 + user_modules/sequences/security.lua | 3 + 3 files changed, 157 insertions(+) create mode 100644 test_scripts/Smoke/Policies/002_PTU_all_flows_Protected_Mode.lua diff --git a/test_scripts/Smoke/Policies/002_PTU_all_flows_Protected_Mode.lua b/test_scripts/Smoke/Policies/002_PTU_all_flows_Protected_Mode.lua new file mode 100644 index 0000000000..84bd17ee59 --- /dev/null +++ b/test_scripts/Smoke/Policies/002_PTU_all_flows_Protected_Mode.lua @@ -0,0 +1,153 @@ +--------------------------------------------------------------------------------------------------- +-- Script verifies PTU sequence in protected mode +-- Supported PROPRIETARY, EXTERNAL_PROPRIETARY and HTTP flows +--------------------------------------------------------------------------------------------------- +--[[ Required Shared libraries ]] +local runner = require('user_modules/script_runner') +local common = require("test_scripts/Security/SSLHandshakeFlow/common") +local utils = require("user_modules/utils") +local SDL = require('SDL') +local atf_logger = require("atf_logger") +local constants = require('protocol_handler/ford_protocol_constants') + +--[[ Test Configuration ]] +runner.testSettings.isSelfIncluded = false +config.defaultProtocolVersion = 2 +constants.FRAME_SIZE["P2"] = 1400 + +--[[ Local Variables ]] +local policyMode = SDL.buildOptions.extendedPolicy + +local policyModes = { + P = "PROPRIETARY", + EP = "EXTERNAL_PROPRIETARY", + H = "HTTP" +} + +--[[ Local Functions ]] +local function log(...) + local str = "[" .. atf_logger.formated_time(true) .. "]" + for i, p in pairs({...}) do + local delimiter = "\t" + if i == 1 then delimiter = " " end + str = str .. delimiter .. p + end + utils.cprint(35, str) +end + +local function startServiceProtectedACK() + local serviceId = 7 + common.getMobileSession():StartSecureService(serviceId) + common.getMobileSession():ExpectControlMessage(serviceId, { + frameInfo = common.frameInfo.START_SERVICE_ACK, + encryption = true + }) + common.getMobileSession():ExpectHandshakeMessage() +end + +local function getPTS(pBinData) + local pts = pBinData + if policyMode == policyModes.P then + pts = common.json.decode(pBinData).HTTPRequest.body + end + return common.json.decode(pts) +end + +local function getPTUFromPTS(pPTSTable) + local ptu = utils.cloneTable(pPTSTable) + if next(ptu) ~= nil then + local keysToRemove = { "consumer_friendly_messages", "device_data", "module_meta", "usage_and_error_counts", "vehicle_data" } + for _, k in pairs(keysToRemove) do ptu.policy_table[k] = nil end + ptu.policy_table.functional_groupings["DataConsent-2"].rpcs = common.json.null + ptu.policy_table.module_config.preloaded_pt = nil + ptu.policy_table.module_config.preloaded_date = nil + end + return ptu +end + +local function regExpFinishedMsg() + common.getHMIConnection():ExpectNotification("SDL.OnStatusUpdate", { status = "UP_TO_DATE" }) + :Do(function() log("SDL->HMI: N:", "SDL.OnStatusUpdate(UP_TO_DATE)") end) + common.getHMIConnection():ExpectRequest("VehicleInfo.GetVehicleData", { odometer = true }) + :Do(function() log("SDL->HMI: N:", "VehicleInfo.GetVehicleData(odometer)") end) +end + +local function policyTableUpdateProprietary() + log("HMI->SDL: RQ:", "SDL.GetPolicyConfigurationData") + local cid = common.getHMIConnection():SendRequest("SDL.GetPolicyConfigurationData", + { policyType = "module_config", property = "endpoints" }) + common.getHMIConnection():ExpectResponse(cid) + :Do(function() + log("SDL->HMI: RS:", "SDL.GetPolicyConfigurationData") + common.getHMIConnection():SendNotification("BasicCommunication.OnSystemRequest", + { requestType = "PROPRIETARY", fileName = common.sdl.getPTSFilePath() }) + common.getMobileSession():ExpectEncryptedNotification("OnSystemRequest", { requestType = "PROPRIETARY" }) + :Do(function(_, d1) + log("SDL->MOB: N:", "OnSystemRequest (encrypted)") + local ptuFileName = os.tmpname() + local ptsTable = getPTS(d1.binaryData) + local ptuTable = getPTUFromPTS(ptsTable) + utils.tableToJsonFile(ptuTable, ptuFileName) + common.getHMIConnection():ExpectRequest("BasicCommunication.SystemRequest") + :Do(function(_, d2) + log("SDL->HMI: RQ:", "BC.SystemRequest") + log("HMI->SDL: RS:", "BC.SystemRequest") + common.getHMIConnection():SendResponse(d2.id, d2.method, "SUCCESS", { }) + log("HMI->SDL: N:", "SDL.OnReceivedPolicyUpdate") + common.getHMIConnection():SendNotification("SDL.OnReceivedPolicyUpdate", { policyfile = d2.params.fileName }) + regExpFinishedMsg() + end) + log("MOB->SDL: RQ:", "SystemRequest (encrypted)") + local cid2 = common.getMobileSession():SendEncryptedRPC("SystemRequest", { requestType = "PROPRIETARY" }, ptuFileName) + common.getMobileSession():ExpectEncryptedResponse(cid2, { success = true, resultCode = "SUCCESS" }) + :Do(function() log("SDL->MOB: RS:", "SystemRequest (encrypted)") end) + :Do(function() os.remove(ptuFileName) end) + end) + end) +end + +local function policyTableUpdateHttp() + local ptuFileName = os.tmpname() + local ptsTable = common.sdl.getPTS() + local ptuTable = getPTUFromPTS(ptsTable) + utils.tableToJsonFile(ptuTable, ptuFileName) + regExpFinishedMsg() + log("MOB->SDL: RQ:", "SystemRequest (encrypted)") + local cid = common.getMobileSession():SendEncryptedRPC("SystemRequest", + { requestType = "HTTP", fileName = "PolicyTableUpdate" }, ptuFileName) + common.getMobileSession():ExpectEncryptedResponse(cid, { success = true, resultCode = "SUCCESS" }) + :Do(function() log("SDL->MOB: RS:", "SystemRequest (encrypted)") end) + :Do(function() os.remove(ptuFileName) end) +end + +local function policyTableUpdate() + if policyMode == policyModes.P or policyMode == policyModes.EP then + policyTableUpdateProprietary() + elseif policyMode == policyModes.H then + policyTableUpdateHttp() + end +end + +local function checkPTUStatus() + local cid = common.getHMIConnection():SendRequest("SDL.GetStatusUpdate") + log("HMI->SDL: RQ: SDL.GetStatusUpdate") + common.getHMIConnection():ExpectResponse(cid, { result = { status = "UP_TO_DATE" }}) + :Do(function(_, d) + log("HMI->SDL: RS: SDL.GetStatusUpdate", tostring(d.result.status)) + end) +end + +--[[ Scenario ]] +runner.Title("Preconditions") +runner.Step("Clean environment", common.preconditions) +runner.Step("Init SDL certificates", common.initSDLCertificates, { "./files/Security/client_credential.pem" }) +runner.Step("Start SDL, HMI, connect Mobile, start Session", common.start) + +runner.Title("Test") +runner.Step("Register App", common.registerApp) +runner.Step("Switch RPC Service to Protected mode ACK", startServiceProtectedACK) +runner.Step("PTU in secure mode SUCCESS", policyTableUpdate) +runner.Step("Check Status", checkPTUStatus) + +runner.Title("Postconditions") +runner.Step("Stop SDL, clean-up certificates", common.postconditions) diff --git a/test_sets/smoke_tests.txt b/test_sets/smoke_tests.txt index cf3822cd05..fc04947719 100644 --- a/test_sets/smoke_tests.txt +++ b/test_sets/smoke_tests.txt @@ -70,6 +70,7 @@ ./test_scripts/Smoke/HeartBeat/003_HeartBeat_App_send_HB.lua ./test_scripts/Smoke/HeartBeat/004_HeartBeat_no_heartbeat_v2_protocol.lua ./test_scripts/Smoke/Policies/001_PTU_all_flows.lua +./test_scripts/Smoke/Policies/002_PTU_all_flows_Protected_Mode.lua ./test_scripts/Smoke/Registration/001_Register_5_connection.lua ./test_scripts/Smoke/Registration/002_Register_5_session.lua ./test_scripts/Smoke/Registration/003_Register_App.lua diff --git a/user_modules/sequences/security.lua b/user_modules/sequences/security.lua index dbe9aef1d7..ae090ffe57 100644 --- a/user_modules/sequences/security.lua +++ b/user_modules/sequences/security.lua @@ -67,6 +67,9 @@ local function registerExpectServiceEventFunc(pMobSession) :Do(function(_, data) if data.encryption == true and data.frameInfo == constants.FRAME_INFO.START_SERVICE_ACK then session.security:registerSecureService(pServiceId) + if data.serviceType == constants.SERVICE_TYPE.RPC then + session.security:registerSecureService(constants.SERVICE_TYPE.BULK_DATA) + end end end) :ValidIf(function(_, data)