github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/idutil/data_types.go (about)

     1  // Copyright 2019 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package idutil
     6  
     7  import (
     8  	"github.com/keybase/client/go/kbfs/kbfscrypto"
     9  	"github.com/keybase/client/go/kbfs/kbfsmd"
    10  	"github.com/keybase/client/go/kbfs/tlf"
    11  	kbname "github.com/keybase/client/go/kbun"
    12  	"github.com/keybase/client/go/protocol/keybase1"
    13  )
    14  
    15  const (
    16  	// PublicUIDName is the name given to keybase1.PublicUID.  This string
    17  	// should correspond to an illegal or reserved Keybase user name.
    18  	PublicUIDName = "_public"
    19  )
    20  
    21  // RevokedKeyInfo contains any KBFS-relevant data to user keys that
    22  // have been revoked or belong to a account before it was reset.
    23  type RevokedKeyInfo struct {
    24  	// Fields are exported so they can be copied by the codec.
    25  	Time       keybase1.Time
    26  	MerkleRoot keybase1.MerkleRootV2
    27  
    28  	// These fields never need copying.
    29  	sigChainLocation keybase1.SigChainLocation
    30  	resetSeqno       keybase1.Seqno
    31  	isReset          bool
    32  	filledInMerkle   bool
    33  }
    34  
    35  // SigChainLocation returns the sigchain location for this revocation.
    36  func (rki RevokedKeyInfo) SigChainLocation() keybase1.SigChainLocation {
    37  	return rki.sigChainLocation
    38  }
    39  
    40  // SetSigChainLocation sets the sigchain location for this revocation.
    41  func (rki *RevokedKeyInfo) SetSigChainLocation(loc keybase1.SigChainLocation) {
    42  	rki.sigChainLocation = loc
    43  }
    44  
    45  // FilledInMerkle returns whether or not this key info has had its
    46  // merkle data (like the sigchain location or the reset info) filled
    47  // in yet.
    48  func (rki RevokedKeyInfo) FilledInMerkle() bool {
    49  	return rki.filledInMerkle
    50  }
    51  
    52  // SetFilledInMerkle sets whether or not this key info has had its
    53  // merkle data (like the sigchain location or the reset info) filled
    54  // in yet.
    55  func (rki *RevokedKeyInfo) SetFilledInMerkle(filledIn bool) {
    56  	rki.filledInMerkle = filledIn
    57  }
    58  
    59  // ResetInfo returns, if this key belongs to an account before it was
    60  // reset, data about that reset.
    61  func (rki RevokedKeyInfo) ResetInfo() (keybase1.Seqno, bool) {
    62  	return rki.resetSeqno, rki.isReset
    63  }
    64  
    65  // SetResetInfo sets, if this key belongs to an account before it was
    66  // reset, data about that reset.
    67  func (rki *RevokedKeyInfo) SetResetInfo(seqno keybase1.Seqno, isReset bool) {
    68  	rki.resetSeqno = seqno
    69  	rki.isReset = isReset
    70  }
    71  
    72  // UserInfo contains all the info about a keybase user that kbfs cares
    73  // about.
    74  type UserInfo struct {
    75  	Name            kbname.NormalizedUsername
    76  	UID             keybase1.UID
    77  	VerifyingKeys   []kbfscrypto.VerifyingKey
    78  	CryptPublicKeys []kbfscrypto.CryptPublicKey
    79  	KIDNames        map[keybase1.KID]string
    80  	EldestSeqno     keybase1.Seqno
    81  
    82  	// Revoked keys, and the time at which they were revoked.
    83  	RevokedVerifyingKeys   map[kbfscrypto.VerifyingKey]RevokedKeyInfo
    84  	RevokedCryptPublicKeys map[kbfscrypto.CryptPublicKey]RevokedKeyInfo
    85  }
    86  
    87  // DeepCopy returns a copy of `ui`, including deep copies of all slice
    88  // and map members.
    89  func (ui UserInfo) DeepCopy() UserInfo {
    90  	copyUI := ui
    91  	copyUI.VerifyingKeys = make(
    92  		[]kbfscrypto.VerifyingKey, len(ui.VerifyingKeys))
    93  	copy(copyUI.VerifyingKeys, ui.VerifyingKeys)
    94  	copyUI.CryptPublicKeys = make(
    95  		[]kbfscrypto.CryptPublicKey, len(ui.CryptPublicKeys))
    96  	copy(copyUI.CryptPublicKeys, ui.CryptPublicKeys)
    97  	copyUI.KIDNames = make(map[keybase1.KID]string, len(ui.KIDNames))
    98  	for k, v := range ui.KIDNames {
    99  		copyUI.KIDNames[k] = v
   100  	}
   101  	copyUI.RevokedVerifyingKeys = make(
   102  		map[kbfscrypto.VerifyingKey]RevokedKeyInfo,
   103  		len(ui.RevokedVerifyingKeys))
   104  	for k, v := range ui.RevokedVerifyingKeys {
   105  		copyUI.RevokedVerifyingKeys[k] = v
   106  	}
   107  	copyUI.RevokedCryptPublicKeys = make(
   108  		map[kbfscrypto.CryptPublicKey]RevokedKeyInfo,
   109  		len(ui.RevokedCryptPublicKeys))
   110  	for k, v := range ui.RevokedCryptPublicKeys {
   111  		copyUI.RevokedCryptPublicKeys[k] = v
   112  	}
   113  	return copyUI
   114  }
   115  
   116  // TeamInfo contains all the info about a keybase team that kbfs cares
   117  // about.
   118  type TeamInfo struct {
   119  	// Maybe this should be bare string?  The service doesn't give us
   120  	// a nice type, unfortunately.  Also note that for implicit teams,
   121  	// this is an auto-generated name that shouldn't be shown to
   122  	// users.
   123  	Name         kbname.NormalizedUsername
   124  	TID          keybase1.TeamID
   125  	CryptKeys    map[kbfsmd.KeyGen]kbfscrypto.TLFCryptKey
   126  	LatestKeyGen kbfsmd.KeyGen
   127  	RootID       keybase1.TeamID // for subteams only
   128  
   129  	Writers map[keybase1.UID]bool
   130  	Readers map[keybase1.UID]bool
   131  
   132  	// Last writers map a KID to the last time the writer associated
   133  	// with that KID trasitioned from writer to non-writer.
   134  	LastWriters map[kbfscrypto.VerifyingKey]keybase1.MerkleRootV2
   135  }
   136  
   137  // ImplicitTeamInfo contains information needed after
   138  // resolving/identifying an implicit team.  TeamInfo is used for
   139  // anything else.
   140  type ImplicitTeamInfo struct {
   141  	Name  kbname.NormalizedUsername // The "display" name for the i-team.
   142  	TID   keybase1.TeamID
   143  	TlfID tlf.ID
   144  }
   145  
   146  // SessionInfo contains all the info about the keybase session that
   147  // kbfs cares about.
   148  type SessionInfo struct {
   149  	Name           kbname.NormalizedUsername
   150  	UID            keybase1.UID
   151  	CryptPublicKey kbfscrypto.CryptPublicKey
   152  	VerifyingKey   kbfscrypto.VerifyingKey
   153  }