github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/externals/proof_service_dns.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  	"strings"
     8  
     9  	libkb "github.com/keybase/client/go/libkb"
    10  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    11  	jsonw "github.com/keybase/go-jsonw"
    12  )
    13  
    14  // =============================================================================
    15  // Dns
    16  //
    17  
    18  type DNSChecker struct {
    19  	proof libkb.RemoteProofChainLink
    20  }
    21  
    22  var _ libkb.ProofChecker = (*DNSChecker)(nil)
    23  
    24  func NewDNSChecker(p libkb.RemoteProofChainLink) (*DNSChecker, libkb.ProofError) {
    25  	return &DNSChecker{p}, nil
    26  }
    27  
    28  func (rc *DNSChecker) GetTorError() libkb.ProofError { return libkb.ProofErrorDNSOverTor }
    29  
    30  func (rc *DNSChecker) CheckStatus(m libkb.MetaContext, h libkb.SigHint, pcm libkb.ProofCheckerMode,
    31  	pvlU keybase1.MerkleStoreEntry) (*libkb.SigHint, libkb.ProofError) {
    32  	// TODO CORE-8951 see if we can populate verifiedHint with anything useful.
    33  	if pcm != libkb.ProofCheckerModeActive {
    34  		m.Debug("DNS check skipped since proof checking was not in active mode (%s)", h.GetAPIURL())
    35  		return nil, libkb.ProofErrorUnchecked
    36  	}
    37  	return nil, CheckProofPvl(m, keybase1.ProofType_DNS, rc.proof, h, pvlU)
    38  }
    39  
    40  //
    41  // =============================================================================
    42  
    43  type DNSServiceType struct{ libkb.BaseServiceType }
    44  
    45  func (t *DNSServiceType) Key() string { return t.GetTypeName() }
    46  
    47  func (t *DNSServiceType) NormalizeUsername(s string) (string, error) {
    48  	if !libkb.IsValidHostname(s) {
    49  		return "", libkb.NewInvalidHostnameError(s)
    50  	}
    51  	return strings.ToLower(s), nil
    52  }
    53  
    54  func (t *DNSServiceType) NormalizeRemoteName(_ libkb.MetaContext, s string) (string, error) {
    55  	// Allow a leading 'dns://' and preserve case.
    56  	s = strings.TrimPrefix(s, "dns://")
    57  	if !libkb.IsValidHostname(s) {
    58  		return "", libkb.NewInvalidHostnameError(s)
    59  	}
    60  	return s, nil
    61  }
    62  
    63  func (t *DNSServiceType) GetPrompt() string {
    64  	return "Your DNS domain"
    65  }
    66  
    67  func (t *DNSServiceType) ToServiceJSON(un string) *jsonw.Wrapper {
    68  	ret := jsonw.NewDictionary()
    69  	_ = ret.SetKey("protocol", jsonw.NewString("dns"))
    70  	_ = ret.SetKey("domain", jsonw.NewString(un))
    71  	return ret
    72  }
    73  
    74  func (t *DNSServiceType) FormatProofText(ctx libkb.MetaContext, ppr *libkb.PostProofRes,
    75  	kbUsername, remoteUsername string, sigID keybase1.SigID) (string, error) {
    76  	return (ppr.Text + "\n"), nil
    77  }
    78  
    79  func (t *DNSServiceType) PostInstructions(un string) *libkb.Markup {
    80  	return libkb.FmtMarkup(`Please save the following as a DNS TXT entry for
    81  <strong>` + un + `</strong> OR <strong>_keybase.` + un + `</strong>:`)
    82  }
    83  
    84  func (t *DNSServiceType) DisplayName() string   { return "Dns" }
    85  func (t *DNSServiceType) GetTypeName() string   { return "dns" }
    86  func (t *DNSServiceType) PickerSubtext() string { return t.GetTypeName() }
    87  
    88  func (t *DNSServiceType) RecheckProofPosting(tryNumber int, status keybase1.ProofStatus, dn string) (warning *libkb.Markup, err error) {
    89  	warning = libkb.FmtMarkup(`<p>We couldn't find a DNS proof for ` + dn + ` ... <strong>yet</strong></p>
    90  <p>DNS propagation can be slow; we'll keep trying and email you the result</p>`)
    91  	err = libkb.WaitForItError{}
    92  	return
    93  }
    94  func (t *DNSServiceType) GetProofType() string { return t.BaseGetProofType(t) }
    95  
    96  func (t *DNSServiceType) CheckProofText(text string, id keybase1.SigID, sig string) (err error) {
    97  	return t.BaseCheckProofTextShort(text, id, true)
    98  }
    99  
   100  func (t *DNSServiceType) GetAPIArgKey() string { return "remote_host" }
   101  func (t *DNSServiceType) LastWriterWins() bool { return false }
   102  
   103  func (t *DNSServiceType) MakeProofChecker(l libkb.RemoteProofChainLink) libkb.ProofChecker {
   104  	return &DNSChecker{l}
   105  }