Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Oct 20, 2023
1 parent 7b34757 commit 84015d6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;

public class CryptographySignatureValidation {
class CryptographySignatureValidation {
/**
* This function returns whether the signature matches validation.
* It throws an error if it is unable to perform this check, for reasons including:
Expand Down Expand Up @@ -133,7 +133,7 @@ private static void ensurePublicKeyMatchesExpectedValue(
rsaFromFile.exponent = rsaFromFile.exponent.trim();
rsaFromFile.modulus = rsaFromFile.modulus.trim();
if (!rsaFromFile.exponent.equals(rsaKeyValue.exponent)
|| !rsaFromFile.modulus.equals(rsaKeyValue.modulus)) {
|| !rsaFromFile.modulus.equals(rsaKeyValue.modulus)) {
throw new CouldNotVerifySignatureException(
"%s was signed with a different public key than %s.\nActual modulus: %s\nExpected: %s"
.formatted(signatureKeyFile.getAbsolutePath(), publicKeyFile.getAbsolutePath(),
Expand Down Expand Up @@ -242,7 +242,7 @@ private static <T> T readFromXml(File xmlFile, Class<T> classType) throws IOExce
}
}

public static class CouldNotVerifySignatureException extends Exception {
static class CouldNotVerifySignatureException extends Exception {
CouldNotVerifySignatureException(String message) {
super(message);
}
Expand Down
95 changes: 0 additions & 95 deletions src/main/java/network/brightspots/rcv/CryptographyXMLParsers.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

public class CryptographyXmlParsers {
class CryptographyXmlParsers {
@JacksonXmlRootElement(localName = "Signature", namespace = "http://www.w3.org/2000/09/xmldsig#")
public static class HartSignature {
@JacksonXmlProperty(localName = "SignedInfo")
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/network/brightspots/rcv/HartCvrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ void readCastVoteRecords(List<CastVoteRecord> castVoteRecords)
for (File child : children) {
String childNameLower = child.getName().toLowerCase();
if (childNameLower.endsWith("xml") && !childNameLower.endsWith(".sig.xml")) {
File signatureXML = new File(child.getAbsolutePath() + ".sig.xml");
File signatureXml = new File(child.getAbsolutePath() + ".sig.xml");
boolean isHashVerified;
try {
isHashVerified = CryptographySignatureValidation.verifyPublicKeySignature(
publicKeyTxt, signatureXML, child);
publicKeyTxt, signatureXml, child);
} catch (CryptographySignatureValidation.CouldNotVerifySignatureException e) {
Logger.severe("Failure while trying to verify hash %s of %s: \n%s",
signatureXML.getAbsolutePath(), child.getAbsolutePath(), e.getMessage());
signatureXml.getAbsolutePath(), child.getAbsolutePath(), e.getMessage());
throw new CastVoteRecord.CvrParseException();
}
if (!isHashVerified) {
Logger.severe("Incorrect hash %s of %s",
signatureXML.getAbsolutePath(), child.getAbsolutePath());
signatureXml.getAbsolutePath(), child.getAbsolutePath());
throw new CastVoteRecord.CvrParseException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

import static network.brightspots.rcv.CryptographySignatureValidation.CouldNotVerifySignatureException;
import static network.brightspots.rcv.CryptographySignatureValidation.verifyPublicKeySignature;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -78,7 +77,7 @@ void testModifiedDataFile() throws IOException {
Files.write(modifiedDataFile.toPath(), "not the original data".getBytes());

Assertions.assertThrows(CouldNotVerifySignatureException.class, () ->
verifyPublicKeySignature(DEFAULT_PUBLIC_KEY_FILE, DEFAULT_SIGNATURE_FILE, modifiedDataFile)
verifyPublicKeySignature(DEFAULT_PUBLIC_KEY_FILE, DEFAULT_SIGNATURE_FILE, modifiedDataFile)
);
}

Expand All @@ -101,7 +100,7 @@ void testFailsIfFilenameDiffers() throws IOException {
Files.copy(DEFAULT_DATA_FILE.toPath(), modifiedDataFile.toPath());

Assertions.assertThrows(CouldNotVerifySignatureException.class, () ->
verifyPublicKeySignature(DEFAULT_PUBLIC_KEY_FILE, DEFAULT_SIGNATURE_FILE, modifiedDataFile)
verifyPublicKeySignature(DEFAULT_PUBLIC_KEY_FILE, DEFAULT_SIGNATURE_FILE, modifiedDataFile)
);
}

Expand Down

0 comments on commit 84015d6

Please sign in to comment.