コード例 #1
0
ファイル: rekey_test.go プロジェクト: qbit/client
func rekeySetup(tc libkb.TestContext) (gregor1.UID, *gregorHandler, *RekeyUIHandler) {
	tc.G.SetService()

	kbUID, err := keybase1.UIDFromString("9f9611a4b7920637b1c2a839b2a0e119")
	if err != nil {
		tc.T.Fatal(err)
	}
	gUID := gregor1.UID(kbUID.ToBytes())
	did, err := libkb.NewDeviceID()
	if err != nil {
		tc.T.Fatal(err)
	}
	tc.G.Env.GetConfigWriter().SetUserConfig(libkb.NewUserConfig(kbUID, "", nil, did), true)

	h, err := newGregorHandler(tc.G)
	if err != nil {
		tc.T.Fatal(err)
	}

	rekeyHandler := NewRekeyUIHandler(tc.G, 0)
	rekeyHandler.alwaysAlive = true
	rekeyHandler.notifyStart = make(chan int, 10)
	rekeyHandler.notifyComplete = make(chan int, 10)
	rekeyHandler.scorer = fakeScoreProblemFoldersEmpty
	h.PushHandler(rekeyHandler)

	return gUID, h, rekeyHandler
}
コード例 #2
0
ファイル: key_lookup.go プロジェクト: qbit/client
func keyLookup(g *GlobalContext, arg keyLookupArg) (username string, uid keybase1.UID, err error) {
	httpArgs := make(HTTPArgs)
	switch {
	case arg.fp != nil:
		httpArgs["fingerprint"] = S{arg.fp.String()}
	case len(arg.hexID) > 0:
		httpArgs["pgp_key_id"] = S{Val: arg.hexID}
	case arg.uintID > 0:
		httpArgs["pgp_key_id"] = UHex{Val: arg.uintID}
	case !arg.kid.IsNil():
		httpArgs["kid"] = S{Val: arg.kid.String()}
	default:
		return username, uid, InvalidArgumentError{Msg: "invalid pgp lookup arg"}
	}

	var data keyBasicsReply

	// lookup key on api server
	args := APIArg{
		Endpoint:     "key/basics",
		Args:         httpArgs,
		Contextified: NewContextified(g),
	}

	if err = g.API.GetDecode(args, &data); err != nil {
		if ase, ok := err.(AppStatusError); ok && ase.Code == SCKeyNotFound {
			err = NotFoundError{}
		}
		return username, uid, err
	}

	uid, err = keybase1.UIDFromString(data.UID)
	return data.Username, uid, nil
}
コード例 #3
0
ファイル: gregor.go プロジェクト: qbit/client
func (g *gregorHandler) notifyFavoritesChanged(ctx context.Context, uid gregor.UID) error {
	kbUID, err := keybase1.UIDFromString(hex.EncodeToString(uid.Bytes()))
	if err != nil {
		return err
	}
	g.G().NotifyRouter.HandleFavoritesChanged(kbUID)
	return nil
}
コード例 #4
0
ファイル: uid.go プロジェクト: paul-pearce/client-beta
// UsernameToUID works for users created after "Fri Feb  6 19:33:08 EST 2015".  Some of
// them had buggy Username -> UID conversions, in which case we need to hash the
// original case to recover their UID.
func UsernameToUIDPreserveCase(s string) keybase1.UID {
	h := sha256.Sum256([]byte(s))
	var uid [keybase1.UID_LEN]byte
	copy(uid[:], h[0:keybase1.UID_LEN-1])
	uid[keybase1.UID_LEN-1] = keybase1.UID_SUFFIX_2
	ret, _ := keybase1.UIDFromString(hex.EncodeToString(uid[:]))
	return ret
}
コード例 #5
0
ファイル: uid.go プロジェクト: paul-pearce/client-beta
func UIDFromHex(s string) (keybase1.UID, error) {
	u, err := keybase1.UIDFromString(s)
	if err != nil {
		var nilUID keybase1.UID
		return nilUID, err
	}
	return u, nil
}
コード例 #6
0
ファイル: gregor.go プロジェクト: qbit/client
func (h IdentifyUIHandler) handleShowTrackerPopupCreate(ctx context.Context, cli gregor1.IncomingInterface,
	item gregor.Item) error {

	h.G().Log.Debug("handleShowTrackerPopupCreate: %+v", item)
	if item.Body() == nil {
		return errors.New("gregor handler for show_tracker_popup: nil message body")
	}
	body, err := jsonw.Unmarshal(item.Body().Bytes())
	if err != nil {
		h.G().Log.Debug("body failed to unmarshal", err)
		return err
	}
	uidString, err := body.AtPath("uid").GetString()
	if err != nil {
		h.G().Log.Debug("failed to extract uid", err)
		return err
	}
	uid, err := keybase1.UIDFromString(uidString)
	if err != nil {
		h.G().Log.Debug("failed to convert UID from string", err)
		return err
	}

	identifyUI, err := h.G().UIRouter.GetIdentifyUI()
	if err != nil {
		h.G().Log.Debug("failed to get IdentifyUI", err)
		return err
	}
	if identifyUI == nil {
		h.G().Log.Debug("got nil IdentifyUI")
		return errors.New("got nil IdentifyUI")
	}
	secretUI, err := h.G().UIRouter.GetSecretUI(0)
	if err != nil {
		h.G().Log.Debug("failed to get SecretUI", err)
		return err
	}
	if secretUI == nil {
		h.G().Log.Debug("got nil SecretUI")
		return errors.New("got nil SecretUI")
	}
	engineContext := engine.Context{
		IdentifyUI: identifyUI,
		SecretUI:   secretUI,
	}

	identifyReason := keybase1.IdentifyReason{
		Type: keybase1.IdentifyReasonType_TRACK,
		// TODO: text here?
	}
	identifyArg := keybase1.Identify2Arg{Uid: uid, Reason: identifyReason}
	identifyEng := engine.NewIdentify2WithUID(h.G(), &identifyArg)
	identifyEng.SetResponsibleGregorItem(item)
	return identifyEng.Run(&engineContext)
}
コード例 #7
0
ファイル: gregor.go プロジェクト: qbit/client
func (h IdentifyUIHandler) handleShowTrackerPopupDismiss(ctx context.Context, cli gregor1.IncomingInterface,
	item gregor.Item) error {

	h.G().Log.Debug("handleShowTrackerPopupDismiss: %+v", item)
	if item.Body() == nil {
		return errors.New("gregor dismissal for show_tracker_popup: nil message body")
	}
	body, err := jsonw.Unmarshal(item.Body().Bytes())
	if err != nil {
		h.G().Log.Debug("body failed to unmarshal", err)
		return err
	}
	uidString, err := body.AtPath("uid").GetString()
	if err != nil {
		h.G().Log.Debug("failed to extract uid", err)
		return err
	}
	uid, err := keybase1.UIDFromString(uidString)
	if err != nil {
		h.G().Log.Debug("failed to convert UID from string", err)
		return err
	}
	user, err := libkb.LoadUser(libkb.NewLoadUserByUIDArg(h.G(), uid))
	if err != nil {
		h.G().Log.Debug("failed to load user from UID", err)
		return err
	}

	identifyUI, err := h.G().UIRouter.GetIdentifyUI()
	if err != nil {
		h.G().Log.Debug("failed to get IdentifyUI", err)
		return err
	}
	if identifyUI == nil {
		h.G().Log.Debug("got nil IdentifyUI")
		return errors.New("got nil IdentifyUI")
	}

	reason := keybase1.DismissReason{
		Type: keybase1.DismissReasonType_HANDLED_ELSEWHERE,
	}
	identifyUI.Dismiss(user.GetName(), reason)

	return nil
}
コード例 #8
0
ファイル: login_provision.go プロジェクト: qbit/client
func (e *loginProvision) uidByKID(kid keybase1.KID) (keybase1.UID, error) {
	var nilUID keybase1.UID
	arg := libkb.APIArg{
		Endpoint:     "key/owner",
		NeedSession:  false,
		Contextified: libkb.NewContextified(e.G()),
		Args:         libkb.HTTPArgs{"kid": libkb.S{Val: kid.String()}},
	}
	res, err := e.G().API.Get(arg)
	if err != nil {
		return nilUID, err
	}
	suid, err := res.Body.AtPath("uid").GetString()
	if err != nil {
		return nilUID, err
	}
	return keybase1.UIDFromString(suid)
}
コード例 #9
0
ファイル: cmd_ca.go プロジェクト: mark-adams/client
func (c *CmdCA) runPromptLoop() error {
	var err error
	var s string
	re := regexp.MustCompile(`(\s|,|:)+`)

	api := auth.NewUserKeyAPIer(c.G().Log, c.G().API)
	ca := auth.NewCredentialAuthority(c.G().Log, api)

	for {
		s, err = c.G().UI.GetTerminalUI().Prompt(0, "ca> ")
		if err != nil {
			break
		}
		s = strings.TrimSpace(s)
		if len(s) == 0 {
			break
		}
		v := re.Split(s, -1)
		if len(v) != 3 {
			c.G().Log.Errorf("Need a triple: [<uid>,<username>,<kid>]")
			continue
		}

		uid, e2 := keybase1.UIDFromString(v[0])
		if e2 != nil {
			c.G().Log.Errorf("Bad UID %s: %s", v[0], e2)
			continue
		}

		un := libkb.NewNormalizedUsername(v[1])

		kid, e2 := keybase1.KIDFromStringChecked(v[2])
		if e2 != nil {
			c.G().Log.Errorf("Bad KID %s: %s", v[2], e2)
			continue
		}

		if e2 := ca.CheckUserKey(context.TODO(), uid, &un, &kid); e2 != nil {
			c.G().Log.Errorf("Bad check: %s", e2)
		}

	}
	return err
}
コード例 #10
0
ファイル: login_provision.go プロジェクト: polluks/client
func (e *LoginProvision) loadUserByKID(kid keybase1.KID) (*libkb.User, error) {
	arg := libkb.APIArg{
		Endpoint:     "key/owner",
		NeedSession:  false,
		Contextified: libkb.NewContextified(e.G()),
		Args:         libkb.HTTPArgs{"kid": libkb.S{Val: kid.String()}},
	}
	res, err := e.G().API.Get(arg)
	if err != nil {
		return nil, err
	}
	suid, err := res.Body.AtPath("uid").GetString()
	if err != nil {
		return nil, err
	}
	uid, err := keybase1.UIDFromString(suid)
	if err != nil {
		return nil, err
	}
	e.G().Log.Debug("key/owner result uid: %s", uid)
	loadArg := libkb.NewLoadUserArg(e.G())
	loadArg.UID = uid
	return libkb.LoadUser(loadArg)
}
コード例 #11
0
ファイル: keygen_test.go プロジェクト: qbit/client
func TestCreateIds(t *testing.T) {
	tc := SetupTest(t, "createIds", 1)
	defer tc.Cleanup()

	// We need to fake the call to G.Env.GetUsername().  The best way to do this is to
	// fake an entire UserConfig. Most of these fields won't be used in this test, so it's
	// ok to give empty UIDs/Salts.
	uid, _ := keybase1.UIDFromString("00000000000000000000000000000019")
	var nilDeviceID keybase1.DeviceID
	tc.G.Env.GetConfigWriter().SetUserConfig(NewUserConfig(uid, "foo", []byte{}, nilDeviceID), true)

	for _, test := range cidTests {
		arg := &PGPGenArg{PrimaryBits: 1024, SubkeyBits: 1024, PGPUids: test.pgpUIDArg}
		if err := arg.Init(); err != nil {
			t.Errorf("%s: arg init err: %s", test.name, err)
			continue
		}
		err := arg.CreatePGPIDs()
		if err != test.errOut {
			t.Errorf("%s: error %v, expected %v", test.name, err, test.errOut)
			continue
		}
		if test.errOut != nil {
			// this is an error test, no need to do anything else
			continue
		}
		if len(arg.Ids) != len(test.idsOut) {
			t.Errorf("%s: %d IDs, expected %d.", test.name, len(arg.Ids), len(test.idsOut))
			continue
		}
		for i, id := range arg.Ids {
			if id != test.idsOut[i] {
				t.Errorf("%s: id %d = %+v, expected %+v", test.name, i, id, test.idsOut[i])
			}
		}

		if len(arg.Ids) == 0 {
			continue
		}

		// test the PGPKeyBundle
		bundle, err := GeneratePGPKeyBundle(tc.G, *arg, tc.G.UI.GetLogUI())
		if err != nil {
			t.Errorf("%s: bundle error: %s", test.name, err)
		}
		if len(bundle.Identities) != len(test.idsOut) {
			t.Errorf("%s: %d bundle ids, expected %d", test.name, len(bundle.Identities), len(test.idsOut))
			continue
		}
		pids, err := arg.PGPUserIDs()
		if err != nil {
			t.Errorf("%s: pgp user id conversion error: %q", test.name, err)
			continue
		}
		for _, id := range pids {
			bundleID, ok := bundle.Identities[id.Id]
			if !ok {
				t.Errorf("%s: no bundle identity found for %q", test.name, id.Id)
				continue
			}
			if *(bundleID.UserId) != *id {
				t.Errorf("%s: bundle UserId = %+v, expected %+v", test.name, bundleID.UserId, id)
				continue
			}
		}
	}
}