Skip to content

Commit e1055d8

Browse files
committed
feat: add client certificate management for mTLS authentication
1 parent 37e36e3 commit e1055d8

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/main/java/com/laker/postman/service/http/ssl/SSLCertificateValidator.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private static String extractCN(String dn) {
170170
}
171171

172172
/**
173-
* 检查主机名是否匹配(支持通配符
173+
* 检查主机名是否匹配(支持通配符和 www 前缀
174174
*/
175175
private static boolean hostnameMatches(String hostname, String pattern) {
176176
if (hostname == null || pattern == null) {
@@ -180,12 +180,22 @@ private static boolean hostnameMatches(String hostname, String pattern) {
180180
hostname = hostname.toLowerCase();
181181
pattern = pattern.toLowerCase();
182182

183-
// 完全匹配
183+
// 1. 完全匹配
184184
if (hostname.equals(pattern)) {
185185
return true;
186186
}
187187

188-
// 通配符匹配 (*.example.com)
188+
// 2. www 前缀匹配
189+
// 允许 csdn.com 匹配证书 CN=www.csdn.com
190+
// 允许 www.csdn.com 匹配证书 CN=csdn.com
191+
if (hostname.startsWith("www.") && pattern.equals(hostname.substring(4))) {
192+
return true;
193+
}
194+
if (pattern.startsWith("www.") && hostname.equals(pattern.substring(4))) {
195+
return true;
196+
}
197+
198+
// 3. 通配符匹配 (*.example.com)
189199
if (pattern.startsWith("*.")) {
190200
String patternSuffix = pattern.substring(1); // .example.com
191201

0 commit comments

Comments
 (0)