|
|
|
@ -61,6 +61,15 @@ public class SysProfileController extends BaseController { |
|
|
|
String postGroup = userService.selectUserPostGroup(user.getUserId()); |
|
|
|
// 单独做一个vo专门给个人中心用 避免数据被脱敏
|
|
|
|
ProfileUserVo profileUser = BeanUtil.toBean(user, ProfileUserVo.class); |
|
|
|
// phonenumber 已为 HSM 密文(本地不可解), 改经备用字段 crypto_remark_two(AES 密文)解密为明文返回;
|
|
|
|
// 未迁移存量用户降级尝试解密 phonenumber 本身(AES 密文形态), 均失败保持原值
|
|
|
|
String phonePlain = ICryptoSensitiveHsmService.decryptWithSrnwgAes(user.getCryptoRemarkTwo()); |
|
|
|
if (phonePlain == null) { |
|
|
|
phonePlain = ICryptoSensitiveHsmService.decryptWithSrnwgAes(user.getPhonenumber()); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(phonePlain)) { |
|
|
|
profileUser.setPhonenumber(phonePlain); |
|
|
|
} |
|
|
|
ProfileVo profileVo = new ProfileVo(profileUser, roleGroup, postGroup); |
|
|
|
return R.ok(profileVo); |
|
|
|
} |
|
|
|
@ -127,47 +136,29 @@ public class SysProfileController extends BaseController { |
|
|
|
String salt = user.getSalt(); |
|
|
|
String loginAccount = StringUtils.isNotBlank(user.getLoginName()) ? user.getLoginName() : user.getUserName(); |
|
|
|
|
|
|
|
boolean oldPasswordCorrect = false; |
|
|
|
String bizId = String.valueOf(user.getUserId()); |
|
|
|
// HSM 密文内容为 MD5(loginAccount+旧密码+salt),须以 MD5 形态校验,明文口径永远不匹配
|
|
|
|
// 取消密码服务平台(HSM)依赖: 旧密码以备用字段 crypto_remark_one(MD5原值)校验, 兼容未迁移存量用户直比 password 列
|
|
|
|
String oldEncrypted = DigestUtil.md5Hex(loginAccount + bo.getOldPassword() + salt); |
|
|
|
try { |
|
|
|
oldPasswordCorrect = ICryptoSensitiveHsmService.verifyPassword("sys_user", bizId, oldEncrypted); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("HSM校验旧密码失败, userId={}, 降级MD5校验", user.getUserId()); |
|
|
|
} |
|
|
|
if (!oldPasswordCorrect) { |
|
|
|
oldPasswordCorrect = oldEncrypted.equals(user.getPassword()); |
|
|
|
} |
|
|
|
boolean oldPasswordCorrect = oldEncrypted.equals(user.getCryptoRemarkOne()) |
|
|
|
|| oldEncrypted.equals(user.getPassword()); |
|
|
|
if (!oldPasswordCorrect) { |
|
|
|
return R.fail("修改密码失败,旧密码错误"); |
|
|
|
} |
|
|
|
|
|
|
|
String newEncrypted = DigestUtil.md5Hex(loginAccount + bo.getNewPassword() + salt); |
|
|
|
// 新旧相同校验: 迁移后 user.getPassword() 为 HSM 密文, MD5 直比失效, 补充 HSM 口径比对
|
|
|
|
boolean sameAsOld = newEncrypted.equals(user.getPassword()) |
|
|
|
|| ICryptoSensitiveHsmService.verifyPassword("sys_user", bizId, newEncrypted); |
|
|
|
// 新旧相同校验: 已迁移用户 password 列为 HSM 密文, MD5 直比不可靠, 以备用字段为准并兼容未迁移用户
|
|
|
|
boolean sameAsOld = newEncrypted.equals(user.getCryptoRemarkOne()) |
|
|
|
|| newEncrypted.equals(user.getPassword()); |
|
|
|
if (sameAsOld) { |
|
|
|
return R.fail("新密码不能与旧密码相同"); |
|
|
|
} |
|
|
|
int rows = DataPermissionHelper.ignore(() -> userService.resetUserPwd(user.getUserId(), newEncrypted)); |
|
|
|
if (rows > 0) { |
|
|
|
// 取消 HSM 双轨写入: password 列已写入新 MD5, 仅同步刷新备用字段 crypto_remark_one 保证口径一致
|
|
|
|
// (完整性摘要由每日 syncIntegrityHashModifiedUsers 定时任务按库中实际值兜底补算)
|
|
|
|
try { |
|
|
|
// 修复: 双轨写入 password=HSM密文 + crypto_remark_one=新MD5原值
|
|
|
|
// (原逻辑只覆写 password, crypto_remark_one 停留旧 MD5, 改密后双轨失真且降级校验拿不到最新值)
|
|
|
|
ICryptoSensitiveHsmService.saveUserPasswordDualTrack(user.getUserId(), newEncrypted); |
|
|
|
ICryptoSensitiveHsmService.saveUserPasswordRemark(user.getUserId(), newEncrypted); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("HSM加密新密码失败, userId={}", user.getUserId(), e); |
|
|
|
} |
|
|
|
try { |
|
|
|
SysUserVo updatedUser = userService.selectUserById(user.getUserId()); |
|
|
|
ICryptoSensitiveHsmService.saveIntegrityHash("sys_user", bizId, |
|
|
|
"password,phonenumber,certificateNumber", |
|
|
|
updatedUser.getPassword() != null ? updatedUser.getPassword() : "", |
|
|
|
updatedUser.getPhonenumber() != null ? updatedUser.getPhonenumber() : "", |
|
|
|
updatedUser.getCertificateNumber() != null ? updatedUser.getCertificateNumber() : ""); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("HSM完整性摘要更新失败, userId={}", user.getUserId(), e); |
|
|
|
log.warn("更新密码备用字段失败, userId={}", user.getUserId(), e); |
|
|
|
} |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|