diff --git a/memberships/src/main/java/com/salesforce/apollo/membership/stereotomy/IdentifierMember.java b/memberships/src/main/java/com/salesforce/apollo/membership/stereotomy/IdentifierMember.java index 72fab9f28..18902ab5d 100644 --- a/memberships/src/main/java/com/salesforce/apollo/membership/stereotomy/IdentifierMember.java +++ b/memberships/src/main/java/com/salesforce/apollo/membership/stereotomy/IdentifierMember.java @@ -6,32 +6,25 @@ */ package com.salesforce.apollo.membership.stereotomy; -import java.io.InputStream; - import com.salesforce.apollo.crypto.Digest; import com.salesforce.apollo.crypto.JohnHancock; import com.salesforce.apollo.crypto.SigningThreshold; import com.salesforce.apollo.crypto.Verifier; import com.salesforce.apollo.membership.Member; -import com.salesforce.apollo.stereotomy.event.EstablishmentEvent; -import com.salesforce.apollo.stereotomy.identifier.SelfAddressingIdentifier; + +import java.io.InputStream; /** - * @author hal.hildebrand * */ public class IdentifierMember implements Member { - private final EstablishmentEvent event; - private final Digest id; + private final Verifier verifier; + private final Digest id; - public IdentifierMember(EstablishmentEvent event) { - if (!(event.getIdentifier() instanceof SelfAddressingIdentifier)) { - throw new IllegalArgumentException("Event identifier must be self identifying: " - + event.getIdentifier().getClass()); - } - this.event = event; - this.id = ((SelfAddressingIdentifier) event.getIdentifier()).getDigest(); + public IdentifierMember(Digest id, Verifier verifier) { + this.id = id; + this.verifier = verifier; } @Override @@ -80,6 +73,6 @@ public boolean verify(SigningThreshold threshold, JohnHancock signature, InputSt } private Verifier verifier() { - return new DefaultVerifier(event.getKeys()); + return verifier; } } diff --git a/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java b/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java index 0bfd7afa8..69d7e0ced 100644 --- a/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java +++ b/model/src/main/java/com/salesforce/apollo/model/demesnes/DemesneImpl.java @@ -178,11 +178,9 @@ public void stop() { @Override public void viewChange(Digest viewId, List joining, List leaving) { final var current = domain; - joining.forEach(coords -> { - EstablishmentEvent keyEvent; - keyEvent = (EstablishmentEvent) kerl.getKeyState(coords); - current.activate(new IdentifierMember(keyEvent)); - }); + joining.forEach(coords -> current.activate( + new IdentifierMember(coords.getIdentifier().getDigest(kerl.getDigestAlgorithm()), + new KerlVerifier<>(coords.getIdentifier(), kerl)))); leaving.forEach(id -> current.getContext().remove(id)); } diff --git a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/ControlledIdentifier.java b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/ControlledIdentifier.java index 747f1264c..e10b96054 100644 --- a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/ControlledIdentifier.java +++ b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/ControlledIdentifier.java @@ -26,8 +26,7 @@ import java.util.Optional; /** - * A controlled identifier, representing the current state of the identifier at - * all times. + * A controlled identifier, representing the current state of the identifier at all times. * * @author hal.hildebrand */ @@ -74,13 +73,11 @@ public interface ControlledIdentifier extends BoundIdentif ControlledIdentifier newIdentifier(Builder newBuilder); /** - * Provision a certificate that encodes this identifier using a generated Basic - * Identifier. The certificate returned is signed by this self same generated - * basic identifier + * Provision a certificate that encodes this identifier using a generated Basic Identifier. The certificate returned + * is signed by this self same generated basic identifier *

- * A new key pair is generated and this becomes the signing key of the - * certificate. This new public key is then signed by this identifier's current - * key state's key(s).. + * A new key pair is generated and this becomes the signing key of the certificate. This new public key is then + * signed by this identifier's current key state's key(s).. *

* The values are encoded into the SubjectDN of the certificate as follows: *

    @@ -89,25 +86,21 @@ public interface ControlledIdentifier extends BoundIdentif * generated public key that signs the certificate *
* - * @param validFrom - the Instant which the generated certificate - * becomes valid - * @param valid - how long the certificate will be valid - * @param extensions - any extra stuff to put into ye pot - * @param signatureAlgorithm - the sig algorithm to use - * @return a CertificateWithPrivateKey that is self signed by the public key of - * the X509Certificate + * @param validFrom - the Instant which the generated certificate becomes valid + * @param valid - how long the certificate will be valid + * @param extensions - any extra stuff to put into ye pot + * @param algo - the sig algorithm to use + * @return a CertificateWithPrivateKey that is self-signed by the public key of the X509Certificate */ - CertificateWithPrivateKey provision(Instant validFrom, Duration valid, - List extensions, SignatureAlgorithm algo); + CertificateWithPrivateKey provision(Instant validFrom, Duration valid, List extensions, + SignatureAlgorithm algo); /** - * Provision a certificate that encodes this identifier using a generated Basic - * Identifier. The certificate returned is signed by this self same generated - * basic identifier + * Provision a certificate that encodes this identifier using a generated Basic Identifier. The certificate returned + * is signed by this self same generated basic identifier *

- * A new key pair is generated and this becomes the signing key of the - * certificate. This new public key is then signed by this identifier's current - * key state's key(s). + * A new key pair is generated and this becomes the signing key of the certificate. This new public key is then + * signed by this identifier's current key state's key(s). *

* The values are encoded into the SubjectDN of the certificate as follows: *

    @@ -116,15 +109,12 @@ CertificateWithPrivateKey provision(Instant validFrom, Duration valid, * generated public key that signs the certificate *
* - * @param validFrom - the Instant which the generated certificate - * becomes valid - * @param valid - how long the certificate will be valid - * @param signatureAlgorithm - the sig algorithm to use - * @return a CertificateWithPrivateKey that is self signed by the public key of - * the X509Certificate + * @param validFrom - the Instant which the generated certificate becomes valid + * @param valid - how long the certificate will be valid + * @param algo - the sig algorithm to use + * @return a CertificateWithPrivateKey that is self-signed by the public key of the X509Certificate */ - default CertificateWithPrivateKey provision(Instant validFrom, Duration valid, - SignatureAlgorithm algo) { + default CertificateWithPrivateKey provision(Instant validFrom, Duration valid, SignatureAlgorithm algo) { return provision(validFrom, valid, Collections.emptyList(), algo); } diff --git a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyVerifier.java b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/KerlVerifier.java similarity index 82% rename from stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyVerifier.java rename to stereotomy/src/main/java/com/salesforce/apollo/stereotomy/KerlVerifier.java index c389243b0..57e6b7b6e 100644 --- a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyVerifier.java +++ b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/KerlVerifier.java @@ -14,14 +14,14 @@ * * @author hal.hildebrand **/ -public class StereotomyVerifier implements Verifier { +public class KerlVerifier implements Verifier { - private final D identifier; - private final StereotomyImpl stereotomy; + private final D identifier; + private final KERL kerl; - public StereotomyVerifier(D identifier, StereotomyImpl stereotomy) { + public KerlVerifier(D identifier, KERL kerl) { this.identifier = identifier; - this.stereotomy = stereotomy; + this.kerl = kerl; } public D identifier() { @@ -49,7 +49,7 @@ public boolean verify(SigningThreshold threshold, JohnHancock signature, InputSt } private Optional verifierFor(ULong sequenceNumber) { - KeyState keyState = stereotomy.kerl.getKeyState(identifier, sequenceNumber); + KeyState keyState = kerl.getKeyState(identifier, sequenceNumber); if (keyState == null) { return Optional.empty(); } @@ -57,7 +57,7 @@ private Optional verifierFor(ULong sequenceNumber) { } public Optional verifierFor(EventCoordinates coordinates) { - KeyState keyState = stereotomy.kerl.getKeyState(coordinates); + KeyState keyState = kerl.getKeyState(coordinates); if (keyState == null) { return Optional.empty(); } diff --git a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyImpl.java b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyImpl.java index f87657a05..414532136 100644 --- a/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyImpl.java +++ b/stereotomy/src/main/java/com/salesforce/apollo/stereotomy/StereotomyImpl.java @@ -450,7 +450,7 @@ public EstablishmentEvent getLastEstablishingEvent() { @Override public Optional getVerifier() { - return Optional.of(new StereotomyVerifier(getIdentifier(), StereotomyImpl.this)); + return Optional.of(new KerlVerifier(getIdentifier(), kerl)); } @Override diff --git a/thoth/src/main/java/com/salesforce/apollo/thoth/Ani.java b/thoth/src/main/java/com/salesforce/apollo/thoth/Ani.java index 60118f6bc..63689d31a 100644 --- a/thoth/src/main/java/com/salesforce/apollo/thoth/Ani.java +++ b/thoth/src/main/java/com/salesforce/apollo/thoth/Ani.java @@ -51,6 +51,7 @@ public EventValidation eventValidation(Duration timeout) { @Override public Filtered filtered(EventCoordinates coordinates, SigningThreshold threshold, JohnHancock signature, InputStream message) { + KeyState ks = kerl.getKeyState(coordinates); var v = new Verifier.DefaultVerifier(ks.getKeys()); return v.filtered(threshold, signature, message); @@ -94,14 +95,12 @@ public Verifiers verifiers(Duration timeout) { @Override public Optional verifierFor(EventCoordinates coordinates) { - EstablishmentEvent ke = (EstablishmentEvent) kerl.getKeyEvent(coordinates); - return Optional.ofNullable(new Verifier.DefaultVerifier(ke.getKeys())); + return Optional.of(new KerlVerifier<>(coordinates.getIdentifier(), kerl)); } @Override public Optional verifierFor(Identifier identifier) { - EstablishmentEvent ke = (EstablishmentEvent) kerl.getKeyState(identifier); - return Optional.ofNullable(new Verifier.DefaultVerifier(ke.getKeys())); + return Optional.of(new KerlVerifier<>(identifier, kerl)); } }; } @@ -147,4 +146,5 @@ private boolean performKerlValidation(EventCoordinates coord, Duration timeout) private boolean validateKerl(KeyEvent event, Duration timeout) { return performKerlValidation(event.getCoordinates(), timeout); } + }