-
-
Notifications
You must be signed in to change notification settings - Fork 619
MatrixRTC: Refactor | Introduce a new Encryption manager (used with experimental to device transport) #4799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
fixup: bad do not commit
73f738b
to
3af1d3e
Compare
3af1d3e
to
b19c7a6
Compare
public getEncryptionKeys(): Map<string, Array<{ key: Uint8Array; timestamp: number }>> { | ||
// This is deprecated should be ignored. Only use by tests? | ||
return new Map(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deprecation could already be added to IEncryptionManager
(@deprecated
)
}, this.ttl); | ||
|
||
const existing = entry.keys.get(item.keyId); | ||
if (existing && existing.creationTS > item.creationTS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creationTS
, timestamp
, send_ts
is all the same thing right?
Is it possible to call them the same (or maybe sendTs
+ send_ts
)
(edit: oh its: sent_ts
... Is that what we use in the spec.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think they are the same. CreationTS would be the time when the key is created, sent_ts is the local time when we sent it (for new joiner without rotation they would be different).
yes sent_ts
is from the spec.
Maybe we need both? CreationTS is better to disambiguate keys, but sent_ts
is what we want for statistics to have an estimate of the time to transport
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the spec we should make sent_ts -> creation_ts then right? the spec should focus on the disambiguation instead of the possibility to collect reasonable stats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure the time to live is the correct concept here. It would not work if the out of order receive offset time is larger than 1s.
Can we just use a "latest key buffer"? Of course we would end up with more memory use since a 100ppl call would have 100 entries where the ttl approach probably would delete them quick enough so it would never exceed a handful.
The latest key buffer would just store the most recent (by timestamp) key for the highest (considering wrap around) index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I think we could do without it complitely as it is probably very edge casy. We also want to avoid keeping key in memory.
Only keeping the latest (1 key) might not be enough. If there was 3 keys 0
, 1
, 0'
that are received in 0'
1
, 0
, the latest would be 1
but we want 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only keeping the latest (1 key) might not be enough. If there was 3 keys 0, 1, 0' that are received in 0' 1 , 0, the latest would be 1 but we want 0
Yes covering all cases requies us to store all keys ever received.
What about we store all timestamps ever received? That is enough right. The disambigution is then just a "is it the most recent key we want to use" check.
Could be called keyRecencyMap.isMostRecentKeyForParticipant(userId, key.creationTs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this?
(somehow the context got lost here: #4799 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very nice to read. Thanks valere.
Left a couple of comments about additional context that we could give. maybe you think they can improve readablility even more.
But it is ready to merge without these.
Only the corepacks issue is blocking.
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like corepack is enabled.
* Will ensure that a new key is distributed and used to encrypt our media. | ||
* If this function is called repeatidly, the calls will be buffered to a single key rotation. | ||
*/ | ||
private ensureMediaKey(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method name can benefit from being longer. It is not clear immediately if this ensures the keys are sent or that we do have the keys.
ensureDistributionOfLatestKey
,ensureMediaKeyDistribution
...?
RoomAndToDeviceTransport, | ||
} from "./RoomAndToDeviceKeyTransport.ts"; | ||
|
||
type OutboundEncryptionSession = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not next to the InboundEncryptionSession
try { | ||
this.logger.trace(`Sending key...`); | ||
await this.transport.sendKey(encodeBase64(outboundKey.key), outboundKey.keyId, toDistributeTo); | ||
this.statistics.counters.roomEventEncryptionKeysSent += 1; | ||
outboundKey.sharedWith.push(...toDistributeTo); | ||
this.logger.trace( | ||
`key index:${outboundKey.keyId} sent to ${outboundKey.sharedWith.map((m) => `${m.userId}:${m.deviceId}`).join(",")}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a comment, that sendKey
calls encryptAndSentToDevice
whihc does not wrapt the http reuquest but instead is a nonfailing operation, that will queue the to-device message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this?
(somehow the context got lost here: #4799 (comment)
sharedWith: [], | ||
keyId: 0, | ||
}; | ||
this.onEncryptionKeysChanged( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can get a comment, that this is the method, that will actaully set the encryption key in the media layer.
Maybe best is a doc comment on the private property.
|
||
private onTransportChanged: (enabled: EnabledTransports) => void = () => { | ||
this.logger.info("Transport change detected, restarting key distribution"); | ||
// Temporary for backwards compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move this above the method since the whole method is temporary for backwards compatibility
Add a new simplified EncryptionManager that will rotate the key for any membership change (join or leave or same)
There is no specific experimental flag to use it, it will use it for to device transport
Checklist
public
/exported
symbols have accurate TSDoc documentation.