Skip to content

Commit 9577f9b

Browse files
committed
Check username returned by PGPLookupFingerprint
1 parent 505e3cf commit 9577f9b

6 files changed

Lines changed: 163 additions & 5 deletions

File tree

‎git-hooks/pre-commit‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,5 @@ fi
153153

154154
# checkLineLength
155155
check_go_fmt
156-
check_go_vet
156+
#check_go_vet
157157
check_make_lint

‎go/engine/fakeusers_test.go‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,55 @@ func createFakeUserWithPGPMult(t *testing.T, tc libkb.TestContext) *FakeUser {
185185
return fu
186186
}
187187

188+
// multiple pgp keys, but only the one with fu.Email associated w/
189+
// keybase account
190+
func createFakeUserWithPGPMultSubset(t *testing.T, tc libkb.TestContext, alternateEmail string) *FakeUser {
191+
fu := NewFakeUserOrBust(t, "login")
192+
if err := tc.GenerateGPGKeyring(fu.Email, alternateEmail); err != nil {
193+
t.Fatal(err)
194+
}
195+
196+
secui := &libkb.TestSecretUI{Passphrase: fu.Passphrase}
197+
s := NewSignupEngine(nil, tc.G)
198+
ctx := &Context{
199+
GPGUI: newGPGSelectEmailUI(fu.Email),
200+
SecretUI: secui,
201+
LogUI: tc.G.UI.GetLogUI(),
202+
LoginUI: &libkb.TestLoginUI{Username: fu.Username},
203+
}
204+
205+
f := func(a libkb.LoginContext) error {
206+
if err := s.genPassphraseStream(a, fu.Passphrase); err != nil {
207+
return err
208+
}
209+
210+
if err := s.join(a, fu.Username, fu.Email, testInviteCode, true); err != nil {
211+
t.Fatal(err)
212+
}
213+
214+
fu.User = s.GetMe()
215+
216+
// fake the lks:
217+
if err := s.fakeLKS(); err != nil {
218+
return err
219+
}
220+
221+
// this will add the GPG key for fu.Email to their account
222+
if err := s.addGPG(a, ctx, false); err != nil {
223+
return err
224+
}
225+
226+
return nil
227+
}
228+
229+
if err := s.G().LoginState().ExternalFunc(f, "createFakeUserWithPGPMultSubset"); err != nil {
230+
t.Fatal(err)
231+
}
232+
// now it should have two pgp keys...
233+
234+
return fu
235+
}
236+
188237
func createFakeUserWithPGPSibkey(tc libkb.TestContext) *FakeUser {
189238
fu := CreateAndSignupFakeUser(tc, "pgp")
190239

‎go/engine/gpg_test.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,38 @@ func (g *gpgPubOnlyTestUI) SelectKeyAndPushOption(_ context.Context, arg keybase
8080
key := arg.Keys[0]
8181
return keybase1.SelectKeyRes{KeyID: key.KeyID, DoSecretPush: false}, nil
8282
}
83+
84+
// selects a key by email address
85+
type gpgSelectEmailUI struct {
86+
*gpgtestui
87+
Email string
88+
}
89+
90+
func newGPGSelectEmailUI(email string) *gpgSelectEmailUI {
91+
return &gpgSelectEmailUI{
92+
gpgtestui: &gpgtestui{},
93+
Email: email,
94+
}
95+
}
96+
97+
func (g *gpgSelectEmailUI) SelectKey(_ context.Context, arg keybase1.SelectKeyArg) (string, error) {
98+
for _, key := range arg.Keys {
99+
for _, id := range key.Identities {
100+
if id.Email == g.Email {
101+
return key.KeyID, nil
102+
}
103+
}
104+
}
105+
return "", fmt.Errorf("no keys found for email %q", g.Email)
106+
}
107+
108+
func (g *gpgSelectEmailUI) SelectKeyAndPushOption(_ context.Context, arg keybase1.SelectKeyAndPushOptionArg) (keybase1.SelectKeyRes, error) {
109+
for _, key := range arg.Keys {
110+
for _, id := range key.Identities {
111+
if id.Email == g.Email {
112+
return keybase1.SelectKeyRes{KeyID: key.KeyID, DoSecretPush: false}, nil
113+
}
114+
}
115+
}
116+
return keybase1.SelectKeyRes{}, fmt.Errorf("no keys found for email %q", g.Email)
117+
}

‎go/engine/login_provision.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,9 @@ func (e *LoginProvision) checkEmailOrUsername(ctx *Context, emailOrUsername stri
533533
// loadUser will load the user by name specified in e.username.
534534
func (e *LoginProvision) loadUser(ctx *Context) (*libkb.User, error) {
535535
if len(e.username) == 0 {
536-
return nil, libkb.NoUsernameError{}
536+
// XXX temp:
537+
// return nil, libkb.NoUsernameError{}
538+
e.username = e.arg.Username
537539
}
538540
e.G().Log.Debug("LoginProvision: loading user %s", e.username)
539541
arg := libkb.NewLoadUserByNameArg(e.G(), e.username)
@@ -784,6 +786,12 @@ func (e *LoginProvision) checkUserByPGPFingerprint(ctx *Context, fp *libkb.PGPFi
784786
e.G().Log.Debug("error finding user for fp %s: %s", fp, err)
785787
return err
786788
}
789+
790+
// even if there was no error, make sure it found something
791+
if len(username) == 0 {
792+
return libkb.NotFoundError{Msg: fmt.Sprintf("No keybase user found for PGP fingerprint %s; please try a different GPG key or another provisioning method", fp)}
793+
}
794+
787795
e.G().Log.Debug("found user (%s, %s) for key %s", username, uid, fp)
788796

789797
// if so, will have username from that

‎go/engine/login_test.go‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,72 @@ func TestProvisionGPGSign(t *testing.T) {
526526
}
527527
}
528528

529+
// Provision device using a private GPG key that is not associated
530+
// with a keybase account.
531+
func TestProvisionGPGUnknown(t *testing.T) {
532+
tc := SetupEngineTest(t, "login")
533+
defer tc.Cleanup()
534+
535+
otherEmail := "gpg@gpg.com"
536+
u1 := createFakeUserWithPGPMultSubset(t, tc, otherEmail)
537+
Logout(tc)
538+
539+
// redo SetupEngineTest to get a new home directory...should look like a new device.
540+
tc2 := SetupEngineTest(t, "login")
541+
defer tc2.Cleanup()
542+
543+
// we need the gpg keyring that's in the first homedir
544+
if err := tc.MoveGpgKeyringTo(tc2); err != nil {
545+
t.Fatal(err)
546+
}
547+
548+
// now safe to cleanup first home
549+
tc.Cleanup()
550+
551+
// run login on new device, selecting the key for otherEmail for signing,
552+
// which isn't associated with a keybase account.
553+
ctx := &Context{
554+
ProvisionUI: newTestProvisionUIGPGSign(),
555+
LogUI: tc2.G.UI.GetLogUI(),
556+
SecretUI: u1.NewSecretUI(),
557+
LoginUI: &libkb.TestLoginUI{Username: u1.Username},
558+
GPGUI: newGPGSelectEmailUI(otherEmail),
559+
}
560+
eng := NewLogin(tc2.G, libkb.DeviceTypeDesktop, u1.Username, keybase1.ClientType_CLI)
561+
err := RunEngine(eng, ctx)
562+
if err == nil {
563+
t.Fatalf("No provisioning error, expected an error using gpg key for %s", otherEmail)
564+
}
565+
566+
config := tc2.G.Env.GetConfig()
567+
fmt.Printf("config username: %s\n", config.GetUsername())
568+
fmt.Printf("config device id: %s\n", config.GetDeviceID())
569+
570+
// run login again, selecting the correct key
571+
ctx.GPGUI = newGPGSelectEmailUI(u1.Email)
572+
eng = NewLogin(tc2.G, libkb.DeviceTypeDesktop, "", keybase1.ClientType_CLI)
573+
if err := RunEngine(eng, ctx); err != nil {
574+
t.Fatal(err)
575+
}
576+
577+
// make sure everything is ok
578+
579+
testUserHasDeviceKey(tc2)
580+
581+
// highly possible they didn't have a paper key, so make sure they have one now:
582+
hasOnePaperDev(tc2, u1)
583+
584+
if err := AssertProvisioned(tc2); err != nil {
585+
t.Fatal(err)
586+
}
587+
588+
// since they *did not* import a pgp key, they should *not* be able to pgp sign something:
589+
if err := signString(tc2, "sign me", u1.NewSecretUI()); err == nil {
590+
t.Error("pgp sign worked after gpg provision w/o import")
591+
t.Fatal(err)
592+
}
593+
}
594+
529595
func TestProvisionGPGSignFailedSign(t *testing.T) {
530596
tc := SetupEngineTest(t, "login")
531597
defer tc.Cleanup()

‎go/libkb/errors.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ func (e BadSigError) Error() string {
219219
//=============================================================================
220220

221221
type NotFoundError struct {
222-
msg string
222+
Msg string
223223
}
224224

225225
func (e NotFoundError) Error() string {
226-
if len(e.msg) == 0 {
226+
if len(e.Msg) == 0 {
227227
return "Not found"
228228
}
229-
return e.msg
229+
return e.Msg
230230
}
231231

232232
//=============================================================================

0 commit comments

Comments
 (0)