/
cmd_ca.go
97 lines (80 loc) · 2.08 KB
/
cmd_ca.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"regexp"
"strings"
"github.com/keybase/cli"
"github.com/keybase/client/go/auth"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
context "golang.org/x/net/context"
)
type CmdCA struct {
libkb.Contextified
}
func (c *CmdCA) ParseArgv(ctx *cli.Context) error {
return nil
}
func (c *CmdCA) Run() error {
return c.runPromptLoop()
}
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) != 4 {
c.G().Log.Errorf("Need a quad: [<uid>,<username>,<loadDeleted>,<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[3])
if e2 != nil {
c.G().Log.Errorf("Bad KID %s: %s", v[3], e2)
continue
}
loadDeleted := false
switch v[2] {
case "1", "true":
loadDeleted = true
case "0", "false":
default:
c.G().Log.Errorf("Bad loadDeleted value: %s", v[2])
}
if e2 := ca.CheckUserKey(context.TODO(), uid, &un, &kid, loadDeleted); e2 != nil {
c.G().Log.Errorf("Bad check: %s", e2)
}
}
return err
}
func NewCmdCA(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "ca",
Description: "Query the server about whether keys are valid for given users",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdCA{Contextified: libkb.NewContextified(g)}, "show-notifications", c)
},
Flags: []cli.Flag{},
}
}
func (c *CmdCA) GetUsage() libkb.Usage {
return libkb.Usage{API: true}
}