forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proof_support_github.go
125 lines (97 loc) · 3.59 KB
/
proof_support_github.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package libkb
import (
"regexp"
"strings"
keybase1 "github.com/keybase/client/go/protocol"
jsonw "github.com/keybase/go-jsonw"
)
//=============================================================================
// Github
//
type GithubChecker struct {
proof RemoteProofChainLink
}
func NewGithubChecker(p RemoteProofChainLink) (*GithubChecker, ProofError) {
return &GithubChecker{p}, nil
}
func (rc *GithubChecker) GetTorError() ProofError { return nil }
func (rc *GithubChecker) CheckHint(h SigHint) ProofError {
given := strings.ToLower(h.apiURL)
u := strings.ToLower(rc.proof.GetRemoteUsername())
ok1 := "https://gist.github.com/" + u + "/"
ok2 := "https://gist.githubusercontent.com/" + u + "/"
if strings.HasPrefix(given, ok1) || strings.HasPrefix(given, ok2) {
return nil
}
return NewProofError(keybase1.ProofStatus_BAD_API_URL,
"Bad hint from server; URL start with either '%s' OR '%s'", ok1, ok2)
}
func (rc *GithubChecker) CheckStatus(h SigHint) ProofError {
res, err := G.XAPI.GetText(APIArg{
Endpoint: h.apiURL,
NeedSession: false,
})
if err != nil {
return XapiError(err, h.apiURL)
}
var sigBody []byte
sigBody, _, err = OpenSig(rc.proof.GetArmoredSig())
var ret ProofError
if err != nil {
return NewProofError(keybase1.ProofStatus_BAD_SIGNATURE,
"Bad signature: %s", err)
}
if !FindBase64Block(res.Body, sigBody, false) {
ret = NewProofError(keybase1.ProofStatus_TEXT_NOT_FOUND, "signature not found in body")
}
return ret
}
//
//=============================================================================
type GithubServiceType struct{ BaseServiceType }
func (t GithubServiceType) AllStringKeys() []string { return t.BaseAllStringKeys(t) }
func (t GithubServiceType) CheckUsername(s string) (err error) {
if !regexp.MustCompile(`^@?(?i:[a-z0-9][a-z0-9-]{0,38})$`).MatchString(s) {
err = BadUsernameError{s}
}
return
}
func (t GithubServiceType) ToChecker() Checker {
return t.BaseToChecker(t, "alphanumeric, up to 39 characters")
}
func (t GithubServiceType) GetPrompt() string {
return "Your username on Github"
}
func (t GithubServiceType) ToServiceJSON(un string) *jsonw.Wrapper {
return t.BaseToServiceJSON(t, un)
}
func (t GithubServiceType) PostInstructions(un string) *Markup {
return FmtMarkup(`Please <strong>publicly</strong> post the following Gist,
and name it <strong><color name="red">keybase.md</color></strong>`)
}
func (t GithubServiceType) DisplayName(un string) string { return "Github" }
func (t GithubServiceType) GetTypeName() string { return "github" }
func (t GithubServiceType) RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, _ string) (warning *Markup, err error) {
if status == keybase1.ProofStatus_PERMISSION_DENIED {
warning = FmtMarkup("Permission denied! Make sure your gist is <strong>public</strong>.")
} else {
warning, err = t.BaseRecheckProofPosting(tryNumber, status)
}
return
}
func (t GithubServiceType) GetProofType() string { return t.BaseGetProofType(t) }
func (t GithubServiceType) CheckProofText(text string, id keybase1.SigID, sig string) (err error) {
return t.BaseCheckProofTextFull(text, id, sig)
}
//=============================================================================
func init() {
RegisterServiceType(GithubServiceType{})
RegisterSocialNetwork("github")
RegisterProofCheckHook("github",
func(l RemoteProofChainLink) (ProofChecker, ProofError) {
return NewGithubChecker(l)
})
}
//=============================================================================