github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/engine/paperkey_submit.go (about) 1 // Copyright 2016 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package engine 5 6 import ( 7 "github.com/keybase/client/go/libkb" 8 ) 9 10 // PaperKeySubmit is an engine. 11 type PaperKeySubmit struct { 12 libkb.Contextified 13 paperPhrase string 14 deviceWithKeys *libkb.DeviceWithKeys 15 } 16 17 // NewPaperKeySubmit creates a PaperKeySubmit engine. 18 func NewPaperKeySubmit(g *libkb.GlobalContext, paperPhrase string) *PaperKeySubmit { 19 return &PaperKeySubmit{ 20 Contextified: libkb.NewContextified(g), 21 paperPhrase: paperPhrase, 22 } 23 } 24 25 // Name is the unique engine name. 26 func (e *PaperKeySubmit) Name() string { 27 return "PaperKeySubmit" 28 } 29 30 // Prereqs returns the engine prereqs. 31 func (e *PaperKeySubmit) Prereqs() Prereqs { 32 return Prereqs{Device: true} 33 } 34 35 // RequiredUIs returns the required UIs. 36 func (e *PaperKeySubmit) RequiredUIs() []libkb.UIKind { 37 return []libkb.UIKind{} 38 } 39 40 // SubConsumers returns the other UI consumers for this engine. 41 func (e *PaperKeySubmit) SubConsumers() []libkb.UIConsumer { 42 return []libkb.UIConsumer{ 43 &PaperKeyGen{}, 44 } 45 } 46 47 // Run starts the engine. 48 func (e *PaperKeySubmit) Run(m libkb.MetaContext) error { 49 me, err := libkb.LoadMe(libkb.NewLoadUserArgWithMetaContext(m)) 50 if err != nil { 51 return err 52 } 53 54 e.deviceWithKeys, err = matchPaperKey(m, me, e.paperPhrase) 55 if err != nil { 56 return err 57 } 58 59 m.ActiveDevice().CacheProvisioningKey(m, e.deviceWithKeys) 60 61 // send a notification that a paper key has been cached 62 // for rekey purposes 63 m.G().NotifyRouter.HandlePaperKeyCached(me.GetUID(), e.deviceWithKeys.EncryptionKey().GetKID(), e.deviceWithKeys.SigningKey().GetKID()) 64 65 // XXX - this is temporary until KBFS handles the above notification 66 m.G().UserChanged(m.Ctx(), me.GetUID()) 67 68 return nil 69 }