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

bugfix: make Sep10Challenge.verifyTransactionSignatures resilient against account IDs that are not compliant with ed25519 #440

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

## Pending

## 0.34.1

* Fix the `Sep10Challenge.verifyTransactionSignatures` method to handle/ignore signers that are not ed25519 compliant. ([#440](https://github.com/stellar/java-stellar-sdk/pull/440))

## 0.34.0
* Add memo to `Sep10Challenge.newChallenge()` and `Sep10Challenge.readChallengeTransaction`. ([#435](https://github.com/stellar/java-stellar-sdk/pull/435))

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

sourceCompatibility = 1.6
version = '0.34.0'
version = '0.34.1'
group = 'stellar'
jar.enabled = false

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/stellar/sdk/Sep10Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,14 @@ private static Set<String> verifyTransactionSignatures(Transaction transaction,
}

for (String signer : signers) {
KeyPair keyPair = KeyPair.fromAccountId(signer);
KeyPair keyPair;
try {
keyPair = KeyPair.fromAccountId(signer);
} catch (RuntimeException e) {
System.out.printf("Couldn't parse the signer \"%s\" as a valid Public Key.", signer);
Copy link
Contributor

Choose a reason for hiding this comment

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

this console output is non-standard for the sdk which by default does not generate that type of output or logger outputs. So, to maintain consistency, would remove this and the stacktrace prints. the callers of this method could check the returned set, and determine which signers are missing, then it could deduce something was wrong and log something from the app layer, etc.

e.printStackTrace();
continue;
}
SignatureHint hint = keyPair.getSignatureHint();

for (Signature signature : signatures.get(hint)) {
Expand Down
39 changes: 38 additions & 1 deletion src/test/java/org/stellar/sdk/Sep10ChallengeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testChallenge() throws InvalidSep10ChallengeException {
}

@Test
public void testNewChallengeRejectsMuxedClientAccount() throws InvalidSep10ChallengeException {
public void testNewChallengeRejectsMuxedClientAccount() {
try {
KeyPair server = KeyPair.random();

Expand Down Expand Up @@ -1608,6 +1608,43 @@ public void testVerifyChallengeTransactionThresholdValidServerAndMultipleClientK
assertEquals(new HashSet<String>(Arrays.asList(masterClient.getAccountId(), signerClient1.getAccountId())), signersFound);
}

@Test
public void testVerifyChallengeTransactionThresholdValidServerAndMultipleClientKeyMeetingThresholdSomeUnusedAndOneNotEd25519Compliant() throws IOException, InvalidSep10ChallengeException {
Copy link
Contributor

Choose a reason for hiding this comment

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

now that's a test case name, good coverage to assert the change! maybe condense the name down to just the non-compliant aspect.

Network network = Network.TESTNET;
KeyPair server = KeyPair.random();
KeyPair masterClient = KeyPair.random();
KeyPair signerClient1 = KeyPair.random();
KeyPair signerClient2 = KeyPair.random();
long now = System.currentTimeMillis() / 1000L;
long end = now + 300;
TimeBounds timeBounds = new TimeBounds(now, end);
String domainName = "example.com";
String webAuthDomain = "example.com";

Transaction transaction = Sep10Challenge.newChallenge(
server,
network,
masterClient.getAccountId(),
domainName,
webAuthDomain,
timeBounds
);

transaction.sign(masterClient);
transaction.sign(signerClient1);

Set<Sep10Challenge.Signer> signers = new HashSet<Sep10Challenge.Signer>(Arrays.asList(
new Sep10Challenge.Signer(masterClient.getAccountId(), 1),
new Sep10Challenge.Signer(signerClient1.getAccountId(), 2),
new Sep10Challenge.Signer(signerClient2.getAccountId(), 4),
new Sep10Challenge.Signer("GA2T6GR7VXXXBETTERSAFETHANSORRYXXXPROTECTEDBYLOBSTRVAULT", 1)
));

int threshold = 3;
Set<String> signersFound = Sep10Challenge.verifyChallengeTransactionThreshold(transaction.toEnvelopeXdrBase64(), server.getAccountId(), network, domainName, webAuthDomain, threshold, signers);
assertEquals(new HashSet<String>(Arrays.asList(masterClient.getAccountId(), signerClient1.getAccountId())), signersFound);
}

@Test
public void testVerifyChallengeTransactionThresholdValidServerAndMultipleClientKeyMeetingThresholdSomeUnusedIgnorePreauthTxHashAndXHash() throws IOException, InvalidSep10ChallengeException {
Network network = Network.TESTNET;
Expand Down