From 04abe38601a52110175c0b9a9262566fc7f6bc9d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 22 Nov 2023 11:08:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E5=9C=BA=E6=99=AF=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=A4=9A=E8=AF=81=E4=B9=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../apache/jmeter/config/KeystoreConfig.java | 5 ++-- .../org/apache/jmeter/util/SSLManager.java | 26 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/config/KeystoreConfig.java b/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/config/KeystoreConfig.java index c158360b2f..17ca8b439c 100644 --- a/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/config/KeystoreConfig.java +++ b/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/config/KeystoreConfig.java @@ -123,10 +123,11 @@ public class KeystoreConfig extends ConfigTestElement implements TestBean, TestS dto.setPath(path); SSLManager.keyMap.put(resourceId, dto); } - SSLManager.getInstance().configureKeystore(Boolean.parseBoolean(preload), + + /*SSLManager.getInstance().configureKeystore(Boolean.parseBoolean(preload), startIndexAsInt, endIndexAsInt, - clientCertAliasVarName, in, password); + clientCertAliasVarName, in, password);*/ } diff --git a/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/util/SSLManager.java b/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/util/SSLManager.java index 74f6f7ecc4..1eff29ae60 100644 --- a/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/util/SSLManager.java +++ b/framework/sdk-parent/jmeter/src/main/java/org/apache/jmeter/util/SSLManager.java @@ -146,7 +146,23 @@ public abstract class SSLManager { } else { log.warn("Keystore file not found, loading empty keystore"); this.defaultpw = ""; // Ensure not null - this.keyStore.load(null, ""); + try { + // 重新加载认证文件 + JMeterContext threadContext = JMeterContextService.getContext(); + if (threadContext != null && threadContext.getCurrentSampler() != null) { + String resourceId = threadContext.getCurrentSampler().getPropertyAsString("MS-RESOURCE-ID"); + log.info("重新加载认证文件{}", resourceId); + if (StringUtils.isNotBlank(resourceId) && keyMap.containsKey(resourceId)) { + KeystoreDTO dto = keyMap.get(resourceId); + // 加载认证文件 + InputStream in = new FileInputStream(new File(dto.getPath())); + this.keyStore.load(in, dto.getPwd()); + + } + } + } catch (Exception e) { + log.error("证书处理失败{}", e.getMessage()); + } } } } catch (Exception e) { @@ -357,18 +373,18 @@ public abstract class SSLManager { try { // 重新加载认证文件 JMeterContext threadContext = JMeterContextService.getContext(); - if (SSLManager.manager.keyStore == null && threadContext != null && threadContext.getCurrentSampler() != null) { - + if (threadContext != null && threadContext.getCurrentSampler() != null) { String resourceId = threadContext.getCurrentSampler().getPropertyAsString("MS-RESOURCE-ID"); log.info("重新加载认证文件{}", resourceId); if (StringUtils.isNotBlank(resourceId) && keyMap.containsKey(resourceId)) { KeystoreDTO dto = keyMap.get(resourceId); + SSLManager.manager = new JsseSSLManager(null); + SSLManager.manager.keyStore = null; // 加载认证文件 InputStream in = new FileInputStream(new File(dto.getPath())); SSLManager.manager.configureKeystore(Boolean.parseBoolean(dto.getPreload()), dto.getStartIndex(), dto.getEndIndex(), dto.getClientCertAliasVarName(), in, dto.getPwd()); - keyMap.remove(resourceId); - log.info("移除认证文件{}", resourceId); + log.info("加载认证文件完成 {}", resourceId); } } } catch (Exception e) {