diff --git a/source/crypto/crypto-sm/src/main/java/com/jd/blockchain/crypto/utils/sm/SM2Utils.java b/source/crypto/crypto-sm/src/main/java/com/jd/blockchain/crypto/utils/sm/SM2Utils.java index 47fe9f6c..7a993c1d 100644 --- a/source/crypto/crypto-sm/src/main/java/com/jd/blockchain/crypto/utils/sm/SM2Utils.java +++ b/source/crypto/crypto-sm/src/main/java/com/jd/blockchain/crypto/utils/sm/SM2Utils.java @@ -1,5 +1,6 @@ package com.jd.blockchain.crypto.utils.sm; +import com.jd.blockchain.utils.io.BytesUtils; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1Integer; import org.bouncycastle.asn1.ASN1Sequence; @@ -99,7 +100,7 @@ public class SM2Utils { public static byte[] sign(byte[] data, byte[] privateKey, SecureRandom random, String ID){ ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(new BigInteger(1,privateKey), DOMAIN_PARAMS); - CipherParameters params = new ParametersWithID(new ParametersWithRandom(privKey,random),ID.getBytes()); + CipherParameters params = new ParametersWithID(new ParametersWithRandom(privKey,random), BytesUtils.toBytes(ID)); return sign(data,params); } @@ -153,8 +154,7 @@ public class SM2Utils { ECPoint pubKeyPoint = resolvePubKeyBytes(publicKey); ECPublicKeyParameters pubKey = new ECPublicKeyParameters(pubKeyPoint, DOMAIN_PARAMS); - ParametersWithID params = new ParametersWithID(pubKey,ID.getBytes()); - + ParametersWithID params = new ParametersWithID(pubKey, BytesUtils.toBytes(ID)); return verify(data,params,signature); } diff --git a/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java b/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java index 2cec1a5f..93ca75ff 100644 --- a/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java +++ b/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java @@ -6,6 +6,7 @@ import java.io.File; import java.io.FileOutputStream; import java.lang.management.ManagementFactory; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -49,7 +50,7 @@ public class GatewayBooter { bootInfos.add(String.format("GW_BOOT_PID = [%s] \r\n", pid)); try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { for (String bootInfo : bootInfos) { - outputStream.write(bootInfo.getBytes()); + outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8)); } outputStream.flush(); } diff --git a/source/deployment/deployment-peer/src/main/java/com/jd/blockchain/boot/peer/PeerBooter.java b/source/deployment/deployment-peer/src/main/java/com/jd/blockchain/boot/peer/PeerBooter.java index 1bde8881..c8784892 100644 --- a/source/deployment/deployment-peer/src/main/java/com/jd/blockchain/boot/peer/PeerBooter.java +++ b/source/deployment/deployment-peer/src/main/java/com/jd/blockchain/boot/peer/PeerBooter.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -70,7 +71,7 @@ public class PeerBooter { bootInfos.add(String.format("PEER_BOOT_PID = [%s] \r\n", pid)); try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { for (String bootInfo : bootInfos) { - outputStream.write(bootInfo.getBytes()); + outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8)); } outputStream.flush(); } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java index 43595152..60d418a5 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java @@ -253,10 +253,10 @@ public class ContractLedgerContext implements LedgerContext { public boolean isJson(String str) { boolean result = false; try { - Object obj=JSON.parse(str); + Object obj = JSON.parse(str); result = true; } catch (Exception e) { - result=false; + result = false; } return result; } @@ -278,10 +278,11 @@ public class ContractLedgerContext implements LedgerContext { public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) { BytesValue bytesValue; if (isJson(value)) { - bytesValue = new BytesValueEntry(BytesValueType.JSON, value.getBytes()); + + bytesValue = new BytesValueEntry(BytesValueType.JSON, BytesUtils.toBytes(value)); } else { - bytesValue = new BytesValueEntry(BytesValueType.TEXT, value.getBytes()); + bytesValue = new BytesValueEntry(BytesValueType.TEXT, BytesUtils.toBytes(value)); } this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); generatedOpList.add(op); diff --git a/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/ClientOperationUtil.java b/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/ClientOperationUtil.java index f5790c06..c8fd9de8 100644 --- a/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/ClientOperationUtil.java +++ b/source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/ClientOperationUtil.java @@ -18,6 +18,7 @@ import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.codec.Base58Utils; import com.jd.blockchain.utils.codec.HexUtils; import com.jd.blockchain.utils.io.BytesSlice; +import com.jd.blockchain.utils.io.BytesUtils; import org.apache.commons.codec.binary.Base64; import java.lang.reflect.Field; @@ -120,7 +121,7 @@ public class ClientOperationUtil { String ledgerSeedStr = legerInitObj.getString("ledgerSeed"); // 种子需要做Base64转换 - ledgerInitSettingData.setLedgerSeed(Base64.decodeBase64(ledgerSeedStr.getBytes())); + ledgerInitSettingData.setLedgerSeed(Base64.decodeBase64(BytesUtils.toBytes(ledgerSeedStr))); String consensusProvider = legerInitObj.getString("consensusProvider"); @@ -175,7 +176,7 @@ public class ClientOperationUtil { BlockchainIdentityData blockchainIdentity = blockchainIdentity(contract); String chainCodeStr = jsonObject.getString("chainCode"); - ContractCodeDeployOpTemplate contractCodeDeployOpTemplate = new ContractCodeDeployOpTemplate(blockchainIdentity, chainCodeStr.getBytes()); + ContractCodeDeployOpTemplate contractCodeDeployOpTemplate = new ContractCodeDeployOpTemplate(blockchainIdentity, BytesUtils.toBytes(chainCodeStr)); return contractCodeDeployOpTemplate; } @@ -184,7 +185,7 @@ public class ClientOperationUtil { String contractAddress = contractAddressObj.getString("value"); String argsStr = jsonObject.getString("args"); String event = jsonObject.getString("event"); - return new ContractEventSendOpTemplate(Bytes.fromBase58(contractAddress), event, argsStr.getBytes()); + return new ContractEventSendOpTemplate(Bytes.fromBase58(contractAddress), event, BytesUtils.toBytes(argsStr)); } private static BlockchainIdentityData blockchainIdentity(JSONObject jsonObject) { diff --git a/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java b/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java index 08df2cc5..7d91a198 100644 --- a/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java +++ b/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java @@ -30,6 +30,7 @@ import com.jd.blockchain.tools.initializer.LedgerInitProperties; import com.jd.blockchain.tools.keygen.KeyGenCommand; import com.jd.blockchain.transaction.*; import com.jd.blockchain.utils.Bytes; +import com.jd.blockchain.utils.io.BytesUtils; import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; import java.util.*; @@ -210,7 +211,7 @@ public class MockerNodeContext implements BlockchainQueryService { // 合约发布 // 注意此处只是将其放入内存中,而不需要真正编译为字节码 TxBuilder txBuilder = txBuilder(); - txBuilder.contracts().deploy(contractIdentity, contract.getClass().getName().getBytes()); + txBuilder.contracts().deploy(contractIdentity, BytesUtils.toBytes(contract.getClass().getName())); // 执行 txProcess(txRequest(txBuilder)); return contractIdentity; diff --git a/source/tools/tools-mocker/src/main/resources/bftsmart.config b/source/tools/tools-mocker/src/main/resources/bftsmart.config new file mode 100644 index 00000000..870fcde2 --- /dev/null +++ b/source/tools/tools-mocker/src/main/resources/bftsmart.config @@ -0,0 +1,167 @@ +# Copyright (c) 2007-2013 Alysson Bessani, Eduardo Alchieri, Paulo Sousa, and the authors indicated in the @author tags +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +############################################ +###### Consensus Commit Block Parameters: transaction count ###### +############################################ +system.block.txsize=500 + +############################################ +###### Consensus Commit Block Parameters: delay time ###### +############################################ +system.block.maxdelay=5000 + +############################################ +###### #Consensus Participant0 ###### +############################################ + +system.server.0.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 +system.server.0.network.host=127.0.0.1 +system.server.0.network.port=16000 +system.server.0.network.secure=false + +############################################ +###### #Consensus Participant1 ###### +############################################ + +system.server.1.pubkey=3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX +system.server.1.network.host=127.0.0.1 +system.server.1.network.port=16100 +system.server.1.network.secure=false + +############################################ +###### #Consensus Participant2 ###### +############################################ + +system.server.2.pubkey=3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x +system.server.2.network.host=127.0.0.1 +system.server.2.network.port=16200 +system.server.2.network.secure=false + +############################################ +###### #Consensus Participant3 ###### +############################################ + +system.server.3.pubkey=3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk +system.server.3.network.host=127.0.0.1 +system.server.3.network.port=16300 +system.server.3.network.secure=false + +############################################ +####### Communication Configurations ####### +############################################ + +#HMAC algorithm used to authenticate messages between processes (HmacMD5 is the default value) +#This parameter is not currently being used +#system.authentication.hmacAlgorithm = HmacSHA1 + +#Specify if the communication system should use a thread to send data (true or false) +system.communication.useSenderThread = true + +#Force all processes to use the same public/private keys pair and secret key. This is useful when deploying experiments +#and benchmarks, but must not be used in production systems. +system.communication.defaultkeys = true + +############################################ +### Replication Algorithm Configurations ### +############################################ + +#Number of servers in the group +system.servers.num = 4 + +#Maximum number of faulty replicas +system.servers.f = 1 + +#Timeout to asking for a client request +system.totalordermulticast.timeout = 2000 + +#Maximum batch size (in number of messages) +system.totalordermulticast.maxbatchsize = 500 + +#Number of nonces (for non-determinism actions) generated +system.totalordermulticast.nonces = 10 + +#if verification of leader-generated timestamps are increasing +#it can only be used on systems in which the network clocks +#are synchronized +system.totalordermulticast.verifyTimestamps = false + +#Quantity of messages that can be stored in the receive queue of the communication system +system.communication.inQueueSize = 500000 + +# Quantity of messages that can be stored in the send queue of each replica +system.communication.outQueueSize = 500000 + +#Set to 1 if SMaRt should use signatures, set to 0 if otherwise +system.communication.useSignatures = 0 + +#Set to 1 if SMaRt should use MAC's, set to 0 if otherwise +system.communication.useMACs = 1 + +#Set to 1 if SMaRt should use the standard output to display debug messages, set to 0 if otherwise +system.debug = 0 + +#Print information about the replica when it is shutdown +system.shutdownhook = true + +############################################ +###### State Transfer Configurations ####### +############################################ + +#Activate the state transfer protocol ('true' to activate, 'false' to de-activate) +system.totalordermulticast.state_transfer = true + +#Maximum ahead-of-time message not discarded +system.totalordermulticast.highMark = 10000 + +#Maximum ahead-of-time message not discarded when the replica is still on EID 0 (after which the state transfer is triggered) +system.totalordermulticast.revival_highMark = 10 + +#Number of ahead-of-time messages necessary to trigger the state transfer after a request timeout occurs +system.totalordermulticast.timeout_highMark = 200 + +############################################ +###### Log and Checkpoint Configurations ### +############################################ + +system.totalordermulticast.log = true +system.totalordermulticast.log_parallel = false +system.totalordermulticast.log_to_disk = false +system.totalordermulticast.sync_log = false + +#Period at which BFT-SMaRt requests the state to the application (for the state transfer state protocol) +system.totalordermulticast.checkpoint_period = 1000 +system.totalordermulticast.global_checkpoint_period = 120000 + +system.totalordermulticast.checkpoint_to_disk = false +system.totalordermulticast.sync_ckp = false + + +############################################ +###### Reconfiguration Configurations ###### +############################################ + +#Replicas ID for the initial view, separated by a comma. +# The number of replicas in this parameter should be equal to that specified in 'system.servers.num' +system.initial.view = 0,1,2,3 + +#The ID of the trust third party (TTP) +system.ttp.id = 7002 + +#This sets if the system will function in Byzantine or crash-only mode. Set to "true" to support Byzantine faults +system.bft = true + +#Custom View Storage; +#view.storage.handler=bftsmart.reconfiguration.views.DefaultViewStorage \ No newline at end of file diff --git a/source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/AccountMockerTest.java b/source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/AccountMockerTest.java similarity index 97% rename from source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/AccountMockerTest.java rename to source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/AccountMockerTest.java index 55699a40..d52a3732 100644 --- a/source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/AccountMockerTest.java +++ b/source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/AccountMockerTest.java @@ -1,4 +1,4 @@ -package com.jd.blockchain.test; +package test.com.jd.blockchain.contract; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.mocker.MockerNodeContext; diff --git a/source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/MockTest.java b/source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/MockTest.java similarity index 98% rename from source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/MockTest.java rename to source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/MockTest.java index 7cd85dbc..b9362607 100644 --- a/source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/MockTest.java +++ b/source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/MockTest.java @@ -1,4 +1,4 @@ -package com.jd.blockchain.test; +package test.com.jd.blockchain.contract; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.BlockchainKeyGenerator; diff --git a/source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/SampleTest.java b/source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/SampleTest.java similarity index 97% rename from source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/SampleTest.java rename to source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/SampleTest.java index e66d534e..c388ef99 100644 --- a/source/tools/tools-mocker/src/test/java/com/jd/blockchain/test/SampleTest.java +++ b/source/tools/tools-mocker/src/test/java/test/com/jd/blockchain/contract/SampleTest.java @@ -1,4 +1,4 @@ -package com.jd.blockchain.test; +package test.com.jd.blockchain.contract; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.KVDataEntry; diff --git a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/security/DESUtils.java b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/security/DESUtils.java index fb74c378..064f8a1b 100644 --- a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/security/DESUtils.java +++ b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/security/DESUtils.java @@ -1,5 +1,7 @@ package com.jd.blockchain.utils.security; +import com.jd.blockchain.utils.io.BytesUtils; + import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; @@ -32,7 +34,7 @@ public class DESUtils { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES); SecretKey secretKey = keyFactory.generateSecret(keySpec); cipher.init(Cipher.ENCRYPT_MODE, secretKey); - return cipher.doFinal(code.getBytes()); + return cipher.doFinal(BytesUtils.toBytes(code)); } /** DES解密 */