-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor common STR verification functionality * Close #144
- Loading branch information
Showing
5 changed files
with
273 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// This module implements a generic CONIKS auditor, i.e. the | ||
// functionality that clients and auditors need to verify | ||
// a server's STR history. | ||
|
||
package protocol | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/coniks-sys/coniks-go/crypto/sign" | ||
) | ||
|
||
type auditorState struct { | ||
// SavedSTR stores the latest verified signed tree root. | ||
SavedSTR *DirSTR | ||
signKey sign.PublicKey | ||
} | ||
|
||
// NewAuditorState creates an auditor state for a specific directory. | ||
func newAuditorState(signKey sign.PublicKey, saved *DirSTR) *auditorState { | ||
return &auditorState{ | ||
SavedSTR: saved, | ||
signKey: signKey, | ||
} | ||
} | ||
|
||
// verifySTR checks whether the received STR is the same with | ||
// the saved STR in the audit state using reflect.DeepEqual(). | ||
// FIXME: check whether the STR was issued on time and whatnot. | ||
// Maybe it has something to do w/ #81 and client transitioning between epochs. | ||
// Try to verify w/ what's been saved | ||
func (a *auditorState) verifySTR(str *DirSTR) error { | ||
if reflect.DeepEqual(a.SavedSTR, str) { | ||
return nil | ||
} | ||
return CheckBadSTR | ||
} | ||
|
||
// verifySTRConsistency checks the consistency between 2 snapshots. | ||
// 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 its consistency state, | ||
// or an auditor's pinned signing key in its history. | ||
func (a *auditorState) verifySTRConsistency(savedSTR, str *DirSTR) error { | ||
// verify STR's signature | ||
if !a.signKey.Verify(str.Serialize(), str.Signature) { | ||
return CheckBadSignature | ||
} | ||
if str.VerifyHashChain(savedSTR) { | ||
return nil | ||
} | ||
|
||
// TODO: verify the directory's policies as well. See #115 | ||
return CheckBadSTR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.