Skip to content

Commit 657a378

Browse files
authored
optimize the certificate notice (#301)
1 parent 05c7fad commit 657a378

File tree

3 files changed

+56
-21
lines changed

3 files changed

+56
-21
lines changed

sdk-core/src/main/java/org/fisco/bcos/sdk/network/ConnectionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private boolean checkConnectionResult(
359359
/** connect success, check ssl handshake result. */
360360
SslHandler sslhandler = connectFuture.channel().pipeline().get(SslHandler.class);
361361
String checkerMessage =
362-
"! Please check the certificate and ensure that the SDK and the node are in the same agency!";
362+
"! Please make sure the certificate is correctly configured and copied, ensure that the SDK and the node are in the same agency!";
363363
if (Objects.isNull(sslhandler)) {
364364
String sslHandshakeFailedMessage =
365365
" ssl handshake failed:/"

sdk-core/src/main/java/org/fisco/bcos/sdk/network/NetworkException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public class NetworkException extends Exception {
2929
private int errorCode = 0;
3030

3131
public NetworkException(String message, int errorCode) {
32-
super(message + "\n" + SystemInformation.getSystemInformation());
32+
super(message);
3333
this.errorCode = errorCode;
3434
}
3535

3636
public NetworkException(String message) {
37-
super(message + "\n" + SystemInformation.getSystemInformation());
37+
super(message);
3838
}
3939

4040
public NetworkException(Throwable cause) {

sdk-core/src/main/java/org/fisco/bcos/sdk/network/NetworkImp.java

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.fisco.bcos.sdk.config.exceptions.ConfigException;
2626
import org.fisco.bcos.sdk.model.CryptoType;
2727
import org.fisco.bcos.sdk.model.Message;
28+
import org.fisco.bcos.sdk.utils.SystemInformation;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
3031

@@ -152,30 +153,39 @@ private CheckCertExistenceResult checkCertExistence(boolean isSM) {
152153
public void start() throws NetworkException {
153154
boolean tryEcdsaConnect = false;
154155
CheckCertExistenceResult result = null;
156+
String ecdsaCryptoInfo = configOption.getCryptoMaterialConfig().toString();
155157
try {
156158
try {
157159
result = checkCertExistence(false);
158160
if (result.isCheckPassed()) {
159161
logger.debug("start connManager with ECDSA sslContext");
160162
connManager.startConnect(configOption);
161163
connManager.startReconnectSchedule();
162-
tryEcdsaConnect = true;
163164
return;
164165
} else {
165166
logger.warn(
166-
"Try to connect node with ECDSA sslContext failed, expected certPath: "
167-
+ configOption.getCryptoMaterialConfig().toString()
167+
"Try to connect node with ECDSA sslContext failed, the tried NON-SM certPath: "
168+
+ ecdsaCryptoInfo
168169
+ ", currentPath: "
169170
+ new File("").getAbsolutePath());
170171
}
171172
} catch (NetworkException e) {
172-
tryEcdsaConnect = true;
173173
configOption.reloadConfig(CryptoType.SM_TYPE);
174-
result = checkCertExistence(true);
175-
if (e.getErrorCode() == NetworkException.CONNECT_FAILED
176-
|| !result.isCheckPassed()) {
177-
throw e;
174+
if (e.getErrorCode() == NetworkException.CONNECT_FAILED) {
175+
String errorMessage = e.getMessage();
176+
errorMessage +=
177+
"\n* If your blockchain is NON-SM, please provide the NON-SM certificates: "
178+
+ ecdsaCryptoInfo
179+
+ ".\n";
180+
errorMessage +=
181+
"\n* If your blockchain is SM, please provide the SM certificates: "
182+
+ configOption.getCryptoMaterialConfig().toString()
183+
+ "\n";
184+
throw new NetworkException(
185+
errorMessage + "\n" + SystemInformation.getSystemInformation());
178186
}
187+
// means that all the ECDSA certificates exist
188+
tryEcdsaConnect = true;
179189
connManager.stopNetty();
180190
logger.debug(
181191
"start connManager with the ECDSA sslContext failed, try to use SM sslContext, error info: {}",
@@ -186,24 +196,49 @@ public void start() throws NetworkException {
186196
result = checkCertExistence(true);
187197
if (!result.isCheckPassed()) {
188198
if (tryEcdsaConnect) {
189-
throw new NetworkException("Certificate not exist:" + result.getErrorMessage());
199+
String errorMessage =
200+
"\n* Try init the sslContext failed.\n\n* If your blockchain channel config is NON-SM, please provide the NON-SM certificates: "
201+
+ ecdsaCryptoInfo
202+
+ ".\n";
203+
errorMessage +=
204+
"\n* If your blockchain channel config is SM, please provide the missing certificates: "
205+
+ result.getErrorMessage()
206+
+ "\n";
207+
throw new NetworkException(errorMessage);
190208
} else {
191-
throw new NetworkException(
192-
"Not providing all the certificates to connect to the node! Please provide the certificates to connect with the block-chain, expected certPath: ["
209+
String errorMessage =
210+
"\n# Not providing all the certificates to connect to the node! Please provide the certificates to connect with the block-chain.\n";
211+
errorMessage +=
212+
"\n* If your blockchain is NON-SM, please provide the NON-SM certificates: "
213+
+ ecdsaCryptoInfo
214+
+ ". \n";
215+
errorMessage +=
216+
"\n* If your blockchain is SM, please provide the SM certificates: "
193217
+ configOption.getCryptoMaterialConfig().toString()
194-
+ "]");
218+
+ "\n";
219+
throw new NetworkException(errorMessage);
195220
}
196221
}
197-
if (tryEcdsaConnect) {
222+
try {
198223
// create a new connectionManager to connect the node with the SM sslContext
199224
connManager = new ConnectionManager(configOption, handler);
225+
connManager.startConnect(configOption);
226+
connManager.startReconnectSchedule();
227+
} catch (NetworkException e) {
228+
String errorMessage = e.getMessage();
229+
errorMessage +=
230+
"\n* If your blockchain channel config is NON-SM, please provide the NON-SM certificates: "
231+
+ ecdsaCryptoInfo
232+
+ ".\n";
233+
errorMessage +=
234+
"\n* If your blockchain channel config is SM, please provide the SM certificates: "
235+
+ configOption.getCryptoMaterialConfig().toString()
236+
+ "\n";
237+
throw new NetworkException(
238+
errorMessage + "\n" + SystemInformation.getSystemInformation());
200239
}
201-
connManager.startConnect(configOption);
202-
connManager.startReconnectSchedule();
203240
} catch (ConfigException e) {
204-
throw new NetworkException(
205-
"start connManager with the SM algorithm failed, error info: " + e.getMessage(),
206-
e);
241+
throw new NetworkException(e);
207242
}
208243
}
209244

0 commit comments

Comments
 (0)