Skip to content

Commit

Permalink
moar cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Dec 25, 2023
1 parent 21013b2 commit 61915ce
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -258,6 +263,11 @@ public int digestLength() {
},

SHA2_512 {
@Override
public String algorithmName() {
return "SHA-512";
}

@Override
public byte digestCode() {
return 7;
Expand All @@ -271,6 +281,11 @@ public int digestLength() {
},

SHA3_256 {
@Override
public String algorithmName() {
return "SHA3-256";
}

@Override
public byte digestCode() {
return 8;
Expand All @@ -282,6 +297,11 @@ public int digestLength() {
}

}, SHA3_512 {
@Override
public String algorithmName() {
return "SHA3-512";
}

@Override
public byte digestCode() {
return 9;
Expand Down
7 changes: 1 addition & 6 deletions grpc/src/main/proto/choam.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 0 additions & 18 deletions model/src/main/java/com/salesforce/apollo/model/Domain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -107,20 +103,6 @@ public Domain(ControlledIdentifierMember member, Parameters.Builder params, Stri
member.getId(), dbURL, checkpointBaseDir);
}

public static void addMembers(Connection connection, List<byte[]> 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<Path, URL> resources = new HashMap<>();
resources.put(of("/initialize.xml"), res("/initialize.xml"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Participant>newBuilder()
.setId(group)
.setCardinality(params.runtime().foundation().getFoundation().getMembershipCount())
.build();
var base = Context.<Participant>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(), "");
Expand Down
19 changes: 7 additions & 12 deletions model/src/main/resources/initialize.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.5.xsd">
<databaseChangeLog 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">

<include file="stereotomy/initialize.xml" relativeToChangelogFile="true" />
<include file="delphinius/initialize.xml" relativeToChangelogFile="true" />
<include file="model/model.xml" relativeToChangelogFile="true" />

<changeSet id="addmember-0" author="hhildebrand">
<sql>create alias apollo_kernel.add_members for
"com.salesforce.apollo.model.Domain.addMembers"
</sql>
</changeSet>
</databaseChangeLog>
<include file="stereotomy/initialize.xml" relativeToChangelogFile="true"/>
<include file="delphinius/initialize.xml" relativeToChangelogFile="true"/>
<include file="model/model.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 7 additions & 21 deletions schemas/src/main/resources/model/model.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd
http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.5.xsd">
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">

<changeSet author="hhildebrand" id="model-1">
<sql>create schema if not exists apollo_kernel</sql>

<createTable tableName="member" schemaName="apollo_kernel">
<column name="identifier" type="INT8">
<constraints nullable="false" primaryKey="true" />
</column>
</createTable>

<addForeignKeyConstraint onDelete="CASCADE"
baseColumnNames="identifier" baseTableName="member"
baseTableSchemaName="apollo_kernel"
constraintName="member_identifier_fk"
referencedTableName="identifier" referencedColumnNames="id"
referencedTableSchemaName="stereotomy" />
</changeSet>
</databaseChangeLog>
<changeSet author="hhildebrand" id="model-0">
<sql>create schema if not exists apollo_kernel</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -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<Digest> nextKeyDigests) {
var st = signingThresholdRepresentation(signingThreshold);
var digestAlgorithm = nextKeyDigests.get(0).getAlgorithm();
var digestAlgorithm = nextKeyDigests.getFirst().getAlgorithm();

var digest = digestAlgorithm.digest(st);// digest

Expand Down

0 comments on commit 61915ce

Please sign in to comment.