From 61915cea511f051d8b7c21629411e763d7877dd7 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Mon, 25 Dec 2023 10:44:04 -0800 Subject: [PATCH] moar cleanup --- .../apollo/cryptography/DigestAlgorithm.java | 20 +++++++++++++ grpc/src/main/proto/choam.proto | 7 +---- .../apollo/demesnes/FireFliesTrace.java | 5 +--- .../com/salesforce/apollo/model/Domain.java | 18 ------------ .../apollo/model/ProcessDomain.java | 5 +--- model/src/main/resources/initialize.xml | 19 +++++-------- .../apollo/model/ContainmentDomainTest.java | 5 +--- .../salesforce/apollo/model/DomainTest.java | 5 +--- .../apollo/model/FireFliesTest.java | 5 +--- schemas/src/main/resources/model/model.xml | 28 +++++-------------- .../spec/KeyConfigurationDigester.java | 21 +++++++------- 11 files changed, 50 insertions(+), 88 deletions(-) diff --git a/cryptography/src/main/java/com/salesforce/apollo/cryptography/DigestAlgorithm.java b/cryptography/src/main/java/com/salesforce/apollo/cryptography/DigestAlgorithm.java index e06fa97d73..25bb3adb77 100644 --- a/cryptography/src/main/java/com/salesforce/apollo/cryptography/DigestAlgorithm.java +++ b/cryptography/src/main/java/com/salesforce/apollo/cryptography/DigestAlgorithm.java @@ -245,6 +245,11 @@ public byte[] hashOf(InputStream is) { return EMPTY; } }, SHA2_256 { + @Override + public String algorithmName() { + return "SHA-256"; + } + @Override public byte digestCode() { return 6; @@ -258,6 +263,11 @@ public int digestLength() { }, SHA2_512 { + @Override + public String algorithmName() { + return "SHA-512"; + } + @Override public byte digestCode() { return 7; @@ -271,6 +281,11 @@ public int digestLength() { }, SHA3_256 { + @Override + public String algorithmName() { + return "SHA3-256"; + } + @Override public byte digestCode() { return 8; @@ -282,6 +297,11 @@ public int digestLength() { } }, SHA3_512 { + @Override + public String algorithmName() { + return "SHA3-512"; + } + @Override public byte digestCode() { return 9; diff --git a/grpc/src/main/proto/choam.proto b/grpc/src/main/proto/choam.proto index 8da25663aa..76f9aae791 100644 --- a/grpc/src/main/proto/choam.proto +++ b/grpc/src/main/proto/choam.proto @@ -88,13 +88,8 @@ message Assemble { crypto.Digeste nextView = 1; } -message Foundation { - repeated crypto.Digeste membership = 1; - stereotomy.KeyEvent_ authority = 2; -} - message FoundationSeal { - Foundation foundation = 1; + stereotomy.KeyEvent_ foundation = 1; crypto.Sig signature = 2; } diff --git a/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java b/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java index 22e21dc20a..c09eebda2c 100644 --- a/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java +++ b/isolates/src/test/java/com/salesforce/apollo/demesnes/FireFliesTrace.java @@ -13,7 +13,6 @@ import com.salesforce.apollo.choam.Parameters.Builder; import com.salesforce.apollo.choam.Parameters.ProducerParameters; import com.salesforce.apollo.choam.Parameters.RuntimeParameters; -import com.salesforce.apollo.choam.proto.Foundation; import com.salesforce.apollo.choam.proto.FoundationSeal; import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; @@ -197,9 +196,7 @@ public void before() throws Exception { }).collect(Collectors.toMap(controlled -> controlled.getIdentifier().getDigest(), controlled -> controlled)); Digest group = DigestAlgorithm.DEFAULT.getOrigin(); - var foundation = Foundation.newBuilder(); - identities.keySet().forEach(d -> foundation.addMembership(d.toDigeste())); - var sealed = FoundationSeal.newBuilder().setFoundation(foundation).build(); + var sealed = FoundationSeal.newBuilder().build(); identities.forEach((digest, id) -> { var context = new ContextImpl<>(DigestAlgorithm.DEFAULT.getLast(), CARDINALITY, 0.2, 3); final var member = new ControlledIdentifierMember(id); diff --git a/model/src/main/java/com/salesforce/apollo/model/Domain.java b/model/src/main/java/com/salesforce/apollo/model/Domain.java index d33f09759b..2c835d14e1 100644 --- a/model/src/main/java/com/salesforce/apollo/model/Domain.java +++ b/model/src/main/java/com/salesforce/apollo/model/Domain.java @@ -34,8 +34,6 @@ import com.salesforce.apollo.stereotomy.event.protobuf.ProtobufEventFactory; import com.salesforce.apollo.stereotomy.identifier.Identifier; import com.salesforce.apollo.stereotomy.identifier.SelfAddressingIdentifier; -import org.jooq.SQLDialect; -import org.jooq.impl.DSL; import org.joou.ULong; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,8 +51,6 @@ import java.util.concurrent.Executors; import static com.salesforce.apollo.cryptography.QualifiedBase64.qb64; -import static com.salesforce.apollo.model.schema.tables.Member.MEMBER; -import static com.salesforce.apollo.stereotomy.schema.tables.Identifier.IDENTIFIER; import static java.nio.file.Path.of; /** @@ -107,20 +103,6 @@ public Domain(ControlledIdentifierMember member, Parameters.Builder params, Stri member.getId(), dbURL, checkpointBaseDir); } - public static void addMembers(Connection connection, List members) { - var context = DSL.using(connection, SQLDialect.H2); - for (var m : members) { - var id = context.insertInto(IDENTIFIER, IDENTIFIER.PREFIX) - .values(m) - .onDuplicateKeyIgnore() - .returning(IDENTIFIER.ID) - .fetchOne(); - if (id != null) { - context.insertInto(MEMBER).set(MEMBER.IDENTIFIER, id.value1()).onConflictDoNothing().execute(); - } - } - } - public static Txn boostrapMigration() { Map resources = new HashMap<>(); resources.put(of("/initialize.xml"), res("/initialize.xml")); diff --git a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java index ff39c6ae5c..bb30657c07 100644 --- a/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java +++ b/model/src/main/java/com/salesforce/apollo/model/ProcessDomain.java @@ -54,10 +54,7 @@ public ProcessDomain(Digest group, ControlledIdentifierMember member, Builder bu InetSocketAddress endpoint, com.salesforce.apollo.fireflies.Parameters.Builder ff, EventValidation eventValidation) { super(member, builder, dbURL, checkpointBaseDir, runtime); - var base = Context.newBuilder() - .setId(group) - .setCardinality(params.runtime().foundation().getFoundation().getMembershipCount()) - .build(); + var base = Context.newBuilder().setId(group).build(); this.foundation = new View(base, getMember(), endpoint, eventValidation, params.communications(), ff.build(), DigestAlgorithm.DEFAULT, null); final var url = String.format("jdbc:h2:mem:%s-%s;DB_CLOSE_DELAY=-1", member.getId(), ""); diff --git a/model/src/main/resources/initialize.xml b/model/src/main/resources/initialize.xml index 4f200584c1..d105b81b5a 100644 --- a/model/src/main/resources/initialize.xml +++ b/model/src/main/resources/initialize.xml @@ -1,14 +1,9 @@ - + - - - - - - create alias apollo_kernel.add_members for - "com.salesforce.apollo.model.Domain.addMembers" - - - \ No newline at end of file + + + + diff --git a/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java b/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java index c87be7fd12..56858aa233 100644 --- a/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/ContainmentDomainTest.java @@ -13,7 +13,6 @@ import com.salesforce.apollo.choam.Parameters.Builder; import com.salesforce.apollo.choam.Parameters.ProducerParameters; import com.salesforce.apollo.choam.Parameters.RuntimeParameters; -import com.salesforce.apollo.choam.proto.Foundation; import com.salesforce.apollo.choam.proto.FoundationSeal; import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; @@ -81,9 +80,7 @@ public void before() throws Exception { .collect(Collectors.toMap(controlled -> controlled.getIdentifier().getDigest(), controlled -> controlled)); - var foundation = Foundation.newBuilder(); - identities.keySet().forEach(d -> foundation.addMembership(d.toDigeste())); - var sealed = FoundationSeal.newBuilder().setFoundation(foundation).build(); + var sealed = FoundationSeal.newBuilder().build(); final var group = DigestAlgorithm.DEFAULT.getOrigin(); identities.forEach((d, id) -> { final var member = new ControlledIdentifierMember(id); diff --git a/model/src/test/java/com/salesforce/apollo/model/DomainTest.java b/model/src/test/java/com/salesforce/apollo/model/DomainTest.java index ce5afe528a..8aea03d09b 100644 --- a/model/src/test/java/com/salesforce/apollo/model/DomainTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/DomainTest.java @@ -13,7 +13,6 @@ import com.salesforce.apollo.choam.Parameters.Builder; import com.salesforce.apollo.choam.Parameters.ProducerParameters; import com.salesforce.apollo.choam.Parameters.RuntimeParameters; -import com.salesforce.apollo.choam.proto.Foundation; import com.salesforce.apollo.choam.proto.FoundationSeal; import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; @@ -211,9 +210,7 @@ public void before() throws Exception { .collect(Collectors.toMap(controlled -> controlled.getIdentifier().getDigest(), controlled -> controlled)); - var foundation = Foundation.newBuilder(); - identities.keySet().forEach(d -> foundation.addMembership(d.toDigeste())); - var sealed = FoundationSeal.newBuilder().setFoundation(foundation).build(); + var sealed = FoundationSeal.newBuilder().build(); final var group = DigestAlgorithm.DEFAULT.getOrigin(); identities.forEach((d, id) -> { final var member = new ControlledIdentifierMember(id); diff --git a/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java b/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java index 0b12c9c82b..47644e1e31 100644 --- a/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java +++ b/model/src/test/java/com/salesforce/apollo/model/FireFliesTest.java @@ -13,7 +13,6 @@ import com.salesforce.apollo.choam.Parameters.Builder; import com.salesforce.apollo.choam.Parameters.ProducerParameters; import com.salesforce.apollo.choam.Parameters.RuntimeParameters; -import com.salesforce.apollo.choam.proto.Foundation; import com.salesforce.apollo.choam.proto.FoundationSeal; import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; @@ -84,9 +83,7 @@ public void before() throws Exception { }).collect(Collectors.toMap(controlled -> controlled.getIdentifier().getDigest(), controlled -> controlled)); Digest group = DigestAlgorithm.DEFAULT.getOrigin(); - var foundation = Foundation.newBuilder(); - identities.keySet().forEach(d -> foundation.addMembership(d.toDigeste())); - var sealed = FoundationSeal.newBuilder().setFoundation(foundation).build(); + var sealed = FoundationSeal.newBuilder().build(); identities.forEach((digest, id) -> { var context = new ContextImpl<>(DigestAlgorithm.DEFAULT.getLast(), CARDINALITY, 0.2, 3); final var member = new ControlledIdentifierMember(id); diff --git a/schemas/src/main/resources/model/model.xml b/schemas/src/main/resources/model/model.xml index 8a51037d13..1a6cad71fc 100644 --- a/schemas/src/main/resources/model/model.xml +++ b/schemas/src/main/resources/model/model.xml @@ -1,24 +1,10 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd"> - - create schema if not exists apollo_kernel - - - - - - - - - - \ No newline at end of file + + create schema if not exists apollo_kernel + + diff --git a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/identifier/spec/KeyConfigurationDigester.java b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/identifier/spec/KeyConfigurationDigester.java index f91179a63f..23dc386556 100644 --- a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/identifier/spec/KeyConfigurationDigester.java +++ b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/identifier/spec/KeyConfigurationDigester.java @@ -6,30 +6,29 @@ */ package com.salesforce.apollo.stereotomy.identifier.spec; -import static com.salesforce.apollo.cryptography.QualifiedBase64.bs; -import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; - -import java.security.PublicKey; -import java.util.List; -import java.util.stream.Stream; - import com.salesforce.apollo.cryptography.Digest; import com.salesforce.apollo.cryptography.DigestAlgorithm; import com.salesforce.apollo.cryptography.SigningThreshold; import com.salesforce.apollo.cryptography.SigningThreshold.Weighted.Weight; import com.salesforce.apollo.utils.Hex; +import java.security.PublicKey; +import java.util.List; +import java.util.stream.Stream; + +import static com.salesforce.apollo.cryptography.QualifiedBase64.bs; +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; + /** * @author hal.hildebrand - * */ public class KeyConfigurationDigester { public static Digest digest(SigningThreshold signingThreshold, List nextKeyDigests) { var st = signingThresholdRepresentation(signingThreshold); - var digestAlgorithm = nextKeyDigests.get(0).getAlgorithm(); + var digestAlgorithm = nextKeyDigests.getFirst().getAlgorithm(); var digest = digestAlgorithm.digest(st);// digest