From b272bcda4896d30fdf79b4026eab8ca1bdc8c728 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Mon, 18 Sep 2023 16:28:58 -0400 Subject: [PATCH 1/4] Added creationDate field to be used on the passkeys view instead of the cipher.creationDate --- libs/common/src/models/export/fido2key.export.ts | 4 ++++ libs/common/src/vault/api/fido2-key.api.ts | 2 ++ .../src/vault/models/data/fido2-key.data.ts | 2 ++ .../src/vault/models/domain/fido2-key.spec.ts | 15 ++++++++++++++- libs/common/src/vault/models/domain/fido2-key.ts | 6 ++++++ libs/common/src/vault/models/domain/login.spec.ts | 7 +++++++ .../src/vault/models/request/cipher.request.ts | 1 + .../src/vault/models/view/fido2-key.view.ts | 1 + libs/common/src/vault/services/cipher.service.ts | 1 + .../services/fido2/fido2-authenticator.service.ts | 1 + 10 files changed, 39 insertions(+), 1 deletion(-) diff --git a/libs/common/src/models/export/fido2key.export.ts b/libs/common/src/models/export/fido2key.export.ts index 6115016faeb..75979b5dbf6 100644 --- a/libs/common/src/models/export/fido2key.export.ts +++ b/libs/common/src/models/export/fido2key.export.ts @@ -16,6 +16,7 @@ export class Fido2KeyExport { req.counter = "counter"; req.rpName = "rpName"; req.userDisplayName = "userDisplayName"; + req.creationDate = null; return req; } @@ -30,6 +31,7 @@ export class Fido2KeyExport { view.counter = parseInt(req.counter); view.rpName = req.rpName; view.userDisplayName = req.userDisplayName; + view.creationDate = req.creationDate; return view; } @@ -45,6 +47,7 @@ export class Fido2KeyExport { domain.rpName = req.rpName != null ? new EncString(req.rpName) : null; domain.userDisplayName = req.userDisplayName != null ? new EncString(req.userDisplayName) : null; + domain.creationDate = req.creationDate; return domain; } @@ -58,6 +61,7 @@ export class Fido2KeyExport { counter: string; rpName: string; userDisplayName: string; + creationDate: Date = null; constructor(o?: Fido2KeyView | Fido2KeyDomain) { if (o == null) { diff --git a/libs/common/src/vault/api/fido2-key.api.ts b/libs/common/src/vault/api/fido2-key.api.ts index 0d3f425bd94..2205ff089bf 100644 --- a/libs/common/src/vault/api/fido2-key.api.ts +++ b/libs/common/src/vault/api/fido2-key.api.ts @@ -12,6 +12,7 @@ export class Fido2KeyApi extends BaseResponse { rpName: string; userDisplayName: string; discoverable: string; + creationDate: string; constructor(data: any = null) { super(data); @@ -30,5 +31,6 @@ export class Fido2KeyApi extends BaseResponse { this.rpName = this.getResponseProperty("RpName"); this.userDisplayName = this.getResponseProperty("UserDisplayName"); this.discoverable = this.getResponseProperty("Discoverable"); + this.creationDate = this.getResponseProperty("CreationDate"); } } diff --git a/libs/common/src/vault/models/data/fido2-key.data.ts b/libs/common/src/vault/models/data/fido2-key.data.ts index 6f0c49f3e8d..9d7f4b3b4d4 100644 --- a/libs/common/src/vault/models/data/fido2-key.data.ts +++ b/libs/common/src/vault/models/data/fido2-key.data.ts @@ -12,6 +12,7 @@ export class Fido2KeyData { rpName: string; userDisplayName: string; discoverable: string; + creationDate: string; constructor(data?: Fido2KeyApi) { if (data == null) { @@ -29,5 +30,6 @@ export class Fido2KeyData { this.rpName = data.rpName; this.userDisplayName = data.userDisplayName; this.discoverable = data.discoverable; + this.creationDate = data.creationDate; } } diff --git a/libs/common/src/vault/models/domain/fido2-key.spec.ts b/libs/common/src/vault/models/domain/fido2-key.spec.ts index 365dbb1c6e1..74f3c82fe51 100644 --- a/libs/common/src/vault/models/domain/fido2-key.spec.ts +++ b/libs/common/src/vault/models/domain/fido2-key.spec.ts @@ -6,6 +6,12 @@ import { Fido2KeyData } from "../data/fido2-key.data"; import { Fido2Key } from "./fido2-key"; describe("Fido2Key", () => { + let mockDate: Date; + + beforeEach(() => { + mockDate = new Date("2023-01-01T12:00:00.000Z"); + }); + describe("constructor", () => { it("returns all fields null when given empty data parameter", () => { const data = new Fido2KeyData(); @@ -23,10 +29,11 @@ describe("Fido2Key", () => { userDisplayName: null, counter: null, discoverable: null, + creationDate: null, }); }); - it("returns all fields as EncStrings when given full Fido2KeyData", () => { + it("returns all fields as EncStrings except creationDate when given full Fido2KeyData", () => { const data: Fido2KeyData = { credentialId: "credentialId", keyType: "public-key", @@ -39,6 +46,7 @@ describe("Fido2Key", () => { rpName: "rpName", userDisplayName: "userDisplayName", discoverable: "discoverable", + creationDate: mockDate.toISOString(), }; const fido2Key = new Fido2Key(data); @@ -54,6 +62,7 @@ describe("Fido2Key", () => { rpName: { encryptedString: "rpName", encryptionType: 0 }, userDisplayName: { encryptedString: "userDisplayName", encryptionType: 0 }, discoverable: { encryptedString: "discoverable", encryptionType: 0 }, + creationDate: mockDate, }); }); @@ -80,6 +89,7 @@ describe("Fido2Key", () => { fido2Key.rpName = mockEnc("rpName"); fido2Key.userDisplayName = mockEnc("userDisplayName"); fido2Key.discoverable = mockEnc("true"); + fido2Key.creationDate = mockDate; const fido2KeyView = await fido2Key.decrypt(null); @@ -95,6 +105,7 @@ describe("Fido2Key", () => { userDisplayName: "userDisplayName", counter: 2, discoverable: true, + creationDate: mockDate, }); }); }); @@ -113,6 +124,7 @@ describe("Fido2Key", () => { rpName: "rpName", userDisplayName: "userDisplayName", discoverable: "true", + creationDate: mockDate.toISOString(), }; const fido2Key = new Fido2Key(data); @@ -136,6 +148,7 @@ describe("Fido2Key", () => { fido2Key.rpName = createEncryptedEncString("rpName"); fido2Key.userDisplayName = createEncryptedEncString("userDisplayName"); fido2Key.discoverable = createEncryptedEncString("discoverable"); + fido2Key.creationDate = mockDate; const json = JSON.stringify(fido2Key); const result = Fido2Key.fromJSON(JSON.parse(json)); diff --git a/libs/common/src/vault/models/domain/fido2-key.ts b/libs/common/src/vault/models/domain/fido2-key.ts index 61abd655ee2..5162366f31d 100644 --- a/libs/common/src/vault/models/domain/fido2-key.ts +++ b/libs/common/src/vault/models/domain/fido2-key.ts @@ -18,6 +18,7 @@ export class Fido2Key extends Domain { rpName: EncString; userDisplayName: EncString; discoverable: EncString; + creationDate: Date; constructor(obj?: Fido2KeyData) { super(); @@ -43,6 +44,7 @@ export class Fido2Key extends Domain { }, [] ); + this.creationDate = obj.creationDate != null ? new Date(obj.creationDate) : null; } async decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise { @@ -84,12 +86,14 @@ export class Fido2Key extends Domain { encKey ); view.discoverable = discoverable === "true"; + view.creationDate = this.creationDate; return view; } toFido2KeyData(): Fido2KeyData { const i = new Fido2KeyData(); + i.creationDate = this.creationDate.toISOString(); this.buildDataModel(this, i, { credentialId: null, keyType: null, @@ -122,6 +126,7 @@ export class Fido2Key extends Domain { const rpName = EncString.fromJSON(obj.rpName); const userDisplayName = EncString.fromJSON(obj.userDisplayName); const discoverable = EncString.fromJSON(obj.discoverable); + const creationDate = obj.creationDate == null ? null : new Date(obj.creationDate); return Object.assign(new Fido2Key(), obj, { credentialId, @@ -135,6 +140,7 @@ export class Fido2Key extends Domain { rpName, userDisplayName, discoverable, + creationDate, }); } } diff --git a/libs/common/src/vault/models/domain/login.spec.ts b/libs/common/src/vault/models/domain/login.spec.ts index b86573d80e6..ca28ee6a6d8 100644 --- a/libs/common/src/vault/models/domain/login.spec.ts +++ b/libs/common/src/vault/models/domain/login.spec.ts @@ -120,6 +120,7 @@ describe("Login DTO", () => { jest.spyOn(EncString, "fromJSON").mockImplementation(mockFromJson); jest.spyOn(LoginUri, "fromJSON").mockImplementation(mockFromJson); const passwordRevisionDate = new Date("2022-01-31T12:00:00.000Z"); + const fido2CreationDate = new Date("2023-01-01T12:00:00.000Z"); const actual = Login.fromJSON({ uris: ["loginUri1", "loginUri2"] as any, @@ -140,6 +141,7 @@ describe("Login DTO", () => { rpName: "rpName" as EncryptedString, userDisplayName: "userDisplayName" as EncryptedString, discoverable: "discoverable" as EncryptedString, + creationDate: fido2CreationDate.toISOString(), }, ], }); @@ -163,6 +165,7 @@ describe("Login DTO", () => { rpName: "rpName_fromJSON", userDisplayName: "userDisplayName_fromJSON", discoverable: "discoverable_fromJSON", + creationDate: fido2CreationDate, }, ], }); @@ -188,6 +191,7 @@ function initializeFido2Key(key: T): T { key.rpName = "rpName"; key.userDisplayName = "userDisplayName"; key.discoverable = "discoverable"; + key.creationDate = "2023-01-01T12:00:00.000Z"; return key; } @@ -207,5 +211,8 @@ function encryptFido2Key(key: Fido2KeyLike): Fido2Key { encryptionType: 0, } as EncString; encrypted.discoverable = { encryptedString: key.discoverable, encryptionType: 0 } as EncString; + + // not encrypted + encrypted.creationDate = new Date(key.creationDate); return encrypted; } diff --git a/libs/common/src/vault/models/request/cipher.request.ts b/libs/common/src/vault/models/request/cipher.request.ts index 375a9d2d44d..1bab28f6474 100644 --- a/libs/common/src/vault/models/request/cipher.request.ts +++ b/libs/common/src/vault/models/request/cipher.request.ts @@ -83,6 +83,7 @@ export class CipherRequest { key.userDisplayName != null ? key.userDisplayName.encryptedString : null; keyApi.discoverable = key.discoverable != null ? key.discoverable.encryptedString : null; + keyApi.creationDate = key.creationDate != null ? key.creationDate.toISOString() : null; return keyApi; }); } diff --git a/libs/common/src/vault/models/view/fido2-key.view.ts b/libs/common/src/vault/models/view/fido2-key.view.ts index 8af29af70d3..600c12dda98 100644 --- a/libs/common/src/vault/models/view/fido2-key.view.ts +++ b/libs/common/src/vault/models/view/fido2-key.view.ts @@ -14,6 +14,7 @@ export class Fido2KeyView extends ItemView { rpName: string; userDisplayName: string; discoverable: boolean; + creationDate: Date = null; get subTitle(): string { return this.userDisplayName; diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index 05ab34ae5fc..70436484e5a 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -1115,6 +1115,7 @@ export class CipherService implements CipherServiceAbstraction { String(viewKey.discoverable), key ); + domainKey.creationDate = viewKey.creationDate; return domainKey; }) ); diff --git a/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts b/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts index a908542a65d..38b4dea2561 100644 --- a/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts +++ b/libs/common/src/vault/services/fido2/fido2-authenticator.service.ts @@ -385,6 +385,7 @@ async function createKeyView( fido2Key.rpName = params.rpEntity.name; fido2Key.userDisplayName = params.userEntity.displayName; fido2Key.discoverable = params.requireResidentKey; + fido2Key.creationDate = new Date(); return fido2Key; } From 5b39e3030f150477ed9526b621ba103f56dbbe60 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Tue, 19 Sep 2023 09:22:53 -0400 Subject: [PATCH 2/4] Fixed comments from PR --- libs/common/src/models/export/fido2key.export.ts | 4 ++++ libs/common/src/vault/models/domain/fido2-key.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/common/src/models/export/fido2key.export.ts b/libs/common/src/models/export/fido2key.export.ts index 75979b5dbf6..c7ffdf7a5a5 100644 --- a/libs/common/src/models/export/fido2key.export.ts +++ b/libs/common/src/models/export/fido2key.export.ts @@ -16,6 +16,7 @@ export class Fido2KeyExport { req.counter = "counter"; req.rpName = "rpName"; req.userDisplayName = "userDisplayName"; + req.discoverable = "false"; req.creationDate = null; return req; } @@ -31,6 +32,7 @@ export class Fido2KeyExport { view.counter = parseInt(req.counter); view.rpName = req.rpName; view.userDisplayName = req.userDisplayName; + view.discoverable = !!req.discoverable; view.creationDate = req.creationDate; return view; } @@ -47,6 +49,7 @@ export class Fido2KeyExport { domain.rpName = req.rpName != null ? new EncString(req.rpName) : null; domain.userDisplayName = req.userDisplayName != null ? new EncString(req.userDisplayName) : null; + domain.discoverable = req.discoverable != null ? new EncString(req.discoverable) : null; domain.creationDate = req.creationDate; return domain; } @@ -61,6 +64,7 @@ export class Fido2KeyExport { counter: string; rpName: string; userDisplayName: string; + discoverable: string; creationDate: Date = null; constructor(o?: Fido2KeyView | Fido2KeyDomain) { diff --git a/libs/common/src/vault/models/domain/fido2-key.ts b/libs/common/src/vault/models/domain/fido2-key.ts index 5162366f31d..fc4a2b990a2 100644 --- a/libs/common/src/vault/models/domain/fido2-key.ts +++ b/libs/common/src/vault/models/domain/fido2-key.ts @@ -126,7 +126,7 @@ export class Fido2Key extends Domain { const rpName = EncString.fromJSON(obj.rpName); const userDisplayName = EncString.fromJSON(obj.userDisplayName); const discoverable = EncString.fromJSON(obj.discoverable); - const creationDate = obj.creationDate == null ? null : new Date(obj.creationDate); + const creationDate = obj.creationDate != null ? new Date(obj.creationDate) : null; return Object.assign(new Fido2Key(), obj, { credentialId, From 6e602fd03fb7c1b86a50e9018ee7923104041514 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Thu, 21 Sep 2023 09:01:47 -0400 Subject: [PATCH 3/4] added to the constructor and sorted out other comments --- libs/common/src/models/export/fido2key.export.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/common/src/models/export/fido2key.export.ts b/libs/common/src/models/export/fido2key.export.ts index c7ffdf7a5a5..ba25ac80b5b 100644 --- a/libs/common/src/models/export/fido2key.export.ts +++ b/libs/common/src/models/export/fido2key.export.ts @@ -32,7 +32,7 @@ export class Fido2KeyExport { view.counter = parseInt(req.counter); view.rpName = req.rpName; view.userDisplayName = req.userDisplayName; - view.discoverable = !!req.discoverable; + view.discoverable = req.discoverable === "true"; view.creationDate = req.creationDate; return view; } @@ -83,6 +83,8 @@ export class Fido2KeyExport { this.counter = String(o.counter); this.rpName = o.rpName; this.userDisplayName = o.userDisplayName; + this.discoverable = String(o.discoverable); + this.creationDate = o.creationDate; } else { this.credentialId = o.credentialId?.encryptedString; this.keyType = o.keyType?.encryptedString; @@ -94,6 +96,8 @@ export class Fido2KeyExport { this.counter = o.counter?.encryptedString; this.rpName = o.rpName?.encryptedString; this.userDisplayName = o.userDisplayName?.encryptedString; + this.discoverable = o.discoverable?.encryptedString; + this.creationDate = o.creationDate; } } } From 24d84e4a16a65e2d7b51aebafb6c1fb40eec8945 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Thu, 21 Sep 2023 09:03:49 -0400 Subject: [PATCH 4/4] Exported Fido2KeyExport through index.ts --- libs/common/src/models/export/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/common/src/models/export/index.ts b/libs/common/src/models/export/index.ts index b92c68d8143..8c35ee0e1ba 100644 --- a/libs/common/src/models/export/index.ts +++ b/libs/common/src/models/export/index.ts @@ -9,3 +9,4 @@ export { FolderExport } from "./folder.export"; export { IdentityExport } from "./identity.export"; export { LoginUriExport } from "./login-uri.export"; export { SecureNoteExport } from "./secure-note.export"; +export { Fido2KeyExport } from "./fido2key.export";