mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Store own device keys on init
This commit is contained in:
parent
5b0d4ba086
commit
970ba1a907
2 changed files with 13 additions and 4 deletions
|
|
@ -216,7 +216,7 @@ func (mach *OlmMachine) createInboundSession(ctx context.Context, senderKey id.S
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mach.saveAccount()
|
||||
mach.saveAccount(ctx)
|
||||
err = mach.CryptoStore.AddSession(ctx, senderKey, session)
|
||||
if err != nil {
|
||||
zerolog.Ctx(ctx).Error().Err(err).Msg("Failed to store created inbound session")
|
||||
|
|
|
|||
|
|
@ -145,8 +145,8 @@ func (mach *OlmMachine) Load(ctx context.Context) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (mach *OlmMachine) saveAccount() {
|
||||
err := mach.CryptoStore.PutAccount(context.TODO(), mach.account)
|
||||
func (mach *OlmMachine) saveAccount(ctx context.Context) {
|
||||
err := mach.CryptoStore.PutAccount(ctx, mach.account)
|
||||
if err != nil {
|
||||
mach.Log.Error().Err(err).Msg("Failed to save account")
|
||||
}
|
||||
|
|
@ -655,6 +655,15 @@ func (mach *OlmMachine) ShareKeys(ctx context.Context, currentOTKCount int) erro
|
|||
var deviceKeys *mautrix.DeviceKeys
|
||||
if !mach.account.Shared {
|
||||
deviceKeys = mach.account.getInitialKeys(mach.Client.UserID, mach.Client.DeviceID)
|
||||
err := mach.CryptoStore.PutDevice(ctx, mach.Client.UserID, &id.Device{
|
||||
UserID: mach.Client.UserID,
|
||||
DeviceID: mach.Client.DeviceID,
|
||||
IdentityKey: deviceKeys.Keys.GetCurve25519(mach.Client.DeviceID),
|
||||
SigningKey: deviceKeys.Keys.GetEd25519(mach.Client.DeviceID),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to save initial keys: %w", err)
|
||||
}
|
||||
log.Debug().Msg("Going to upload initial account keys")
|
||||
}
|
||||
oneTimeKeys := mach.account.getOneTimeKeys(mach.Client.UserID, mach.Client.DeviceID, currentOTKCount)
|
||||
|
|
@ -673,7 +682,7 @@ func (mach *OlmMachine) ShareKeys(ctx context.Context, currentOTKCount int) erro
|
|||
}
|
||||
mach.lastOTKUpload = time.Now()
|
||||
mach.account.Shared = true
|
||||
mach.saveAccount()
|
||||
mach.saveAccount(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue