crypto/keysharing: ensure forwarding chains is always set

This commit is contained in:
Tulir Asokan 2025-05-06 22:50:46 +03:00
commit bef23edaea
3 changed files with 11 additions and 5 deletions

View file

@ -347,9 +347,6 @@ func (mach *OlmMachine) HandleRoomKeyRequest(ctx context.Context, sender id.User
mach.rejectKeyRequest(ctx, KeyShareRejectInternalError, device, content.Body)
return
}
if igs.ForwardingChains == nil {
igs.ForwardingChains = []string{}
}
forwardedRoomKey := event.Content{
Parsed: &event.ForwardedRoomKeyEventContent{
@ -360,7 +357,7 @@ func (mach *OlmMachine) HandleRoomKeyRequest(ctx context.Context, sender id.User
SessionKey: string(exportedKey),
},
SenderKey: content.Body.SenderKey,
ForwardingKeyChain: igs.ForwardingChains,
ForwardingKeyChain: igs.ForwardingChainsOrEmpty(),
SenderClaimedKey: igs.SigningKey,
},
}

View file

@ -125,7 +125,7 @@ func NewInboundGroupSession(senderKey id.SenderKey, signingKey id.Ed25519, roomI
SigningKey: signingKey,
SenderKey: senderKey,
RoomID: roomID,
ForwardingChains: nil,
ForwardingChains: []string{},
ReceivedAt: time.Now().UTC(),
MaxAge: maxAge.Milliseconds(),
MaxMessages: maxMessages,
@ -133,6 +133,13 @@ func NewInboundGroupSession(senderKey id.SenderKey, signingKey id.Ed25519, roomI
}, nil
}
func (igs *InboundGroupSession) ForwardingChainsOrEmpty() []string {
if igs.ForwardingChains == nil {
return []string{}
}
return igs.ForwardingChains
}
func (igs *InboundGroupSession) ID() id.SessionID {
if igs.id == "" {
igs.id = igs.Internal.ID()

View file

@ -509,6 +509,8 @@ func (store *SQLCryptoStore) postScanInboundGroupSession(sessionBytes, ratchetSa
}
if forwardingChains != "" {
chains = strings.Split(forwardingChains, ",")
} else {
chains = []string{}
}
var rs RatchetSafety
if len(ratchetSafetyBytes) > 0 {