From 6577d92928edb8b80448c9bfebb02e62b6d46257 Mon Sep 17 00:00:00 2001 From: Marcela Melara Date: Thu, 16 Feb 2017 15:20:16 -0500 Subject: [PATCH] Use single generic verifySTRConsistency to be used by client and auditor --- protocol/auditlog.go | 20 +------------------- protocol/consistencychecks.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/protocol/auditlog.go b/protocol/auditlog.go index 3f50141..373a7f4 100644 --- a/protocol/auditlog.go +++ b/protocol/auditlog.go @@ -100,7 +100,7 @@ func (l *ConiksAuditLog) Update(addr string, newSTR *m.SignedTreeRoot) error { h := l.histories[addr] - if err := h.verifySTRConsistency(newSTR); err != nil { + if err := verifySTRConsistency(h.signKey, h.latestSTR, newSTR); err != nil { return err } @@ -110,24 +110,6 @@ func (l *ConiksAuditLog) Update(addr string, newSTR *m.SignedTreeRoot) error { return nil } -// verifySTRConsistency checks the consistency between 2 snapshots. -// It uses the pinned signing key in the directory history -// to verify the STR's signature and verifies -// the hash chain using the latestSTR stored in the history. -// TODO: dedup this: write generic verifySTRConsistency -func (h *directoryHistory) verifySTRConsistency(str *m.SignedTreeRoot) error { - // verify STR's signature - if !h.signKey.Verify(str.Serialize(), str.Signature) { - return CheckBadSignature - } - if str.VerifyHashChain(h.latestSTR) { - return nil - } - - // TODO: verify the directory's policies as well. See #115 - return CheckBadSTR -} - // GetObservedSTR gets the observed STR for the CONIKS directory address indicated // in the AuditingRequest req received from a CONIKS client from the auditor's latest // directory history entry, and returns a tuple of the form diff --git a/protocol/consistencychecks.go b/protocol/consistencychecks.go index ba4a19e..a6d5840 100644 --- a/protocol/consistencychecks.go +++ b/protocol/consistencychecks.go @@ -117,7 +117,7 @@ func (cc *ConsistencyChecks) updateSTR(requestType int, msg *Response) error { return nil } // Otherwise, expect that we've entered a new epoch - if err := cc.verifySTRConsistency(cc.SavedSTR, str); err != nil { + if err := verifySTRConsistency(cc.signKey, cc.SavedSTR, str); err != nil { return err } @@ -140,12 +140,15 @@ func (cc *ConsistencyChecks) verifySTR(str *m.SignedTreeRoot) error { } // verifySTRConsistency checks the consistency between 2 snapshots. -// It uses the pinned signing key in cc -// to verify the STR's signature and should not verify -// the hash chain using the STR stored in cc. -func (cc *ConsistencyChecks) verifySTRConsistency(savedSTR, str *m.SignedTreeRoot) error { +// It uses the signing key signKey to verify the STR's signature. +// The signKey param either comes from a client's +// pinned signing key in cc, or an auditor's pinned signing key +// in its history. +// In the case of a client-side consistency check, verifySTRConsistency() +// should not verify the hash chain using the STR stored in cc. +func verifySTRConsistency(signKey sign.PublicKey, savedSTR, str *m.SignedTreeRoot) error { // verify STR's signature - if !cc.signKey.Verify(str.Serialize(), str.Signature) { + if !signKey.Verify(str.Serialize(), str.Signature) { return CheckBadSignature } if str.VerifyHashChain(savedSTR) {