コード例 #1
0
ファイル: tlf_handle_test.go プロジェクト: gozes/kbfs-beta
func (d *daemonKBPKI) GetNormalizedUsername(ctx context.Context, uid keybase1.UID) (libkb.NormalizedUsername, error) {
	userInfo, err := d.daemon.LoadUserPlusKeys(ctx, uid)
	if err != nil {
		return libkb.NormalizedUsername(""), err
	}
	return userInfo.Name, nil
}
コード例 #2
0
ファイル: kbpki_client.go プロジェクト: keybase/kbfs-beta
// GetNormalizedUsername implements the KBPKI interface for
// KBPKIClient.
func (k *KBPKIClient) GetNormalizedUsername(ctx context.Context, uid keybase1.UID) (
	libkb.NormalizedUsername, error) {
	username, _, err := k.Resolve(ctx, fmt.Sprintf("uid:%s", uid))
	if err != nil {
		return libkb.NormalizedUsername(""), err
	}
	return username, nil
}
コード例 #3
0
ファイル: kbpki_client.go プロジェクト: gozes/kbfs-beta
// GetNormalizedUsername implements the KBPKI interface for
// KBPKIClient.
func (k *KBPKIClient) GetNormalizedUsername(ctx context.Context, uid keybase1.UID) (
	libkb.NormalizedUsername, error) {
	userInfo, err := k.loadUserPlusKeys(ctx, uid)
	if err != nil {
		return libkb.NormalizedUsername(""), err
	}
	return userInfo.Name, nil
}
コード例 #4
0
ファイル: test_common.go プロジェクト: keybase/kbfs-beta
func keySaltForUserDevice(name libkb.NormalizedUsername,
	index int) libkb.NormalizedUsername {
	if index > 0 {
		// We can't include the device index when it's 0, because we
		// have to match what's done in MakeLocalUsers.
		return libkb.NormalizedUsername(string(name) + " " + string(index))
	}
	return name
}
コード例 #5
0
func (k *KeybaseDaemonRPC) setCachedUserInfo(uid keybase1.UID, info UserInfo) {
	k.userCacheLock.Lock()
	defer k.userCacheLock.Unlock()
	if info.Name == libkb.NormalizedUsername("") {
		delete(k.userCache, uid)
	} else {
		k.userCache[uid] = info
	}
}
コード例 #6
0
// Resolve implements the KeybaseDaemon interface for KeybaseDaemonRPC.
func (k *KeybaseDaemonRPC) Resolve(ctx context.Context, assertion string) (
	libkb.NormalizedUsername, keybase1.UID, error) {
	user, err := k.identifyClient.Resolve2(ctx, assertion)
	if err != nil {
		return libkb.NormalizedUsername(""), keybase1.UID(""),
			convertIdentifyError(assertion, err)
	}
	return libkb.NewNormalizedUsername(user.Username), user.Uid, nil
}
コード例 #7
0
ファイル: kbpki_util_test.go プロジェクト: keybase/kbfs-beta
func (d *daemonKBPKI) GetCurrentUserInfo(ctx context.Context) (
	libkb.NormalizedUsername, keybase1.UID, error) {
	const sessionID = 0
	session, err := d.daemon.CurrentSession(ctx, sessionID)
	if err != nil {
		return libkb.NormalizedUsername(""), keybase1.UID(""), err
	}
	return session.Name, session.UID, nil
}
コード例 #8
0
ファイル: kbpki_client.go プロジェクト: keybase/kbfs-beta
// GetCurrentUserInfo implements the KBPKI interface for KBPKIClient.
func (k *KBPKIClient) GetCurrentUserInfo(ctx context.Context) (
	libkb.NormalizedUsername, keybase1.UID, error) {
	s, err := k.session(ctx)
	if err != nil {
		// TODO: something more intelligent; maybe just shut down
		// unless we want anonymous browsing of public data
		return libkb.NormalizedUsername(""), keybase1.UID(""), err
	}
	return s.Name, s.UID, nil
}
コード例 #9
0
func (ts *testState) GetUser(_ context.Context, uid keybase1.UID) (libkb.NormalizedUsername, []keybase1.KID, error) {
	ts.Lock()
	defer ts.Unlock()
	u := ts.users[uid]
	if u == nil {
		return libkb.NormalizedUsername(""), nil, errors.New("user not found")
	}
	ts.numGets++
	return u.username, u.keys, nil
}
コード例 #10
0
func (g testNormalizedUsernameGetter) GetNormalizedUsername(
	ctx context.Context, uid keybase1.UID) (
	libkb.NormalizedUsername, error) {
	name, ok := g[uid]
	if !ok {
		return libkb.NormalizedUsername(""),
			NoSuchUserError{fmt.Sprintf("uid:%s", uid)}
	}
	return name, nil
}
コード例 #11
0
func TestKBPKIClientGetNormalizedUsername(t *testing.T) {
	c, _, _ := makeTestKBPKIClient(t)

	name, err := c.GetNormalizedUsername(context.Background(), keybase1.MakeTestUID(1))
	if err != nil {
		t.Fatal(err)
	}
	if name == libkb.NormalizedUsername("") {
		t.Fatal("empty user")
	}
}
コード例 #12
0
func (ts *testState) GetUser(_ context.Context, uid keybase1.UID) (
	un libkb.NormalizedUsername, sibkeys, subkeys []keybase1.KID, err error) {
	ts.Lock()
	defer ts.Unlock()
	u := ts.users[uid]
	if u == nil {
		return libkb.NormalizedUsername(""), nil, nil, userNotFoundError{}
	}
	ts.numGets++
	return u.username, u.sibkeys, u.subkeys, nil
}
コード例 #13
0
// Resolve implements KeybaseDaemon for KeybaseDaemonLocal.
func (k *KeybaseDaemonLocal) Resolve(ctx context.Context, assertion string) (
	libkb.NormalizedUsername, keybase1.UID, error) {
	k.lock.Lock()
	defer k.lock.Unlock()

	uid, err := k.assertionToUIDLocked(ctx, assertion)
	if err != nil {
		return libkb.NormalizedUsername(""), keybase1.UID(""), err
	}

	return k.localUsers[uid].Name, uid, nil
}
コード例 #14
0
func crTestInit(t *testing.T) (mockCtrl *gomock.Controller, config *ConfigMock,
	cr *ConflictResolver) {
	ctr := NewSafeTestReporter(t)
	mockCtrl = gomock.NewController(ctr)
	config = NewConfigMock(mockCtrl, ctr)
	id, _, _ := NewFolder(t, 1, 1, false, false)
	fbo := newFolderBranchOps(config, FolderBranch{id, MasterBranch}, standard)
	// usernames don't matter for these tests
	config.mockKbpki.EXPECT().GetNormalizedUsername(gomock.Any(), gomock.Any()).
		AnyTimes().Return(libkb.NormalizedUsername("mockUser"), nil)
	return mockCtrl, config, fbo.cr
}
コード例 #15
0
// Test that the session cache works and is invalidated as expected.
func TestKeybaseDaemonSessionCache(t *testing.T) {
	k := MakeLocalUserCryptPublicKeyOrBust(
		libkb.NormalizedUsername("fake username"))
	v := MakeLocalUserVerifyingKeyOrBust(
		libkb.NormalizedUsername("fake username"))
	session := SessionInfo{
		UID:            keybase1.UID("fake uid"),
		Token:          "fake token",
		CryptPublicKey: k,
		VerifyingKey:   v,
	}

	client := &fakeKeybaseClient{session: session}
	c := newKeybaseDaemonRPCWithClient(
		nil, client, logger.NewTestLogger(t))

	// Should fill cache.
	testCurrentSession(t, client, c, session, expectCall)

	// Should be cached.
	testCurrentSession(t, client, c, session, expectCached)

	// Should invalidate cache.
	err := c.LoggedOut(context.Background())
	if err != nil {
		t.Fatal(err)
	}

	// Should fill cache again.
	testCurrentSession(t, client, c, session, expectCall)

	// Should be cached again.
	testCurrentSession(t, client, c, session, expectCached)

	// Should invalidate cache.
	c.OnDisconnected(UsingExistingConnection)

	// Should fill cache again.
	testCurrentSession(t, client, c, session, expectCall)
}
コード例 #16
0
// LoadUserPlusKeys implements the KeybaseDaemon interface for KeybaseDaemonRPC.
func (k *KeybaseDaemonRPC) LoadUserPlusKeys(ctx context.Context, uid keybase1.UID) (
	UserInfo, error) {
	cachedUserInfo := k.getCachedUserInfo(uid)
	if cachedUserInfo.Name != libkb.NormalizedUsername("") {
		return cachedUserInfo, nil
	}

	arg := keybase1.LoadUserPlusKeysArg{Uid: uid}
	res, err := k.userClient.LoadUserPlusKeys(ctx, arg)
	if err != nil {
		return UserInfo{}, err
	}

	return k.processUserPlusKeys(res)
}
コード例 #17
0
ファイル: md_ops.go プロジェクト: keybase/kbfs-beta
// convertVerifyingKeyError gives a better error when the TLF was
// signed by a key that is no longer associated with the last writer.
func (md *MDOpsStandard) convertVerifyingKeyError(ctx context.Context,
	rmds *RootMetadataSigned, err error) error {
	if _, ok := err.(KeyNotFoundError); !ok {
		return err
	}

	tlf := rmds.MD.GetTlfHandle().GetCanonicalPath()
	writer, nameErr := md.config.KBPKI().GetNormalizedUsername(ctx,
		rmds.MD.LastModifyingWriter)
	if nameErr != nil {
		writer = libkb.NormalizedUsername("uid: " +
			rmds.MD.LastModifyingWriter.String())
	}
	md.log.CDebugf(ctx, "Unverifiable update for TLF %s", rmds.MD.ID)
	return UnverifiableTlfUpdateError{tlf, writer, err}
}
コード例 #18
0
func crTestInit(t *testing.T) (mockCtrl *gomock.Controller, config *ConfigMock,
	cr *ConflictResolver) {
	ctr := NewSafeTestReporter(t)
	mockCtrl = gomock.NewController(ctr)
	config = NewConfigMock(mockCtrl, ctr)
	config.SetCodec(NewCodecMsgpack())
	id := FakeTlfID(1, false)
	fbo := newFolderBranchOps(config, FolderBranch{id, MasterBranch}, standard)
	// usernames don't matter for these tests
	config.mockKbpki.EXPECT().GetNormalizedUsername(gomock.Any(), gomock.Any()).
		AnyTimes().Return(libkb.NormalizedUsername("mockUser"), nil)

	mockDaemon := NewMockKeybaseDaemon(mockCtrl)
	mockDaemon.EXPECT().LoadUserPlusKeys(gomock.Any(), gomock.Any()).AnyTimes().Return(UserInfo{Name: "mockUser"}, nil)
	config.SetKeybaseDaemon(mockDaemon)
	return mockCtrl, config, fbo.cr
}
コード例 #19
0
ファイル: test_common.go プロジェクト: gozes/kbfs-beta
// SwitchDeviceForLocalUserOrBust switches the current user's current device
func SwitchDeviceForLocalUserOrBust(t *testing.T, config Config, index int) {
	uid, err := config.KBPKI().GetCurrentUID(context.Background())
	if err != nil {
		t.Fatalf("Couldn't get UID: %v", err)
	}

	kbd, ok := config.KeybaseDaemon().(KeybaseDaemonLocal)
	if !ok {
		t.Fatalf("Bad keybase daemon")
	}

	user, ok := kbd.localUsers[uid]
	if !ok {
		t.Fatalf("No such user: %s", uid)
	}

	if index >= len(user.CryptPublicKeys) {
		t.Fatalf("Wrong crypt public key index: %d", index)
	}
	user.CurrentCryptPublicKeyIndex = index

	if index >= len(user.VerifyingKeys) {
		t.Fatalf("Wrong verifying key index: %d", index)
	}
	user.CurrentVerifyingKeyIndex = index

	// kbd is just a copy, but kbd.localUsers is the same map
	kbd.localUsers[uid] = user

	crypto, ok := config.Crypto().(*CryptoLocal)
	if !ok {
		t.Fatalf("Bad crypto")
	}

	keySalt := user.Name
	if index > 0 {
		keySalt = libkb.NormalizedUsername(string(user.Name) + " " +
			string(index))
	}
	crypto.signingKey = MakeLocalUserSigningKeyOrBust(keySalt)
	crypto.cryptPrivateKey = MakeLocalUserCryptPrivateKeyOrBust(keySalt)
}
コード例 #20
0
ファイル: test_common.go プロジェクト: gozes/kbfs-beta
// AddDeviceForLocalUserOrBust creates a new device for a user and
// returns the index for that device.
func AddDeviceForLocalUserOrBust(t *testing.T, config Config,
	uid keybase1.UID) int {
	kbd, ok := config.KeybaseDaemon().(KeybaseDaemonLocal)
	if !ok {
		t.Fatalf("Bad keybase daemon")
	}

	user, ok := kbd.localUsers[uid]
	if !ok {
		t.Fatalf("No such user: %s", uid)
	}

	index := len(user.VerifyingKeys)
	keySalt := libkb.NormalizedUsername(string(user.Name) + " " + string(index))
	newVerifyingKey := MakeLocalUserVerifyingKeyOrBust(keySalt)
	user.VerifyingKeys = append(user.VerifyingKeys, newVerifyingKey)
	newCryptPublicKey := MakeLocalUserCryptPublicKeyOrBust(keySalt)
	user.CryptPublicKeys = append(user.CryptPublicKeys, newCryptPublicKey)

	// kbd is just a copy, but kbd.localUsers is the same map
	kbd.localUsers[uid] = user

	return index
}