@@ -1,5 +1,6 @@ | |||||
package com.jd.blockchain.crypto.utils.sm; | package com.jd.blockchain.crypto.utils.sm; | ||||
import com.jd.blockchain.utils.io.BytesUtils; | |||||
import org.bouncycastle.asn1.ASN1Encodable; | import org.bouncycastle.asn1.ASN1Encodable; | ||||
import org.bouncycastle.asn1.ASN1Integer; | import org.bouncycastle.asn1.ASN1Integer; | ||||
import org.bouncycastle.asn1.ASN1Sequence; | import org.bouncycastle.asn1.ASN1Sequence; | ||||
@@ -99,7 +100,7 @@ public class SM2Utils { | |||||
public static byte[] sign(byte[] data, byte[] privateKey, SecureRandom random, String ID){ | public static byte[] sign(byte[] data, byte[] privateKey, SecureRandom random, String ID){ | ||||
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(new BigInteger(1,privateKey), DOMAIN_PARAMS); | 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); | return sign(data,params); | ||||
} | } | ||||
@@ -153,8 +154,7 @@ public class SM2Utils { | |||||
ECPoint pubKeyPoint = resolvePubKeyBytes(publicKey); | ECPoint pubKeyPoint = resolvePubKeyBytes(publicKey); | ||||
ECPublicKeyParameters pubKey = new ECPublicKeyParameters(pubKeyPoint, DOMAIN_PARAMS); | 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); | return verify(data,params,signature); | ||||
} | } | ||||
@@ -6,6 +6,7 @@ import java.io.File; | |||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.lang.management.ManagementFactory; | import java.lang.management.ManagementFactory; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.nio.charset.StandardCharsets; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
@@ -49,7 +50,7 @@ public class GatewayBooter { | |||||
bootInfos.add(String.format("GW_BOOT_PID = [%s] \r\n", pid)); | bootInfos.add(String.format("GW_BOOT_PID = [%s] \r\n", pid)); | ||||
try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { | try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { | ||||
for (String bootInfo : bootInfos) { | for (String bootInfo : bootInfos) { | ||||
outputStream.write(bootInfo.getBytes()); | |||||
outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8)); | |||||
} | } | ||||
outputStream.flush(); | outputStream.flush(); | ||||
} | } | ||||
@@ -6,6 +6,7 @@ import java.io.IOException; | |||||
import java.lang.management.ManagementFactory; | import java.lang.management.ManagementFactory; | ||||
import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||
import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
import java.nio.charset.StandardCharsets; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.List; | import java.util.List; | ||||
@@ -70,7 +71,7 @@ public class PeerBooter { | |||||
bootInfos.add(String.format("PEER_BOOT_PID = [%s] \r\n", pid)); | bootInfos.add(String.format("PEER_BOOT_PID = [%s] \r\n", pid)); | ||||
try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { | try (FileOutputStream outputStream = new FileOutputStream(pidFile)) { | ||||
for (String bootInfo : bootInfos) { | for (String bootInfo : bootInfos) { | ||||
outputStream.write(bootInfo.getBytes()); | |||||
outputStream.write(bootInfo.getBytes(StandardCharsets.UTF_8)); | |||||
} | } | ||||
outputStream.flush(); | outputStream.flush(); | ||||
} | } | ||||
@@ -253,10 +253,10 @@ public class ContractLedgerContext implements LedgerContext { | |||||
public boolean isJson(String str) { | public boolean isJson(String str) { | ||||
boolean result = false; | boolean result = false; | ||||
try { | try { | ||||
Object obj=JSON.parse(str); | |||||
Object obj = JSON.parse(str); | |||||
result = true; | result = true; | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
result=false; | |||||
result = false; | |||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
@@ -278,10 +278,11 @@ public class ContractLedgerContext implements LedgerContext { | |||||
public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) { | public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) { | ||||
BytesValue bytesValue; | BytesValue bytesValue; | ||||
if (isJson(value)) { | if (isJson(value)) { | ||||
bytesValue = new BytesValueEntry(BytesValueType.JSON, value.getBytes()); | |||||
bytesValue = new BytesValueEntry(BytesValueType.JSON, BytesUtils.toBytes(value)); | |||||
} | } | ||||
else { | else { | ||||
bytesValue = new BytesValueEntry(BytesValueType.TEXT, value.getBytes()); | |||||
bytesValue = new BytesValueEntry(BytesValueType.TEXT, BytesUtils.toBytes(value)); | |||||
} | } | ||||
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion); | ||||
generatedOpList.add(op); | generatedOpList.add(op); | ||||
@@ -18,6 +18,7 @@ import com.jd.blockchain.utils.Bytes; | |||||
import com.jd.blockchain.utils.codec.Base58Utils; | import com.jd.blockchain.utils.codec.Base58Utils; | ||||
import com.jd.blockchain.utils.codec.HexUtils; | import com.jd.blockchain.utils.codec.HexUtils; | ||||
import com.jd.blockchain.utils.io.BytesSlice; | import com.jd.blockchain.utils.io.BytesSlice; | ||||
import com.jd.blockchain.utils.io.BytesUtils; | |||||
import org.apache.commons.codec.binary.Base64; | import org.apache.commons.codec.binary.Base64; | ||||
import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||
@@ -120,7 +121,7 @@ public class ClientOperationUtil { | |||||
String ledgerSeedStr = legerInitObj.getString("ledgerSeed"); | String ledgerSeedStr = legerInitObj.getString("ledgerSeed"); | ||||
// 种子需要做Base64转换 | // 种子需要做Base64转换 | ||||
ledgerInitSettingData.setLedgerSeed(Base64.decodeBase64(ledgerSeedStr.getBytes())); | |||||
ledgerInitSettingData.setLedgerSeed(Base64.decodeBase64(BytesUtils.toBytes(ledgerSeedStr))); | |||||
String consensusProvider = legerInitObj.getString("consensusProvider"); | String consensusProvider = legerInitObj.getString("consensusProvider"); | ||||
@@ -175,7 +176,7 @@ public class ClientOperationUtil { | |||||
BlockchainIdentityData blockchainIdentity = blockchainIdentity(contract); | BlockchainIdentityData blockchainIdentity = blockchainIdentity(contract); | ||||
String chainCodeStr = jsonObject.getString("chainCode"); | String chainCodeStr = jsonObject.getString("chainCode"); | ||||
ContractCodeDeployOpTemplate contractCodeDeployOpTemplate = new ContractCodeDeployOpTemplate(blockchainIdentity, chainCodeStr.getBytes()); | |||||
ContractCodeDeployOpTemplate contractCodeDeployOpTemplate = new ContractCodeDeployOpTemplate(blockchainIdentity, BytesUtils.toBytes(chainCodeStr)); | |||||
return contractCodeDeployOpTemplate; | return contractCodeDeployOpTemplate; | ||||
} | } | ||||
@@ -184,7 +185,7 @@ public class ClientOperationUtil { | |||||
String contractAddress = contractAddressObj.getString("value"); | String contractAddress = contractAddressObj.getString("value"); | ||||
String argsStr = jsonObject.getString("args"); | String argsStr = jsonObject.getString("args"); | ||||
String event = jsonObject.getString("event"); | 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) { | private static BlockchainIdentityData blockchainIdentity(JSONObject jsonObject) { | ||||
@@ -30,6 +30,7 @@ import com.jd.blockchain.tools.initializer.LedgerInitProperties; | |||||
import com.jd.blockchain.tools.keygen.KeyGenCommand; | import com.jd.blockchain.tools.keygen.KeyGenCommand; | ||||
import com.jd.blockchain.transaction.*; | import com.jd.blockchain.transaction.*; | ||||
import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
import com.jd.blockchain.utils.io.BytesUtils; | |||||
import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; | import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; | ||||
import java.util.*; | import java.util.*; | ||||
@@ -210,7 +211,7 @@ public class MockerNodeContext implements BlockchainQueryService { | |||||
// 合约发布 | // 合约发布 | ||||
// 注意此处只是将其放入内存中,而不需要真正编译为字节码 | // 注意此处只是将其放入内存中,而不需要真正编译为字节码 | ||||
TxBuilder txBuilder = txBuilder(); | TxBuilder txBuilder = txBuilder(); | ||||
txBuilder.contracts().deploy(contractIdentity, contract.getClass().getName().getBytes()); | |||||
txBuilder.contracts().deploy(contractIdentity, BytesUtils.toBytes(contract.getClass().getName())); | |||||
// 执行 | // 执行 | ||||
txProcess(txRequest(txBuilder)); | txProcess(txRequest(txBuilder)); | ||||
return contractIdentity; | return contractIdentity; | ||||
@@ -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 |
@@ -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.crypto.HashDigest; | ||||
import com.jd.blockchain.mocker.MockerNodeContext; | import com.jd.blockchain.mocker.MockerNodeContext; |
@@ -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.crypto.HashDigest; | ||||
import com.jd.blockchain.ledger.BlockchainKeyGenerator; | import com.jd.blockchain.ledger.BlockchainKeyGenerator; |
@@ -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.crypto.HashDigest; | ||||
import com.jd.blockchain.ledger.KVDataEntry; | import com.jd.blockchain.ledger.KVDataEntry; |
@@ -1,5 +1,7 @@ | |||||
package com.jd.blockchain.utils.security; | package com.jd.blockchain.utils.security; | ||||
import com.jd.blockchain.utils.io.BytesUtils; | |||||
import javax.crypto.Cipher; | import javax.crypto.Cipher; | ||||
import javax.crypto.KeyGenerator; | import javax.crypto.KeyGenerator; | ||||
import javax.crypto.SecretKey; | import javax.crypto.SecretKey; | ||||
@@ -32,7 +34,7 @@ public class DESUtils { | |||||
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES); | SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES); | ||||
SecretKey secretKey = keyFactory.generateSecret(keySpec); | SecretKey secretKey = keyFactory.generateSecret(keySpec); | ||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey); | cipher.init(Cipher.ENCRYPT_MODE, secretKey); | ||||
return cipher.doFinal(code.getBytes()); | |||||
return cipher.doFinal(BytesUtils.toBytes(code)); | |||||
} | } | ||||
/** DES解密 */ | /** DES解密 */ | ||||