Skip to content

Commit 7ca17b6

Browse files
Tom DNettotwitchyliquid64
Tom DNetto
authored andcommitted
tka: validate key after UpdateKey before applying state
Signed-off-by: Tom DNetto <tom@tailscale.com>
1 parent e945d87 commit 7ca17b6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

tka/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ type State struct {
2929

3030
// DisablementSecrets are KDF-derived values which can be used
3131
// to turn off the TKA in the event of a consensus-breaking bug.
32-
// An AUM of type DisableNL should contain a secret when results
33-
// in one of these values when run through the disablement KDF.
3432
//
3533
// TODO(tom): This is an alpha feature, remove this mechanism once
3634
// we have confidence in our implementation.
@@ -169,6 +167,9 @@ func (s State) applyVerifiedAUM(update AUM) (State, error) {
169167
if update.Meta != nil {
170168
k.Meta = update.Meta
171169
}
170+
if err := k.StaticValidate(); err != nil {
171+
return State{}, fmt.Errorf("updated key fails validation: %v", err)
172+
}
172173
out := s.cloneForUpdate(&update)
173174
for i := range out.Keys {
174175
if bytes.Equal(out.Keys[i].ID(), update.KeyID) {

tka/state_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func TestApplyUpdatesChain(t *testing.T) {
181181
}
182182

183183
func TestApplyUpdateErrors(t *testing.T) {
184+
tooLargeVotes := uint(99999)
184185
tcs := []struct {
185186
Name string
186187
Updates []AUM
@@ -205,6 +206,12 @@ func TestApplyUpdateErrors(t *testing.T) {
205206
State{},
206207
ErrNoSuchKey,
207208
},
209+
{
210+
"UpdateKey now fails validation",
211+
[]AUM{{MessageKind: AUMUpdateKey, KeyID: []byte{1}, Votes: &tooLargeVotes}},
212+
State{Keys: []Key{{Kind: Key25519, Public: []byte{1}}}},
213+
errors.New("updated key fails validation: excessive key weight: 99999 > 4096"),
214+
},
208215
{
209216
"Bad lastAUMHash",
210217
[]AUM{

0 commit comments

Comments
 (0)