Skip to content

Commit 6fae362

Browse files
committed
fix(proxy): 修复文件证书更新逻辑
- 添加对证书路径为空的检查 - 优化证书更新事件处理逻辑 - 修复证书更新时的路径检查问题 Signed-off-by: Async <raisinata@foxmail.com>
1 parent dc2a4c2 commit 6fae362

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

proxy/src/main/java/org/apache/rocketmq/proxy/service/cert/FileCertChangeSource.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
117
package org.apache.rocketmq.proxy.service.cert;
218

319
import java.util.Collections;

proxy/src/main/java/org/apache/rocketmq/proxy/service/cert/TlsCertificateManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public void shutdown() throws Exception {
6969
public void onCertChanged(CertChangeEvent event) {
7070
log.info("cert changed: {}", event);
7171
if (event.getSourceType() == CertChangeEvent.SourceType.FILE) {
72+
if (event.getValues().isEmpty()) {
73+
log.warn("cert path is empty, ignore");
74+
return;
75+
}
7276
String path = event.getValues().get(0);
7377
if (path.equals(ConfigurationManager.getProxyConfig().getTlsCertPath())) {
7478
certChanged = true;
@@ -85,6 +89,10 @@ public void onCertChanged(CertChangeEvent event) {
8589
keyChanged = false;
8690
}
8791
} else if (event.getSourceType() == CertChangeEvent.SourceType.INLINE) {
92+
if (event.getValues().size() != 2) {
93+
log.warn("cert inline is invalid, ignore");
94+
return;
95+
}
8896
for (TlsContextReloadListener listener : reloadListeners) {
8997
listener.onTlsContextReload(
9098
IOUtils.toInputStream(event.getValues().get(0), StandardCharsets.UTF_8),

remoting/src/main/java/org/apache/rocketmq/remoting/netty/TlsHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface DecryptionStrategy {
6666
* Decrypt the target encrpted private key file.
6767
*
6868
* @param privateKeyEncryptPath A pathname string
69-
* @param forClient tells whether it's a client-side key file
69+
* @param forClient tells whether it's a client-side key file
7070
* @return An input stream for a decrypted key file
7171
* @throws IOException if an I/O error has occurred
7272
*/
@@ -125,9 +125,9 @@ public static SslContext buildSslContext(boolean forClient, InputStream certInpu
125125
}
126126

127127
return sslContextBuilder.keyManager(
128-
!isNullOrEmpty(tlsClientCertPath) ? new FileInputStream(tlsClientCertPath) : null,
129-
!isNullOrEmpty(tlsClientKeyPath) ? decryptionStrategy.decryptPrivateKey(tlsClientKeyPath, true) : null,
130-
!isNullOrEmpty(tlsClientKeyPassword) ? tlsClientKeyPassword : null)
128+
!isNullOrEmpty(tlsClientCertPath) ? new FileInputStream(tlsClientCertPath) : null,
129+
!isNullOrEmpty(tlsClientKeyPath) ? decryptionStrategy.decryptPrivateKey(tlsClientKeyPath, true) : null,
130+
!isNullOrEmpty(tlsClientKeyPassword) ? tlsClientKeyPassword : null)
131131
.build();
132132
}
133133
} else {

0 commit comments

Comments
 (0)