Skip to content

Commit 4b3a42f

Browse files
authored
teams: bugfixes for hidden team chain rotations (keybase#18336)
- don't attempt to rotate public teams - add a test for using hidden rotations as an implicit admin - use implicit admin pinning as visible rotations do, to fix broken functionality - still don't flip the switch on hidden teams in dev via clkr, since we still have to fix TestMemberAddRace
1 parent c22ed42 commit 4b3a42f

5 files changed

Lines changed: 58 additions & 4 deletions

File tree

‎go/sig3/prot.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,16 @@ type Signer struct {
7575
}
7676

7777
type Team struct {
78-
TeamID TeamID `codec:"i"`
79-
IsImplicit bool `codec:"m"`
80-
IsPublic bool `codec:"p"`
78+
Admin *ChainLocation `codec:"a,omitempty"` // If working as an implicit admin, where that permission comes from
79+
TeamID TeamID `codec:"i"`
80+
IsImplicit bool `codec:"m"`
81+
IsPublic bool `codec:"p"`
82+
}
83+
84+
type ChainLocation struct {
85+
TeamID TeamID `codec:"i"`
86+
Seqno Seqno `codec:"s"`
87+
ChainType ChainType `codec:"t"`
8188
}
8289

8390
type MerkleRoot struct {

‎go/teams/handler.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ func HandleRotateRequest(ctx context.Context, g *libkb.GlobalContext, msg keybas
7878
}
7979

8080
g.Log.CDebugf(ctx, "rotating team %s (%s)", team.Name(), teamID)
81-
if err := team.Rotate(ctx, keybase1.RotationType_VISIBLE); err != nil {
81+
82+
// Setting rotationType to CLKR in dev still breaks TestMemberAddRace, which we will fix in a subsequent PR
83+
brokenTestMemberAddRace := true
84+
rotationType := keybase1.RotationType_CLKR
85+
if teamID.IsPublic() || brokenTestMemberAddRace {
86+
rotationType = keybase1.RotationType_VISIBLE
87+
}
88+
89+
if err := team.Rotate(ctx, rotationType); err != nil {
8290
g.Log.CDebugf(ctx, "rotating team %s (%s) error: %s", team.Name(), teamID, err)
8391
return err
8492
}

‎go/teams/hidden/hidden.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type GenerateKeyRotationParams struct {
7272
NewSigningKey libkb.NaclSigningKeyPair
7373
NewEncryptionKey libkb.NaclDHKeyPair
7474
Check keybase1.PerTeamSeedCheck
75+
Admin *sig3.ChainLocation
7576
}
7677

7778
// GenerateKeyRotation generates and signs a new sig3 KeyRotation. The result can be passed to
@@ -150,6 +151,7 @@ func generateKeyRotationSig3(mctx libkb.MetaContext, p GenerateKeyRotationParams
150151
EldestSeqno: p.Me.GetEldestSeqno(),
151152
},
152153
Team: &sig3.Team{
154+
Admin: p.Admin,
153155
TeamID: *teamIDimport,
154156
IsPublic: p.IsPublic,
155157
IsImplicit: p.IsImplicit,

‎go/teams/rotate_hidden_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,13 @@ func TestRotateHiddenOtherFTL(t *testing.T) {
174174
require.NoError(t, err)
175175
require.Equal(t, keybase1.Seqno(2), ch.RatchetSet.Ratchets[keybase1.RatchetType_MAIN].Triple.Seqno)
176176
}
177+
178+
func TestRotateHiddenImplicitAdmin(t *testing.T) {
179+
tc, _, _, _, _, sub := memberSetupSubteam(t)
180+
defer tc.Cleanup()
181+
team, err := GetForTestByStringName(context.TODO(), tc.G, sub)
182+
require.NoError(t, err)
183+
require.EqualValues(t, 1, team.Generation())
184+
err = team.Rotate(context.TODO(), keybase1.RotationType_HIDDEN)
185+
require.NoError(t, err)
186+
}

‎go/teams/teams.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"github.com/keybase/client/go/libkb"
1919
"github.com/keybase/client/go/protocol/keybase1"
20+
"github.com/keybase/client/go/sig3"
2021
hidden "github.com/keybase/client/go/teams/hidden"
2122
jsonw "github.com/keybase/go-jsonw"
2223
)
@@ -628,6 +629,26 @@ func (t *Team) rotatePostHidden(ctx context.Context, section SCTeamSection, mr *
628629
return err
629630
}
630631

632+
func teamAdminToSig3ChainLocation(admin *SCTeamAdmin) (*sig3.ChainLocation, error) {
633+
if admin == nil {
634+
return nil, nil
635+
}
636+
id, err := admin.TeamID.ToTeamID()
637+
if err != nil {
638+
return nil, err
639+
}
640+
s3id, err := sig3.ImportTeamID(id)
641+
if err != nil {
642+
return nil, err
643+
}
644+
return &sig3.ChainLocation{
645+
TeamID: *s3id,
646+
Seqno: admin.Seqno,
647+
ChainType: sig3.ChainType(admin.SeqType),
648+
}, nil
649+
650+
}
651+
631652
func (t *Team) rotateHiddenGenerateSigMultiItem(mctx libkb.MetaContext, section SCTeamSection, mr *libkb.MerkleRoot) (ret *libkb.SigMultiItem, ratchets *keybase1.HiddenTeamChainRatchetSet, err error) {
632653

633654
currentSeqno := t.CurrentSeqno()
@@ -662,6 +683,11 @@ func (t *Team) rotateHiddenGenerateSigMultiItem(mctx libkb.MetaContext, section
662683
return nil, nil, err
663684
}
664685

686+
admin, err := teamAdminToSig3ChainLocation(section.Admin)
687+
if err != nil {
688+
return nil, nil, err
689+
}
690+
665691
ret, ratchets, err = hidden.GenerateKeyRotation(mctx, hidden.GenerateKeyRotationParams{
666692
TeamID: t.ID,
667693
IsPublic: t.IsPublic(),
@@ -675,6 +701,7 @@ func (t *Team) rotateHiddenGenerateSigMultiItem(mctx libkb.MetaContext, section
675701
NewSigningKey: sk,
676702
NewEncryptionKey: ek,
677703
Check: t.keyManager.Check(),
704+
Admin: admin,
678705
})
679706

680707
return ret, ratchets, err

0 commit comments

Comments
 (0)