github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/secretkeys.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 package engine 5 6 import ( 7 "fmt" 8 9 "github.com/keybase/client/go/libkb" 10 keybase1 "github.com/keybase/client/go/protocol/keybase1" 11 ) 12 13 type SecretKeysEngine struct { 14 libkb.Contextified 15 result keybase1.SecretKeys 16 } 17 18 func NewSecretKeysEngine(g *libkb.GlobalContext) *SecretKeysEngine { 19 return &SecretKeysEngine{ 20 Contextified: libkb.NewContextified(g), 21 } 22 } 23 24 func (e *SecretKeysEngine) Name() string { 25 return "SecretKey" 26 } 27 28 func (e *SecretKeysEngine) Prereqs() Prereqs { 29 return Prereqs{ 30 Device: true, 31 } 32 } 33 34 func (e *SecretKeysEngine) RequiredUIs() []libkb.UIKind { 35 return []libkb.UIKind{ 36 libkb.LogUIKind, 37 libkb.SecretUIKind, 38 } 39 } 40 41 func (e *SecretKeysEngine) SubConsumers() []libkb.UIConsumer { 42 return []libkb.UIConsumer{} 43 } 44 45 func (e *SecretKeysEngine) Run(m libkb.MetaContext) (err error) { 46 defer m.Trace("SecretKeysEngine#Run", &err)() 47 48 me, err := libkb.LoadMe(libkb.NewLoadUserArgWithMetaContext(m)) 49 if err != nil { 50 return err 51 } 52 53 // Clear out all the cached secret key state. This forces a password prompt 54 // below. 55 m.ActiveDevice().ClearCaches() 56 57 ska := libkb.SecretKeyArg{ 58 Me: me, 59 KeyType: libkb.DeviceSigningKeyType, 60 } 61 sigKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, m.SecretKeyPromptArg(ska, "to revoke another key")) 62 if err != nil { 63 return err 64 } 65 if err = sigKey.CheckSecretKey(); err != nil { 66 return err 67 } 68 sigNaclKey, ok := sigKey.(libkb.NaclSigningKeyPair) 69 if !ok { 70 return fmt.Errorf("Expected a NaCl signing key.") 71 } 72 m.Debug("| got signing key") 73 74 ska.KeyType = libkb.DeviceEncryptionKeyType 75 encKey, err := m.G().Keyrings.GetSecretKeyWithPrompt(m, m.SecretKeyPromptArg(ska, "to revoke another key")) 76 if err != nil { 77 return err 78 } 79 if err = encKey.CheckSecretKey(); err != nil { 80 return err 81 } 82 encNaclKey, ok := encKey.(libkb.NaclDHKeyPair) 83 if !ok { 84 return fmt.Errorf("Expected a NaCl encryption key.") 85 } 86 m.Debug("| got encryption key") 87 88 e.result.Signing = [64]byte(*sigNaclKey.Private) 89 e.result.Encryption = [32]byte(*encNaclKey.Private) 90 91 return nil 92 } 93 94 func (e *SecretKeysEngine) Result() keybase1.SecretKeys { 95 return e.result 96 }