1
0
mirror of synced 2026-10-16 20:36:15 +08:00

fix(security): 默认校验服务器证书并使用安全随机数

- DefaultApacheHttpClientBuilder / DefaultHttpComponentsClientBuilder 默认不再信任所有证书,
  hc5 实现同时改用 DefaultHostnameVerifier,新增 skipServerCertificateVerification 开关供调试场景使用
- WxCryptUtil、RandomUtils、wxpay v3 SignUtils 改用 SecureRandom 生成随机串/nonce
- WxCryptUtil 回调签名比较改为 MessageDigest.isEqual,避免时序攻击

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Binary Wang
2026-07-31 03:38:33 +00:00
parent 6014c833bc
commit ec981e9609
6 changed files with 107 additions and 21 deletions

View File

@@ -4,7 +4,6 @@ import me.chanjar.weixin.common.error.WxRuntimeException;
import java.security.*;
import java.util.Base64;
import java.util.Random;
/**
* @author cloudx
@@ -33,13 +32,13 @@ public class SignUtils {
return genRandomStr(32);
}
private static volatile Random random;
private static volatile SecureRandom random;
private static Random getRandom() {
private static SecureRandom getRandom() {
if (random == null) {
synchronized (SignUtils.class) {
if (random == null) {
random = new Random();
random = new SecureRandom();
}
}
}
@@ -54,7 +53,7 @@ public class SignUtils {
*/
public static String genRandomStr(int length) {
String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random r = getRandom();
SecureRandom r = getRandom();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
int number = r.nextInt(base.length());