Fix key format on the wire to be base64

This commit is contained in:
David Baker
2023-10-20 17:31:15 +01:00
parent 5ab706e26b
commit 9126fb3f3e
4 changed files with 8 additions and 24 deletions

View File

@@ -58,7 +58,7 @@
"i18next-http-backend": "^2.0.0", "i18next-http-backend": "^2.0.0",
"livekit-client": "^1.12.3", "livekit-client": "^1.12.3",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#9a42886e26267e0e4508bb4f40f4ab4de6db9a2e", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#4120641b3d3983733044967812e475bc3610d1e7",
"matrix-widget-api": "^1.3.1", "matrix-widget-api": "^1.3.1",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"pako": "^2.0.4", "pako": "^2.0.4",

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { BaseKeyProvider, createKeyMaterialFromString } from "livekit-client"; import { BaseKeyProvider, createKeyMaterialFromBuffer } from "livekit-client";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { import {
MatrixRTCSession, MatrixRTCSession,
@@ -56,12 +56,12 @@ export class MatrixKeyProvider extends BaseKeyProvider {
} }
private onEncryptionKeyChanged = async ( private onEncryptionKeyChanged = async (
encryptionKey: string, encryptionKey: Uint8Array,
encryptionKeyIndex: number, encryptionKeyIndex: number,
participantId: string, participantId: string,
): Promise<void> => { ): Promise<void> => {
this.onSetEncryptionKey( this.onSetEncryptionKey(
await createKeyMaterialFromString(encryptionKey), await createKeyMaterialFromBuffer(encryptionKey),
participantId, participantId,
encryptionKeyIndex, encryptionKeyIndex,
); );

View File

@@ -28,6 +28,7 @@ import {
GroupCallIntent, GroupCallIntent,
GroupCallType, GroupCallType,
} from "matrix-js-sdk/src/webrtc/groupCall"; } from "matrix-js-sdk/src/webrtc/groupCall";
import { secureRandomBase64 } from "matrix-js-sdk/src/randomstring";
import type { MatrixClient } from "matrix-js-sdk/src/client"; import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { Room } from "matrix-js-sdk/src/models/room"; import type { Room } from "matrix-js-sdk/src/models/room";
@@ -73,23 +74,6 @@ function waitForSync(client: MatrixClient): Promise<void> {
}); });
} }
function secureRandomString(entropyBytes: number): string {
const key = new Uint8Array(entropyBytes);
crypto.getRandomValues(key);
// encode to base64url as this value goes into URLs
// base64url is just base64 with thw two non-alphanum characters swapped out for
// ones that can be put in a URL without encoding. Browser JS has a native impl
// for base64 encoding but only a string (there isn't one that takes a UInt8Array
// yet) so just use the built-in one and convert, replace the chars and strip the
// padding from the end (otherwise we'd need to pull in another dependency).
return btoa(
key.reduce((acc, current) => acc + String.fromCharCode(current), ""),
)
.replace("+", "-")
.replace("/", "_")
.replace(/=*$/, "");
}
/** /**
* Initialises and returns a new standalone Matrix Client. * Initialises and returns a new standalone Matrix Client.
* If true is passed for the 'restore' parameter, a check will be made * If true is passed for the 'restore' parameter, a check will be made
@@ -363,7 +347,7 @@ export async function createRoom(
let password; let password;
if (e2ee) { if (e2ee) {
password = secureRandomString(16); password = secureRandomBase64(16);
setLocalStorageItem( setLocalStorageItem(
getRoomSharedKeyLocalStorageKey(result.room_id), getRoomSharedKeyLocalStorageKey(result.room_id),
password, password,

View File

@@ -7042,9 +7042,9 @@ matrix-events-sdk@0.0.1:
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd" resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd"
integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA== integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#9a42886e26267e0e4508bb4f40f4ab4de6db9a2e": "matrix-js-sdk@github:matrix-org/matrix-js-sdk#4120641b3d3983733044967812e475bc3610d1e7":
version "29.0.0" version "29.0.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/9a42886e26267e0e4508bb4f40f4ab4de6db9a2e" resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/4120641b3d3983733044967812e475bc3610d1e7"
dependencies: dependencies:
"@babel/runtime" "^7.12.5" "@babel/runtime" "^7.12.5"
"@matrix-org/matrix-sdk-crypto-wasm" "^2.0.0" "@matrix-org/matrix-sdk-crypto-wasm" "^2.0.0"