用户加密漏洞

This commit is contained in:
mashuai 2024-05-22 16:43:43 +08:00
parent a74db9ac70
commit 661bd5c028
1 changed files with 23 additions and 3 deletions

View File

@ -1,6 +1,9 @@
package com.bonus.sgzb.auth.controller; package com.bonus.sgzb.auth.controller;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.bonus.sgzb.auth.form.*; import com.bonus.sgzb.auth.form.*;
@ -23,6 +26,8 @@ import com.bonus.sgzb.common.security.service.TokenService;
import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.common.security.utils.SecurityUtils;
import com.bonus.sgzb.system.api.model.LoginUser; import com.bonus.sgzb.system.api.model.LoginUser;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map; import java.util.Map;
/** /**
@ -54,12 +59,27 @@ public class TokenController {
//web端登录 //web端登录
@PostMapping("login") @PostMapping("login")
public R<?> login(@RequestBody LoginBody form) { public R<?> login(@RequestBody LoginBody form) throws Exception {
// 定义密钥
String key = "CCNXrpassWordKey";
byte[] encryptedBytes = Base64.getDecoder().decode(form.getPassword());
byte[] iv = new byte[16];
System.arraycopy(encryptedBytes, 0, iv, 0, iv.length);
byte[] cipherText = new byte[encryptedBytes.length - iv.length];
System.arraycopy(encryptedBytes, iv.length, cipherText, 0, cipherText.length);
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(iv));
byte[] decryptedBytes = cipher.doFinal(cipherText);
String decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8);
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
String uuid = form.getUuid(); String uuid = form.getUuid();
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString(); String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
if (StringUtils.isBlank(captcha)){ if (StringUtils.isBlank(captcha)) {
return R.fail("验证码超时,请重新刷新"); return R.fail("验证码超时,请重新刷新");
} }
if (form.getCode() != null && form.getCode().equals(captcha)) { if (form.getCode() != null && form.getCode().equals(captcha)) {