Skip to content

Commit

Permalink
base64 encode the session before passing to libolm/goolm
Browse files Browse the repository at this point in the history
also log the number of imported sessions for fun

Signed-off-by: Sumner Evans <sumner@beeper.com>
  • Loading branch information
adamvy authored and sumnerevans committed Jan 17, 2024
1 parent 3c7b450 commit 19f1adb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crypto/keybackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crypto

import (
"context"
"encoding/base64"
"fmt"
"time"

Expand Down Expand Up @@ -84,6 +85,8 @@ func (mach *OlmMachine) DownloadAndStoreLatestKeyBackup(ctx context.Context, meg
return err
}

var count int

for roomID, backup := range keys.Rooms {
for sessionID, keyBackupData := range backup.Sessions {
sessionData, err := keyBackupData.SessionData.Decrypt(megolmBackupKey)
Expand All @@ -95,9 +98,12 @@ func (mach *OlmMachine) DownloadAndStoreLatestKeyBackup(ctx context.Context, meg
if err != nil {
return err
}
count++
}
}

log.Info().Int("count", count).Msg("successfully imported sessions from backup")

return nil
}

Expand All @@ -110,7 +116,7 @@ func (mach *OlmMachine) importRoomKeyFromBackup(ctx context.Context, roomID id.R
return fmt.Errorf("ignoring room key in backup with weird algorithm %s", keyBackupData.Algorithm)
}

igsInternal, err := olm.InboundGroupSessionImport([]byte(keyBackupData.SessionKey))
igsInternal, err := olm.InboundGroupSessionImport([]byte(base64.RawStdEncoding.EncodeToString(keyBackupData.SessionKey)))
if err != nil {
return fmt.Errorf("failed to import inbound group session: %w", err)
} else if igsInternal.ID() != sessionID {
Expand Down

0 comments on commit 19f1adb

Please sign in to comment.