Merge pull request #194 from vector-im/bwindels/olm-create-session-worker-fixes

Fix creating outbound olm sessions in worker
This commit is contained in:
Bruno Windels 2020-11-10 17:35:09 +00:00 committed by GitHub
commit 98323a7099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -37,9 +37,15 @@ export class OlmWorker {
account.unpickle("", pickle); account.unpickle("", pickle);
} }
async createOutboundSession(account, newSession, theirIdentityKey, theirOneTimeKey) { async createOutboundOlmSession(account, newSession, theirIdentityKey, theirOneTimeKey) {
const accountPickle = account.pickle(""); const accountPickle = account.pickle("");
const sessionPickle = await this._workerPool.send({type: "olm_create_outbound", accountPickle, theirIdentityKey, theirOneTimeKey}).response(); let randomValues;
if (window.msCrypto) {
randomValues = [
window.msCrypto.getRandomValues(new Uint8Array(64)),
];
}
const sessionPickle = await this._workerPool.send({type: "olm_create_outbound", accountPickle, theirIdentityKey, theirOneTimeKey, randomValues}).response();
newSession.unpickle("", sessionPickle); newSession.unpickle("", sessionPickle);
} }

View File

@ -142,13 +142,14 @@ class MessageHandler {
}); });
} }
_olmCreateOutbound(accountPickle, theirIdentityKey, theirOneTimeKey) { _olmCreateOutbound(randomValues, accountPickle, theirIdentityKey, theirOneTimeKey) {
return this._toMessage(() => { return this._toMessage(() => {
this._feedRandomValues(randomValues);
const account = new this._olm.Account(); const account = new this._olm.Account();
const newSession = new this._olm.Session(); const newSession = new this._olm.Session();
try { try {
account.unpickle("", accountPickle); account.unpickle("", accountPickle);
newSession.create_outbound(account, newSession, theirIdentityKey, theirOneTimeKey); newSession.create_outbound(account, theirIdentityKey, theirOneTimeKey);
return newSession.pickle(""); return newSession.pickle("");
} finally { } finally {
account.free(); account.free();
@ -168,7 +169,7 @@ class MessageHandler {
} else if (type === "olm_create_account_otks") { } else if (type === "olm_create_account_otks") {
this._sendReply(message, this._olmCreateAccountAndOTKs(message.randomValues, message.otkAmount)); this._sendReply(message, this._olmCreateAccountAndOTKs(message.randomValues, message.otkAmount));
} else if (type === "olm_create_outbound") { } else if (type === "olm_create_outbound") {
this._sendReply(message, this._olmCreateOutbound(message.accountPickle, message.theirIdentityKey, message.theirOneTimeKey)); this._sendReply(message, this._olmCreateOutbound(message.randomValues, message.accountPickle, message.theirIdentityKey, message.theirOneTimeKey));
} }
} }
} }