Skip to content

Commit 7f24897

Browse files
author
Cruz Monrreal
authored
Merge pull request #9660 from blind-owl/clean_cellular_trace
Cellular: clean sensitive information from trace
2 parents 5a8970a + b6a0892 commit 7f24897

File tree

8 files changed

+115
-0
lines changed

8 files changed

+115
-0
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,29 @@ TEST_F(TestAT_CellularContext, connect_disconnect_sync)
495495
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
496496
EXPECT_TRUE(ctx1.is_connected() == false);
497497

498+
ATHandler_stub::get_debug_clear();
499+
EXPECT_FALSE(ATHandler_stub::is_get_debug_run());
500+
ATHandler_stub::debug_call_count_clear();
501+
at.set_debug(true);
498502
ASSERT_EQ(ctx1.connect("1234", "internet", "usern", "pwd"), NSAPI_ERROR_OK);
503+
EXPECT_TRUE(ATHandler_stub::is_get_debug_run());
504+
EXPECT_TRUE(ATHandler_stub::set_debug_call_count_get() == 3);
505+
EXPECT_TRUE(at.get_debug());
506+
EXPECT_TRUE(ctx1.is_connected() == true);
507+
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
508+
EXPECT_TRUE(ctx1.is_connected() == false);
509+
510+
ATHandler_stub::get_debug_clear();
511+
EXPECT_FALSE(ATHandler_stub::is_get_debug_run());
512+
ATHandler_stub::debug_call_count_clear();
513+
at.set_debug(false);
514+
ASSERT_EQ(ctx1.connect("1234", "internet", "usern", "pwd"), NSAPI_ERROR_OK);
515+
EXPECT_TRUE(ATHandler_stub::is_get_debug_run());
516+
EXPECT_TRUE(ATHandler_stub::set_debug_call_count_get() == 3);
517+
EXPECT_FALSE(at.get_debug());
518+
EXPECT_TRUE(ctx1.is_connected() == true);
519+
ASSERT_EQ(ctx1.disconnect(), NSAPI_ERROR_OK);
520+
EXPECT_TRUE(ctx1.is_connected() == false);
499521

500522
// More connect test after we are re-writted getting of PDP context...
501523
}

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,35 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context)
315315
delete dev;
316316
}
317317

318+
TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_set_pin_verify_debug)
319+
{
320+
EventQueue que;
321+
FileHandle_stub fh1;
322+
ATHandler at(&fh1, que, 0, ",");
323+
AT_CellularDevice *dev = new AT_CellularDevice(&fh1);
324+
325+
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
326+
ATHandler_stub::get_debug_clear();
327+
EXPECT_FALSE(ATHandler_stub::is_get_debug_run());
328+
ATHandler_stub::debug_call_count_clear();
329+
at.set_debug(true);
330+
EXPECT_TRUE(NSAPI_ERROR_OK == dev->set_pin("12"));
331+
EXPECT_TRUE(ATHandler_stub::is_get_debug_run());
332+
EXPECT_TRUE(ATHandler_stub::set_debug_call_count_get() == 3);
333+
EXPECT_TRUE(at.get_debug());
334+
335+
ATHandler_stub::get_debug_clear();
336+
EXPECT_FALSE(ATHandler_stub::is_get_debug_run());
337+
ATHandler_stub::debug_call_count_clear();
338+
at.set_debug(false);
339+
EXPECT_TRUE(NSAPI_ERROR_OK == dev->set_pin("11"));
340+
EXPECT_TRUE(ATHandler_stub::is_get_debug_run());
341+
EXPECT_TRUE(ATHandler_stub::set_debug_call_count_get() == 3);
342+
EXPECT_FALSE(at.get_debug());
343+
344+
delete dev;
345+
}
346+
318347
TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_set_pin)
319348
{
320349
FileHandle_stub fh1;

UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,29 @@ int ATHandler_stub::urc_amount = 0;
5757
mbed::Callback<void()> ATHandler_stub::callback[kATHandler_urc_table_max_size];
5858
char *ATHandler_stub::urc_string_table[kATHandler_urc_table_max_size] = {'\0'};
5959

60+
bool ATHandler_stub::get_debug_flag = false;
61+
uint8_t ATHandler_stub::set_debug_call_count = 0;
62+
63+
bool ATHandler_stub::is_get_debug_run()
64+
{
65+
return ATHandler_stub::get_debug_flag;
66+
}
67+
68+
void ATHandler_stub::get_debug_clear()
69+
{
70+
ATHandler_stub::get_debug_flag = false;
71+
}
72+
73+
uint8_t ATHandler_stub::set_debug_call_count_get()
74+
{
75+
return ATHandler_stub::set_debug_call_count;
76+
}
77+
78+
void ATHandler_stub::debug_call_count_clear()
79+
{
80+
ATHandler_stub::set_debug_call_count = 0;
81+
}
82+
6083
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
6184
_nextATHandler(0),
6285
_fileHandle(fh),
@@ -76,9 +99,17 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
7699

77100
void ATHandler::set_debug(bool debug_on)
78101
{
102+
++ATHandler_stub::set_debug_call_count;
79103
ATHandler_stub::debug_on = debug_on;
80104
}
81105

106+
bool ATHandler::get_debug() const
107+
{
108+
ATHandler_stub::get_debug_flag = true;
109+
110+
return ATHandler_stub::debug_on;
111+
}
112+
82113
ATHandler::~ATHandler()
83114
{
84115
ATHandler_stub::ref_count = kATHandler_destructor_ref_ount;

UNITTESTS/stubs/ATHandler_stub.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ extern int resp_stop_success_count;
6464
extern bool process_oob_urc;
6565
extern int urc_amount;
6666
extern char *urc_string_table[kATHandler_urc_table_max_size];
67+
68+
extern bool get_debug_flag;
69+
bool is_get_debug_run();
70+
void get_debug_clear();
71+
extern uint8_t set_debug_call_count;
72+
uint8_t set_debug_call_count_get();
73+
void debug_call_count_clear();
6774
}
6875

6976
#endif

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ void ATHandler::set_debug(bool debug_on)
112112
_debug_on = debug_on;
113113
}
114114

115+
bool ATHandler::get_debug() const
116+
{
117+
return _debug_on;
118+
}
119+
115120
ATHandler::~ATHandler()
116121
{
117122
while (_oobs) {

features/cellular/framework/AT/ATHandler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ class ATHandler {
431431
*/
432432
void set_debug(bool debug_on);
433433

434+
/**
435+
* Get degug state set by @ref set_debug
436+
*
437+
* @return current state of debug
438+
*/
439+
bool get_debug() const;
440+
434441
/** Set debug_on for all ATHandlers in the _atHandlers list
435442
*
436443
* @param debug_on Set true to enable debug traces

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,15 @@ nsapi_error_t AT_CellularContext::do_user_authentication()
315315
_at.cmd_start("AT+CGAUTH=");
316316
_at.write_int(_cid);
317317
_at.write_int(_authentication_type);
318+
319+
const bool stored_debug_state = _at.get_debug();
320+
_at.set_debug(false);
321+
318322
_at.write_string(_uname);
319323
_at.write_string(_pwd);
324+
325+
_at.set_debug(stored_debug_state);
326+
320327
_at.cmd_stop_read_resp();
321328
if (_at.get_last_error() != NSAPI_ERROR_OK) {
322329
return NSAPI_ERROR_AUTH_FAILURE;

features/cellular/framework/AT/AT_CellularDevice.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,14 @@ nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
176176

177177
_at->lock();
178178
_at->cmd_start("AT+CPIN=");
179+
180+
const bool stored_debug_state = _at->get_debug();
181+
_at->set_debug(false);
182+
179183
_at->write_string(sim_pin);
184+
185+
_at->set_debug(stored_debug_state);
186+
180187
_at->cmd_stop_read_resp();
181188
return _at->unlock_return_error();
182189
}

0 commit comments

Comments
 (0)