Separate NodeKey from implementation (#690)

This change allows the newly defined "SecurityModule" to work against a generic API, while the NodeKey interface adapts these generic types to the types already used throughout Besu (i.e. those defined in Secp256k1).

Signed-off-by: Trent Mohay <trent.mohay@consensys.net>
pull/704/head
Trent Mohay 5 years ago committed by GitHub
parent 36bdae457b
commit 57d0379bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      besu/build.gradle
  2. 4
      besu/src/main/java/org/hyperledger/besu/cli/subcommands/PublicKeySubCommand.java
  3. 4
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  4. 4
      besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
  5. 4
      besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
  6. 6
      besu/src/test/java/org/hyperledger/besu/RunnerTest.java
  7. 4
      besu/src/test/java/org/hyperledger/besu/chainexport/RlpBlockExporterTest.java
  8. 4
      besu/src/test/java/org/hyperledger/besu/chainimport/JsonBlockImporterTest.java
  9. 6
      besu/src/test/java/org/hyperledger/besu/chainimport/RlpBlockImporterTest.java
  10. 1
      consensus/clique/build.gradle
  11. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/CliqueProtocolScheduleTest.java
  12. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueBlockCreatorTest.java
  13. 4
      consensus/clique/src/test/java/org/hyperledger/besu/consensus/clique/blockcreation/CliqueMinerExecutorTest.java
  14. 6
      consensus/ibft/build.gradle
  15. 4
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/support/NetworkLayout.java
  16. 4
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/GossipTest.java
  17. 4
      consensus/ibft/src/integration-test/java/org/hyperledger/besu/consensus/ibft/tests/SpuriousBehaviourTest.java
  18. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHashingTest.java
  19. 26
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftBlockHeaderValidationRulesetFactoryTest.java
  20. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftGossipTest.java
  21. 6
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/IbftHelpersTest.java
  22. 8
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftCoinbaseValidationRuleTest.java
  23. 16
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/headervalidationrules/IbftCommitSealsValidationRuleTest.java
  24. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/queries/IbftQueryServiceImplTest.java
  25. 6
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  26. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/IbftRoundTest.java
  27. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/RoundChangeArtifactsTest.java
  28. 10
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/RoundChangeManagerTest.java
  29. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/statemachine/RoundStateTest.java
  30. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/FutureRoundProposalMessageValidatorTest.java
  31. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/MessageValidatorTest.java
  32. 5
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/ProposalBlockConsistencyValidatorTest.java
  33. 8
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/RoundChangeCertificateValidatorTest.java
  34. 4
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/RoundChangeMessageValidatorTest.java
  35. 8
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/RoundChangeSignedDataValidatorTest.java
  36. 8
      consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/validation/SignedDataValidatorTest.java
  37. 4
      crypto/build.gradle
  38. 19
      crypto/src/main/java/org/hyperledger/besu/crypto/BouncyCastleSecurityModule.java
  39. 27
      crypto/src/main/java/org/hyperledger/besu/crypto/NodeKey.java
  40. 34
      crypto/src/main/java/org/hyperledger/besu/crypto/PublicKey.java
  41. 40
      crypto/src/main/java/org/hyperledger/besu/crypto/SecurityModule.java
  42. 51
      crypto/src/main/java/org/hyperledger/besu/crypto/Signature.java
  43. 26
      crypto/src/test-support/java/org/hyperledger/besu/crypto/NodeKeyUtils.java
  44. 1
      ethereum/api/build.gradle
  45. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceRpcApisTest.java
  46. 1
      ethereum/eth/build.gradle
  47. 4
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java
  48. 1
      ethereum/p2p/build.gradle
  49. 4
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java
  50. 6
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryPacketSedesTest.java
  51. 8
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java
  52. 5
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java
  53. 5
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/NetworkingServiceLifecycleTest.java
  54. 20
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java
  55. 4
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java
  56. 12
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/ECIESHandshakeTest.java
  57. 4
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/EncryptedMessageTest.java
  58. 4
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/handshake/ecies/InitiatorHandshakeMessageV4Test.java

@ -67,6 +67,7 @@ dependencies {
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(':testutil')
testImplementation 'com.google.auto.service:auto-service'

@ -22,7 +22,6 @@ import org.hyperledger.besu.cli.BesuCommand;
import org.hyperledger.besu.cli.DefaultCommandValues;
import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.AddressSubCommand;
import org.hyperledger.besu.cli.subcommands.PublicKeySubCommand.ExportSubCommand;
import org.hyperledger.besu.crypto.SECP256K1;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Util;
@ -190,6 +189,7 @@ public class PublicKeySubCommand implements Runnable {
@FunctionalInterface
public interface KeyLoader {
SECP256K1.KeyPair load(final File keyFile) throws IOException;
KeyPair load(final File keyFile) throws IOException;
}
}

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static org.hyperledger.besu.crypto.KeyPairUtil.loadKeyPair;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.BouncyCastleSecurityModule;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods;
@ -127,7 +127,7 @@ public abstract class BesuControllerBuilder<C> {
}
public BesuControllerBuilder<C> nodePrivateKeyFile(final File nodePrivateKeyFile) {
this.nodeKey = new BouncyCastleNodeKey(loadKeyPair(nodePrivateKeyFile));
this.nodeKey = new NodeKey(new BouncyCastleSecurityModule(loadKeyPair(nodePrivateKeyFile)));
return this;
}

@ -20,7 +20,7 @@ import static org.hyperledger.besu.ethereum.privacy.PrivateStateRootResolver.EMP
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.GasLimitCalculator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1;
import org.hyperledger.besu.enclave.Enclave;
import org.hyperledger.besu.enclave.EnclaveFactory;
@ -165,7 +165,7 @@ public class PrivacyReorgTest {
.storageProvider(new InMemoryStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.dataDirectory(dataDir)
.clock(TestClock.fixed())

@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.GasLimitCalculator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.enclave.EnclaveFactory;
import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.Address;
@ -114,7 +114,7 @@ public class PrivacyTest {
.storageProvider(new InMemoryStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.dataDirectory(dataDir)
.clock(TestClock.fixed())

@ -25,9 +25,9 @@ import org.hyperledger.besu.config.JsonUtil;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.GasLimitCalculator;
import org.hyperledger.besu.controller.MainnetBesuControllerBuilder;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.KeyPairUtil;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.api.graphql.GraphQLConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
@ -145,7 +145,7 @@ public final class RunnerTest {
final Path dataDirAhead = temp.newFolder().toPath();
final Path dbAhead = dataDirAhead.resolve("database");
final int blockCount = 500;
final NodeKey aheadDbNodeKey = new BouncyCastleNodeKey(KeyPairUtil.loadKeyPair(dbAhead));
final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dbAhead));
final SynchronizerConfiguration syncConfigAhead =
SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build();
final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();
@ -240,7 +240,7 @@ public final class RunnerTest {
.dataDirectory(dataDirBehind)
.networkId(networkId)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.storageProvider(new InMemoryStorageProvider())
.metricsSystem(noOpMetricsSystem)
.privacyParameters(PrivacyParameters.DEFAULT)

@ -21,7 +21,7 @@ import org.hyperledger.besu.chainimport.RlpBlockImporter;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.GasLimitCalculator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockBody;
@ -85,7 +85,7 @@ public final class RlpBlockExporterTest {
.storageProvider(new InMemoryStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
.dataDirectory(dataDir)

@ -22,7 +22,7 @@ import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.JsonUtil;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.GasLimitCalculator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Block;
@ -422,7 +422,7 @@ public abstract class JsonBlockImporterTest {
.minTransactionGasPrice(Wei.ZERO)
.enabled(true)
.build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
.dataDirectory(dataDir)

@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.controller.BesuController;
import org.hyperledger.besu.controller.GasLimitCalculator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.InMemoryStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
@ -63,7 +63,7 @@ public final class RlpBlockImporterTest {
.storageProvider(new InMemoryStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
.dataDirectory(dataDir)
@ -103,7 +103,7 @@ public final class RlpBlockImporterTest {
.storageProvider(new InMemoryStorageProvider())
.networkId(BigInteger.valueOf(10))
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
.dataDirectory(dataDir)

@ -48,6 +48,7 @@ dependencies {
implementation 'org.apache.tuweni:tuweni-units'
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(':metrics:core')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(':testutil')

@ -18,8 +18,8 @@ import static org.assertj.core.api.Java6Assertions.assertThat;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
@ -28,7 +28,7 @@ import org.junit.Test;
public class CliqueProtocolScheduleTest {
private static final NodeKey NODE_KEY = BouncyCastleNodeKey.generate();
private static final NodeKey NODE_KEY = NodeKeyUtils.generate();
@Test
public void protocolSpecsAreCreatedAtBlockDefinedInJson() {

@ -32,8 +32,8 @@ import org.hyperledger.besu.consensus.common.EpochManager;
import org.hyperledger.besu.consensus.common.VoteProposer;
import org.hyperledger.besu.consensus.common.VoteTally;
import org.hyperledger.besu.consensus.common.VoteTallyCache;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.GenesisState;
@ -63,7 +63,7 @@ import org.junit.Test;
public class CliqueBlockCreatorTest {
private final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
private final NodeKey proposerNodeKey = NodeKeyUtils.generate();
private final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
private final KeyPair otherKeyPair = KeyPair.generate();
private final List<Address> validatorList = Lists.newArrayList();

@ -30,8 +30,8 @@ import org.hyperledger.besu.consensus.common.EpochManager;
import org.hyperledger.besu.consensus.common.VoteProposer;
import org.hyperledger.besu.consensus.common.VoteTally;
import org.hyperledger.besu.consensus.common.VoteTallyCache;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
@ -60,7 +60,7 @@ public class CliqueMinerExecutorTest {
private static final int EPOCH_LENGTH = 10;
private static final GenesisConfigOptions GENESIS_CONFIG_OPTIONS =
GenesisConfigFile.fromConfig("{}").getConfigOptions();
private final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
private final NodeKey proposerNodeKey = NodeKeyUtils.generate();
private final Random random = new Random(21341234L);
private Address localAddress;
private final List<Address> validatorList = Lists.newArrayList();

@ -44,15 +44,17 @@ dependencies {
implementation 'org.apache.tuweni:tuweni-bytes'
implementation 'org.apache.tuweni:tuweni-units'
integrationTestImplementation project(path: ':config:', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':config:', configuration: 'testSupportArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(':metrics:core')
testImplementation project(':testutil')
integrationTestImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
integrationTestImplementation project(':metrics:core')
integrationTestImplementation project(':testutil')

@ -14,8 +14,8 @@
*/
package org.hyperledger.besu.consensus.ibft.support;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Util;
@ -54,7 +54,7 @@ public class NetworkLayout {
final TreeMap<Address, NodeParams> addressKeyMap = new TreeMap<>();
for (int i = 0; i < validatorCount; i++) {
final NodeKey newNodeKey = BouncyCastleNodeKey.generate();
final NodeKey newNodeKey = NodeKeyUtils.generate();
final Address nodeAddress = Util.publicKeyToAddress(newNodeKey.getPublicKey());
addressKeyMap.put(nodeAddress, new NodeParams(nodeAddress, newNodeKey));
}

@ -31,7 +31,7 @@ import org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers;
import org.hyperledger.besu.consensus.ibft.support.TestContext;
import org.hyperledger.besu.consensus.ibft.support.TestContextBuilder;
import org.hyperledger.besu.consensus.ibft.support.ValidatorPeer;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Block;
import java.time.Clock;
@ -118,7 +118,7 @@ public class GossipTest {
@Test
public void messageWithUnknownValidatorIsNotGossiped() {
final MessageFactory unknownMsgFactory = new MessageFactory(BouncyCastleNodeKey.generate());
final MessageFactory unknownMsgFactory = new MessageFactory(NodeKeyUtils.generate());
final Proposal unknownProposal =
unknownMsgFactory.createProposal(roundId, block, Optional.empty());

@ -27,8 +27,8 @@ import org.hyperledger.besu.consensus.ibft.support.RoundSpecificPeers;
import org.hyperledger.besu.consensus.ibft.support.TestContext;
import org.hyperledger.besu.consensus.ibft.support.TestContextBuilder;
import org.hyperledger.besu.consensus.ibft.support.ValidatorPeer;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Hash;
@ -98,7 +98,7 @@ public class SpuriousBehaviourTest {
@Test
public void nonValidatorsCannotTriggerResponses() {
final NodeKey nonValidatorNodeKey = BouncyCastleNodeKey.generate();
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final NodeParams nonValidatorParams =
new NodeParams(
Util.publicKeyToAddress(nonValidatorNodeKey.getPublicKey()), nonValidatorNodeKey);

@ -17,8 +17,8 @@ package org.hyperledger.besu.consensus.ibft;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Java6Assertions.assertThat;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.crypto.SECP256K1.PrivateKey;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
@ -98,7 +98,7 @@ public class IbftBlockHashingTest {
return IntStream.rangeClosed(1, 4)
.mapToObj(
i ->
new BouncyCastleNodeKey(
NodeKeyUtils.createFrom(
(KeyPair.create(PrivateKey.create(UInt256.valueOf(i).toBytes())))))
.collect(Collectors.toList());
}

@ -19,8 +19,8 @@ import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.consensus.ibft.IbftContextBuilder.setupContextWithValidators;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -46,7 +46,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderPasses() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -67,7 +67,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnExtraData() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -88,11 +88,11 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnCoinbaseData() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final Address nonProposerAddress =
Util.publicKeyToAddress(BouncyCastleNodeKey.generate().getPublicKey());
Util.publicKeyToAddress(NodeKeyUtils.generate().getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -114,7 +114,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnNonce() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -135,7 +135,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnTimestamp() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -158,7 +158,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnMixHash() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -181,7 +181,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnOmmers() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -204,7 +204,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnDifficulty() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -227,7 +227,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnAncestor() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -248,7 +248,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnGasUsage() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);
@ -272,7 +272,7 @@ public class IbftBlockHeaderValidationRulesetFactoryTest {
@Test
public void ibftValidateHeaderFailsOnGasLimitRange() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress = Util.publicKeyToAddress(proposerNodeKey.getPublicKey());
final List<Address> validators = singletonList(proposerAddress);

@ -22,8 +22,8 @@ import org.hyperledger.besu.consensus.ibft.messagedata.RoundChangeMessageData;
import org.hyperledger.besu.consensus.ibft.messagewrappers.IbftMessage;
import org.hyperledger.besu.consensus.ibft.network.MockPeerFactory;
import org.hyperledger.besu.consensus.ibft.network.ValidatorMulticaster;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection;
@ -54,7 +54,7 @@ public class IbftGossipTest {
private <P extends IbftMessage<?>> void assertRebroadcastToAllExceptSignerAndSender(
final Function<NodeKey, P> createPayload, final Function<P, MessageData> createMessageData) {
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
final P payload = createPayload.apply(nodeKey);
final MessageData messageData = createMessageData.apply(payload);
final Message message = new DefaultMessage(peerConnection, messageData);

@ -22,8 +22,8 @@ import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate;
import org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Hash;
@ -86,7 +86,7 @@ public class IbftHelpersTest {
// sources, it is only responsible for determine which of the list or RoundChange messages
// contains the newest
// NOTE: This capability is tested as part of the NewRoundMessageValidationTests.
final NodeKey proposerKey = BouncyCastleNodeKey.generate();
final NodeKey proposerKey = NodeKeyUtils.generate();
final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
final Block proposedBlock = mock(Block.class);
when(proposedBlock.getHash()).thenReturn(Hash.fromHexStringLenient("1"));
@ -138,7 +138,7 @@ public class IbftHelpersTest {
@Test
public void allRoundChangeHaveNoPreparedReturnsEmptyOptional() {
final NodeKey proposerKey = BouncyCastleNodeKey.generate();
final NodeKey proposerKey = NodeKeyUtils.generate();
final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4);

@ -21,8 +21,8 @@ import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.consensus.ibft.IbftExtraDataFixture;
import org.hyperledger.besu.consensus.ibft.Vote;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -63,7 +63,7 @@ public class IbftCoinbaseValidationRuleTest {
@Test
public void proposerInValidatorListPassesValidation() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final Address proposerAddress =
Address.extract(Hash.hash(proposerNodeKey.getPublicKey().getEncodedBytes()));
@ -83,9 +83,9 @@ public class IbftCoinbaseValidationRuleTest {
@Test
public void proposerNotInValidatorListFailsValidation() {
final NodeKey proposerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey proposerNodeKey = NodeKeyUtils.generate();
final NodeKey otherValidatorNodeKey = BouncyCastleNodeKey.generate();
final NodeKey otherValidatorNodeKey = NodeKeyUtils.generate();
final Address otherValidatorNodeAddress =
Address.extract(Hash.hash(otherValidatorNodeKey.getPublicKey().getEncodedBytes()));

@ -22,8 +22,8 @@ import static org.hyperledger.besu.consensus.ibft.headervalidationrules.HeaderVa
import org.hyperledger.besu.consensus.ibft.IbftContext;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -46,9 +46,7 @@ public class IbftCommitSealsValidationRuleTest {
@Test
public void correctlyConstructedHeaderPassesValidation() {
final List<NodeKey> committerNodeKeys =
IntStream.range(0, 2)
.mapToObj(i -> BouncyCastleNodeKey.generate())
.collect(Collectors.toList());
IntStream.range(0, 2).mapToObj(i -> NodeKeyUtils.generate()).collect(Collectors.toList());
final List<Address> committerAddresses =
committerNodeKeys.stream()
@ -66,7 +64,7 @@ public class IbftCommitSealsValidationRuleTest {
@Test
public void insufficientCommitSealsFailsValidation() {
final NodeKey committerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey committerNodeKey = NodeKeyUtils.generate();
final Address committerAddress =
Address.extract(Hash.hash(committerNodeKey.getPublicKey().getEncodedBytes()));
@ -85,13 +83,13 @@ public class IbftCommitSealsValidationRuleTest {
@Test
public void committerNotInValidatorListFailsValidation() {
final NodeKey committerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey committerNodeKey = NodeKeyUtils.generate();
final Address committerAddress = Util.publicKeyToAddress(committerNodeKey.getPublicKey());
final List<Address> validators = singletonList(committerAddress);
// Insert an extraData block with committer seals.
final NodeKey nonValidatorNodeKey = BouncyCastleNodeKey.generate();
final NodeKey nonValidatorNodeKey = NodeKeyUtils.generate();
final BlockHeader header =
createProposedBlockHeader(validators, singletonList(nonValidatorNodeKey), false);
@ -143,7 +141,7 @@ public class IbftCommitSealsValidationRuleTest {
@Test
public void headerContainsDuplicateSealsFailsValidation() {
final NodeKey committerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey committerNodeKey = NodeKeyUtils.generate();
final List<Address> validators =
singletonList(Util.publicKeyToAddress(committerNodeKey.getPublicKey()));
final BlockHeader header =
@ -165,7 +163,7 @@ public class IbftCommitSealsValidationRuleTest {
final List<NodeKey> committerKeys = Lists.newArrayList();
for (int i = 0; i < validatorCount; i++) { // need -1 to account for proposer
final NodeKey committerNodeKey = BouncyCastleNodeKey.generate();
final NodeKey committerNodeKey = NodeKeyUtils.generate();
committerKeys.add(committerNodeKey);
validators.add(Address.extract(Hash.hash(committerNodeKey.getPublicKey().getEncodedBytes())));
}

@ -22,8 +22,8 @@ import org.hyperledger.besu.consensus.ibft.IbftBlockHashing;
import org.hyperledger.besu.consensus.ibft.IbftBlockHeaderFunctions;
import org.hyperledger.besu.consensus.ibft.IbftBlockInterface;
import org.hyperledger.besu.consensus.ibft.IbftExtraData;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.Address;
@ -53,7 +53,7 @@ public class IbftQueryServiceImplTest {
@Mock private Blockchain blockchain;
private final List<NodeKey> validatorKeys =
Lists.newArrayList(BouncyCastleNodeKey.generate(), BouncyCastleNodeKey.generate());
Lists.newArrayList(NodeKeyUtils.generate(), NodeKeyUtils.generate());
private final List<NodeKey> signingKeys = Lists.newArrayList(validatorKeys.get(0));
private final int ROUND_NUMBER_IN_BLOCK = 5;

@ -47,8 +47,8 @@ import org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate;
import org.hyperledger.besu.consensus.ibft.validation.FutureRoundProposalMessageValidator;
import org.hyperledger.besu.consensus.ibft.validation.MessageValidator;
import org.hyperledger.besu.consensus.ibft.validation.MessageValidatorFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Address;
@ -81,7 +81,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class IbftBlockHeightManagerTest {
private final NodeKey nodeKey = BouncyCastleNodeKey.generate();
private final NodeKey nodeKey = NodeKeyUtils.generate();
private final MessageFactory messageFactory = new MessageFactory(nodeKey);
private final BlockHeaderTestFixture headerTestFixture = new BlockHeaderTestFixture();
@ -119,7 +119,7 @@ public class IbftBlockHeightManagerTest {
@Before
public void setup() {
for (int i = 0; i < 3; i++) {
final BouncyCastleNodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
validators.add(Util.publicKeyToAddress(nodeKey.getPublicKey()));
validatorMessageFactory.add(new MessageFactory(nodeKey));
}

@ -36,8 +36,8 @@ import org.hyperledger.besu.consensus.ibft.network.IbftMessageTransmitter;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate;
import org.hyperledger.besu.consensus.ibft.validation.MessageValidator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.MinedBlockObserver;
@ -67,7 +67,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class IbftRoundTest {
private final NodeKey nodeKey = BouncyCastleNodeKey.generate();
private final NodeKey nodeKey = NodeKeyUtils.generate();
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 0);
private final MessageFactory messageFactory = new MessageFactory(nodeKey);
private final Subscribers<MinedBlockObserver> subscribers = Subscribers.create();

@ -22,8 +22,8 @@ import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.TestHelpers;
import org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Block;
import java.util.List;
@ -44,7 +44,7 @@ public class RoundChangeArtifactsTest {
@Before
public void setup() {
for (int i = 0; i < 4; i++) {
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
final MessageFactory messageFactory = new MessageFactory(nodeKey);
messageFactories.add(messageFactory);
}

@ -31,8 +31,8 @@ import org.hyperledger.besu.consensus.ibft.validation.ProposalBlockConsistencyVa
import org.hyperledger.besu.consensus.ibft.validation.RoundChangeMessageValidator;
import org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator;
import org.hyperledger.besu.consensus.ibft.validation.SignedDataValidator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs;
import org.hyperledger.besu.ethereum.core.Address;
@ -53,10 +53,10 @@ public class RoundChangeManagerTest {
private RoundChangeManager manager;
private final NodeKey proposerKey = BouncyCastleNodeKey.generate();
private final NodeKey validator1Key = BouncyCastleNodeKey.generate();
private final NodeKey validator2Key = BouncyCastleNodeKey.generate();
private final NodeKey nonValidatorKey = BouncyCastleNodeKey.generate();
private final NodeKey proposerKey = NodeKeyUtils.generate();
private final NodeKey validator1Key = NodeKeyUtils.generate();
private final NodeKey validator2Key = NodeKeyUtils.generate();
private final NodeKey nonValidatorKey = NodeKeyUtils.generate();
private final ConsensusRoundIdentifier ri1 = new ConsensusRoundIdentifier(2, 1);
private final ConsensusRoundIdentifier ri2 = new ConsensusRoundIdentifier(2, 2);

@ -26,8 +26,8 @@ import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.validation.MessageValidator;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Block;
@ -61,7 +61,7 @@ public class RoundStateTest {
@Before
public void setup() {
for (int i = 0; i < 3; i++) {
final NodeKey newNodeKey = BouncyCastleNodeKey.generate();
final NodeKey newNodeKey = NodeKeyUtils.generate();
validatorKeys.add(newNodeKey);
validators.add(Util.publicKeyToAddress(newNodeKey.getPublicKey()));
validatorMessageFactories.add(new MessageFactory(newNodeKey));

@ -24,7 +24,7 @@ import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.TestHelpers;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
@ -38,7 +38,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class FutureRoundProposalMessageValidatorTest {
private final MessageFactory messageFactoy = new MessageFactory(BouncyCastleNodeKey.generate());
private final MessageFactory messageFactoy = new MessageFactory(NodeKeyUtils.generate());
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 1);
private final Block proposedBlock = TestHelpers.createProposalBlock(emptyList(), roundIdentifier);

@ -31,8 +31,8 @@ import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.BlockValidator;
import org.hyperledger.besu.ethereum.BlockValidator.BlockProcessingOutputs;
import org.hyperledger.besu.ethereum.ProtocolContext;
@ -55,7 +55,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MessageValidatorTest {
private final NodeKey nodeKey = BouncyCastleNodeKey.generate();
private final NodeKey nodeKey = NodeKeyUtils.generate();
private final MessageFactory messageFactory = new MessageFactory(nodeKey);
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 0);

@ -22,7 +22,7 @@ import org.hyperledger.besu.consensus.ibft.IbftBlockInterface;
import org.hyperledger.besu.consensus.ibft.TestHelpers;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Block;
import java.util.Collections;
@ -36,8 +36,7 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class ProposalBlockConsistencyValidatorTest {
private final MessageFactory proposerMessageFactory =
new MessageFactory(BouncyCastleNodeKey.generate());
private final MessageFactory proposerMessageFactory = new MessageFactory(NodeKeyUtils.generate());
private final long chainHeight = 2;
private final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(chainHeight, 4);

@ -28,8 +28,8 @@ import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.payload.RoundChangeCertificate;
import org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts;
import org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator.MessageValidatorForHeightFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Util;
@ -44,9 +44,9 @@ import org.junit.Test;
public class RoundChangeCertificateValidatorTest {
private final NodeKey proposerKey = BouncyCastleNodeKey.generate();
private final NodeKey validatorKey = BouncyCastleNodeKey.generate();
private final NodeKey otherValidatorKey = BouncyCastleNodeKey.generate();
private final NodeKey proposerKey = NodeKeyUtils.generate();
private final NodeKey validatorKey = NodeKeyUtils.generate();
private final NodeKey otherValidatorKey = NodeKeyUtils.generate();
private final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
private final MessageFactory validatorMessageFactory = new MessageFactory(validatorKey);
private final List<Address> validators = Lists.newArrayList();

@ -22,7 +22,7 @@ import static org.mockito.Mockito.verify;
import org.hyperledger.besu.consensus.ibft.ConsensusRoundIdentifier;
import org.hyperledger.besu.consensus.ibft.messagewrappers.RoundChange;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.junit.Test;
@ -30,7 +30,7 @@ public class RoundChangeMessageValidatorTest {
private final RoundChangePayloadValidator payloadValidator =
mock(RoundChangePayloadValidator.class);
private final MessageFactory messageFactory = new MessageFactory(BouncyCastleNodeKey.generate());
private final MessageFactory messageFactory = new MessageFactory(NodeKeyUtils.generate());
private final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 1);
private final ProposalBlockConsistencyValidator proposalBlockConsistencyValidator =

@ -29,8 +29,8 @@ import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.consensus.ibft.payload.PreparedCertificate;
import org.hyperledger.besu.consensus.ibft.statemachine.PreparedRoundArtifacts;
import org.hyperledger.besu.consensus.ibft.validation.RoundChangePayloadValidator.MessageValidatorForHeightFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Hash;
@ -46,9 +46,9 @@ import org.junit.Test;
public class RoundChangeSignedDataValidatorTest {
private final NodeKey proposerKey = BouncyCastleNodeKey.generate();
private final NodeKey validatorKey = BouncyCastleNodeKey.generate();
private final NodeKey nonValidatorKey = BouncyCastleNodeKey.generate();
private final NodeKey proposerKey = NodeKeyUtils.generate();
private final NodeKey validatorKey = NodeKeyUtils.generate();
private final NodeKey nonValidatorKey = NodeKeyUtils.generate();
private final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
private final MessageFactory validatorMessageFactory = new MessageFactory(validatorKey);
private final MessageFactory nonValidatorMessageFactory = new MessageFactory(nonValidatorKey);

@ -25,8 +25,8 @@ import org.hyperledger.besu.consensus.ibft.messagewrappers.Commit;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Prepare;
import org.hyperledger.besu.consensus.ibft.messagewrappers.Proposal;
import org.hyperledger.besu.consensus.ibft.payload.MessageFactory;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Hash;
@ -44,9 +44,9 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class SignedDataValidatorTest {
private final NodeKey proposerKey = BouncyCastleNodeKey.generate();
private final NodeKey validatorKey = BouncyCastleNodeKey.generate();
private final NodeKey nonValidatorKey = BouncyCastleNodeKey.generate();
private final NodeKey proposerKey = NodeKeyUtils.generate();
private final NodeKey validatorKey = NodeKeyUtils.generate();
private final NodeKey nonValidatorKey = NodeKeyUtils.generate();
private final MessageFactory proposerMessageFactory = new MessageFactory(proposerKey);
private final MessageFactory validatorMessageFactory = new MessageFactory(validatorKey);
private final MessageFactory nonValidatorMessageFactory = new MessageFactory(nonValidatorKey);

@ -44,3 +44,7 @@ dependencies {
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
}
artifacts {
testSupportArtifacts testSupportJar
}

@ -15,35 +15,32 @@
package org.hyperledger.besu.crypto;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.crypto.SECP256K1.PublicKey;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.apache.tuweni.bytes.Bytes32;
public class BouncyCastleNodeKey implements NodeKey {
public class BouncyCastleSecurityModule implements SecurityModule {
private final KeyPair nodeKeys;
public BouncyCastleNodeKey(final KeyPair nodeKeys) {
public BouncyCastleSecurityModule(final KeyPair nodeKeys) {
this.nodeKeys = nodeKeys;
}
public static BouncyCastleNodeKey generate() {
return new BouncyCastleNodeKey(KeyPair.generate());
}
@Override
public Signature sign(final Bytes32 dataHash) {
return SECP256K1.sign(dataHash, nodeKeys);
final SECP256K1.Signature signature = SECP256K1.sign(dataHash, nodeKeys);
return new Signature(signature.getR(), signature.getS(), signature.getRecId());
}
@Override
public PublicKey getPublicKey() {
return nodeKeys.getPublicKey();
final SECP256K1.PublicKey pubKey = nodeKeys.getPublicKey();
return new PublicKey(pubKey.getEncodedBytes());
}
@Override
public Bytes32 calculateECDHKeyAgreement(final PublicKey publicKey) {
return SECP256K1.calculateECDHKeyAgreement(nodeKeys.getPrivateKey(), publicKey);
final SECP256K1.PublicKey pubKey = SECP256K1.PublicKey.create(publicKey.getEncoded());
return SECP256K1.calculateECDHKeyAgreement(nodeKeys.getPrivateKey(), pubKey);
}
}

@ -14,16 +14,29 @@
*/
package org.hyperledger.besu.crypto;
import org.hyperledger.besu.crypto.SECP256K1.PublicKey;
import org.hyperledger.besu.crypto.SECP256K1.Signature;
import org.apache.tuweni.bytes.Bytes32;
public interface NodeKey {
public class NodeKey {
private final SecurityModule securityModule;
public NodeKey(final SecurityModule securityModule) {
this.securityModule = securityModule;
}
Signature sign(Bytes32 dataHash);
public SECP256K1.Signature sign(final Bytes32 dataHash) {
final Signature signature = securityModule.sign(dataHash);
return SECP256K1.Signature.create(
signature.getR(), signature.getS(), signature.getRecoveryId());
}
PublicKey getPublicKey();
public SECP256K1.PublicKey getPublicKey() {
final PublicKey pubKey = securityModule.getPublicKey();
return SECP256K1.PublicKey.create(pubKey.getEncoded());
}
Bytes32 calculateECDHKeyAgreement(PublicKey publicKey);
public Bytes32 calculateECDHKeyAgreement(final SECP256K1.PublicKey partyKey) {
final PublicKey pubKey = new PublicKey(partyKey.getEncodedBytes());
return securityModule.calculateECDHKeyAgreement(pubKey);
}
}

@ -0,0 +1,34 @@
/*
* Copyright ConsenSys AG.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.crypto;
import org.apache.tuweni.bytes.Bytes;
public class PublicKey {
private final Bytes encoded;
public PublicKey(final Bytes encoded) {
this.encoded = encoded;
}
public static PublicKey create(final Bytes encoded) {
return new PublicKey(encoded);
}
public Bytes getEncoded() {
return encoded;
}
}

@ -0,0 +1,40 @@
/*
* Copyright ConsenSys AG.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.crypto;
import org.apache.tuweni.bytes.Bytes32;
/**
* Provides a generic interface for classes which wrap/hide a cryptographic private key. This
* interface ensures cryptographic functions required by Ethereum are available to the application
* at large, without releasing the content of the private key.
*/
public interface SecurityModule {
/**
* @param dataHash The Keccack hash of a set of data, which is to be signed.
* @return the signature (R, S, recId) generated by signing the hash with the node key
*/
Signature sign(Bytes32 dataHash);
/** @return the public key associated with the key stored behind this interface. */
PublicKey getPublicKey();
/**
* @param partyKey the key with which an agreement is to be created.
* @return The bytes forming the agreement
*/
Bytes32 calculateECDHKeyAgreement(PublicKey partyKey);
}

@ -0,0 +1,51 @@
/*
* Copyright ConsenSys AG.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.crypto;
import java.math.BigInteger;
public final class Signature {
/**
* The recovery id to reconstruct the public key used to create the signature.
*
* <p>The recId is an index from 0 to 3 which indicates which of the 4 possible keys is the
* correct one. Because the key recovery operation yields multiple potential keys, the correct key
* must either be stored alongside the signature, or you must be willing to try each recId in turn
* until you find one that outputs the key you are expecting.
*/
private final byte recoveryId;
private final BigInteger r;
private final BigInteger s;
public Signature(final BigInteger r, final BigInteger s, final byte recoveryId) {
this.r = r;
this.s = s;
this.recoveryId = recoveryId;
}
public byte getRecoveryId() {
return recoveryId;
}
public BigInteger getR() {
return r;
}
public BigInteger getS() {
return s;
}
}

@ -0,0 +1,26 @@
/*
* Copyright ConsenSys AG.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.crypto;
public class NodeKeyUtils {
public static NodeKey createFrom(final SECP256K1.KeyPair keyPair) {
return new NodeKey(new BouncyCastleSecurityModule(keyPair));
}
public static NodeKey generate() {
return new NodeKey(new BouncyCastleSecurityModule(SECP256K1.KeyPair.generate()));
}
}

@ -64,6 +64,7 @@ dependencies {
testImplementation project(':config')
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(':services:kvstore')

@ -20,7 +20,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.hyperledger.besu.config.StubGenesisConfigOptions;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.api.jsonrpc.health.HealthService;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
@ -253,7 +253,7 @@ public class JsonRpcHttpServiceRpcApisTest {
final P2PNetwork p2pNetwork =
DefaultP2PNetwork.builder()
.supportedCapabilities(Capability.create("eth", 63))
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.vertx(vertx)
.config(config)
.metricsSystem(new NoOpMetricsSystem())

@ -48,6 +48,7 @@ dependencies {
testImplementation project(':config')
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(':crypto')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(':ethereum:mock-p2p')

@ -23,8 +23,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.GenesisState;
@ -91,7 +91,7 @@ public class TestNode implements Closeable {
checkNotNull(discoveryCfg);
final int listenPort = port != null ? port : 0;
this.nodeKey = kp != null ? new BouncyCastleNodeKey(kp) : BouncyCastleNodeKey.generate();
this.nodeKey = kp != null ? NodeKeyUtils.createFrom(kp) : NodeKeyUtils.generate();
final NetworkingConfiguration networkingConfiguration =
NetworkingConfiguration.create()

@ -47,6 +47,7 @@ dependencies {
// test dependencies.
testImplementation project(path: ':ethereum:core', configuration: 'testArtifacts')
testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(':testutil')
testImplementation('io.pkts:pkts-core') {

@ -22,8 +22,8 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.p2p.discovery.PeerDiscoveryTestHelper.AgentBuilder;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.FindNeighborsPacketData;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.MockPeerDiscoveryAgent;
@ -337,7 +337,7 @@ public class PeerDiscoveryAgentTest {
final MockPeerDiscoveryAgent agent = helper.startDiscoveryAgent();
final DiscoveryPeer agentPeer = agent.getAdvertisedPeer().get();
final NodeKey remoteKeyPair = BouncyCastleNodeKey.generate();
final NodeKey remoteKeyPair = NodeKeyUtils.generate();
final String remoteIp = "1.2.3.4";
final MockPeerDiscoveryAgent remoteAgent =
helper.createDiscoveryAgent(

@ -17,8 +17,8 @@ package org.hyperledger.besu.ethereum.p2p.discovery;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.FindNeighborsPacketData;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.NeighborsPacketData;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.Packet;
@ -43,7 +43,7 @@ public class PeerDiscoveryPacketSedesTest {
final byte[] r = new byte[64];
new Random().nextBytes(r);
final Bytes target = Bytes.wrap(r);
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
final FindNeighborsPacketData packetData = FindNeighborsPacketData.create(target);
final Packet packet = Packet.create(PacketType.FIND_NEIGHBORS, packetData, nodeKey);
@ -113,7 +113,7 @@ public class PeerDiscoveryPacketSedesTest {
new Random().nextBytes(r);
final Bytes target = Bytes.wrap(r);
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
final FindNeighborsPacketData data = FindNeighborsPacketData.create(target);
final Packet packet = Packet.create(PacketType.FIND_NEIGHBORS, data, nodeKey);

@ -17,8 +17,8 @@ package org.hyperledger.besu.ethereum.p2p.discovery;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Arrays.asList;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.MockPeerDiscoveryAgent;
import org.hyperledger.besu.ethereum.p2p.discovery.internal.Packet;
@ -49,7 +49,7 @@ public class PeerDiscoveryTestHelper {
Map<Bytes, MockPeerDiscoveryAgent> agents = new HashMap<>();
public static List<NodeKey> generateNodeKeys(final int count) {
return Stream.generate(BouncyCastleNodeKey::generate).limit(count).collect(Collectors.toList());
return Stream.generate(NodeKeyUtils::generate).limit(count).collect(Collectors.toList());
}
/**
@ -67,7 +67,7 @@ public class PeerDiscoveryTestHelper {
}
public DiscoveryPeer createDiscoveryPeer() {
return createDiscoveryPeer(BouncyCastleNodeKey.generate());
return createDiscoveryPeer(NodeKeyUtils.generate());
}
public DiscoveryPeer createDiscoveryPeer(final NodeKey nodeKey) {
@ -189,7 +189,7 @@ public class PeerDiscoveryTestHelper {
private PeerPermissions peerPermissions = PeerPermissions.noop();
private String advertisedHost = "127.0.0.1";
private OptionalInt bindPort = OptionalInt.empty();
private NodeKey nodeKey = BouncyCastleNodeKey.generate();
private NodeKey nodeKey = NodeKeyUtils.generate();
private AgentBuilder(
final Map<Bytes, MockPeerDiscoveryAgent> agents, final AtomicInteger nextAvailablePort) {

@ -24,9 +24,8 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration;
@ -326,7 +325,7 @@ public final class DefaultP2PNetworkTest {
private DefaultP2PNetwork.Builder builder() {
final NodeKey nodeKey = new BouncyCastleNodeKey(KeyPair.generate());
final NodeKey nodeKey = NodeKeyUtils.generate();
return DefaultP2PNetwork.builder()
.config(config)

@ -18,9 +18,8 @@ import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.p2p.NetworkingTestHelper.configWithRandomPorts;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.SECP256K1;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.discovery.PeerDiscoveryServiceException;
@ -39,7 +38,7 @@ import org.junit.Test;
public class NetworkingServiceLifecycleTest {
private final Vertx vertx = Vertx.vertx();
private final NodeKey nodeKey = new BouncyCastleNodeKey(SECP256K1.KeyPair.generate());
private final NodeKey nodeKey = NodeKeyUtils.generate();
private final NetworkingConfiguration config = configWithRandomPorts();
@After

@ -21,8 +21,8 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration;
@ -66,7 +66,7 @@ public class P2PNetworkTest {
@Test
public void handshaking() throws Exception {
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
try (final P2PNetwork listener = builder().nodeKey(nodeKey).build();
final P2PNetwork connector = builder().build()) {
@ -88,8 +88,8 @@ public class P2PNetworkTest {
@Test
public void preventMultipleConnections() throws Exception {
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
try (final P2PNetwork listener = builder().nodeKey(nodeKey).build();
final NodeKey listenNodeKey = NodeKeyUtils.generate();
try (final P2PNetwork listener = builder().nodeKey(listenNodeKey).build();
final P2PNetwork connector = builder().build()) {
listener.start();
@ -121,7 +121,7 @@ public class P2PNetworkTest {
*/
@Test
public void limitMaxPeers() throws Exception {
final NodeKey nodeKey = BouncyCastleNodeKey.generate();
final NodeKey nodeKey = NodeKeyUtils.generate();
final int maxPeers = 1;
final NetworkingConfiguration listenerConfig =
NetworkingConfiguration.create()
@ -176,17 +176,17 @@ public class P2PNetworkTest {
@Test
public void rejectPeerWithNoSharedCaps() throws Exception {
final NodeKey listenerCryptoOps = BouncyCastleNodeKey.generate();
final NodeKey connectorCryptoOps = BouncyCastleNodeKey.generate();
final NodeKey listenerNodeKey = NodeKeyUtils.generate();
final NodeKey connectorNodeKey = NodeKeyUtils.generate();
final SubProtocol subprotocol1 = subProtocol("eth");
final Capability cap1 = Capability.create(subprotocol1.getName(), 63);
final SubProtocol subprotocol2 = subProtocol("oth");
final Capability cap2 = Capability.create(subprotocol2.getName(), 63);
try (final P2PNetwork listener =
builder().nodeKey(listenerCryptoOps).supportedCapabilities(cap1).build();
builder().nodeKey(listenerNodeKey).supportedCapabilities(cap1).build();
final P2PNetwork connector =
builder().nodeKey(connectorCryptoOps).supportedCapabilities(cap2).build()) {
builder().nodeKey(connectorNodeKey).supportedCapabilities(cap2).build()) {
listener.start();
connector.start();
final EnodeURL listenerEnode = listener.getLocalEnode().get();
@ -331,7 +331,7 @@ public class P2PNetworkTest {
return DefaultP2PNetwork.builder()
.vertx(vertx)
.config(config)
.nodeKey(BouncyCastleNodeKey.generate())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.supportedCapabilities(Arrays.asList(Capability.create("eth", 63)));
}

@ -29,7 +29,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration;
import org.hyperledger.besu.ethereum.p2p.discovery.DiscoveryPeer;
@ -972,7 +972,7 @@ public class RlpxAgentTest {
private RlpxAgent agent() {
config.setLimitRemoteWireConnectionsEnabled(true);
return RlpxAgent.builder()
.nodeKey(new BouncyCastleNodeKey(KEY_PAIR))
.nodeKey(NodeKeyUtils.createFrom(KEY_PAIR))
.config(config)
.peerPermissions(peerPermissions)
.peerPrivileges(peerPrivileges)

@ -16,7 +16,7 @@ package org.hyperledger.besu.ethereum.p2p.rlpx.handshake.ecies;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1.KeyPair;
import org.hyperledger.besu.crypto.SECP256K1.PrivateKey;
import org.hyperledger.besu.ethereum.p2p.rlpx.handshake.Handshaker.HandshakeStatus;
@ -101,7 +101,7 @@ public class ECIESHandshakeTest {
// Prepare the handshaker to take the initiator role.
initiator.prepareInitiator(
new BouncyCastleNodeKey(Input.initiatorKeyPair), Input.responderKeyPair.getPublicKey());
NodeKeyUtils.createFrom(Input.initiatorKeyPair), Input.responderKeyPair.getPublicKey());
// Set the test vectors.
initiator.setEphKeyPair(Input.initiatorEphKeyPair);
@ -115,7 +115,7 @@ public class ECIESHandshakeTest {
final ECIESHandshaker responder = new ECIESHandshaker();
// Prepare the handshaker with the responder's keypair.
responder.prepareResponder(new BouncyCastleNodeKey(Input.responderKeyPair));
responder.prepareResponder(NodeKeyUtils.createFrom(Input.responderKeyPair));
// Set the test data.
responder.setEphKeyPair(Input.responderEphKeyPair);
@ -149,7 +149,7 @@ public class ECIESHandshakeTest {
final ECIESHandshaker responder = new ECIESHandshaker();
// Prepare the handshaker with the responder's keypair.
responder.prepareResponder(new BouncyCastleNodeKey(Input.responderKeyPair));
responder.prepareResponder(NodeKeyUtils.createFrom(Input.responderKeyPair));
// Set the test data.
responder.setEphKeyPair(Input.responderEphKeyPair);
@ -167,7 +167,7 @@ public class ECIESHandshakeTest {
// Initiator end of the handshake.
final ECIESHandshaker initiator = new ECIESHandshaker();
initiator.prepareInitiator(
new BouncyCastleNodeKey(Input.initiatorKeyPair), Input.responderKeyPair.getPublicKey());
NodeKeyUtils.createFrom(Input.initiatorKeyPair), Input.responderKeyPair.getPublicKey());
initiator.firstMessage();
initiator.setInitiatorMsgEnc(Bytes.wrap(Messages.initiatorMsgEnc));
initiator.setEphKeyPair(Input.initiatorEphKeyPair);
@ -175,7 +175,7 @@ public class ECIESHandshakeTest {
// Responder end of the handshake.
final ECIESHandshaker responder = new ECIESHandshaker();
responder.prepareResponder(new BouncyCastleNodeKey(Input.responderKeyPair));
responder.prepareResponder(NodeKeyUtils.createFrom(Input.responderKeyPair));
responder.setEphKeyPair(Input.responderEphKeyPair);
responder.setResponderNonce(Input.responderNonce);

@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.p2p.rlpx.handshake.ecies;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1;
import java.util.concurrent.ThreadLocalRandom;
@ -35,7 +35,7 @@ public final class EncryptedMessageTest {
final Bytes initial = Bytes.wrap(message);
final Bytes encrypted = EncryptedMessage.encryptMsgEip8(initial, keyPair.getPublicKey());
final Bytes decrypted =
EncryptedMessage.decryptMsgEIP8(encrypted, new BouncyCastleNodeKey(keyPair));
EncryptedMessage.decryptMsgEIP8(encrypted, NodeKeyUtils.createFrom(keyPair));
Assertions.assertThat(decrypted.slice(0, 288)).isEqualTo(initial);
}
}

@ -14,8 +14,8 @@
*/
package org.hyperledger.besu.ethereum.p2p.rlpx.handshake.ecies;
import org.hyperledger.besu.crypto.BouncyCastleNodeKey;
import org.hyperledger.besu.crypto.KeyPairUtil;
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.crypto.SECP256K1;
import java.io.File;
@ -59,7 +59,7 @@ public final class InitiatorHandshakeMessageV4Test {
public void encodeDecodeRoundtrip() {
final InitiatorHandshakeMessageV4 initial =
InitiatorHandshakeMessageV4.decode(
EXAMPLE_MESSAGE, new BouncyCastleNodeKey(EXAMPLE_KEYPAIR));
EXAMPLE_MESSAGE, NodeKeyUtils.createFrom(EXAMPLE_KEYPAIR));
final Bytes encoded = initial.encode();
Assertions.assertThat(encoded).isEqualTo(EXAMPLE_MESSAGE.slice(0, encoded.size()));
}

Loading…
Cancel
Save