/// <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> /// 查找eSight主机信息,并且打开. /// </summary> /// <param name="hostIP">主机IP</param> /// <returns>返回查找到的eSight,没有找到返回为null</returns> public IESSession FindAndOpenESSession(string hostIP) { try { IESSession iESSession = FindESSession(hostIP); if (iESSession != null) { iESSession.Open(); iESSession.SaveToDB();//保存状态。 } return(iESSession); } catch (Exception se) { LogUtil.HWLogger.API.Error(se); throw; } }