github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/ephemeral/handler.go (about) 1 package ephemeral 2 3 import ( 4 "fmt" 5 6 "github.com/keybase/client/go/libkb" 7 "github.com/keybase/client/go/protocol/keybase1" 8 ) 9 10 func HandleNewTeamEK(mctx libkb.MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration) (err error) { 11 defer mctx.Trace("HandleNewTeamEK", &err)() 12 13 ekLib := mctx.G().GetEKLib() 14 if ekLib == nil { 15 return fmt.Errorf("ekLib not found") 16 } 17 ekLib.PurgeTeamEKCachesForTeamIDAndGeneration(mctx, teamID, generation) 18 mctx.G().NotifyRouter.HandleNewTeamEK(mctx.Ctx(), teamID, generation) 19 return nil 20 } 21 22 func HandleNewTeambotEK(mctx libkb.MetaContext, teamID keybase1.TeamID, generation keybase1.EkGeneration) (err error) { 23 defer mctx.Trace("HandleNewTeambotEK", &err)() 24 25 ekLib := mctx.G().GetEKLib() 26 if ekLib == nil { 27 return fmt.Errorf("ekLib not found") 28 } 29 ekLib.PurgeTeambotEKCachesForTeamIDAndGeneration(mctx, teamID, generation) 30 mctx.G().NotifyRouter.HandleNewTeambotEK(mctx.Ctx(), teamID, generation) 31 return nil 32 } 33 34 // HandleTeambotEKNeeded forces a teambot ek to be generated since the bot does 35 // not have access. All team members are notified and race to publish the 36 // requested key. 37 func HandleTeambotEKNeeded(mctx libkb.MetaContext, teamID keybase1.TeamID, botUID keybase1.UID, 38 generation keybase1.EkGeneration, forceCreateGen *keybase1.EkGeneration) (err error) { 39 defer mctx.Trace("HandleTeambotEKNeeded", &err)() 40 defer func() { 41 mctx.G().NotifyRouter.HandleTeambotEKNeeded(mctx.Ctx(), teamID, botUID, generation, forceCreateGen) 42 }() 43 44 ekLib := mctx.G().GetEKLib() 45 if ekLib == nil { 46 return fmt.Errorf("ekLib not found") 47 } 48 49 // Bot user needs the latest key 50 if forceCreateGen != nil { 51 // clear our caches here so we can force publish a key 52 ekLib.PurgeTeamEKCachesForTeamID(mctx, teamID) 53 ekLib.PurgeAllTeambotMetadataCaches(mctx) 54 _, _, err = ekLib.ForceCreateTeambotEK(mctx, teamID, botUID.ToBytes(), *forceCreateGen) 55 return err 56 } else if generation == 0 { 57 // clear our caches here so we can force publish a key 58 ekLib.PurgeTeamEKCachesForTeamID(mctx, teamID) 59 ekLib.PurgeAllTeambotMetadataCaches(mctx) 60 _, _, err = ekLib.GetOrCreateLatestTeambotEK(mctx, teamID, botUID.ToBytes()) 61 return err 62 } 63 64 // Bot needs a specific generation 65 ekLib.PurgeTeamEKCachesForTeamIDAndGeneration(mctx, teamID, generation) 66 ekLib.PurgeTeambotMetadataCache(mctx, teamID, botUID, generation) 67 _, err = ekLib.GetTeambotEK(mctx, teamID, botUID.ToBytes(), generation, nil) 68 return err 69 }