HideDateInLog: - for all raw logging to hide sensitive information like passwords

This commit is contained in:
Thomas Wiedebusch
2023-05-16 12:10:34 +02:00
parent ec281ac5c2
commit 73eb6afc45
8 changed files with 33 additions and 17 deletions
@@ -20,7 +20,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
public abstract void SetDefaultResponseTimeout();
public abstract List<Byte> DecodeDataForPhysicalLayer(Byte command, Byte[] payload);
public abstract List<Byte> DecodeDataForPhysicalLayer(Byte command, Byte[] payload, Boolean hideDateInLog = false);
public abstract List<Byte> DecodeDataForLogicLayer(List<Byte> rawData);
@@ -28,7 +28,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
/// <summary>
/// Send out data (including transport protocol specific data like CRC) to physical port (like UART or IrDA)
/// </summary>
List<Byte> DecodeDataForPhysicalLayer(Byte command , Byte[] payload);
List<Byte> DecodeDataForPhysicalLayer(Byte command , Byte[] payload, Boolean hideDateInLog = false);
/// <summary>
/// Received data have to be checked and converted to request protocol
@@ -139,7 +139,11 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
/// <remarks date="2018-Mar-13" author="T.Wiedebusch">
/// - Initial
/// </remarks>
public override List<Byte> DecodeDataForPhysicalLayer(Byte requestProtocolCommand, Byte[] requestProtocolPayload)
/// <remarks date="2023-Mai-16" author="T.Wiedebusch">
/// - Hide data in log forwarded to DecodeDateForPhysicalLayer to hide passwords in log files.
/// </remarks>
public override List<Byte> DecodeDataForPhysicalLayer(Byte requestProtocolCommand, Byte[] requestProtocolPayload,
Boolean hideDateInLog = false)
{
var irdaCrcInputBuffer = new List<Byte>
{
@@ -165,7 +169,10 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
irdaRecord.Add((Byte)(crcResult & 0xFF));
irdaRecord.Add((Byte)(crcResult >> 8));
Logger.Info($"DecodeDataForPhysicalLayer PC->Cordonel({BitConverter.ToString(irdaRecord.ToArray())})");
// avoid logging of passwords or other sensitive data
Logger.Info(hideDateInLog
? "DecodeDataForPhysicalLayer PC->Cordonel(*******************)"
: $"DecodeDataForPhysicalLayer PC->Cordonel({BitConverter.ToString(irdaRecord.ToArray())})");
return irdaRecord;
}
@@ -37,7 +37,7 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
}
/// <inheritdoc />
public override List<Byte> DecodeDataForPhysicalLayer(Byte command, Byte[] payload)
public override List<Byte> DecodeDataForPhysicalLayer(Byte command, Byte[] payload, Boolean hideDateInLog = false)
{
throw new ApplicationException("Streaming port cannot send data");
}
@@ -111,7 +111,8 @@ namespace Xylem.Common.Hardware.Interfaces.Protocols.TransmitProtocol
}
/// <inheritdoc />
public override List<Byte> DecodeDataForPhysicalLayer(Byte requestProtocolCommand, Byte[] requestProtocolPayload)
public override List<Byte> DecodeDataForPhysicalLayer(Byte requestProtocolCommand,
Byte[] requestProtocolPayload, Boolean hideDataInLog = false)
{
var uartHeader = new List<Byte>();
var uartPayload = requestProtocolPayload.ToList();
@@ -456,7 +456,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
private String _currentActionText = "";
/// <summary>
/// Hold the current process name e.g. FlowTest, Preadjustemtn for logging
/// Hold the current process name e.g. FlowTest, Preadjustement for logging
/// </summary>
public String CurrentActionText
{
@@ -472,13 +472,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
}
/// <inheritdoc />
public void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData = true)
{
SetupFromConfigFile(slot, ignoreCorruptedData, true, true);
}
/// <summary>
/// Setup water meter from configuration file:
/// -slot,
@@ -488,9 +481,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// </summary>
/// <param name="slot"></param>
/// <param name="ignoreCorruptedData"></param>
/// <param name="useRequest"></param>
/// <param name="useStreaming"></param>
/// <exception cref="ApplicationException"></exception>
public void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData = true )
{
SetupFromConfigFile(slot, ignoreCorruptedData, true, true);
}
/// <inheritdoc />
public void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData, Boolean useRequest, Boolean useStreaming)
{
@@ -308,6 +308,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
/// <remarks date="2020-Jan-18" author="T.Wiedebusch">
/// - Initial skip retry error code set to 0x0004 (e.g FW not installed 0x0004).
/// </remarks>
/// <remarks date="2023-Mai-16" author="T.Wiedebusch">
/// - Hide data in log forwarded to DecodeDateForPhysicalLayer to hide passwords in log files.
/// </remarks>
private RequestRecord AddRecordToSendFifo(Byte cmd, Byte[] payload, RegisterDefinition register = null,
Boolean hideDataInLog = false, UInt16 skipRetryErrorCode = CommunicationConfig.SkipRetryErrorCode)
{
@@ -316,7 +319,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
//encode request protocol data with transmit protocol
var transmit = GetTransmitProtocol();
var dataEncodedWithTransmitProtocol = transmit.DecodeDataForPhysicalLayer(cmd, payload);
var dataEncodedWithTransmitProtocol = transmit.DecodeDataForPhysicalLayer(cmd, payload, hideDataInLog);
//remind port specific response timeout
var transmitPortSettings = transmit.GetTransmitPortSettings();
@@ -91,7 +91,13 @@ namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore
/// has to be calculated depending on flow-rate and nominal diameter (DN)
/// </summary>
Int32 IntermediateUpdateTimeS { get; set; }
/// <summary>
/// Skip the test bench preparation process
/// </summary>
Boolean SkipPreparationForTestBench { get; set; }
/// <summary>
/// Set the current action test
/// </summary>
String CurrentActionText { get; set; }
#endregion
@@ -106,6 +112,8 @@ namespace Xylem.Common.Hardware.WaterMeter.WaterMeterCore
/// </summary>
/// <param name="slot">Slot Number for Test bench</param>
/// <param name="ignoreCorruptedData">don´t send CRC error or telegrams with error flag to caller</param>
/// <param name="useRequest"></param>
/// <param name="useStreaming"></param>
void SetupFromConfigFile(Int32 slot, Boolean ignoreCorruptedData = true, Boolean useRequest = true, Boolean useStreaming = true);