PasswordFile generation changed, token no longer outside of WEB service visible

This commit is contained in:
Thomas Wiedebusch
2023-02-23 16:35:25 +01:00
parent 3dd36f7a9a
commit 165ea0b719
10 changed files with 182 additions and 90 deletions
@@ -65,11 +65,22 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MeterPwdHandlerDb.cs" />
<Compile Include="MeterPwdDb.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\CommonCore.Configuration\CommonCore.Configuration.csproj">
<Project>{9EB1F659-6F73-4F65-BCAB-4114FD94F5FC}</Project>
<Name>CommonCore.Configuration</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\..\SoftwareAccessHelper\SoftwareAccessHelper.csproj">
<Project>{A33E3C6D-EAAE-4A20-A0EE-F9E6922FD029}</Project>
<Name>SoftwareAccessHelper</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -37,6 +37,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd
/// </summary>
public String Skeleton = "";
/// <summary>
/// Password, which is the Skeleton, if password file not installed, or the PwdLevel8, if the password file is installed .
/// </summary>
public String Password = "";
/// <summary>
/// List of hashes.
/// </summary>
public List<Byte[]> ListOfHashes = new List<Byte[]>();
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Xylem.Common.CommonCore.Configuration;
using Xylem.Common.Logic.SoftwareAccessHelper;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd
{
/// <summary>
/// Class for meter password handler DB interfaces.
/// </summary>
[Serializable]
public static class MeterPwdHandlerDb
{
/// <summary>
/// Acquires the actual password from DB. Initially, this is the Skeleton-Key, if the password file is
/// written it is the Lvl8Pwd.
/// </summary>
/// <param name="pcbId">input the PcbId</param>
/// <param name="password">output of password</param>
/// <returns>true if successfully executed</returns>
/// <remarks date="2023-Feb-23" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean GetPasswordFromDb(String pcbId, out String password)
{
var url = ServiceUrls.GenesisGetPasswordServiceUrl();
password = "";
try
{
var http = (HttpWebRequest)WebRequest.Create(url + pcbId);
var response = (HttpWebResponse)http.GetResponse();
var responseStream = response.GetResponseStream();
if (responseStream == null)
{
return false;
}
using (var sr = new StreamReader(responseStream))
{
var responseJson = sr.ReadToEnd();
password = responseJson.Trim('"');
}
}
catch (Exception )
{
return false;
}
return true;
}
/// <summary>
/// Collect order number, radio address, skeleton key, password hashes and passwords from DB.
/// </summary>
/// <param name="pcbId">input the PcbId</param>
/// <param name="passwordContainer">output of passwordContainer</param>
/// <returns>true if successfully executed</returns>
/// <remarks date="2023-Feb-23" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean SetPwdFromSkeletonToLvl8inDd(String pcbId, MeterPwdDb passwordContainer)
{
try
{
var newPwd = Encoding.UTF8.GetString(passwordContainer.ListOfPasswords.Last());
var passwordSetServiceUrl = ServiceUrls.GenesisSetPasswordServiceUrl();
var responseJson = LocalWebRequest.GetRequest(passwordSetServiceUrl + pcbId + "&Password=" + newPwd, 8000);
if (responseJson.ToLower().Contains("store"))
{
return true;
}
return false;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// Collect order number, radio address, skeleton key, password hashes and passwords from DB.
/// </summary>
/// <param name="pcbId">input the PcbId</param>
/// <param name="passwordContainer">output of passwordContainer</param>
/// <returns>true if successfully executed</returns>
/// <remarks date="2023-Feb-23" author="Roland Drabesch/Thomas Wiedebusch">
/// - Initial.
/// </remarks>
public static Boolean RequestPwdFileFromDb(String pcbId, out MeterPwdDb passwordContainer)
{
passwordContainer = new MeterPwdDb();
try
{
var url = ServiceUrls.GenesisGetPasswordContainerServiceUrl();
var requestResponse = LocalWebRequest.GetRequestWithError(url + pcbId, out var errorCode, 20000, isRetry: true);
if (errorCode == HttpStatusCode.OK.GetHashCode())
{
passwordContainer = JsonConvert.DeserializeObject<MeterPwdDb>(requestResponse);
return true;
}
return false;
}
catch (Exception)
{
return false;
}
}
}
}