~aleteoryx/muditaos

49b7ab85090e8ba7e81e0dc5e4c3a7a9c7fd2458 — Alek Rudnik 4 years ago 488aedc
[EGD-7005] Removed sensitive data cellular

Removed sensitive data from service and module cellular.
Logger factory introduced to easily manage sensitive logs.
M cmake/modules/ProjectConfig.cmake => cmake/modules/ProjectConfig.cmake +9 -0
@@ 5,6 5,14 @@ else()
    set (LOG_USE_COLOR 1 CACHE INTERNAL "")
endif()

# add LOG_SENSITIVE_DATA enable option
option(LOG_SENSITIVE_DATA "LOG_SENSITIVE_DATA" OFF)
if (${LOG_SENSITIVE_DATA} STREQUAL "ON")
    set (LOG_SENSITIVE_DATA_ENABLED 1 CACHE INTERNAL "")
else()
    set (LOG_SENSITIVE_DATA_ENABLED 0 CACHE INTERNAL "")
endif()

# add SystemView enable option
option(SYSTEMVIEW "SYSTEMVIEW" OFF)
if((${PROJECT_TARGET} STREQUAL "TARGET_RT1051") AND (${SYSTEMVIEW} STREQUAL "ON"))


@@ 44,6 52,7 @@ endif()
#Config options described in README.md
set(PROJECT_CONFIG_DEFINITIONS
        LOG_USE_COLOR=${LOG_USE_COLOR}
        LOG_SENSITIVE_DATA_ENABLED=${LOG_SENSITIVE_DATA_ENABLED}
        LOG_REDIRECT=${LOG_REDIRECT}
        SYSTEM_VIEW_ENABLED=${SYSTEM_VIEW_ENABLED}
        USBCDC_ECHO_ENABLED=${USBCDC_ECHO_ENABLED}

M module-cellular/modem/ATCommon.cpp => module-cellular/modem/ATCommon.cpp +13 -7
@@ 31,19 31,25 @@ void Channel::cmdLog(std::string cmd, const Result &result, std::chrono::millise
    cmd.erase(std::remove(cmd.begin(), cmd.end(), '\n'), cmd.end());
    switch (result.code) {
    case Result::Code::TIMEOUT: {
        LOG_ERROR("[AT]: >%s<, timeout %s - please check the value with Quectel_EC25&EC21_AT_Commands_Manual_V1.3.pdf",
                  cmd.c_str(),
                  utils::to_string(timeout.count()).c_str());
        LOG_ERROR("AT response: timeout");
        LOG_SENSITIVE(
            LOGERROR,
            "[AT]: >%s<, timeout %s - please check the value with Quectel_EC25&EC21_AT_Commands_Manual_V1.3.pdf",
            cmd.c_str(),
            utils::to_string(timeout.count()).c_str());
    } break;
    case Result::Code::ERROR: {
        LOG_ERROR("[AT]: >%s<, >%s<", cmd.c_str(), !result.response.empty() ? result.response.back().c_str() : "");
        LOG_ERROR("AT response: error");
        LOG_SENSITIVE(
            LOGERROR, "[AT]: >%s<, >%s<", cmd.c_str(), result.response.size() ? result.response.back().c_str() : "");
    } break;
    default:
        LOG_INFO("[AT]: >%s<, >%s<", cmd.c_str(), !result.response.empty() ? result.response.back().c_str() : "");
        LOG_SENSITIVE(
            LOGDEBUG, "[AT]: >%s<, >%s<", cmd.c_str(), result.response.size() ? result.response.back().c_str() : "");
        break;
    }
    for (const auto &s : result.response) {
        LOG_INFO("[AT] > %s", s.c_str());
    for ([[maybe_unused]] const auto &s : result.response) {
        LOG_SENSITIVE(LOGINFO, "[AT] > %s", s.c_str());
    }
}


M module-cellular/modem/ATParser.cpp => module-cellular/modem/ATParser.cpp +2 -3
@@ 37,12 37,11 @@ std::vector<ATParser::Urc> ATParser::parseUrc()
        if (pos != std::string::npos) {
            resp.push_back(el.second);
            maxPos = std::max(pos + el.first.length(), maxPos);
            LOG_DEBUG("%s", ("[URC]: " + el.first).c_str());
            LOG_SENSITIVE(LOGDEBUG, "%s", ("[URC]: " + el.first).c_str());
        }
    }

    if (urcBuffer.find("+QIND: \"FOTA\"") != std::string::npos) {
        LOG_DEBUG("%s", urcBuffer.c_str());
        resp.push_back(ATParser::Urc::Fota);
        return resp;
    }


@@ 87,7 86,7 @@ at::Result ATParser::processNewData(sys::Service *service, const bsp::cellular::
                fotaData = std::string(urcBuffer);
                urcBuffer.erase();
            }
            LOG_DEBUG("parsing FOTA:\"%s\"", fotaData.c_str());
            LOG_DEBUG("parsing FOTA");
            FotaService::API::sendRawProgress(service, fotaData);
        }
        else {

M module-cellular/modem/mux/CellularMux.cpp => module-cellular/modem/mux/CellularMux.cpp +1 -1
@@ 801,7 801,7 @@ bool CellularMux::searchATCommandResponse(const std::vector<std::string> &respon
        resp.append(s);
    }

    LOG_CUSTOM(level, "Invalid response: %s", resp.c_str());
    LOG_SENSITIVE(level, "Invalid response: %s", resp.c_str());
    // numberOfExpectedTokens == 0, means do not validate number of tokens
    LOG_CUSTOM(level,
               " - Number of tokens %u, number of expected tokens %u",

M module-cellular/modem/mux/CellularMuxFrame.h => module-cellular/modem/mux/CellularMuxFrame.h +4 -7
@@ 136,8 136,7 @@ class CellularMuxFrame
            }
            if (serData[3] == 0xFF) // ugly hack for Quectel misimplementation of the standard
                Length = myLen - 6;
            // LOG_DEBUG("[Frame] %s Addr: 0x%02X, Ctrl: 0x%02X, Len: %i",
            // TypeOfFrame_text[static_cast<TypeOfFrame_e>(Control)].c_str(), Address, Control, Length);

            data.clear();
            data.insert(data.begin(),
                        serData.begin() + 4,


@@ 164,10 163,10 @@ class CellularMuxFrame
            if ((FCS != 0xCF) && (serData[3] != 0xFF) &&
                (Control !=
                 static_cast<uint8_t>(
                     TypeOfFrame_e::UA))) { // error - but fuck FCS check if it's faulty Quectel UIH frame or UA frame
                     TypeOfFrame_e::UA))) { // error - but ignore FCS check if it's faulty Quectel UIH frame or UA frame
                LOG_PRINTF("\n{");
                for (auto el : serData) {
                    LOG_PRINTF("%02X ", el);
                for ([[maybe_unused]] const auto &el : serData) {
                    LOG_SENSITIVE(LOGDEBUG, "%02X ", el);
                }
                LOG_PRINTF("}\n");



@@ 188,14 187,12 @@ class CellularMuxFrame
  public:
    explicit CellularMuxFrame(frame_t frame)
    {
        // LOG_DEBUG("Serializing given frame");
        pv_serData = frame.serialize();
        pv_frame   = frame;
    }

    explicit CellularMuxFrame(const std::vector<uint8_t> &serData)
    {
        // LOG_DEBUG("Deserializing serData");
        pv_frame.deserialize(serData);
        pv_serData = serData;
    }

M module-cellular/modem/mux/DLCChannel.cpp => module-cellular/modem/mux/DLCChannel.cpp +1 -1
@@ 46,7 46,7 @@ void DLCChannel::sendData(std::vector<uint8_t> &data)

bool DLCChannel::establish()
{
    LOG_DEBUG("Sending %s frame to DLCI %i", TypeOfFrame_text[chanParams.TypeOfFrame].c_str(), DLCI);
    LOG_SENSITIVE(LOGDEBUG, "Sending %s frame to DLCI %i", TypeOfFrame_text[chanParams.TypeOfFrame].c_str(), DLCI);

    CellularMuxFrame frame_c(CellularMuxFrame::frame_t(static_cast<uint8_t>(DLCI << 2) | (1 << 1),
                                                       static_cast<uint8_t>(chanParams.TypeOfFrame)));

M module-services/service-cellular/NetworkSettings.cpp => module-services/service-cellular/NetworkSettings.cpp +0 -1
@@ 257,7 257,6 @@ std::string NetworkSettings::printVoLTEDebug()
            for (auto el : resp.response) {
                buffer = el + "\r\n";
            }
            LOG_DEBUG("VOLTEDEBUG:\r\n%s", buffer.c_str());
            return buffer;
        }
    }

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +6 -5
@@ 160,7 160,7 @@ ServiceCellular::ServiceCellular()
        LOG_DEBUG("Notifications callback called with %u data bytes", static_cast<unsigned int>(data.size()));

        std::string logStr = utils::removeNewLines(data);
        LOG_DEBUG("Data: %s", logStr.c_str());
        LOG_SENSITIVE(LOGDEBUG, "Data: %s", logStr.c_str());
        atURCStream.write(data);
        auto vUrc = atURCStream.getURCList();



@@ 938,13 938,13 @@ std::optional<std::shared_ptr<sys::Message>> ServiceCellular::identifyNotificati
    std::string str(data.begin(), data.end());

    std::string logStr = utils::removeNewLines(str);
    LOG_DEBUG("Notification:: %s", logStr.c_str());
    LOG_SENSITIVE(LOGDEBUG, "Notification:: %s", logStr.c_str());

    auto urc = at::urc::UrcFactory::Create(str);
    urc->Handle(urcHandler);

    if (!urc->isHandled()) {
        LOG_WARN("Unhandled notification: %s", logStr.c_str());
        LOG_SENSITIVE(LOGWARN, "Unhandled notification: %s", logStr.c_str());
    }

    return urcHandler.getResponse();


@@ 984,8 984,9 @@ auto ServiceCellular::sendSMS(SMSRecord record) -> bool
                else {
                    result = false;
                }
                if (!result)
                    LOG_ERROR("Message to: %s send failure", receiver.c_str());
                if (!result) {
                    LOG_ERROR("Message send failure");
                }
            }
        }
        // split text, and send concatenated messages

M module-utils/log/log.hpp => module-utils/log/log.hpp +5 -0
@@ 76,6 76,11 @@ extern "C"
#define LOG_ERROR(...)               log_Log(LOGERROR, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
#define LOG_FATAL(...)               log_Log(LOGFATAL, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
#define LOG_CUSTOM(loggerLevel, ...) log_Log(loggerLevel, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
#if LOG_SENSITIVE_DATA_ENABLED
#define LOG_SENSITIVE(loggerLevel, ...) log_Log(loggerLevel, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
#else
#define LOG_SENSITIVE(loggerLevel, ...)
#endif

#ifdef __cplusplus
}