github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/paperkey_primary.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 // PaperKeyPrimary creates the initial paper backup key for a user. It 5 // differs from the PaperKey engine in that it already knows the 6 // signing key and it doesn't offer to revoke any devices, plus it 7 // uses a different UI call to display the phrase. 8 package engine 9 10 import ( 11 "github.com/keybase/client/go/libkb" 12 keybase1 "github.com/keybase/client/go/protocol/keybase1" 13 ) 14 15 // PaperKeyPrimary is an engine. 16 type PaperKeyPrimary struct { 17 passphrase libkb.PaperKeyPhrase 18 args *PaperKeyPrimaryArgs 19 libkb.Contextified 20 } 21 22 type PaperKeyPrimaryArgs struct { 23 SigningKey libkb.GenericKey 24 EncryptionKey libkb.NaclDHKeyPair 25 Me *libkb.User 26 PerUserKeyring *libkb.PerUserKeyring // optional 27 } 28 29 // NewPaperKeyPrimary creates a PaperKeyPrimary engine. 30 func NewPaperKeyPrimary(g *libkb.GlobalContext, args *PaperKeyPrimaryArgs) *PaperKeyPrimary { 31 return &PaperKeyPrimary{ 32 args: args, 33 Contextified: libkb.NewContextified(g), 34 } 35 } 36 37 // Name is the unique engine name. 38 func (e *PaperKeyPrimary) Name() string { 39 return "PaperKeyPrimary" 40 } 41 42 // GetPrereqs returns the engine prereqs. 43 func (e *PaperKeyPrimary) Prereqs() Prereqs { 44 return Prereqs{ 45 Device: true, 46 } 47 } 48 49 // RequiredUIs returns the required UIs. 50 func (e *PaperKeyPrimary) RequiredUIs() []libkb.UIKind { 51 return []libkb.UIKind{ 52 libkb.LoginUIKind, 53 } 54 } 55 56 // SubConsumers returns the other UI consumers for this engine. 57 func (e *PaperKeyPrimary) SubConsumers() []libkb.UIConsumer { 58 return []libkb.UIConsumer{&PaperKeyGen{}} 59 } 60 61 // Run starts the engine. 62 func (e *PaperKeyPrimary) Run(m libkb.MetaContext) error { 63 var err error 64 e.passphrase, err = libkb.MakePaperKeyPhrase(libkb.PaperKeyVersion) 65 if err != nil { 66 return err 67 } 68 69 kgarg := &PaperKeyGenArg{ 70 Passphrase: e.passphrase, 71 Me: e.args.Me, 72 SigningKey: e.args.SigningKey, 73 EncryptionKey: e.args.EncryptionKey, 74 PerUserKeyring: e.args.PerUserKeyring, 75 } 76 kgeng := NewPaperKeyGen(e.G(), kgarg) 77 if err := RunEngine2(m, kgeng); err != nil { 78 return err 79 } 80 81 // If they refuse to write down their key, don't kill the login flow, just print an 82 // ugly warning, which likely they won't see... 83 w := m.UIs().LoginUI.DisplayPrimaryPaperKey(m.Ctx(), keybase1.DisplayPrimaryPaperKeyArg{Phrase: e.passphrase.String()}) 84 if w != nil { 85 m.G().Log.Errorf("Display paper key failure: %s", w.Error()) 86 } 87 88 return nil 89 }