Skip to content

Commit

Permalink
Don't assert name during decryption (#13802)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Sep 18, 2018
1 parent 12b6173 commit be2453b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
3 changes: 1 addition & 2 deletions go/chat/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ func (s *BlockingSender) addPrevPointersAndCheckConvID(ctx context.Context, msg

for _, msg2 := range thread.Messages {
if msg2.IsValid() {
err = s.checkConvID(ctx, conv, msg, msg2)
if err != nil {
if err = s.checkConvID(ctx, conv, msg, msg2); err != nil {
return resMsg, err
}
break
Expand Down
24 changes: 24 additions & 0 deletions go/chat/subteam_rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ func TestChatSubteamRename(t *testing.T) {
require.NoError(t, err)
convs = append(convs, ncres.Conv.Info)
versMap[ncres.Conv.GetConvID().String()] = ncres.Conv.Info.Version

// Write a message so we have something that uses the old team name in the chat history.
_, err = ctc.as(t, users[0]).chatLocalHandler().PostLocal(context.TODO(), chat1.PostLocalArg{
ConversationID: ncres.Conv.Info.Id,
Msg: chat1.MessagePlaintext{
ClientHeader: chat1.MessageClientHeader{
Conv: ncres.Conv.Info.Triple,
MessageType: chat1.MessageType_TEXT,
TlfName: ncres.Conv.Info.TlfName,
},
MessageBody: chat1.NewMessageBodyWithText(chat1.MessageText{
Body: "Hello",
}),
},
})
require.NoError(t, err)
}
}

Expand Down Expand Up @@ -157,6 +173,14 @@ func TestChatSubteamRename(t *testing.T) {
},
})
require.NoError(t, err)
// Make sure user1 (user0 did all the sends) can decrypt everything
// in conversation.
tv, err := tc.Context().ConvSource.Pull(context.TODO(), convID, users[1].GetUID().ToBytes(), chat1.GetThreadReason_GENERAL, nil,
nil)
require.NoError(t, err)
for _, msg := range tv.Messages {
require.True(t, msg.IsValid())
}
}
})
}
22 changes: 14 additions & 8 deletions go/chat/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ func encryptionKeyViaFTL(m libkb.MetaContext, name string, tlfID chat1.TLFID) (r
return ftlRes.ApplicationKeys[0], ni, nil
}

func decryptionKeyViaFTL(m libkb.MetaContext, name string, tlfID chat1.TLFID, keyGeneration int) (res types.CryptKey, err error) {
func decryptionKeyViaFTL(m libkb.MetaContext, tlfID chat1.TLFID, keyGeneration int) (res types.CryptKey, err error) {

ftlRes, err := getKeyViaFTL(m, name, tlfID, keyGeneration)
// We don't pass a `name` during decryption.
ftlRes, err := getKeyViaFTL(m, "" /*name*/, tlfID, keyGeneration)
if err != nil {
return nil, err
}
Expand All @@ -76,16 +77,21 @@ func getKeyViaFTL(m libkb.MetaContext, name string, tlfID chat1.TLFID, keyGenera
if err != nil {
return res, err
}

teamName, err := keybase1.TeamNameFromString(name)
if err != nil {
return res, err
// The `name` parameter is optional since subteams can be renamed and
// messages with the old name must be successfully decrypted.
var teamNamePtr *keybase1.TeamName
if name != "" {
teamName, err := keybase1.TeamNameFromString(name)
if err != nil {
return res, err
}
teamNamePtr = &teamName
}
arg := keybase1.FastTeamLoadArg{
ID: teamID,
Public: false,
Applications: []keybase1.TeamApplication{keybase1.TeamApplication_CHAT},
AssertTeamName: &teamName,
AssertTeamName: teamNamePtr,
}

if keyGeneration > 0 {
Expand Down Expand Up @@ -357,7 +363,7 @@ func (t *TeamsNameInfoSource) DecryptionKey(ctx context.Context, name string, te

m := libkb.NewMetaContext(ctx, t.G().ExternalG())
if !kbfsEncrypted && !public && membersType == chat1.ConversationMembersType_TEAM && m.G().FeatureFlags.Enabled(m, libkb.FeatureFTL) {
res, err = decryptionKeyViaFTL(m, name, teamID, keyGeneration)
res, err = decryptionKeyViaFTL(m, teamID, keyGeneration)
if shouldFallbackToSlowLoadAfterFTLError(m, err) {
// See comment above in EncryptionKey()
err = nil
Expand Down

0 comments on commit be2453b

Please sign in to comment.