Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SECP256R1AcceptanceTest #2321

Merged

Conversation

daniel-iobuilders
Copy link
Contributor

Signed-off-by: Daniel Lehrner daniel@io.builders

PR description

SECP256R1AcceptanceTest needed to set SECP256R1 as signature algorithm instance. Because this variable is static and is used in BesuNode to create a key pair it could happen that other tests were using the SECP256R1 signature algorithm by accident becuase of this, depending on the order in which the tests were executed. This caused the acceptance tests to be flaky.
This PR introduces the possibility to set a pre-generated key pair in BesuNodeFactory. This allows to set a SECP256R1 key pair without changing SignatureAlgorithmFactory.instance, which avoids that other tests can happen to use SECP256R1 when they expect SECP256K1.

Fixed Issue(s)

reintroduces test which was ignored in #2267

Changelog

…y use it when the nodes are started as their own processes

Signed-off-by: Daniel Lehrner <daniel@io.builders>
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few comments but overall LGTM

throw new IllegalArgumentException("Cannot store generated private key.");
}
}

public static File getDefaultKeyFile(final Path homeDirectory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also rename this one s/homeDirectory/directory

final File privateKeyDir = file.getParentFile();
privateKeyDir.mkdirs();
final Path tempPath = Files.createTempFile(privateKeyDir.toPath(), ".tmp", "");
Files.write(
tempPath,
keyKair.getPrivateKey().getEncodedBytes().toString().getBytes(StandardCharsets.UTF_8));
keyPair.getPrivateKey().getEncodedBytes().toString().getBytes(StandardCharsets.UTF_8));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot!

}

private KeyPair createKeyPair(final String privateKey) {
return SIGNATURE_ALGORITHM.createKeyPair(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be clearer to name this SECP256R1_ SIGNATURE_ALGORITHM

@macfarla macfarla merged commit 8803fcd into hyperledger:master Jun 16, 2021
@daniel-iobuilders daniel-iobuilders deleted the fix_secp256r1_acceptance_test branch June 17, 2021 08:37
jflo pushed a commit to jflo/besu that referenced this pull request Jun 17, 2021
* don't set SECP256R1 as signature algorithm instance in the tests, only use it when the nodes are started as their own processes

Signed-off-by: Daniel Lehrner <daniel@io.builders>

* renamed some variables for better readability

Signed-off-by: Daniel Lehrner <daniel@io.builders>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* don't set SECP256R1 as signature algorithm instance in the tests, only use it when the nodes are started as their own processes

Signed-off-by: Daniel Lehrner <daniel@io.builders>

* renamed some variables for better readability

Signed-off-by: Daniel Lehrner <daniel@io.builders>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants