github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/externals/proof_service_facebook.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package externals 5 6 import ( 7 "regexp" 8 "strings" 9 10 libkb "github.com/keybase/client/go/libkb" 11 keybase1 "github.com/keybase/client/go/protocol/keybase1" 12 jsonw "github.com/keybase/go-jsonw" 13 ) 14 15 // ============================================================================= 16 // Facebook 17 // 18 19 type FacebookChecker struct { 20 proof libkb.RemoteProofChainLink 21 } 22 23 var _ libkb.ProofChecker = (*FacebookChecker)(nil) 24 25 func NewFacebookChecker(p libkb.RemoteProofChainLink) (*FacebookChecker, libkb.ProofError) { 26 return &FacebookChecker{p}, nil 27 } 28 29 func (rc *FacebookChecker) GetTorError() libkb.ProofError { return nil } 30 31 func (rc *FacebookChecker) CheckStatus(mctx libkb.MetaContext, h libkb.SigHint, _ libkb.ProofCheckerMode, 32 pvlU keybase1.MerkleStoreEntry) (*libkb.SigHint, libkb.ProofError) { 33 // TODO CORE-8951 see if we can populate verifiedHint with anything useful. 34 return nil, CheckProofPvl(mctx, keybase1.ProofType_FACEBOOK, rc.proof, h, pvlU) 35 } 36 37 // 38 // ============================================================================= 39 40 type FacebookServiceType struct{ libkb.BaseServiceType } 41 42 func (t *FacebookServiceType) Key() string { return t.GetTypeName() } 43 44 var facebookUsernameRegexp = regexp.MustCompile(`^(?i:[a-z0-9.]{1,50})$`) 45 46 func (t *FacebookServiceType) NormalizeUsername(s string) (string, error) { 47 if !facebookUsernameRegexp.MatchString(s) { 48 return "", libkb.NewBadUsernameError(s) 49 } 50 // Convert to lowercase. Don't strip out dots, because while Facebook makes 51 // them optional, there are still dots in a user's "canonical" account name. 52 return strings.ToLower(s), nil 53 } 54 55 func (t *FacebookServiceType) NormalizeRemoteName(mctx libkb.MetaContext, s string) (string, error) { 56 // Allow a leading '@'. 57 s = strings.TrimPrefix(s, "@") 58 return t.NormalizeUsername(s) 59 } 60 61 func (t *FacebookServiceType) GetPrompt() string { 62 return "Your username on Facebook" 63 } 64 65 func (t *FacebookServiceType) ToServiceJSON(un string) *jsonw.Wrapper { 66 return t.BaseToServiceJSON(t, un) 67 } 68 69 func (t *FacebookServiceType) PostInstructions(un string) *libkb.Markup { 70 return libkb.FmtMarkup( 71 `<p>Please follow this link and make a <strong>public</strong> Facebook post.</p> 72 <p>The text can be whatever you want, but the post <strong>must be public</strong>.</p>`) 73 } 74 75 func (t *FacebookServiceType) DisplayName() string { return "Facebook" } 76 func (t *FacebookServiceType) GetTypeName() string { return "facebook" } 77 func (t *FacebookServiceType) PickerSubtext() string { return "facebook.com" } 78 79 func (t *FacebookServiceType) RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, _ string) (warning *libkb.Markup, err error) { 80 if status == keybase1.ProofStatus_PERMISSION_DENIED { 81 warning = libkb.FmtMarkup("Permission denied! We can't support <strong>private</strong> posts.") 82 } else { 83 warning, err = t.BaseRecheckProofPosting(tryNumber, status) 84 } 85 return 86 } 87 func (t *FacebookServiceType) GetProofType() string { return t.BaseGetProofType(t) } 88 89 func (t *FacebookServiceType) CheckProofText(text string, id keybase1.SigID, sig string) error { 90 // The "proof" here is a Facebook link that the user clicks on to go 91 // through a post flow. The exact nature of the link tends to change (e.g. 92 // it used to not point to a login interstitial, but now it does), and 93 // users are going to need to eyeball the final post in their browsers 94 // anyway, so we don't check anything here. 95 return nil 96 } 97 98 func (t *FacebookServiceType) MakeProofChecker(l libkb.RemoteProofChainLink) libkb.ProofChecker { 99 return &FacebookChecker{l} 100 }