Skip to content

Commit d97c291

Browse files
authored
Merge pull request #358 from cyjseagull/dev-2.8.1
sync code from master
2 parents 874a00b + 8d04737 commit d97c291

File tree

19 files changed

+212
-100
lines changed

19 files changed

+212
-100
lines changed

.ci/ci_check.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22

33
set -e
4+
tag="v2.8.0"
45
LOG_INFO() {
56
local content=${1}
67
echo -e "\033[32m ${content}\033[0m"
@@ -28,7 +29,6 @@ download_tassl()
2829

2930
download_build_chain()
3031
{
31-
tag=$(curl -sS "https://gitee.com/api/v5/repos/FISCO-BCOS/FISCO-BCOS/tags" | grep -oe "\"name\":\"v[2-9]*\.[0-9]*\.[0-9]*\"" | cut -d \" -f 4 | sort -V | tail -n 1)
3232
LOG_INFO "--- current tag: $tag"
3333
curl -LO "https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/${tag}/build_chain.sh" && chmod u+x build_chain.sh
3434
}

Changelog.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
## v2.8.0
2+
(2021-07-27)
3+
Added:
4+
* Using Hardware Secure Module(HSM) to make cryptography operations.
5+
* Support use PCI crypto card or crypto machine to make SM2 SM3 calculation.
6+
* Support use HSM internal key to sign transaction.
7+
8+
Update:
9+
* Update crypto dependency version of sdk-crypto module.
10+
* Support to read the certificate from the jar package.
11+
* The interface that sent the transaction returns the transaction hash.
12+
* Add VRF random number generation and random number verification interface.
13+
14+
----
15+
添加:
16+
* 新增支持使用硬件加密模块进行密码计算。
17+
* 支持使用符合国密《GMT0018-2012密码设备应用接口规范》标准的PCI加密卡/加密机进行SM2,SM3运算。
18+
* 支持使用密码卡/密码机内部密钥进行交易签名。
19+
20+
更新:
21+
* 更新sdk-crypto模块所使用的密码算法库版本。
22+
* 支持从jar包中读取证书。
23+
* 发送交易的接口返回交易哈希。
24+
* 添加VRF随机数生成和随机数验证接口。
25+
126
## v2.7.2
227
(2021-03-24)
328
Please read documentation of Java SDK.

build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ ext {
2121
javapoetVersion = "1.7.0"
2222
picocliVersion = "3.6.0"
2323
nettyVersion = "4.1.53.Final"
24-
nettySMSSLContextVersion = "1.2.0"
24+
nettySMSSLContextVersion = "1.3.0"
2525
toml4jVersion = "0.7.2"
2626
bcprovJDK15onVersion = "1.60"
27-
webankJavaCryptoVersion = "1.0.0-005-SNAPSHOT"
28-
webankHsmCryptoVersion = "1.0.0-008-SNAPSHOT"
27+
webankJavaCryptoVersion = "1.0.0"
28+
webankHsmCryptoVersion = "1.0.0-GMT0018"
2929

3030
slf4jVersion = "1.7.30"
3131
junitVersion = "4.12"
@@ -37,7 +37,7 @@ ext {
3737
// integrationTest.mustRunAfter test
3838
allprojects {
3939
group = 'org.fisco-bcos.java-sdk'
40-
version = '2.8.0-SNAPSHOT'
40+
version = '2.8.0-GMT0018'
4141
apply plugin: 'maven'
4242
apply plugin: 'maven-publish'
4343
apply plugin: 'idea'
@@ -72,6 +72,7 @@ allprojects {
7272

7373
dependencies {
7474
compile ("org.slf4j:slf4j-api:${slf4jVersion}")
75+
compile ("org.slf4j:slf4j-log4j12:${slf4jVersion}")
7576
testCompile ("junit:junit:${junitVersion}")
7677
}
7778

sdk-core/src/main/java/org/fisco/bcos/sdk/config/model/AccountConfig.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ public AccountConfig(ConfigProperty configProperty) throws ConfigException {
5252
}
5353

5454
private void checkAccountConfig(ConfigProperty configProperty) throws ConfigException {
55-
Map<String, Object> cryptoProvider = configProperty.getCryptoProvider();
56-
if (cryptoProvider != null) {
57-
String cryptoType = ConfigProperty.getValue(cryptoProvider, "type", SSM);
58-
if (cryptoType != null && cryptoType.equals(HSM)) {
59-
if (!this.accountKeyIndex.equals("") && this.accountPassword.equals("")) {
60-
throw new ConfigException(
61-
"cannot load hsm inner key, please config the password");
62-
}
55+
Map<String, Object> cryptoMaterial = configProperty.getCryptoMaterial();
56+
String cryptoType = SSM;
57+
if (cryptoMaterial != null) {
58+
cryptoType = ConfigProperty.getValue(cryptoMaterial, "cryptoProvider", SSM);
59+
}
60+
if (cryptoType.equalsIgnoreCase(HSM)) {
61+
if (accountKeyIndex == null) {
62+
throw new ConfigException(
63+
"load account failed, you are using hardware secure moduele(HSM), please config accountKeyIndex.");
6364
}
65+
return;
6466
}
6567
if (this.accountAddress.equals("")) {
6668
return;

sdk-core/src/main/java/org/fisco/bcos/sdk/config/model/CryptoMaterialConfig.java

+47
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package org.fisco.bcos.sdk.config.model;
1717

18+
import static org.fisco.bcos.sdk.model.CryptoProviderType.SSM;
19+
1820
import java.io.File;
1921
import java.io.InputStream;
2022
import java.util.Map;
@@ -32,6 +34,9 @@ public class CryptoMaterialConfig {
3234
private String sdkPrivateKeyPath;
3335
private String enSSLCertPath;
3436
private String enSSLPrivateKeyPath;
37+
private String cryptoProvider = "ssm";
38+
private String sslKeyIndex;
39+
private String enSslKeyIndex;
3540

3641
private InputStream caInputStream;
3742
private InputStream sdkCertInputStream;
@@ -113,6 +118,22 @@ public CryptoMaterialConfig(ConfigProperty configProperty, int cryptoType)
113118
cryptoMaterialProperty,
114119
"enSslKey",
115120
defaultCryptoMaterialConfig.getEnSSLPrivateKeyPath()));
121+
this.cryptoProvider =
122+
ConfigProperty.getValue(
123+
cryptoMaterialProperty,
124+
"cryptoProvider",
125+
defaultCryptoMaterialConfig.getCryptoProvider());
126+
this.sslKeyIndex =
127+
ConfigProperty.getValue(
128+
cryptoMaterialProperty,
129+
"sslKeyIndex",
130+
defaultCryptoMaterialConfig.getSslKeyIndex());
131+
this.enSslKeyIndex =
132+
ConfigProperty.getValue(
133+
cryptoMaterialProperty,
134+
"enSslKeyIndex",
135+
defaultCryptoMaterialConfig.getEnSslKeyIndex());
136+
116137
logger.debug(
117138
"Load cryptoMaterial, caCertPath: {}, sdkCertPath: {}, sdkPrivateKeyPath:{}, enSSLCertPath: {}, enSSLPrivateKeyPath:{}",
118139
this.getCaCertPath(),
@@ -131,6 +152,7 @@ public CryptoMaterialConfig getDefaultCaCertPath(int cryptoType, String certPath
131152
cryptoMaterialConfig.setCaCertPath(certPath + File.separator + "ca.crt");
132153
cryptoMaterialConfig.setSdkCertPath(certPath + File.separator + "sdk.crt");
133154
cryptoMaterialConfig.setSdkPrivateKeyPath(certPath + File.separator + "sdk.key");
155+
cryptoMaterialConfig.setCryptoProvider(SSM);
134156
} else if (cryptoType == CryptoType.SM_TYPE) {
135157
cryptoMaterialConfig.setCaCertPath(
136158
certPath + File.separator + smDir + File.separator + "gmca.crt");
@@ -142,6 +164,7 @@ public CryptoMaterialConfig getDefaultCaCertPath(int cryptoType, String certPath
142164
certPath + File.separator + smDir + File.separator + "gmensdk.crt");
143165
cryptoMaterialConfig.setEnSSLPrivateKeyPath(
144166
certPath + File.separator + smDir + File.separator + "gmensdk.key");
167+
cryptoMaterialConfig.setCryptoProvider(SSM);
145168
} else {
146169
throw new ConfigException(
147170
"load CryptoMaterialConfig failed, only support ecdsa and sm now, expected 0 or 1, but provided "
@@ -246,6 +269,30 @@ public void setEnSSLPrivateKeyInputStream(InputStream enSSLPrivateKeyInputStream
246269
this.enSSLPrivateKeyInputStream = enSSLPrivateKeyInputStream;
247270
}
248271

272+
public String getCryptoProvider() {
273+
return cryptoProvider;
274+
}
275+
276+
public void setCryptoProvider(String cryptoProvider) {
277+
this.cryptoProvider = cryptoProvider;
278+
}
279+
280+
public String getSslKeyIndex() {
281+
return sslKeyIndex;
282+
}
283+
284+
public void setSslKeyIndex(String sslKeyIndex) {
285+
this.sslKeyIndex = sslKeyIndex;
286+
}
287+
288+
public String getEnSslKeyIndex() {
289+
return enSslKeyIndex;
290+
}
291+
292+
public void setEnSslKeyIndex(String enSslKeyIndex) {
293+
this.enSslKeyIndex = enSslKeyIndex;
294+
}
295+
249296
@Override
250297
public String toString() {
251298
return "CryptoMaterialConfig{"

sdk-core/src/main/java/org/fisco/bcos/sdk/model/PrecompiledConstant.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public class PrecompiledConstant {
1818
// constant value
19-
public static final int CNS_MAX_VERSION_LENGTH = 40;
19+
public static final int CNS_MAX_VERSION_LENGTH = 128;
2020
public static final int TABLE_KEY_MAX_LENGTH = 255;
2121
public static final int TABLE_FIELD_NAME_MAX_LENGTH = 64;
2222
public static final int USER_TABLE_NAME_MAX_LENGTH = 48;

sdk-core/src/main/java/org/fisco/bcos/sdk/model/PrecompiledRetCode.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PrecompiledRetCode {
3838
public static final RetCode CODE_COMMITTEE_MEMBER_CANNOT_BE_OPERATOR =
3939
new RetCode(-52005, "The committee member cannot be operator");
4040
public static final RetCode CODE_OPERATOR_CANNOT_BE_COMMITTEE_MEMBER =
41-
new RetCode(-52004, "The operator cannot be committee member");
41+
new RetCode(-52004, "The operator or cnsManager cannot be committee member");
4242
public static final RetCode CODE_INVALID_THRESHOLD =
4343
new RetCode(-52003, "Invalid threshold, threshold should from 0 to 99");
4444
public static final RetCode CODE_INVALID_REQUEST_PERMISSION_DENIED =
@@ -51,7 +51,8 @@ public class PrecompiledRetCode {
5151
// ContractLifeCyclePrecompiled -51999 ~ -51900
5252
public static final RetCode CODE_INVALID_REVOKE_LAST_AUTHORIZATION =
5353
new RetCode(
54-
-51907, "The permission of the last contract status manager can't be revoked");
54+
-51907,
55+
"There is only one contract status manager left, and the revoke operation cannot be performed");
5556
public static final RetCode CODE_INVALID_NON_EXIST_AUTHORIZATION =
5657
new RetCode(-51906, "The contract status manager doesn't exist");
5758
public static final RetCode CODE_INVALID_NO_AUTHORIZED =

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

+39-22
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package org.fisco.bcos.sdk.network;
1717

18+
import static org.fisco.bcos.sdk.model.CryptoProviderType.HSM;
19+
1820
import io.netty.bootstrap.Bootstrap;
1921
import io.netty.channel.Channel;
2022
import io.netty.channel.ChannelFuture;
@@ -34,11 +36,7 @@
3436
import io.netty.handler.timeout.IdleStateHandler;
3537
import io.netty.util.concurrent.Future;
3638
import java.io.IOException;
37-
import java.security.NoSuchAlgorithmException;
38-
import java.security.NoSuchProviderException;
3939
import java.security.Security;
40-
import java.security.cert.CertificateException;
41-
import java.security.spec.InvalidKeySpecException;
4240
import java.util.ArrayList;
4341
import java.util.List;
4442
import java.util.Map;
@@ -96,8 +94,13 @@ public void startConnect(ConfigOption configOption) throws NetworkException {
9694
}
9795
logger.debug(" start connect. ");
9896
/** init netty * */
99-
initNetty(configOption);
100-
running = true;
97+
try {
98+
initNetty(configOption);
99+
running = true;
100+
} catch (Exception e) {
101+
logger.debug("init failed " + e.getMessage());
102+
throw new NetworkException("init failed " + e.getMessage());
103+
}
101104

102105
/** try connection */
103106
for (ConnectionInfo connect : connectionInfoList) {
@@ -263,27 +266,34 @@ private SslContext initSMSslContext(ConfigOption configOption) throws NetworkExc
263266
try {
264267
// Get file, file existence is already checked when check config file.
265268
// Init SslContext
266-
logger.info(" build SM ssl context with configured certificates ");
267269
return SMSslClientContextFactory.build(
268270
configOption.getCryptoMaterialConfig().getCaInputStream(),
269271
configOption.getCryptoMaterialConfig().getEnSSLCertInputStream(),
270272
configOption.getCryptoMaterialConfig().getEnSSLPrivateKeyInputStream(),
271273
configOption.getCryptoMaterialConfig().getSdkCertInputStream(),
272274
configOption.getCryptoMaterialConfig().getSdkPrivateKeyInputStream());
273-
} catch (IOException
274-
| CertificateException
275-
| NoSuchAlgorithmException
276-
| InvalidKeySpecException
277-
| NoSuchProviderException e) {
278-
logger.error(
279-
"initSMSslContext failed, caCert:{}, sslCert: {}, sslKey: {}, enCert: {}, enKey: {}, error: {}, e: {}",
280-
configOption.getCryptoMaterialConfig().getCaCertPath(),
281-
configOption.getCryptoMaterialConfig().getSdkCertPath(),
282-
configOption.getCryptoMaterialConfig().getSdkPrivateKeyPath(),
283-
configOption.getCryptoMaterialConfig().getEnSSLCertPath(),
284-
configOption.getCryptoMaterialConfig().getEnSSLPrivateKeyPath(),
285-
e.getMessage(),
286-
e);
275+
} catch (Exception e) {
276+
if (configOption.getCryptoMaterialConfig().getCryptoProvider().equalsIgnoreCase(HSM)) {
277+
logger.error(
278+
"initSMSslContext failed, caCert:{}, sslCert: {}, sslKeyIndex: {}, enCert: {}, enSslKeyIndex: {}, error: {}, e: {}",
279+
configOption.getCryptoMaterialConfig().getCaCertPath(),
280+
configOption.getCryptoMaterialConfig().getSdkCertPath(),
281+
configOption.getCryptoMaterialConfig().getSslKeyIndex(),
282+
configOption.getCryptoMaterialConfig().getEnSSLCertPath(),
283+
configOption.getCryptoMaterialConfig().getEnSslKeyIndex(),
284+
e.getMessage(),
285+
e);
286+
} else {
287+
logger.error(
288+
"initSMSslContext failed, caCert:{}, sslCert: {}, sslKey: {}, enCert: {}, enSslKey: {}, error: {}, e: {}",
289+
configOption.getCryptoMaterialConfig().getCaCertPath(),
290+
configOption.getCryptoMaterialConfig().getSdkCertPath(),
291+
configOption.getCryptoMaterialConfig().getSdkPrivateKeyPath(),
292+
configOption.getCryptoMaterialConfig().getEnSSLCertPath(),
293+
configOption.getCryptoMaterialConfig().getEnSSLPrivateKeyPath(),
294+
e.getMessage(),
295+
e);
296+
}
287297
throw new NetworkException(
288298
"SSL context init failed, please make sure your cert and key files are properly configured. error info: "
289299
+ e.getMessage(),
@@ -299,7 +309,14 @@ private void initNetty(ConfigOption configOption) throws NetworkException {
299309
// set connection timeout
300310
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) TimeoutConfig.connectTimeout);
301311
int sslCryptoType = configOption.getCryptoMaterialConfig().getSslCryptoType();
302-
SslContext sslContext =
312+
SslContext sslContext;
313+
if (configOption.getCryptoMaterialConfig().getCryptoProvider() != null
314+
&& configOption.getCryptoMaterialConfig().getCryptoProvider().equalsIgnoreCase(HSM)
315+
&& sslCryptoType == CryptoType.ECDSA_TYPE) {
316+
throw new NetworkException(
317+
"NON-SM not support hardware secure module yet, please do not config cryptoMatirial.cryptoProvider = hsm.");
318+
}
319+
sslContext =
303320
(sslCryptoType == CryptoType.ECDSA_TYPE
304321
? initSslContext(configOption)
305322
: initSMSslContext(configOption));

0 commit comments

Comments
 (0)