diff --git a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/ServiceSignCommand.java b/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/ServiceSignCommand.java deleted file mode 100644 index 51b97849cee..00000000000 --- a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/ServiceSignCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2016-2023 Hedera Hashgraph, LLC - * - * 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. - */ - -package com.hedera.services.cli; - -import com.swirlds.cli.PlatformCli; -import com.swirlds.cli.utility.AbstractCommand; -import com.swirlds.cli.utility.SubcommandOf; -import picocli.CommandLine; - -/** - * A collection of operations on signing all necessary stream files generated by services. - */ -@CommandLine.Command( - name = "service-sign", - mixinStandardHelpOptions = true, - description = "Operations to sign all necessary stream files generated by services.") -@SubcommandOf(PlatformCli.class) -public final class ServiceSignCommand extends AbstractCommand { - - private ServiceSignCommand() {} -} diff --git a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/AccountBalanceSigningUtils.java b/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/AccountBalanceSigningUtils.java deleted file mode 100644 index 224d83688cf..00000000000 --- a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/AccountBalanceSigningUtils.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2023 Hedera Hashgraph, LLC - * - * 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. - */ - -package com.hedera.services.cli.sign; - -import static com.hedera.services.cli.sign.SignUtils.TYPE_FILE_HASH; -import static com.hedera.services.cli.sign.SignUtils.TYPE_SIGNATURE; -import static com.hedera.services.cli.sign.SignUtils.integerToBytes; -import static com.hedera.services.cli.sign.SignUtils.sign; -import static com.swirlds.common.stream.LinkedObjectStreamUtilities.computeEntireHash; -import static com.swirlds.logging.LogMarker.FILE_SIGN; - -import com.swirlds.common.crypto.Hash; -import com.swirlds.platform.util.BootstrapUtils; -import edu.umd.cs.findbugs.annotations.NonNull; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Path; -import java.security.InvalidKeyException; -import java.security.KeyPair; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.SignatureException; -import java.util.Objects; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * Utility class for signing account balance files - */ -public class AccountBalanceSigningUtils { - - private static final Logger logger = LogManager.getLogger(AccountBalanceSigningUtils.class); - /** - * Hidden constructor - */ - private AccountBalanceSigningUtils() {} - - - - /** - * Sets up the constructable registry, and configures - *

- * Should be called before using stream utilities - *

- * Do NOT call this during standard node operation, as it will interfere with static settings - */ - public static void initializeSystem() { - BootstrapUtils.setupConstructableRegistry(); - - // we don't want deserialization to fail based on any of these settings, not needed for services - // SettingsCommon.maxTransactionCountPerEvent = Integer.MAX_VALUE; - // SettingsCommon.maxTransactionBytesPerEvent = Integer.MAX_VALUE; - // SettingsCommon.transactionMaxBytes = Integer.MAX_VALUE; - // SettingsCommon.maxAddressSizeAllowed = Integer.MAX_VALUE; - } - - /** - * Generates a signature file for the account balance file - * - * @param signatureFileDestination the full path where the signature file will be generated - * @param streamFileToSign the stream file to be signed - * @param keyPair the keyPair used for signing - * @return true if the signature file was generated successfully, false otherwise - */ - public static boolean signAccountBalanceFile( - @NonNull final Path signatureFileDestination, - @NonNull final Path streamFileToSign, - @NonNull final KeyPair keyPair) { - - Objects.requireNonNull(signatureFileDestination, "signatureFileDestination must not be null"); - Objects.requireNonNull(streamFileToSign, "streamFileToSign must not be null"); - Objects.requireNonNull(keyPair, "keyPair must not be null"); - - try { - final Hash entireHash = computeEntireHash(streamFileToSign.toFile()); - final byte[] fileHashByte = entireHash.getValue(); - final byte[] signature = sign(fileHashByte, keyPair); - - generateSigBalanceFile(signatureFileDestination.toFile(), signature, fileHashByte); - - System.out.println("Generated signature file: " + signatureFileDestination); - - return true; - } catch (final SignatureException | IOException e) { - System.err.println("Failed to sign file " + streamFileToSign.getFileName() + ". Exception: " + e); - return false; - } catch (final InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException e) { - throw new RuntimeException("Irrecoverable error encountered", e); - } - } - - private static void generateSigBalanceFile(final File filePath, final byte[] signature, final byte[] fileHash) { - try (final BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(filePath))) { - output.write(TYPE_FILE_HASH); - output.write(fileHash); - output.write(TYPE_SIGNATURE); - output.write(integerToBytes(signature.length)); - output.write(signature); - output.flush(); - } catch (final IOException e) { - logger.error( - FILE_SIGN.getMarker(), - "generateSigBalanceFile :: Fail to generate signature file for {}. Exception: {}", - filePath, - e); - } - } -} diff --git a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/AccountBalanceType.java b/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/AccountBalanceType.java deleted file mode 100644 index b2b4a6d6198..00000000000 --- a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/AccountBalanceType.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2020-2023 Hedera Hashgraph, LLC - * - * 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. - */ - -package com.hedera.services.cli.sign; - -import com.swirlds.common.stream.StreamType; - -/** - * Contains properties related to Account Balance file type; - * Its constructor is private. Users need to use the singleton to denote this type - */ -public final class AccountBalanceType implements StreamType { - /** - * description of the streamType, used for logging - */ - public static final String ACCOUNT_BALANCE_DESCRIPTION = "account balance"; - /** - * file name extension - */ - public static final String ACCOUNT_BALANCE_EXTENSION = "pb"; - /** - * file name extension of signature file - */ - public static final String ACCOUNT_BALANCE_SIG_EXTENSION = "pb_sig"; - /** - * a singleton denotes AccountBalanceType - */ - private static final AccountBalanceType INSTANCE = new AccountBalanceType(); - - private AccountBalanceType() {} - - public static AccountBalanceType getInstance() { - return INSTANCE; - } - - @Override - public String getDescription() { - return ACCOUNT_BALANCE_DESCRIPTION; - } - - @Override - public String getExtension() { - return ACCOUNT_BALANCE_EXTENSION; - } - - @Override - public String getSigExtension() { - return ACCOUNT_BALANCE_SIG_EXTENSION; - } - - @Override - // not used in BalanceFile - public int[] getFileHeader() { - return new int[0]; - } - - @Override - // not used in BalanceFile - public byte[] getSigFileHeader() { - return new byte[0]; - } -} diff --git a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/BalanceFileSignCommand.java b/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/BalanceFileSignCommand.java deleted file mode 100644 index eee1e5e6a77..00000000000 --- a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/BalanceFileSignCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2023 Hedera Hashgraph, LLC - * - * 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. - */ - -package com.hedera.services.cli.sign; - -import com.hedera.services.cli.ServiceSignCommand; -import com.swirlds.cli.utility.SubcommandOf; -import com.swirlds.platform.cli.SignCommand; -import edu.umd.cs.findbugs.annotations.NonNull; -import java.nio.file.Path; -import java.security.KeyPair; -import picocli.CommandLine; - -/** - * A subcommand of the {@link SignCommand}, for signing account balance files - */ -@CommandLine.Command(name = "balance", mixinStandardHelpOptions = true, description = "Sign account balance files") -@SubcommandOf(ServiceSignCommand.class) -public final class BalanceFileSignCommand extends SignCommand { - /** - * {@inheritDoc} - */ - @Override - public boolean generateSignatureFile( - @NonNull Path signatureFileDestination, @NonNull Path fileToSign, @NonNull KeyPair keyPair) { - - return AccountBalanceSigningUtils.signAccountBalanceFile(signatureFileDestination, fileToSign, keyPair); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isFileSupported(@NonNull final Path path) { - return AccountBalanceType.getInstance().isStreamFile(path.toFile()); - } - - /** - * {@inheritDoc} - */ - @Override - public Integer call() { - AccountBalanceSigningUtils.initializeSystem(); - - return super.call(); - } -} diff --git a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/SignUtils.java b/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/SignUtils.java deleted file mode 100644 index c794437a3b5..00000000000 --- a/hedera-node/cli-clients/src/main/java/com/hedera/services/cli/sign/SignUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2023 Hedera Hashgraph, LLC - * - * 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. - */ - -package com.hedera.services.cli.sign; - -import static com.swirlds.common.utility.CommonUtils.hex; -import static com.swirlds.logging.LogMarker.FILE_SIGN; - -import com.swirlds.common.crypto.SignatureType; -import java.nio.ByteBuffer; -import java.security.InvalidKeyException; -import java.security.KeyPair; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.security.Signature; -import java.security.SignatureException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class SignUtils { - /** - * next bytes are signature - */ - public static final byte TYPE_SIGNATURE = 3; - /** - * next 48 bytes are hash384 of content of the file to be signed - */ - public static final byte TYPE_FILE_HASH = 4; - - private static final int BYTES_COUNT_IN_INT = 4; - private static final Logger logger = LogManager.getLogger(SignUtils.class); - - private SignUtils(){} - - public static byte[] sign(final byte[] data, final KeyPair sigKeyPair) - throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, SignatureException { - final Signature signature; - signature = Signature.getInstance(SignatureType.RSA.signingAlgorithm(), SignatureType.RSA.provider()); - signature.initSign(sigKeyPair.getPrivate()); - if (logger.isDebugEnabled()) { - logger.debug( - FILE_SIGN.getMarker(), - "data is being signed, publicKey={}", - hex(sigKeyPair.getPublic().getEncoded())); - } - - signature.update(data); - return signature.sign(); - } - - public static byte[] integerToBytes(final int number) { - final ByteBuffer b = ByteBuffer.allocate(BYTES_COUNT_IN_INT); - b.putInt(number); - return b.array(); - } -} diff --git a/hedera-node/cli-clients/src/main/java/module-info.java b/hedera-node/cli-clients/src/main/java/module-info.java index 27d7491d112..57090a3548e 100644 --- a/hedera-node/cli-clients/src/main/java/module-info.java +++ b/hedera-node/cli-clients/src/main/java/module-info.java @@ -8,6 +8,4 @@ requires com.swirlds.platform; requires com.swirlds.common; requires info.picocli; - requires org.apache.logging.log4j; - requires com.swirlds.logging; } diff --git a/settings.gradle.kts b/settings.gradle.kts index 1a32bf4f2ee..4b2ea9ed66a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -144,7 +144,7 @@ dependencyResolutionManagement { version("netty-version", "4.1.66.Final") version("protobuf-java-version", "3.19.4") version("slf4j-version", "2.0.3") - version("swirlds-version", "0.38.0-adhoc.xa85f09f3") + version("swirlds-version", "0.38.0-adhoc.xcca9daa7") version("tuweni-version", "2.2.0") version("jna-version", "5.12.1") version("jsr305-version", "3.0.2")