forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
proof_support_facebook.go
110 lines (85 loc) · 3.81 KB
/
proof_support_facebook.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package externals
import (
"regexp"
"strings"
libkb "github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
jsonw "github.com/keybase/go-jsonw"
)
//=============================================================================
// Facebook
//
type FacebookChecker struct {
proof libkb.RemoteProofChainLink
}
var _ libkb.ProofChecker = (*FacebookChecker)(nil)
func NewFacebookChecker(p libkb.RemoteProofChainLink) (*FacebookChecker, libkb.ProofError) {
return &FacebookChecker{p}, nil
}
func (rc *FacebookChecker) GetTorError() libkb.ProofError { return nil }
func (rc *FacebookChecker) CheckStatus(ctx libkb.ProofContext, h libkb.SigHint, _ libkb.ProofCheckerMode, pvlU libkb.PvlUnparsed) libkb.ProofError {
return CheckProofPvl(ctx, keybase1.ProofType_FACEBOOK, rc.proof, h, pvlU)
}
//
//=============================================================================
type FacebookServiceType struct{ libkb.BaseServiceType }
func (t FacebookServiceType) AllStringKeys() []string { return t.BaseAllStringKeys(t) }
var facebookUsernameRegexp = regexp.MustCompile(`^(?i:[a-z0-9.]{1,50})$`)
func (t FacebookServiceType) NormalizeUsername(s string) (string, error) {
if !facebookUsernameRegexp.MatchString(s) {
return "", libkb.NewBadUsernameError(s)
}
// Convert to lowercase and strip out dots.
return strings.ToLower(strings.Replace(s, ".", "", -1)), nil
}
func (t FacebookServiceType) NormalizeRemoteName(ctx libkb.ProofContext, s string) (string, error) {
// Allow a leading '@'.
s = strings.TrimPrefix(s, "@")
if !facebookUsernameRegexp.MatchString(s) {
return "", libkb.NewBadUsernameError(s)
}
// This is the normalization function that gets called by the Prove engine.
// Avoid stripping dots, so that we can preserve them when the username is
// displayed.
return strings.ToLower(s), nil
}
func (t FacebookServiceType) GetPrompt() string {
return "Your username on Facebook"
}
func (t FacebookServiceType) ToServiceJSON(un string) *jsonw.Wrapper {
return t.BaseToServiceJSON(t, un)
}
func (t FacebookServiceType) PostInstructions(un string) *libkb.Markup {
return libkb.FmtMarkup(
`<p>Please follow this link and make a <strong>public</strong> Facebook post.</p>
<p>The text can be whatever you want, but the post <strong>must be public</strong>.</p>`)
}
func (t FacebookServiceType) DisplayName(un string) string { return "Facebook" }
func (t FacebookServiceType) GetTypeName() string { return "facebook" }
func (t FacebookServiceType) RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, _ string) (warning *libkb.Markup, err error) {
if status == keybase1.ProofStatus_PERMISSION_DENIED {
warning = libkb.FmtMarkup("Permission denied! We can't support <strong>private</strong> posts.")
} else {
warning, err = t.BaseRecheckProofPosting(tryNumber, status)
}
return
}
func (t FacebookServiceType) GetProofType() string { return t.BaseGetProofType(t) }
func (t FacebookServiceType) CheckProofText(text string, id keybase1.SigID, sig string) error {
// The "proof" here is a Facebook link that the user clicks on to go
// through a post flow. The exact nature of the link tends to change (e.g.
// it used to not point to a login interstitial, but now it does), and
// users are going to need to eyeball the final post in their browsers
// anyway, so we don't check anything here.
return nil
}
func (t FacebookServiceType) MakeProofChecker(l libkb.RemoteProofChainLink) libkb.ProofChecker {
return &FacebookChecker{l}
}
//=============================================================================
func init() {
externalServices.Register(FacebookServiceType{})
}
//=============================================================================