Skip to content

Commit

Permalink
Merge pull request #158 from adamvy/sumner/be-21873
Browse files Browse the repository at this point in the history
base64 encode the session before passing to libolm/goolm
  • Loading branch information
adamvy authored Jan 17, 2024
2 parents 3c7b450 + 6f15787 commit ce6b911
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 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,10 @@ 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))
encoded := make([]byte, base64.StdEncoding.EncodedLen(len(keyBackupData.SessionKey)))
base64.StdEncoding.Encode(encoded, keyBackupData.SessionKey)

igsInternal, err := olm.InboundGroupSessionImport(encoded)
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 ce6b911

Please sign in to comment.