Skip to content
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

[PM-3980] Add a creationDate field to the Fido2Key object #6334

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libs/common/src/models/export/fido2key.export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class Fido2KeyExport {
req.counter = "counter";
req.rpName = "rpName";
req.userDisplayName = "userDisplayName";
req.discoverable = "false";
req.creationDate = null;
return req;
}

Expand All @@ -30,6 +32,8 @@ export class Fido2KeyExport {
view.counter = parseInt(req.counter);
view.rpName = req.rpName;
view.userDisplayName = req.userDisplayName;
view.discoverable = req.discoverable === "true";
view.creationDate = req.creationDate;
return view;
}

Expand All @@ -45,6 +49,8 @@ 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;
}

Expand All @@ -58,6 +64,8 @@ export class Fido2KeyExport {
counter: string;
rpName: string;
userDisplayName: string;
discoverable: string;
creationDate: Date = null;

constructor(o?: Fido2KeyView | Fido2KeyDomain) {
if (o == null) {
Expand All @@ -75,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;
Expand All @@ -86,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;
}
}
}
1 change: 1 addition & 0 deletions libs/common/src/models/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
2 changes: 2 additions & 0 deletions libs/common/src/vault/api/fido2-key.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Fido2KeyApi extends BaseResponse {
rpName: string;
userDisplayName: string;
discoverable: string;
creationDate: string;

constructor(data: any = null) {
super(data);
Expand All @@ -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");
}
}
2 changes: 2 additions & 0 deletions libs/common/src/vault/models/data/fido2-key.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Fido2KeyData {
rpName: string;
userDisplayName: string;
discoverable: string;
creationDate: string;

constructor(data?: Fido2KeyApi) {
if (data == null) {
Expand All @@ -29,5 +30,6 @@ export class Fido2KeyData {
this.rpName = data.rpName;
this.userDisplayName = data.userDisplayName;
this.discoverable = data.discoverable;
this.creationDate = data.creationDate;
}
}
15 changes: 14 additions & 1 deletion libs/common/src/vault/models/domain/fido2-key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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",
Expand All @@ -39,6 +46,7 @@ describe("Fido2Key", () => {
rpName: "rpName",
userDisplayName: "userDisplayName",
discoverable: "discoverable",
creationDate: mockDate.toISOString(),
};
const fido2Key = new Fido2Key(data);

Expand All @@ -54,6 +62,7 @@ describe("Fido2Key", () => {
rpName: { encryptedString: "rpName", encryptionType: 0 },
userDisplayName: { encryptedString: "userDisplayName", encryptionType: 0 },
discoverable: { encryptedString: "discoverable", encryptionType: 0 },
creationDate: mockDate,
});
});

Expand All @@ -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);

Expand All @@ -95,6 +105,7 @@ describe("Fido2Key", () => {
userDisplayName: "userDisplayName",
counter: 2,
discoverable: true,
creationDate: mockDate,
});
});
});
Expand All @@ -113,6 +124,7 @@ describe("Fido2Key", () => {
rpName: "rpName",
userDisplayName: "userDisplayName",
discoverable: "true",
creationDate: mockDate.toISOString(),
};

const fido2Key = new Fido2Key(data);
Expand All @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions libs/common/src/vault/models/domain/fido2-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Fido2Key extends Domain {
rpName: EncString;
userDisplayName: EncString;
discoverable: EncString;
creationDate: Date;

constructor(obj?: Fido2KeyData) {
super();
Expand All @@ -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<Fido2KeyView> {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ? new Date(obj.creationDate) : null;

return Object.assign(new Fido2Key(), obj, {
credentialId,
Expand All @@ -135,6 +140,7 @@ export class Fido2Key extends Domain {
rpName,
userDisplayName,
discoverable,
creationDate,
});
}
}
7 changes: 7 additions & 0 deletions libs/common/src/vault/models/domain/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -140,6 +141,7 @@ describe("Login DTO", () => {
rpName: "rpName" as EncryptedString,
userDisplayName: "userDisplayName" as EncryptedString,
discoverable: "discoverable" as EncryptedString,
creationDate: fido2CreationDate.toISOString(),
},
],
});
Expand All @@ -163,6 +165,7 @@ describe("Login DTO", () => {
rpName: "rpName_fromJSON",
userDisplayName: "userDisplayName_fromJSON",
discoverable: "discoverable_fromJSON",
creationDate: fido2CreationDate,
},
],
});
Expand All @@ -188,6 +191,7 @@ function initializeFido2Key<T extends Fido2KeyLike>(key: T): T {
key.rpName = "rpName";
key.userDisplayName = "userDisplayName";
key.discoverable = "discoverable";
key.creationDate = "2023-01-01T12:00:00.000Z";
return key;
}

Expand All @@ -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;
}
1 change: 1 addition & 0 deletions libs/common/src/vault/models/request/cipher.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/vault/models/view/fido2-key.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class Fido2KeyView extends ItemView {
rpName: string;
userDisplayName: string;
discoverable: boolean;
creationDate: Date = null;

get subTitle(): string {
return this.userDisplayName;
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/vault/services/cipher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ export class CipherService implements CipherServiceAbstraction {
String(viewKey.discoverable),
key
);
domainKey.creationDate = viewKey.creationDate;
return domainKey;
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down