/// <summary> /// 刷新密码。时机是每次启动时,这里会加在这个单例的初始化。 /// 重置密钥,并且更新密码。 /// 规则1:密钥须支持可更新,并明确更新周期,在一次性可编程的芯片中保存的密钥除外 /// 说明:工作密钥及密钥加密密钥在使用过程中,都应保证其可以更新。对于根密钥暂不要求必须支持可更新。 /// </summary> private void RefreshPwds() { HWLogger.DEFAULT.InfoFormat("Refresh eSightpwd with encryption..."); lock (LockRefreshPwds) { lock (this.eSightSessions) { using (var mutex = new Mutex(false, "huawei.SCOM.ESightPlugin.engine")) { if (mutex.WaitOne(TimeSpan.FromSeconds(60), false)) { string oldMainKey; // 2017-10-11 检查是否需要升级的密钥。 if (!EncryptUtil.IsCompatibleVersion()) { oldMainKey = EncryptUtil.GetMainKey1060(); HWLogger.DEFAULT.InfoFormat("oldMainKey:{0}", oldMainKey); if (string.IsNullOrEmpty(oldMainKey)) { return; } EncryptUtil.ClearAndUpgradeKey(); } else { // 旧的key oldMainKey = EncryptUtil.GetMainKeyWithoutInit(); if (string.IsNullOrEmpty(oldMainKey)) { return; } // 重新初始化主密钥。 EncryptUtil.InitMainKey(); } var newMainKey = EncryptUtil.GetMainKeyFromPath(); // LogUtil.HWLogger.DEFAULT.InfoFormat("Change key,oldMainKey={1},newMainKey={1}",oldMainKey,newMainKey); // 遍历所有session. var hostlist = ESightDal.Instance.GetList(); foreach (var eSightHost in hostlist) { var pwd = EncryptUtil.DecryptWithKey(oldMainKey, eSightHost.LoginPd); var enPwd = EncryptUtil.EncryptWithKey(newMainKey, pwd); var iEsSession = this.FindEsSession(eSightHost.HostIP); iEsSession.ESight.LoginPd = enPwd; this.eSightSessions[eSightHost.HostIP.ToUpper()] = iEsSession; ESightDal.Instance.UpdateESightPwd(eSightHost.HostIP, enPwd); } } } } } HWLogger.DEFAULT.InfoFormat("Refresh eSightpwd with encryption successful!"); }
/// <summary> /// 刷新密码。时机是每次启动时,这里会加在这个单例的初始化。 /// 重置密钥,并且更新密码。 /// 规则1:密钥须支持可更新,并明确更新周期,在一次性可编程的芯片中保存的密钥除外 /// 说明:工作密钥及密钥加密密钥在使用过程中,都应保证其可以更新。对于根密钥暂不要求必须支持可更新。 /// </summary> public void RefreshPwds() { LogUtil.HWLogger.DEFAULT.InfoFormat("Refresh password with encryption..."); lock (_lockRefreshPwds) { lock (eSightSessions) { using (var mutex = new System.Threading.Mutex(false, "huawei.sccmplugin.engine")) { if (mutex.WaitOne(TimeSpan.FromSeconds(60), false)) { string oldMainKey = ""; //2017-10-11 检查是否需要升级的密钥。 if (!EncryptUtil.IsCompatibleVersion()) { oldMainKey = EncryptUtil.GetMainKey1060(); LogUtil.HWLogger.DEFAULT.InfoFormat("oldMainKey:{0}", oldMainKey); if (string.IsNullOrEmpty(oldMainKey)) { return; } EncryptUtil.ClearAndUpgradeKey(); } else { //旧的key oldMainKey = EncryptUtil.GetMainKeyWithoutInit(); if (string.IsNullOrEmpty(oldMainKey)) { return; } //重新初始化主密钥。 EncryptUtil.InitMainKey(); } string newMainKey = EncryptUtil.GetMainKeyFromPath(); // LogUtil.HWLogger.DEFAULT.InfoFormat("Change key,oldMainKey={1},newMainKey={1}",oldMainKey,newMainKey); //遍历所有session. IList <HWESightHost> hostlist = ESightEngine.Instance.ListESHost(); foreach (HWESightHost eSightHost in hostlist) { string pwd = EncryptUtil.DecryptWithKey(oldMainKey, eSightHost.LoginPwd); string enPwd = EncryptUtil.EncryptWithKey(newMainKey, pwd); IESSession iESSession = FindESSession(eSightHost.HostIP); iESSession.HWESightHost.LoginPwd = enPwd; eSightSessions[eSightHost.HostIP.ToUpper()] = iESSession; iESSession.SaveToDB(); } } } } } LogUtil.HWLogger.DEFAULT.InfoFormat("Refresh password with encryption successful!"); }
/// <summary> /// 刷新密码。时机是每次启动时,这里会加在这个单例的初始化。 /// 重置密钥,并且更新密码。 /// 规则1:密钥须支持可更新,并明确更新周期,在一次性可编程的芯片中保存的密钥除外 /// 说明:工作密钥及密钥加密密钥在使用过程中,都应保证其可以更新。对于根密钥暂不要求必须支持可更新。 /// </summary> public void RefreshPwds() { LogUtil.HWLogger.DEFAULT.InfoFormat("Refresh pd with encryption..."); lock (_lockRefreshPwds) { using (var mutex = new System.Threading.Mutex(false, "huawei.sccmplugin.engine")) { if (mutex.WaitOne(TimeSpan.FromSeconds(60), false)) { string oldMainKey = ""; //2017-10-11 检查是否需要升级的密钥。 if (!EncryptUtil.IsCompatibleVersion()) { oldMainKey = EncryptUtil.GetMainKey1060(); LogUtil.HWLogger.DEFAULT.InfoFormat("oldMainKey:{0}", oldMainKey); if (string.IsNullOrEmpty(oldMainKey)) { return; } EncryptUtil.ClearAndUpgradeKey(); } else { //旧的key oldMainKey = EncryptUtil.GetMainKeyWithoutInit(); if (string.IsNullOrEmpty(oldMainKey)) { return; } //重新初始化主密钥。 EncryptUtil.InitMainKey(); } string newMainKey = EncryptUtil.GetMainKeyFromPath(); // LogUtil.HWLogger.DEFAULT.InfoFormat("Change key,oldMainKey={1},newMainKey={1}",oldMainKey,newMainKey); //遍历所有session. var hostlist = FusionDirectorWorker.Instance.GetList(); foreach (FusionDirectorModel fd in hostlist) { string pd = EncryptUtil.DecryptWithKey(oldMainKey, fd.LoginPwd); string enPwd = EncryptUtil.EncryptWithKey(newMainKey, pd); fd.LoginPwd = enPwd; FusionDirectorWorker.Instance.Update(fd); } } } } LogUtil.HWLogger.DEFAULT.InfoFormat("Refresh pd with encryption successful!"); }