Skip to content

Commit

Permalink
correct signing key
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellblazer committed Apr 15, 2024
1 parent 45399c0 commit 39fabd1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,17 @@ private void join(SignedViewMember svm, boolean direct) {
polled.add(mid);
if (proposals.putIfAbsent(mid, svm) == null) {
if (direct) {
var sig = params().member().sign(svm.toByteString()).toSig();
var signature = view.sign(svm);
publisher.accept(SignedJoin.newBuilder()
.setJoin(svm)
.setMember(params().member().getId().toDigeste())
.setSignature(sig)
.setSignature(signature.toSig())
.build());
if (log.isTraceEnabled()) {
log.trace("Publishing view member: {} sig: {} on: {}",
ViewContext.print(svm, params().digestAlgorithm()),
params().digestAlgorithm().digest(sig.toByteString()), params().member().getId());
params().digestAlgorithm().digest(signature.toSig().toByteString()),
params().member().getId());
}
} else if (log.isTraceEnabled()) {
log.trace("Adding discovered view member: {} on: {}",
Expand Down
41 changes: 27 additions & 14 deletions choam/src/main/java/com/salesforce/apollo/choam/ViewContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ public Context<Member> context() {
}

public Validate generateValidation(HashedBlock block) {
log.trace("Signing: {} block: {} height: {} on: {}", block.block.getBodyCase(), block.hash, block.height(),
params.member().getId());
if (log.isTraceEnabled()) {
log.trace("Signing: {} block: {} height: {} on: {}", block.block.getBodyCase(), block.hash, block.height(),
params.member().getId());
}
JohnHancock signature = signer.sign(block.block.getHeader().toByteString());
if (signature == null) {
log.error("Unable to sign: {} block: {} height: {} on: {}", block.block.getBodyCase(), block.hash,
Expand Down Expand Up @@ -161,11 +163,21 @@ public Map<Digest, Short> roster() {
return roster;
}

public JohnHancock sign(SignedViewMember svm) {
if (log.isTraceEnabled()) {
log.trace("Signing: {} on: {}", print(svm, params.digestAlgorithm()), params.member().getId());
}
return signer.sign(svm.toByteString());
}

public boolean validate(HashedBlock block, Validate validate) {
Verifier v = verifierOf(validate);
if (v == null) {
log.debug("no validation witness: {} for: {} block: {} on: {}", Digest.from(validate.getWitness().getId()),
block.block.getBodyCase(), block.hash, params.member().getId());
if (log.isDebugEnabled()) {
log.debug("no validation witness: {} for: {} block: {} on: {}",
Digest.from(validate.getWitness().getId()), block.block.getBodyCase(), block.hash,
params.member().getId());
}
return false;
}
return v.verify(JohnHancock.from(validate.getWitness().getSignature()), block.block.getHeader().toByteString());
Expand All @@ -188,22 +200,23 @@ public boolean validate(SignedViewMember svm, Validate validate) {
}

public boolean validate(SignedJoin join) {
if (true) {
return true;
}
Verifier v = verifierOf(join);
if (v == null) {
log.debug("no verifier: {} for join: {} on: {}", Digest.from(join.getMember()),
Digest.from(join.getJoin().getVm().getId()), params.member().getId());
if (log.isDebugEnabled()) {
log.debug("no verifier: {} for join: {} on: {}", Digest.from(join.getMember()),
Digest.from(join.getJoin().getVm().getId()), params.member().getId());
}
return false;
}
var validated = v.verify(JohnHancock.from(join.getSignature()), join.getJoin().toByteString());
if (!validated) {
log.trace("Cannot validate view join: [{}] sig: {} signed by: {} on: {}",
print(join.getJoin(), params.digestAlgorithm()),
params.digestAlgorithm().digest(join.getSignature().toByteString()),
Digest.from(join.getMember()), params().member().getId());
} else {
if (log.isTraceEnabled()) {
log.trace("Cannot validate view join: [{}] sig: {} signed by: {} on: {}",
print(join.getJoin(), params.digestAlgorithm()),
params.digestAlgorithm().digest(join.getSignature().toByteString()),
Digest.from(join.getMember()), params().member().getId());
}
} else if (log.isTraceEnabled()) {
log.trace("Validated view join: [{}] signed by: {} on: {}", print(join.getJoin(), params.digestAlgorithm()),
Digest.from(join.getMember()), params().member().getId());
}
Expand Down

0 comments on commit 39fabd1

Please sign in to comment.