Resolve merge conflicts and fix cryptoKey handling

This commit is contained in:
Thomas Rittson 2022-06-28 11:59:37 +10:00
parent 2df751f607
commit 83e0db5163
4 changed files with 17 additions and 21 deletions

View File

@ -92,7 +92,7 @@ export class LocalBackedSessionStorageService extends AbstractStorageService {
storedKey = await this.keyGenerationService.makeEphemeralKey();
await this.setSessionEncKey(storedKey);
}
return SymmetricCryptoKey.initFromJson(
return SymmetricCryptoKey.fromJSON(
Object.create(SymmetricCryptoKey.prototype, Object.getOwnPropertyDescriptors(storedKey))
);
}

View File

@ -68,7 +68,7 @@ describe("SymmetricCryptoKey", () => {
});
it("serializes and deserializes", () => {
const key = new SymmetricCryptoKey(makeStaticByteArray(64));
const key = new SymmetricCryptoKey(makeStaticByteArray(64).buffer);
const serialized = JSON.stringify(key);
const newKey = SymmetricCryptoKey.fromJSON(JSON.parse(serialized));

View File

@ -56,21 +56,17 @@ export class SymmetricCryptoKey {
}
}
static initFromJson(jsonResult: SymmetricCryptoKey): SymmetricCryptoKey {
if (jsonResult == null) {
return jsonResult;
toJSON(): any {
// The whole object is constructed from the initial key, so just store the B64 key
return { keyB64: this.keyB64 };
}
static fromJSON(obj: any): SymmetricCryptoKey {
if (obj == null) {
return null;
}
if (jsonResult.keyB64 != null) {
jsonResult.key = Utils.fromB64ToArray(jsonResult.keyB64).buffer;
}
if (jsonResult.encKeyB64 != null) {
jsonResult.encKey = Utils.fromB64ToArray(jsonResult.encKeyB64).buffer;
}
if (jsonResult.macKeyB64 != null) {
jsonResult.macKey = Utils.fromB64ToArray(jsonResult.macKeyB64).buffer;
}
return jsonResult;
const arrayBuffer = Utils.fromB64ToArray(obj.keyB64).buffer;
return new SymmetricCryptoKey(arrayBuffer);
}
}

View File

@ -483,7 +483,7 @@ export class StateService<
);
}
@withPrototype(SymmetricCryptoKey, SymmetricCryptoKey.initFromJson)
@withPrototype(SymmetricCryptoKey, SymmetricCryptoKey.fromJSON)
async getCryptoMasterKey(options?: StorageOptions): Promise<SymmetricCryptoKey> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions()))
@ -637,7 +637,7 @@ export class StateService<
);
}
@withPrototype(SymmetricCryptoKey, SymmetricCryptoKey.initFromJson)
@withPrototype(SymmetricCryptoKey, SymmetricCryptoKey.fromJSON)
async getDecryptedCryptoSymmetricKey(options?: StorageOptions): Promise<SymmetricCryptoKey> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultInMemoryOptions()))
@ -676,7 +676,7 @@ export class StateService<
);
}
@withPrototypeForMap(SymmetricCryptoKey, SymmetricCryptoKey.initFromJson)
@withPrototypeForMap(SymmetricCryptoKey, SymmetricCryptoKey.fromJSON)
async getDecryptedOrganizationKeys(
options?: StorageOptions
): Promise<Map<string, SymmetricCryptoKey>> {
@ -783,7 +783,7 @@ export class StateService<
);
}
@withPrototypeForMap(SymmetricCryptoKey, SymmetricCryptoKey.initFromJson)
@withPrototypeForMap(SymmetricCryptoKey, SymmetricCryptoKey.fromJSON)
async getDecryptedProviderKeys(
options?: StorageOptions
): Promise<Map<string, SymmetricCryptoKey>> {
@ -1745,7 +1745,7 @@ export class StateService<
);
}
@withPrototype(SymmetricCryptoKey, SymmetricCryptoKey.initFromJson)
@withPrototype(SymmetricCryptoKey, SymmetricCryptoKey.fromJSON)
async getLegacyEtmKey(options?: StorageOptions): Promise<SymmetricCryptoKey> {
return (
await this.getAccount(this.reconcileOptions(options, await this.defaultOnDiskOptions()))