Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/TR181-AdvSecurity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<syntax>uint32</syntax>
<writable>true</writable>
</parameter>
<parameter>
<name>FlushConntrackTable</name>
<type>boolean</type>
<syntax>bool</syntax>
<writable>true</writable>
</parameter>
</parameters>
</object>
<object>
Expand Down
25 changes: 25 additions & 0 deletions source/AdvSecurityDml/cosa_adv_security_dml.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ DeviceFingerPrint_GetParamBoolValue
return TRUE;
}

rc = strcmp_s("FlushConntrackTable", strlen("FlushConntrackTable"), ParamName, &ind);
ERR_CHK(rc);
if((rc == EOK) && (!ind))
{
/* FlushConntrackTable is a trigger parameter, always returns FALSE */
*pBool = FALSE;
return TRUE;
}

CcspTraceWarning(("%s: Unsupported parameter '%s'\n", __FUNCTION__, ParamName));
return FALSE;
}
Expand Down Expand Up @@ -213,6 +222,22 @@ DeviceFingerPrint_SetParamBoolValue
return TRUE;
}

rc = strcmp_s("FlushConntrackTable", strlen("FlushConntrackTable"), ParamName, &ind);
ERR_CHK(rc);
if((rc == EOK) && (!ind))
{
if( bValue )
{
returnStatus = CosaAdvSecFlushConntrackTable();
if ( returnStatus != ANSC_STATUS_SUCCESS )
{
CcspTraceError(("%s: FlushConntrackTable failed\n", __FUNCTION__));
return FALSE;
}
}
return TRUE;
}

CcspTraceWarning(("%s: Unsupported parameter '%s'\n", __FUNCTION__, ParamName));
return FALSE;
}
Expand Down
17 changes: 17 additions & 0 deletions source/AdvSecurityDml/cosa_adv_security_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3521,3 +3521,20 @@ ANSC_STATUS CosaAdvSecAgentRaptrDeInit(ANSC_HANDLE hThisObject)
CcspTraceWarning (("AdvSecAgentRaptr_RFCEnable:FALSE\n"));
return returnStatus;
}

ANSC_STATUS CosaAdvSecFlushConntrackTable(VOID)
{
ANSC_STATUS returnStatus = ANSC_STATUS_SUCCESS;
int rc = -1;

CcspTraceInfo(("%s: Flushing connection tracking table\n", __FUNCTION__));

rc = v_secure_system("conntrack -F");
if (!WIFEXITED(rc) || WEXITSTATUS(rc) != 0)
{
Comment on lines +3533 to +3534
CcspTraceError(("%s: conntrack flush failed rc = %d\n", __FUNCTION__, WEXITSTATUS(rc)));
returnStatus = ANSC_STATUS_FAILURE;
}

return returnStatus;
}
6 changes: 6 additions & 0 deletions source/AdvSecurityDml/cosa_adv_security_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,10 @@ CosaAdvSecFetchSbConfig
ULONG* pUlSize,
ULONG* puLong
);

ANSC_STATUS
CosaAdvSecFlushConntrackTable
(
VOID
);
#endif
81 changes: 81 additions & 0 deletions source/test/CcspAdvSecurityDmlTest/CcspAdvSecurityDmlTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ TEST_F(CcspAdvSecurityDmlTestFixture, CheckDeviceFingerPrint_GetParamBoolValue_U
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResult), Return(EOK)));

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("FlushConntrackTable"), strlen("FlushConntrackTable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResult), Return(EOK)));

BOOL result = DeviceFingerPrint_GetParamBoolValue(NULL, (char*)ParamName, &resultBool);

EXPECT_FALSE(result);
Expand Down Expand Up @@ -2911,3 +2915,80 @@ TEST_F(CcspAdvSecurityDmlTestFixture, AdvanceSecurityCujoTelemetry_RFC_SetParamB
free(g_pAdvSecAgent->pAdvSecCujoTelemetry_RFC);
free(g_pAdvSecAgent);
}

TEST_F(CcspAdvSecurityDmlTestFixture, CheckDeviceFingerPrint_GetParamBoolValue_FlushConntrackTable) {
BOOL resultBool;
PCOSA_DATAMODEL_AGENT pMyObject = new COSA_DATAMODEL_AGENT;
g_pAdvSecAgent = pMyObject;

const char* ParamName = "FlushConntrackTable";
int comparisonResult = 1;
int comparisonResultMatch = 0;

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("Enable"), strlen("Enable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResult), Return(EOK)));

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("FlushConntrackTable"), strlen("FlushConntrackTable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResultMatch), Return(EOK)));

BOOL result = DeviceFingerPrint_GetParamBoolValue(NULL, (char*)ParamName, &resultBool);

EXPECT_TRUE(result);
EXPECT_FALSE(resultBool);

delete pMyObject;
}

TEST_F(CcspAdvSecurityDmlTestFixture, CheckDeviceFingerPrint_SetParamBoolValue_FlushConntrackTable_True) {
PCOSA_DATAMODEL_AGENT pMyObject = new COSA_DATAMODEL_AGENT;
g_pAdvSecAgent = pMyObject;

const char* ParamName = "FlushConntrackTable";
BOOL bValue = TRUE;
int comparisonResult = 1;
int comparisonResultMatch = 0;

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("Enable"), strlen("Enable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResult), Return(EOK)));

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("FlushConntrackTable"), strlen("FlushConntrackTable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResultMatch), Return(EOK)));

EXPECT_CALL(*g_securewrapperMock, v_secure_system(HasSubstr("conntrack -F"), _))
.Times(1)
.WillOnce(Return(0));

BOOL result = DeviceFingerPrint_SetParamBoolValue(NULL, (char*)ParamName, bValue);

EXPECT_TRUE(result);

Comment on lines +2944 to +2968
delete pMyObject;
}

TEST_F(CcspAdvSecurityDmlTestFixture, CheckDeviceFingerPrint_SetParamBoolValue_FlushConntrackTable_False) {
PCOSA_DATAMODEL_AGENT pMyObject = new COSA_DATAMODEL_AGENT;
g_pAdvSecAgent = pMyObject;

const char* ParamName = "FlushConntrackTable";
BOOL bValue = FALSE;
int comparisonResult = 1;
int comparisonResultMatch = 0;

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("Enable"), strlen("Enable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResult), Return(EOK)));

EXPECT_CALL(*g_safecLibMock, _strcmp_s_chk(StrEq("FlushConntrackTable"), strlen("FlushConntrackTable"), StrEq(ParamName), _, _, _))
.Times(1)
.WillOnce(DoAll(SetArgPointee<3>(comparisonResultMatch), Return(EOK)));

BOOL result = DeviceFingerPrint_SetParamBoolValue(NULL, (char*)ParamName, bValue);

EXPECT_TRUE(result);

delete pMyObject;
}
Loading