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
@@ -229,21 +229,22 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
/// <remarks date="2021-Mar-25" author="Thomas Wiedebusch">
/// - Set DB connection state.
/// </remarks>
/// <remarks date="2023-Feb-23" author="Thomas Wiedebusch">
/// - Used the <see cref="MeterPwdHandlerDb"/> as common interface to request the password container,
/// if the password container does not exist, it will be generated.
/// </remarks>
public Boolean DownloadCordonelPwdFromDb(String pcbId, out PasswordContainer passwordContainer)
{
passwordContainer = new PasswordContainer();
try
{
var url = ServiceUrls.GenesisGetPasswordContainerServiceUrl();
var requestResponse = LocalWebRequest.GetRequest(url + pcbId, 5000);
if (string.IsNullOrEmpty(requestResponse))
if (!MeterPwdHandlerDb.RequestPwdFileFromDb(pcbId, out var meterPwdDb))
{
DbIsConnected = false;
return false;
}
DbIsConnected = true;
var meterPwdDb = JsonConvert.DeserializeObject<MeterPwdDb>(requestResponse);
passwordContainer.PcbId = pcbId;
passwordContainer.SkeletonKey =
@@ -251,7 +252,7 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
passwordContainer.PasswordLvl8 =
Encoding.UTF8.GetString(meterPwdDb.ListOfPasswords[MeterPwdDb.PwdLevel8Idx]);
passwordContainer.EncryptedPasswordFile = new Byte[MeterPwdDb.PwdFileLength];
var hashList = new List<Byte>();
foreach (var hash in meterPwdDb.ListOfHashes)
{
@@ -259,6 +260,19 @@ namespace Xylem.ServiceFwUpdate.Common.FwUpdateDb
}
passwordContainer.EncryptedPasswordFile = hashList.ToArray();
// If the password file is written, the "Password" from meterPwdDb is overwritten from Skeleton-key
// to the "level 8 password" form the LuDB server. The DB password column is the current login password
// for production. Initially the "Password" is the Skeleton-key which can not be part of the list of
// Passwords. The level 8 password is the last in the pwContainer list of passwords.
if (Encoding.UTF8.GetString(meterPwdDb.ListOfPasswords.Last()) != meterPwdDb.Password)
{
if (!MeterPwdHandlerDb.SetPwdFromSkeletonToLvl8inDd(pcbId, meterPwdDb))
{
DbIsConnected = false;
return false;
}
}
return !string.IsNullOrEmpty(passwordContainer.SkeletonKey) &&
!string.IsNullOrEmpty(passwordContainer.PasswordLvl8) &&
passwordContainer.EncryptedPasswordFile.Length >= MeterPwdDb.PwdFileLength;