Skip to content

Commit

Permalink
rename back to KerlVerifier. further usage in membership impls
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Nov 23, 2023
1 parent 3bea61b commit 0943a64
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,6 +73,6 @@ public boolean verify(SigningThreshold threshold, JohnHancock signature, InputSt
}

private Verifier verifier() {
return new DefaultVerifier(event.getKeys());
return verifier;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ public void stop() {
@Override
public void viewChange(Digest viewId, List<EventCoordinates> joining, List<Digest> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -74,13 +73,11 @@ public interface ControlledIdentifier<D extends Identifier> extends BoundIdentif
<I extends Identifier> ControlledIdentifier<I> newIdentifier(Builder<I> 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
* <p>
* 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)..
* <p>
* The values are encoded into the SubjectDN of the certificate as follows:
* <ul>
Expand All @@ -89,25 +86,21 @@ public interface ControlledIdentifier<D extends Identifier> extends BoundIdentif
* generated public key that signs the certificate</li>
* </ul>
*
* @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<CertExtension> extensions, SignatureAlgorithm algo);
CertificateWithPrivateKey provision(Instant validFrom, Duration valid, List<CertExtension> 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
* <p>
* 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).
* <p>
* The values are encoded into the SubjectDN of the certificate as follows:
* <ul>
Expand All @@ -116,15 +109,12 @@ CertificateWithPrivateKey provision(Instant validFrom, Duration valid,
* generated public key that signs the certificate</li>
* </ul>
*
* @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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*
* @author hal.hildebrand
**/
public class StereotomyVerifier<D extends Identifier> implements Verifier {
public class KerlVerifier<D extends Identifier> 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() {
Expand Down Expand Up @@ -49,15 +49,15 @@ public boolean verify(SigningThreshold threshold, JohnHancock signature, InputSt
}

private Optional<Verifier> verifierFor(ULong sequenceNumber) {
KeyState keyState = stereotomy.kerl.getKeyState(identifier, sequenceNumber);
KeyState keyState = kerl.getKeyState(identifier, sequenceNumber);
if (keyState == null) {
return Optional.empty();
}
return Optional.of(new DefaultVerifier(keyState.getKeys()));
}

public Optional<Verifier> verifierFor(EventCoordinates coordinates) {
KeyState keyState = stereotomy.kerl.getKeyState(coordinates);
KeyState keyState = kerl.getKeyState(coordinates);
if (keyState == null) {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public EstablishmentEvent getLastEstablishingEvent() {

@Override
public Optional<Verifier> getVerifier() {
return Optional.of(new StereotomyVerifier<D>(getIdentifier(), StereotomyImpl.this));
return Optional.of(new KerlVerifier<D>(getIdentifier(), kerl));
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions thoth/src/main/java/com/salesforce/apollo/thoth/Ani.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -94,14 +95,12 @@ public Verifiers verifiers(Duration timeout) {

@Override
public Optional<Verifier> 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<Verifier> verifierFor(Identifier identifier) {
EstablishmentEvent ke = (EstablishmentEvent) kerl.getKeyState(identifier);
return Optional.ofNullable(new Verifier.DefaultVerifier(ke.getKeys()));
return Optional.of(new KerlVerifier<>(identifier, kerl));
}
};
}
Expand Down Expand Up @@ -147,4 +146,5 @@ private boolean performKerlValidation(EventCoordinates coord, Duration timeout)
private boolean validateKerl(KeyEvent event, Duration timeout) {
return performKerlValidation(event.getCoordinates(), timeout);
}

}

0 comments on commit 0943a64

Please sign in to comment.