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

Fixes to 0.7 release #526

Merged
merged 23 commits into from Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0fba8b5
Create version 0.7.1-SNAPSHOT for maintainance release
melowe Nov 14, 2018
9545a0a
Optionally disable sync poller to reveal party info discovery issue.
melowe Nov 14, 2018
8b17950
Initialise party info using config data
melowe Nov 14, 2018
326c9df
Add to String to part for better logging.
melowe Nov 14, 2018
5e0b6b2
Adjust test to reflect changes made to impl
melowe Nov 14, 2018
7e186f0
Inject part info service, when admin adds a new peer update party info.
melowe Nov 14, 2018
1320fcf
Randomise start up order.
melowe Nov 14, 2018
2eca709
Ensure that configurations only have a single peer configured and that
melowe Nov 14, 2018
180c782
Validate file contents initial for key file validation.
melowe Nov 15, 2018
25ad7a0
Fix test fuxture where key file has a line
melowe Nov 15, 2018
5fee10f
Fix for Unauthenticated Denial of Service #57
melowe Nov 15, 2018
1305e97
Include base64 public key in exception message. Log key not found at
melowe Nov 13, 2018
5c7e37b
trim extra spaces or newline when read pub/pri keys from file
namtruong Nov 11, 2018
360c66b
trim extra spaces or newline when read pub/pri keys from file
namtruong Nov 11, 2018
a426d01
Update the maven surefire plugin version
prd-fox Nov 9, 2018
b3311ec
use branch name for tag element in release plugin.
melowe Nov 15, 2018
c1b4413
Remove trailing space from tag node
melowe Nov 15, 2018
dfe7845
Allow zero in length validation. return boolean for checks.
melowe Nov 16, 2018
789d187
Revert "Allow zero in length validation. return boolean for checks."
melowe Nov 16, 2018
29270b6
Allow zero in length validation. return boolean for checks.
melowe Nov 16, 2018
4d9d1f7
The intention of this unit test is to test the expected behaviour whe…
namtruong Nov 16, 2018
9e836df
Merge remote-tracking branch 'origin/bugfix/partyinfo' into bugfix/pa…
namtruong Nov 16, 2018
cacb456
Update failsafe version
prd-fox Nov 16, 2018
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
2 changes: 1 addition & 1 deletion argon2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<artifactId>tessera</artifactId>
<groupId>com.quorum.tessera</groupId>
<version>0.7</version>
<version>0.7.1-SNAPSHOT</version>
</parent>


Expand Down
2 changes: 1 addition & 1 deletion config-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.quorum.tessera</groupId>
<artifactId>tessera</artifactId>
<version>0.7</version>
<version>0.7.1-SNAPSHOT</version>
</parent>

<artifactId>config-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.UUID;

import static com.quorum.tessera.test.util.ElUtil.createAndPopulatePaths;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void withConstraintViolations() throws Exception {
cliDelegate.execute("-configfile", configFile.toString());
failBecauseExceptionWasNotThrown(ConstraintViolationException.class);
} catch (ConstraintViolationException ex) {
assertThat(ex.getConstraintViolations()).hasSize(2);
assertThat(ex.getConstraintViolations()).hasSize(4);

}

Expand All @@ -113,7 +114,13 @@ public void keygenWithConfig() throws Exception {

KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator();

FilesystemKeyPair keypair = new FilesystemKeyPair(Paths.get(""), Paths.get(""));
Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");

Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));

FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath);
when(keyGenerator.generate(anyString(), eq(null))).thenReturn(keypair);

Path unixSocketPath = Files.createTempFile(UUID.randomUUID().toString(), ".ipc");
Expand Down Expand Up @@ -175,8 +182,14 @@ public void outputWithoutKeygenOrConfig() {
public void output() throws Exception {

KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator();

FilesystemKeyPair keypair = new FilesystemKeyPair(Paths.get(""), Paths.get(""));

Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");

Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));

FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath);
when(keyGenerator.generate(anyString(), eq(null))).thenReturn(keypair);

Path generatedKey = Paths.get("/tmp/" + UUID.randomUUID().toString());
Expand Down Expand Up @@ -355,7 +368,13 @@ public void suppressStartupForKeygenOption() throws Exception {
@Test
public void allowStartupForKeygenAndConfigfileOptions() throws Exception {
final KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator();
final FilesystemKeyPair keypair = new FilesystemKeyPair(Paths.get(""), Paths.get(""));
Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");

Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));

FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath);
when(keyGenerator.generate(anyString(), eq(null))).thenReturn(keypair);

final Path configFile = createAndPopulatePaths(getClass().getResource("/sample-config.json"));
Expand Down
2 changes: 1 addition & 1 deletion config-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.quorum.tessera</groupId>
<artifactId>tessera</artifactId>
<version>0.7</version>
<version>0.7.1-SNAPSHOT</version>
</parent>
<artifactId>config-migration</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ public void ifConfigParameterIsNotSetInTomlOrCliThenDefaultIsUsed() throws Excep
Path configFile = Files.createTempFile("emptyConfig", ".txt");
Path keysFile = Paths.get("abcxyz");
Files.deleteIfExists(keysFile);
Files.createFile(Paths.get("abcxyz"));
Files.createFile(keysFile);
Files.write(keysFile, Arrays.asList("SOMEDATA"));

String[] requiredParams = {
"--tomlfile=" + configFile.toString(),
Expand Down
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>com.quorum.tessera</groupId>
<artifactId>tessera</artifactId>
<version>0.7</version>
<version>0.7.1-SNAPSHOT</version>
</parent>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.quorum.tessera.config.constraints;

import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;

@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE, TYPE_PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Constraint(validatedBy = ValidContentValidator.class)
@Documented
public @interface ValidContent {

String message() default "{ValidContent.message}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

int minLines() default 0;

int maxLines() default Integer.MAX_VALUE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.quorum.tessera.config.constraints;

import com.quorum.tessera.io.FilesDelegate;
import java.nio.file.Files;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class ValidContentValidator implements ConstraintValidator<ValidContent, Path> {

private ValidContent config;

@Override
public void initialize(ValidContent constraintAnnotation) {
this.config = constraintAnnotation;
}

@Override
public boolean isValid(Path path, ConstraintValidatorContext context) {

if (Objects.isNull(path)) {
return true;
}

if (!Files.exists(path)) {
return true;
}

List<String> lines = FilesDelegate.create().lines(path)
.filter(line -> !Objects.equals("", line))
.collect(Collectors.toList());

return lines.size() >= config.minLines() && lines.size() <= config.maxLines();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import com.quorum.tessera.config.constraints.ValidBase64;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlElement;

public class DirectKeyPair implements ConfigKeyPair {

@Size(min = 1)
@NotNull
@ValidBase64(message = "Invalid Base64 key provided")
@XmlElement
private final String publicKey;


@Size(min = 1)
@NotNull
@ValidBase64(message = "Invalid Base64 key provided")
@XmlElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.quorum.tessera.config.KeyDataConfig;
import com.quorum.tessera.config.adapters.PathAdapter;
import com.quorum.tessera.config.constraints.ValidContent;
import com.quorum.tessera.config.constraints.ValidPath;
import com.quorum.tessera.config.util.JaxbUtil;
import com.quorum.tessera.io.IOCallback;
Expand All @@ -16,12 +17,14 @@

public class FilesystemKeyPair implements ConfigKeyPair {

@ValidContent(minLines = 1,maxLines = 1,message = "file expected to contain a single non empty value")
@NotNull
@ValidPath(checkExists = true, message = "File does not exist")
@XmlElement
@XmlJavaTypeAdapter(PathAdapter.class)
private final Path publicKeyPath;

@ValidContent(minLines = 1,message = "file expected to contain at least one line")
@NotNull
@ValidPath(checkExists = true, message = "File does not exist")
@XmlElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

import static com.quorum.tessera.config.PrivateKeyType.UNLOCKED;
import com.quorum.tessera.encryption.PrivateKey;
import javax.validation.constraints.Size;

@ValidInlineKeypair
public class InlineKeypair implements ConfigKeyPair {

@Size(min = 1)
@NotNull
@ValidBase64(message = "Invalid Base64 key provided")
@XmlElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ private KeyPair convert(ConfigKeyPair configKeyPair) {
}

return new KeyPair(
PublicKey.from(Base64.getDecoder().decode(encodedPub)),
PrivateKey.from(Base64.getDecoder().decode(encodedPriv))
PublicKey.from(Base64.getDecoder().decode(encodedPub.trim())),
PrivateKey.from(Base64.getDecoder().decode(encodedPriv.trim()))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.quorum.tessera.config.constraints;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.UUID;
import javax.validation.ConstraintValidatorContext;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ValidContentValidatorTest {

@Test
public void ignoreNullPath() {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

assertThat(validator.isValid(null, context)).isTrue();

}

@Test
public void ignoreNonExistPath() {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Paths.get(UUID.randomUUID().toString());

assertThat(path).doesNotExist();

assertThat(validator.isValid(path, context)).isTrue();

}

@Test
public void defaultValuesIgnoreEmptyFile() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);

validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isTrue();

}

@Test
public void expectSingleLineButFileIsEmpty() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isFalse();

}

@Test
public void expectSingleLineFileIsValid() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");
Files.write(path, "SOMEDATA".getBytes());

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isTrue();

}

@Test
public void tooManyLines() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");
Files.write(path, Arrays.asList("SOMEDATA","SOMEMOREDATA"));

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isFalse();

}

@Test
public void emptyLine() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");
Files.write(path, Arrays.asList(""));

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isFalse();

}


}
Loading