Skip to content

Commit

Permalink
just see if the key generation passed into decrypt is <= than what we…
Browse files Browse the repository at this point in the history
… have stored (#10565)
  • Loading branch information
mmaxim committed Feb 15, 2018
1 parent 1dce886 commit d30b2a3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions go/chat/keyfinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ func (k *KeyFinderImpl) encCacheKey(name string, tlfID chat1.TLFID, membersType
}

func (k *KeyFinderImpl) decCacheKey(name string, tlfID chat1.TLFID, membersType chat1.ConversationMembersType,
public bool, keyGeneration int, kbfsEncrypted bool) string {
return fmt.Sprintf("_dec:%s|%s|%v|%v|%d|%v", name, tlfID, membersType, public, keyGeneration,
kbfsEncrypted)
public bool, kbfsEncrypted bool) string {
return fmt.Sprintf("_dec:%s|%s|%v|%v|%v", name, tlfID, membersType, public, kbfsEncrypted)
}

func (k *KeyFinderImpl) createNameInfoSource(ctx context.Context,
Expand Down Expand Up @@ -154,10 +153,17 @@ func (k *KeyFinderImpl) FindForDecryption(ctx context.Context,
membersType chat1.ConversationMembersType, public bool,
keyGeneration int, kbfsEncrypted bool) (res *types.NameInfo, err error) {

ckey := k.decCacheKey(tlfName, tlfID, membersType, public, keyGeneration, kbfsEncrypted)
ckey := k.decCacheKey(tlfName, tlfID, membersType, public, kbfsEncrypted)
existing, ok := k.lookupKey(ckey)
if ok {
return existing, nil
effectiveMt := membersType
if kbfsEncrypted {
effectiveMt = chat1.ConversationMembersType_KBFS
}
storedKeys := existing.CryptKeys[effectiveMt]
if len(storedKeys) > 0 && storedKeys[len(storedKeys)-1].Generation() >= keyGeneration {
return existing, nil
}
}
defer func() {
if err == nil {
Expand Down

0 comments on commit d30b2a3

Please sign in to comment.