Skip to content

Commit dcdee1c

Browse files
committed
Close Issue #21
Squashed commit of the following: commit c85d267cc7fd085ebacc27017dfab46769fa194a Author: Maxwell Krohn <themax@gmail.com> Date: Thu Oct 9 17:42:19 2014 -0400 more tests, get it kind of working commit c72d8998d9d5bc834a914b36f98b3c067355c941 Author: Maxwell Krohn <themax@gmail.com> Date: Thu Oct 9 17:23:11 2014 -0400 ready resolution it mainly works, though something is broken now with command-line parsing displaying help commit 4b38bc666c5c934c88e436d2b73a4fe6d3947f76 Author: Maxwell Krohn <themax@gmail.com> Date: Thu Oct 9 17:02:00 2014 -0400 ready to start testing commit 11ca52bff2603929db926200de87de083ce9580d Author: Maxwell Krohn <themax@gmail.com> Date: Thu Oct 9 16:26:56 2014 -0400 more work on username resolution commit 74eee95c771c264ea2c8a7417725ab178c859ab7 Author: Maxwell Krohn <themax@gmail.com> Date: Thu Oct 9 15:38:14 2014 -0400 give up on 80 cols i'll try my best but i can't do it all the time (i.e. long comments and big regexes)
1 parent 8abdded commit dcdee1c

14 files changed

Lines changed: 335 additions & 63 deletions

‎assertion.go‎

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,28 @@ type AssertionUrl interface {
6060
ToString() string
6161
MatchSet(ps ProofSet) bool
6262
MatchProof(p Proof) bool
63+
ToKeyValuePair() (string, string)
64+
CacheKey() string
65+
GetValue() string
66+
ToLookup() (string, string, error)
6367
}
6468

6569
type AssertionUrlBase struct {
6670
Key, Value string
6771
}
6872

73+
func (b AssertionUrlBase) ToKeyValuePair() (string, string) {
74+
return b.Key, b.Value
75+
}
76+
77+
func (b AssertionUrlBase) CacheKey() string {
78+
return b.Key + ":" + b.Value
79+
}
80+
81+
func (b AssertionUrlBase) GetValue() string {
82+
return b.Value
83+
}
84+
6985
func (a AssertionUrlBase) matchSet(v AssertionUrl, ps ProofSet) bool {
7086
proofs := ps.Get(v.Keys())
7187
for _, proof := range proofs {
@@ -76,15 +92,18 @@ func (a AssertionUrlBase) matchSet(v AssertionUrl, ps ProofSet) bool {
7692
return false
7793
}
7894

79-
func (a AssertionKeybase) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
80-
func (a AssertionWeb) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
81-
func (a AssertionSocial) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
82-
func (a AssertionHttp) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
83-
func (a AssertionHttps) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
84-
func (a AssertionDns) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
85-
func (a AssertionFingerprint) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
86-
87-
func (a AssertionWeb) Keys() []string { return []string{"dns", "http", "https"} }
95+
func (a AssertionKeybase) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
96+
func (a AssertionWeb) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
97+
func (a AssertionSocial) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
98+
func (a AssertionHttp) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
99+
func (a AssertionHttps) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
100+
func (a AssertionDns) MatchSet(ps ProofSet) bool { return a.matchSet(a, ps) }
101+
func (a AssertionFingerprint) MatchSet(ps ProofSet) bool {
102+
return a.matchSet(a, ps)
103+
}
104+
func (a AssertionWeb) Keys() []string {
105+
return []string{"dns", "http", "https"}
106+
}
88107
func (a AssertionHttp) Keys() []string { return []string{"http", "https"} }
89108
func (a AssertionUrlBase) Keys() []string { return []string{a.Key} }
90109
func (a AssertionUrlBase) IsKeybase() bool { return false }
@@ -141,16 +160,54 @@ func (a AssertionUrlBase) ToString() string {
141160
return fmt.Sprintf("%s://%s", a.Key, a.Value)
142161
}
143162

144-
func parseToKVPair(s string) (key string, value string) {
145-
colon := strings.IndexByte(s, byte(':'))
146-
if colon < 0 {
147-
value = s
163+
func (k AssertionWeb) ToLookup() (key, value string, err error) {
164+
return "web", k.Value, nil
165+
}
166+
func (k AssertionHttp) ToLookup() (key, value string, err error) {
167+
return "http", k.Value, nil
168+
}
169+
func (k AssertionHttps) ToLookup() (key, value string, err error) {
170+
return "https", k.Value, nil
171+
}
172+
func (k AssertionDns) ToLookup() (key, value string, err error) {
173+
return "dns", k.Value, nil
174+
}
175+
func (k AssertionFingerprint) ToLookup() (key, value string, err error) {
176+
cmp := len(k.Value) - PGP_FINGERPRINT_HEX_LEN
177+
value = k.Value
178+
if len(k.Value) < 4 {
179+
err = fmt.Errorf("fingerprint queries must be at least 2 bytes long")
180+
} else if cmp == 0 {
181+
key = "key_fingerprint"
182+
} else if cmp < 0 {
183+
key = "key_suffix"
148184
} else {
185+
err = fmt.Errorf("bad fingerprint; too long: %s", k.Value)
186+
}
187+
return
188+
}
189+
190+
func parseToKVPair(s string) (key string, value string, err error) {
191+
192+
re := regexp.MustCompile(`^[0-9a-zA-Z@:/_-]`)
193+
if !re.MatchString(s) {
194+
err = fmt.Errorf("Invalid key-value identity: %s", s)
195+
return
196+
}
197+
198+
colon := strings.IndexByte(s, byte(':'))
199+
atsign := strings.IndexByte(s, byte('@'))
200+
if colon >= 0 {
149201
key = s[0:colon]
150202
value = s[(colon + 1):]
151203
if len(value) >= 2 && value[0:2] == "//" {
152204
value = value[2:]
153205
}
206+
} else if atsign >= 0 {
207+
value = s[0:atsign]
208+
key = s[(atsign + 1):]
209+
} else {
210+
value = s
154211
}
155212
key = strings.ToLower(key)
156213
value = strings.ToLower(value)
@@ -161,6 +218,10 @@ func (k AssertionKeybase) IsKeybase() bool {
161218
return true
162219
}
163220

221+
func (k AssertionKeybase) ToLookup() (key, value string, err error) {
222+
return "username", k.Value, nil
223+
}
224+
164225
func (s AssertionSocial) Check() (err error) {
165226
networks := map[string]bool{
166227
"github": true,
@@ -176,12 +237,26 @@ func (s AssertionSocial) Check() (err error) {
176237
return
177238
}
178239

240+
func (k AssertionSocial) ToLookup() (key, value string, err error) {
241+
return k.Key, k.Value, nil
242+
}
243+
179244
func ParseAssertionUrl(s string, strict bool) (ret AssertionUrl, err error) {
180-
key, val := parseToKVPair(s)
245+
key, val, err := parseToKVPair(s)
246+
247+
if err != nil {
248+
return
249+
}
250+
return ParseAssertionUrlKeyValue(key, val, strict)
251+
}
252+
253+
func ParseAssertionUrlKeyValue(key, val string,
254+
strict bool) (ret AssertionUrl, err error) {
181255

182256
if len(key) == 0 {
183257
if strict {
184-
err = fmt.Errorf("Bad assertion, no 'type' given: %s", s)
258+
err = fmt.Errorf("Bad assertion, no 'type' given: %s", val)
259+
return
185260
} else {
186261
key = "keybase"
187262
}

‎assertion_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestSuccess1(t *testing.T) {
2020
}
2121

2222
func TestAssertions1(t *testing.T) {
23-
a := "web://maxk.org && (https://foo.com || http://bar.com) && (twitter://bb || max || fingerprint://aabbcc)"
23+
a := "web://maxk.org && (https://foo.com || http://bar.com) && (bb@twitter || max || fingerprint://aabbcc)"
2424
good_proofsets := []ProofSet{
2525
*NewProofSet([]Proof{
2626
{"dns", "maxk.org"},

‎cmd_config.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (v *CmdConfig) Initialize(ctx *cli.Context) error {
3232
return nil
3333
}
3434

35-
func (v CmdConfig) Run() error {
35+
func (v *CmdConfig) Run() error {
3636
configFile := G.Env.GetConfigFilename()
3737

3838
if v.location {
@@ -87,7 +87,7 @@ func (v CmdConfig) Run() error {
8787
return nil
8888
}
8989

90-
func (v CmdConfig) UseConfig() bool { return true }
91-
func (v CmdConfig) UseKeyring() bool { return false }
92-
func (v CmdConfig) UseAPI() bool { return false }
93-
func (v CmdConfig) UseTerminal() bool { return false }
90+
func (v *CmdConfig) UseConfig() bool { return true }
91+
func (v *CmdConfig) UseKeyring() bool { return false }
92+
func (v *CmdConfig) UseAPI() bool { return false }
93+
func (v *CmdConfig) UseTerminal() bool { return false }

‎cmd_login.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package libkb
22

3-
import ()
3+
import (
4+
"github.com/codegangsta/cli"
5+
)
46

57
type CmdLogin struct{}
68

7-
func (v CmdLogin) Run() error {
9+
func (v *CmdLogin) Run() error {
810

911
err := G.LoginState.Login()
1012
if err != nil {
@@ -13,7 +15,8 @@ func (v CmdLogin) Run() error {
1315
return nil
1416
}
1517

16-
func (v CmdLogin) UseConfig() bool { return true }
17-
func (v CmdLogin) UseKeyring() bool { return true }
18-
func (v CmdLogin) UseAPI() bool { return true }
19-
func (v CmdLogin) UseTerminal() bool { return true }
18+
func (v *CmdLogin) UseConfig() bool { return true }
19+
func (v *CmdLogin) UseKeyring() bool { return true }
20+
func (v *CmdLogin) UseAPI() bool { return true }
21+
func (v *CmdLogin) UseTerminal() bool { return true }
22+
func (c *CmdLogin) Initialize(*cli.Context) error { return nil }

‎cmd_ping.go‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package libkb
22

33
import (
44
"fmt"
5+
"github.com/codegangsta/cli"
56
)
67

78
type CmdPing struct{}
89

9-
func (v CmdPing) Run() error {
10+
func (v *CmdPing) Run() error {
1011
_, err := G.API.Post(ApiArg{
1112
Endpoint: "ping",
1213
Args: HttpArgs{
@@ -26,7 +27,8 @@ func (v CmdPing) Run() error {
2627
return nil
2728
}
2829

29-
func (v CmdPing) UseConfig() bool { return true }
30-
func (v CmdPing) UseKeyring() bool { return false }
31-
func (v CmdPing) UseAPI() bool { return true }
32-
func (v CmdPing) UseTerminal() bool { return false }
30+
func (v *CmdPing) UseConfig() bool { return true }
31+
func (v *CmdPing) UseKeyring() bool { return false }
32+
func (v *CmdPing) UseAPI() bool { return true }
33+
func (v *CmdPing) UseTerminal() bool { return false }
34+
func (c *CmdPing) Initialize(*cli.Context) error { return nil }

‎cmd_resolve.go‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package libkb
2+
3+
import (
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
)
7+
8+
type CmdResolve struct {
9+
input string
10+
}
11+
12+
func (v *CmdResolve) Initialize(ctx *cli.Context) error {
13+
nargs := len(ctx.Args())
14+
var err error
15+
if nargs == 1 {
16+
v.input = ctx.Args()[0]
17+
} else {
18+
err = fmt.Errorf("resolve takes one arg -- the name to resolve")
19+
}
20+
return err
21+
}
22+
23+
func (v *CmdResolve) Run() error {
24+
res, err := ResolveUsername(v.input)
25+
if err == nil {
26+
fmt.Println(res)
27+
}
28+
return err
29+
}
30+
31+
func (v *CmdResolve) UseConfig() bool { return true }
32+
func (v *CmdResolve) UseKeyring() bool { return false }
33+
func (v *CmdResolve) UseAPI() bool { return true }
34+
func (v *CmdResolve) UseTerminal() bool { return false }

‎cmd_version.go‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package libkb
22

33
import (
44
"fmt"
5+
"github.com/codegangsta/cli"
56
"runtime"
67
)
78

@@ -13,12 +14,13 @@ func VersionMessage(linefn func(string)) {
1314
linefn("- Visit https://keybase.io for more details")
1415
}
1516

16-
func (v CmdVersion) Run() error {
17+
func (v *CmdVersion) Run() error {
1718
VersionMessage(func(s string) { fmt.Println(s) })
1819
return nil
1920
}
2021

21-
func (v CmdVersion) UseConfig() bool { return true }
22-
func (v CmdVersion) UseKeyring() bool { return false }
23-
func (v CmdVersion) UseAPI() bool { return false }
24-
func (v CmdVersion) UseTerminal() bool { return false }
22+
func (v *CmdVersion) UseConfig() bool { return true }
23+
func (v *CmdVersion) UseKeyring() bool { return false }
24+
func (v *CmdVersion) UseAPI() bool { return false }
25+
func (v *CmdVersion) UseTerminal() bool { return false }
26+
func (c *CmdVersion) Initialize(*cli.Context) error { return nil }

0 commit comments

Comments
 (0)