1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

[EC-598] feat: tweak key data to contain separate type and algorithm

This commit is contained in:
Andreas Coroiu
2023-03-27 09:45:18 +02:00
parent 800f032e92
commit ad27234576
6 changed files with 39 additions and 17 deletions

View File

@@ -1,12 +1,15 @@
import { BaseResponse } from "../../../models/response/base.response"; import { BaseResponse } from "../../../models/response/base.response";
export class Fido2KeyApi extends BaseResponse { export class Fido2KeyApi extends BaseResponse {
keyType: "ECDSA"; keyType: "public-key";
keyAlgorithm: "ECDSA";
keyCurve: "P-256"; keyCurve: "P-256";
keyValue: string; keyValue: string;
rpId: string; rpId: string;
rpName: string;
userHandle: string; userHandle: string;
// Extras
rpName: string;
userName: string; userName: string;
origin: string; origin: string;
@@ -17,12 +20,13 @@ export class Fido2KeyApi extends BaseResponse {
} }
this.keyType = this.getResponseProperty("KeyType"); this.keyType = this.getResponseProperty("KeyType");
this.keyAlgorithm = this.getResponseProperty("KeyType");
this.keyCurve = this.getResponseProperty("KeyCurve"); this.keyCurve = this.getResponseProperty("KeyCurve");
this.keyValue = this.getResponseProperty("keyValue"); this.keyValue = this.getResponseProperty("keyValue");
this.rpId = this.getResponseProperty("RpId"); this.rpId = this.getResponseProperty("RpId");
this.rpName = this.getResponseProperty("RpName"); this.rpName = this.getResponseProperty("RpName");
this.userHandle = this.getResponseProperty("UserHandle");
this.userName = this.getResponseProperty("UserName"); this.userName = this.getResponseProperty("UserName");
this.userHandle = this.getResponseProperty("UserHandle");
this.origin = this.getResponseProperty("Origin"); this.origin = this.getResponseProperty("Origin");
} }
} }

View File

@@ -1,12 +1,15 @@
import { Fido2KeyApi } from "../api/fido2-key.api"; import { Fido2KeyApi } from "../api/fido2-key.api";
export class Fido2KeyData { export class Fido2KeyData {
keyType: "ECDSA"; keyType: "public-key";
keyAlgorithm: "ECDSA";
keyCurve: "P-256"; keyCurve: "P-256";
keyValue: string; keyValue: string;
rpId: string; rpId: string;
rpName: string;
userHandle: string; userHandle: string;
// Extras
rpName: string;
userName: string; userName: string;
origin: string; origin: string;
@@ -16,11 +19,12 @@ export class Fido2KeyData {
} }
this.keyType = data.keyType; this.keyType = data.keyType;
this.keyAlgorithm = data.keyAlgorithm;
this.keyCurve = data.keyCurve; this.keyCurve = data.keyCurve;
this.keyValue = data.keyValue; this.keyValue = data.keyValue;
this.rpId = data.rpId; this.rpId = data.rpId;
this.rpName = data.rpName;
this.userHandle = data.userHandle; this.userHandle = data.userHandle;
this.rpName = data.rpName;
this.userName = data.userName; this.userName = data.userName;
this.origin = data.origin; this.origin = data.origin;
} }

View File

@@ -8,11 +8,14 @@ import { Fido2KeyView } from "../view/fido2-key.view";
export class Fido2Key extends Domain { export class Fido2Key extends Domain {
keyType: EncString; keyType: EncString;
keyAlgorithm: EncString;
keyCurve: EncString; keyCurve: EncString;
keyValue: EncString; keyValue: EncString;
rpId: EncString; rpId: EncString;
rpName: EncString;
userHandle: EncString; userHandle: EncString;
// Extras
rpName: EncString;
userName: EncString; userName: EncString;
origin: EncString; origin: EncString;
@@ -27,11 +30,12 @@ export class Fido2Key extends Domain {
obj, obj,
{ {
keyType: null, keyType: null,
keyAlgorithm: null,
keyCurve: null, keyCurve: null,
keyValue: null, keyValue: null,
rpId: null, rpId: null,
rpName: null,
userHandle: null, userHandle: null,
rpName: null,
userName: null, userName: null,
origin: null, origin: null,
}, },
@@ -44,11 +48,12 @@ export class Fido2Key extends Domain {
new Fido2KeyView(), new Fido2KeyView(),
{ {
keyType: null, keyType: null,
keyAlgorithm: null,
keyCurve: null, keyCurve: null,
keyValue: null, keyValue: null,
rpId: null, rpId: null,
rpName: null,
userHandle: null, userHandle: null,
rpName: null,
userName: null, userName: null,
origin: null, origin: null,
}, },
@@ -61,11 +66,12 @@ export class Fido2Key extends Domain {
const i = new Fido2KeyData(); const i = new Fido2KeyData();
this.buildDataModel(this, i, { this.buildDataModel(this, i, {
keyType: null, keyType: null,
keyAlgorithm: null,
keyCurve: null, keyCurve: null,
keyValue: null, keyValue: null,
rpId: null, rpId: null,
rpName: null,
userHandle: null, userHandle: null,
rpName: null,
userName: null, userName: null,
origin: null, origin: null,
}); });
@@ -78,21 +84,23 @@ export class Fido2Key extends Domain {
} }
const keyType = EncString.fromJSON(obj.keyType); const keyType = EncString.fromJSON(obj.keyType);
const keyAlgorithm = EncString.fromJSON(obj.keyAlgorithm);
const keyCurve = EncString.fromJSON(obj.keyCurve); const keyCurve = EncString.fromJSON(obj.keyCurve);
const keyValue = EncString.fromJSON(obj.keyValue); const keyValue = EncString.fromJSON(obj.keyValue);
const rpId = EncString.fromJSON(obj.rpId); const rpId = EncString.fromJSON(obj.rpId);
const rpName = EncString.fromJSON(obj.rpName);
const userHandle = EncString.fromJSON(obj.userHandle); const userHandle = EncString.fromJSON(obj.userHandle);
const rpName = EncString.fromJSON(obj.rpName);
const userName = EncString.fromJSON(obj.userName); const userName = EncString.fromJSON(obj.userName);
const origin = EncString.fromJSON(obj.origin); const origin = EncString.fromJSON(obj.origin);
return Object.assign(new Fido2Key(), obj, { return Object.assign(new Fido2Key(), obj, {
keyType, keyType,
keyAlgorithm,
keyCurve, keyCurve,
keyValue, keyValue,
rpId, rpId,
rpName,
userHandle, userHandle,
rpName,
userName, userName,
origin, origin,
}); });

View File

@@ -3,12 +3,15 @@ import { Jsonify } from "type-fest";
import { ItemView } from "../../../vault/models/view/item.view"; import { ItemView } from "../../../vault/models/view/item.view";
export class Fido2KeyView extends ItemView { export class Fido2KeyView extends ItemView {
keyType: "ECDSA"; keyType: "public-key";
keyAlgorithm: "ECDSA";
keyCurve: "P-256"; keyCurve: "P-256";
keyValue: string; keyValue: string;
rpId: string; rpId: string;
rpName: string;
userHandle: string; userHandle: string;
// Extras
rpName: string;
userName: string; userName: string;
origin: string; origin: string;

View File

@@ -182,7 +182,8 @@ describe("FidoAuthenticatorService", () => {
name: params.rpEntity.name, name: params.rpEntity.name,
fido2Key: expect.objectContaining({ fido2Key: expect.objectContaining({
keyType: "ECDSA", keyType: "public-key",
keyAlgorithm: "ECDSA",
keyCurve: "P-256", keyCurve: "P-256",
rpId: params.rpEntity.id, rpId: params.rpEntity.id,
rpName: params.rpEntity.name, rpName: params.rpEntity.name,
@@ -261,7 +262,8 @@ describe("FidoAuthenticatorService", () => {
name: existingCipherView.name, name: existingCipherView.name,
fido2Key: expect.objectContaining({ fido2Key: expect.objectContaining({
keyType: "ECDSA", keyType: "public-key",
keyAlgorithm: "ECDSA",
keyCurve: "P-256", keyCurve: "P-256",
rpId: params.rpEntity.id, rpId: params.rpEntity.id,
rpName: params.rpEntity.name, rpName: params.rpEntity.name,

View File

@@ -134,7 +134,8 @@ export class Fido2AuthenticatorService implements Fido2AuthenticatorServiceAbstr
const pcks8Key = await crypto.subtle.exportKey("pkcs8", keyValue); const pcks8Key = await crypto.subtle.exportKey("pkcs8", keyValue);
const fido2Key = new Fido2KeyView(); const fido2Key = new Fido2KeyView();
fido2Key.keyType = "ECDSA"; fido2Key.keyType = "public-key";
fido2Key.keyAlgorithm = "ECDSA";
fido2Key.keyCurve = "P-256"; fido2Key.keyCurve = "P-256";
fido2Key.keyValue = Fido2Utils.bufferToString(pcks8Key); fido2Key.keyValue = Fido2Utils.bufferToString(pcks8Key);
fido2Key.rpId = params.rpEntity.id; fido2Key.rpId = params.rpEntity.id;