From 43a29dd57ea73160b738d9efbce7d8b09aee2cdd Mon Sep 17 00:00:00 2001 From: Roland Drabesch Date: Tue, 24 Jan 2023 16:36:01 +0100 Subject: [PATCH] passwords handling now safe bin verfify and fix code --- .../Genesis/GenesisFile/MeterPwdFile.cs | 21 +++++++++++ .../Actions/ProductionProcessPasswordFile.cs | 37 ++++++++++++------- .../Controllers/PasswordController.cs | 5 ++- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Common/Hardware/WaterMeter/Genesis/GenesisFile/MeterPwdFile.cs b/Common/Hardware/WaterMeter/Genesis/GenesisFile/MeterPwdFile.cs index 1248e46c..bc6f2c21 100644 --- a/Common/Hardware/WaterMeter/Genesis/GenesisFile/MeterPwdFile.cs +++ b/Common/Hardware/WaterMeter/Genesis/GenesisFile/MeterPwdFile.cs @@ -206,6 +206,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile return false; } + + /// + /// Verify Meter password file + /// generated passowrd file has to be present + /// + /// + /// + /// - Initial. + /// + + public Boolean VerifyMeterPwdFile() + { + if (_hashedPasswordFile == null) + { + return false; + } + + return _meterFile.VerifyMeterFile(StrPasswordFileName, _hashedPasswordFile); + + } + /// /// Erase the meter password file /// diff --git a/Common/ProductionUiCordonel/ProductionProcesses/Actions/ProductionProcessPasswordFile.cs b/Common/ProductionUiCordonel/ProductionProcesses/Actions/ProductionProcessPasswordFile.cs index 7400ac5d..811c0e3a 100644 --- a/Common/ProductionUiCordonel/ProductionProcesses/Actions/ProductionProcessPasswordFile.cs +++ b/Common/ProductionUiCordonel/ProductionProcesses/Actions/ProductionProcessPasswordFile.cs @@ -1,12 +1,12 @@ -using System; +using Newtonsoft.Json; +using ProductionUiCordonel.ProductionProcesses.Enum; +using ProductionUiCordonel.UserControls.FinalTest; +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Windows.Controls; -using Newtonsoft.Json; -using ProductionUiCordonel.ProductionProcesses.Enum; -using ProductionUiCordonel.UserControls.FinalTest; using Xylem.Common.CommonCore.Configuration; using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile; using Xylem.Common.Logic.SoftwareAccessHelper; @@ -52,8 +52,10 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions Boolean ret = RequestPassword(); updateImage(UserControl.RequestPassword, ret); Progress += 16; - - if (Encoding.UTF8.GetString(pwContainer.listOfPasswords.Last()) == pwContainer.Skeleton)//pwContainer.Skeleton ) + //if password file is written the password from pwContainer (DB) is equal to lvl 8 + //password being used in production + // initailly Password from contain is the Skeletonkey wich can not be in the listofPasswords + if (Encoding.UTF8.GetString(pwContainer.listOfPasswords.Last()) == pwContainer.Password) { NewStatus("Passwörter schon geschrieben. Prozess wird übersprungen"); currentProcessState = ProductionProcessState.Done; @@ -70,17 +72,20 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions if (ret) { - ret = WritePasswordFileToMeter(); + ret = WriteAndVerifyPasswordFileToMeter(); } updateImage(UserControl.WriteToMeter, ret); Progress += 16; //Check if new password is in the meter ... even the file write wasn't successful - if (!ret) + if (ret) { Meter.Logout(); ret = Meter.Login(Encoding.UTF8.GetString(pwContainer.listOfPasswords.Last())); - } + + + + // Password in Production DB can be updated if (ret) { ret = UpdatePasswordinDb(); @@ -95,7 +100,7 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions updateImage(UserControl.Logout, ret); Progress += 16; - + //test the production database password if (ret) { ret = Meter.Login(); @@ -123,6 +128,7 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions public Int64? orderNumber = null; public Int64? radioAdress = null; public String Skeleton = ""; + public String Password = ""; public List listOfHashes = new List(); public List listOfPasswords = new List(); } @@ -141,7 +147,7 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions { "Cache-Control", "no-cache" }, { "X-Node-Token", "d5b8c0b2-81f6-4421-80d0-44eb2093e616" } }; - var resp = LocalWebRequest.GetRequestWithError(url, out var errorCode, 20000, header,true); + var resp = LocalWebRequest.GetRequestWithError(url, out var errorCode, 20000, header, true); if (errorCode == HttpStatusCode.OK.GetHashCode()) { pwContainer = JsonConvert.DeserializeObject(resp); @@ -158,11 +164,14 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions meterPwdFile = new MeterPwdFile(Meter); return meterPwdFile.BuildPwdFile(pwContainer.listOfPasswords, 1, pwContainer.Skeleton); } - public Boolean WritePasswordFileToMeter() + public Boolean WriteAndVerifyPasswordFileToMeter() { if (meterPwdFile.UnlockEraseWriteMeterPwdFile()) { - return meterPwdFile.WriteMeterPwdFile(); + if (meterPwdFile.WriteMeterPwdFile()) + { + return meterPwdFile.VerifyMeterPwdFile(); + } } return false; } @@ -173,7 +182,7 @@ namespace ProductionUiCordonel.ProductionProcesses.Actions var passwordSetServiceUrl = ServiceUrls.GenesisSetPasswordServiceUrl(); - var responseJson = LocalWebRequest.GetRequest(passwordSetServiceUrl + Meter.PcbId + "&Password=" + newPs , 8000); + var responseJson = LocalWebRequest.GetRequest(passwordSetServiceUrl + Meter.PcbId + "&Password=" + newPs, 8000); if (responseJson.ToLower().Contains("store")) { return true; diff --git a/Common/Service/MeterProcessState/Controllers/PasswordController.cs b/Common/Service/MeterProcessState/Controllers/PasswordController.cs index 6db89af4..793346a5 100644 --- a/Common/Service/MeterProcessState/Controllers/PasswordController.cs +++ b/Common/Service/MeterProcessState/Controllers/PasswordController.cs @@ -324,6 +324,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers public Int64? orderNumber = null; public Int64? radioAdress = null; public String Skeleton = ""; + public String Password = ""; public List listOfHashes = new List(); public List listOfPasswords = new List(); @@ -383,6 +384,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers sbQuery.AppendLine($" ,[Vergabe_am] "); sbQuery.AppendLine($" ,passwordtbl.KeySetId "); sbQuery.AppendLine($" ,passwordtbl.orderNumber "); + sbQuery.AppendLine($" ,passwordtbl.Password "); sbQuery.AppendLine($" ,passwordtbl.KitronSkeletonKey as Skeleton "); sbQuery.AppendLine($" ,passwordtbl.ProcessorID as ProcessorUid "); sbQuery.AppendLine($" FROM [Auftrag].[dbo].[Genesis_Meter] meter "); @@ -410,6 +412,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers result.orderNumber = (Int32)item["FertigungsauftragNr"]; result.radioAdress = (Int64)item["Adresse"]; result.Skeleton = (String)item["Skeleton"]; + result.Password = (String)item["Password"]; if (item["KeySetId"].GetType() != typeof(System.DBNull)) { result.KeySetId = (String)item["KeySetId"]; @@ -418,7 +421,7 @@ namespace Xylem.Common.Service.MeterProcessState.Controllers } } - + //todo add NA with serailnumber if (!result.orderNumber.HasValue || !result.radioAdress.HasValue) { return Request.CreateResponse(HttpStatusCode.InternalServerError, new PcbIdNotException(new Guid("160B4C44-6EF7-41DC-A48D-4B4105B4779B")));