github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/secretkeys_test.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 "testing" 8 9 "github.com/keybase/client/go/kbcrypto" 10 "github.com/keybase/client/go/libkb" 11 ) 12 13 func TestSecretKeys(t *testing.T) { 14 tc := SetupEngineTest(t, "secretkeys") 15 defer tc.Cleanup() 16 17 u := CreateAndSignupFakeUser(tc, "sk") 18 19 uis := libkb.UIs{ 20 LogUI: tc.G.UI.GetLogUI(), 21 SecretUI: u.NewSecretUI(), 22 } 23 24 // Get the secret keys. 25 e := NewSecretKeysEngine(tc.G) 26 m := NewMetaContextForTest(tc).WithUIs(uis) 27 err := RunEngine2(m, e) 28 if err != nil { 29 t.Fatal(err) 30 } 31 signing := e.Result().Signing 32 33 // Now we want to check that the keys we got actually belong to the user. 34 // Below we just do this check with the signing key, since it's easier to 35 // derive the public key. 36 37 // Build the signing keypair. To do this, we exploit the fact that a NaCl 38 // public signing key is the last 32 bytes of the private signing key. 39 var public kbcrypto.NaclSigningKeyPublic 40 copy(public[:], signing[32:]) 41 pair := libkb.NaclSigningKeyPair{ 42 Public: public, 43 } 44 45 // Check the signing keypair's KID is in the user's KeyFamily. 46 testUser, err := libkb.LoadUser(libkb.NewLoadUserArg(tc.G).WithName(u.Username)) 47 if err != nil { 48 t.Fatal(err) 49 } 50 if found := testUser.GetKeyFamily().AllKIDs[pair.GetKID()]; !found { 51 t.Fatalf("Failed to find %s in the user's key family.", pair.GetKID().String()) 52 } 53 }