From 39fabd16415a09495bcd477865af6ad4f39aaed0 Mon Sep 17 00:00:00 2001 From: Hellblazer Date: Sun, 14 Apr 2024 17:55:49 -0700 Subject: [PATCH] correct signing key --- .../salesforce/apollo/choam/ViewAssembly.java | 7 ++-- .../salesforce/apollo/choam/ViewContext.java | 41 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java b/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java index 847aac3c7..ec33dabea 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/ViewAssembly.java @@ -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: {}", diff --git a/choam/src/main/java/com/salesforce/apollo/choam/ViewContext.java b/choam/src/main/java/com/salesforce/apollo/choam/ViewContext.java index d7aa35adc..59a55e0e7 100644 --- a/choam/src/main/java/com/salesforce/apollo/choam/ViewContext.java +++ b/choam/src/main/java/com/salesforce/apollo/choam/ViewContext.java @@ -82,8 +82,10 @@ public Context 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, @@ -161,11 +163,21 @@ public Map 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()); @@ -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()); }