-
Notifications
You must be signed in to change notification settings - Fork 73
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
Refactor encryption code to use bot-sdk #369
Conversation
- Not handle ephemeral, those come down the AS path - Use the bot sdk
src/components/intent.ts
Outdated
if (!session) { | ||
// No session in the store, attempt a login. | ||
log.debug("ensureRegistered: Attempting encrypted login"); | ||
// Login as the user |
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.
Login is the noun.
// Login as the user | |
// Log in as the user |
src/components/intent.ts
Outdated
private readyPromise?: Promise<unknown>; | ||
private encryptionReadyPromise?: Promise<void>; | ||
|
||
// A client that talks directly to the homeserver, bypassing pan. |
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.
To reduce the knowledge one needs to have to understand this comment, I'd recommend not abbreviating pantalaimon.
// A client that talks directly to the homeserver, bypassing pan. | |
// A client that talks directly to the homeserver, bypassing pantalaimon. |
src/components/intent.ts
Outdated
@@ -1180,51 +1185,81 @@ export class Intent { | |||
} | |||
} | |||
|
|||
// NOTES: | |||
// Still seeing errors about invalid access tokens. | |||
// Still seeing the server attempt to send stuff to pan without sync being enabled. |
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.
// Still seeing the server attempt to send stuff to pan without sync being enabled. | |
// Still seeing the server attempt to send stuff to pantalaimon without sync being enabled. |
src/components/encryption.ts
Outdated
if (!event.event.decrypted) { | ||
private onSyncEvent(roomId: string, event: PanWeakEvent): void { | ||
log.info("BLARGH", roomId, event); | ||
if (!event.decrypted) { | ||
// We only care about encrypted events, and pan appends a decrypted key to each event. |
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.
// We only care about encrypted events, and pan appends a decrypted key to each event. | |
// We only care about encrypted events, and pantalaimon appends a decrypted key to each event. |
src/components/encryption.ts
Outdated
private onSyncEvent(event: any) { | ||
if (!event.event.decrypted) { | ||
private onSyncEvent(roomId: string, event: PanWeakEvent): void { | ||
log.info("BLARGH", roomId, event); |
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.
log.info("BLARGH", roomId, event); |
or
log.info("BLARGH", roomId, event); | |
log.debug("onSyncEvent", roomId, event); |
src/components/encryption.ts
Outdated
// We only care about encrypted events, and pan appends a decrypted key to each event. | ||
return; | ||
} | ||
if (!this.eventsPendingSync.has(event.getId())) { | ||
// TODO: Do we need this? |
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.
Just pointing this out: You've left a TODO here.
src/components/intent.ts
Outdated
if (!this.encryption) { | ||
throw Error('Cannot call getEncryptedSession without enabling encryption'); | ||
} | ||
// We've not got a session so let's see if the store has one. |
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.
// We've not got a session so let's see if the store has one. | |
// We've got no session so let's see if the store has one. |
src/components/intent.ts
Outdated
log.debug("ensureRegistered: failed to ready", ex); | ||
// Failed to ready up - fall through and try again. | ||
} | ||
// Past this point, we're an encryption enabled Intent. |
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.
// Past this point, we're an encryption enabled Intent. | |
// Past this point, we're an encryption-enabled Intent. |
src/bridge.ts
Outdated
}; | ||
clientIntentOpts.registered = this.membershipCache.isUserRegistered(userId); | ||
const encryptionOpts = this.opts.bridgeEncryption; | ||
if (encryptionOpts) { | ||
clientIntentOpts.encryption = { | ||
sessionPromise: encryptionOpts.store.getStoredSession(userId), | ||
origianlHomeserver: this.opts.homeserverUrl, |
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.
typo that hopefully still can be fixed in the entire repo.
origianlHomeserver: this.opts.homeserverUrl, | |
originalHomeserver: this.opts.homeserverUrl, |
70cb5cc
to
8242f6f
Compare
I had an epiphany and decided to refactor the encryption code into a separate subclass so it's easier to understand (and less if/else-ing) |
}; | ||
} | ||
|
||
public async ensureRegistered(forceRegister = false): Promise<"registered=true"|undefined> { |
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's the reason for it returning this awkward string rather than a true (or just void, since it rejects on failure anyway?)
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.
It's a thing that the old old sdk did and we've just carried it forward. I'm not sure if anyone actually expects it..
This code refactors our encryption broker component and intents to generally handle encrypted events better. The changes are: