1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

[PM-4881]: Added userName to fido2credential (#6922)

* [PM-4881]: Added userName to fido2credential

* added user.name as input params

* Fixed some type errors
This commit is contained in:
Anders Åberg 2023-11-23 10:30:16 +01:00 committed by GitHub
parent e60d557f85
commit 564bb03038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 40 additions and 2 deletions

View File

@ -45,6 +45,7 @@ export class WebauthnUtils {
user: {
id: Fido2Utils.bufferToString(keyOptions.user.id),
displayName: keyOptions.user.displayName,
name: keyOptions.user.name,
},
timeout: keyOptions.timeout,
sameOriginWithAncestors,

View File

@ -19,6 +19,7 @@ export class Fido2CredentialExport {
req.keyValue = "keyValue";
req.rpId = "rpId";
req.userHandle = "userHandle";
req.userName = "userName";
req.counter = "counter";
req.rpName = "rpName";
req.userDisplayName = "userDisplayName";
@ -41,6 +42,7 @@ export class Fido2CredentialExport {
view.keyValue = req.keyValue;
view.rpId = req.rpId;
view.userHandle = req.userHandle;
view.userName = req.userName;
view.counter = parseInt(req.counter);
view.rpName = req.rpName;
view.userDisplayName = req.userDisplayName;
@ -63,6 +65,7 @@ export class Fido2CredentialExport {
domain.keyValue = req.keyValue != null ? new EncString(req.keyValue) : null;
domain.rpId = req.rpId != null ? new EncString(req.rpId) : null;
domain.userHandle = req.userHandle != null ? new EncString(req.userHandle) : null;
domain.userName = req.userName != null ? new EncString(req.userName) : null;
domain.counter = req.counter != null ? new EncString(req.counter) : null;
domain.rpName = req.rpName != null ? new EncString(req.rpName) : null;
domain.userDisplayName =
@ -79,6 +82,7 @@ export class Fido2CredentialExport {
keyValue: string;
rpId: string;
userHandle: string;
userName: string;
counter: string;
rpName: string;
userDisplayName: string;
@ -103,6 +107,7 @@ export class Fido2CredentialExport {
this.keyValue = o.keyValue;
this.rpId = o.rpId;
this.userHandle = o.userHandle;
this.userName = o.userName;
this.counter = String(o.counter);
this.rpName = o.rpName;
this.userDisplayName = o.userDisplayName;
@ -115,6 +120,7 @@ export class Fido2CredentialExport {
this.keyValue = o.keyValue?.encryptedString;
this.rpId = o.rpId?.encryptedString;
this.userHandle = o.userHandle?.encryptedString;
this.userName = o.userName?.encryptedString;
this.counter = o.counter?.encryptedString;
this.rpName = o.rpName?.encryptedString;
this.userDisplayName = o.userDisplayName?.encryptedString;

View File

@ -103,6 +103,7 @@ export interface CreateCredentialParams {
user: {
id: string; // b64 encoded
displayName: string;
name: string;
};
/** Forwarded to user interface */
fallbackSupported: boolean;

View File

@ -8,6 +8,7 @@ export class Fido2CredentialApi extends BaseResponse {
keyValue: string;
rpId: string;
userHandle: string;
userName: string;
counter: string;
rpName: string;
userDisplayName: string;
@ -27,6 +28,7 @@ export class Fido2CredentialApi extends BaseResponse {
this.keyValue = this.getResponseProperty("keyValue");
this.rpId = this.getResponseProperty("RpId");
this.userHandle = this.getResponseProperty("UserHandle");
this.userName = this.getResponseProperty("UserName");
this.counter = this.getResponseProperty("Counter");
this.rpName = this.getResponseProperty("RpName");
this.userDisplayName = this.getResponseProperty("UserDisplayName");

View File

@ -8,6 +8,7 @@ export class Fido2CredentialData {
keyValue: string;
rpId: string;
userHandle: string;
userName: string;
counter: string;
rpName: string;
userDisplayName: string;
@ -26,6 +27,7 @@ export class Fido2CredentialData {
this.keyValue = data.keyValue;
this.rpId = data.rpId;
this.userHandle = data.userHandle;
this.userName = data.userName;
this.counter = data.counter;
this.rpName = data.rpName;
this.userDisplayName = data.userDisplayName;

View File

@ -25,6 +25,7 @@ describe("Fido2Credential", () => {
keyValue: null,
rpId: null,
userHandle: null,
userName: null,
rpName: null,
userDisplayName: null,
counter: null,
@ -42,6 +43,7 @@ describe("Fido2Credential", () => {
keyValue: "keyValue",
rpId: "rpId",
userHandle: "userHandle",
userName: "userName",
counter: "counter",
rpName: "rpName",
userDisplayName: "userDisplayName",
@ -58,6 +60,7 @@ describe("Fido2Credential", () => {
keyValue: { encryptedString: "keyValue", encryptionType: 0 },
rpId: { encryptedString: "rpId", encryptionType: 0 },
userHandle: { encryptedString: "userHandle", encryptionType: 0 },
userName: { encryptedString: "userName", encryptionType: 0 },
counter: { encryptedString: "counter", encryptionType: 0 },
rpName: { encryptedString: "rpName", encryptionType: 0 },
userDisplayName: { encryptedString: "userDisplayName", encryptionType: 0 },
@ -85,6 +88,7 @@ describe("Fido2Credential", () => {
credential.keyValue = mockEnc("keyValue");
credential.rpId = mockEnc("rpId");
credential.userHandle = mockEnc("userHandle");
credential.userName = mockEnc("userName");
credential.counter = mockEnc("2");
credential.rpName = mockEnc("rpName");
credential.userDisplayName = mockEnc("userDisplayName");
@ -101,6 +105,7 @@ describe("Fido2Credential", () => {
keyValue: "keyValue",
rpId: "rpId",
userHandle: "userHandle",
userName: "userName",
rpName: "rpName",
userDisplayName: "userDisplayName",
counter: 2,
@ -120,6 +125,7 @@ describe("Fido2Credential", () => {
keyValue: "keyValue",
rpId: "rpId",
userHandle: "userHandle",
userName: "userName",
counter: "2",
rpName: "rpName",
userDisplayName: "userDisplayName",
@ -144,6 +150,7 @@ describe("Fido2Credential", () => {
credential.keyValue = createEncryptedEncString("keyValue");
credential.rpId = createEncryptedEncString("rpId");
credential.userHandle = createEncryptedEncString("userHandle");
credential.userName = createEncryptedEncString("userName");
credential.counter = createEncryptedEncString("2");
credential.rpName = createEncryptedEncString("rpName");
credential.userDisplayName = createEncryptedEncString("userDisplayName");

View File

@ -14,6 +14,7 @@ export class Fido2Credential extends Domain {
keyValue: EncString;
rpId: EncString;
userHandle: EncString;
userName: EncString;
counter: EncString;
rpName: EncString;
userDisplayName: EncString;
@ -37,6 +38,7 @@ export class Fido2Credential extends Domain {
keyValue: null,
rpId: null,
userHandle: null,
userName: null,
counter: null,
rpName: null,
userDisplayName: null,
@ -58,6 +60,7 @@ export class Fido2Credential extends Domain {
keyValue: null,
rpId: null,
userHandle: null,
userName: null,
rpName: null,
userDisplayName: null,
discoverable: null,
@ -102,6 +105,7 @@ export class Fido2Credential extends Domain {
keyValue: null,
rpId: null,
userHandle: null,
userName: null,
counter: null,
rpName: null,
userDisplayName: null,
@ -122,6 +126,7 @@ export class Fido2Credential extends Domain {
const keyValue = EncString.fromJSON(obj.keyValue);
const rpId = EncString.fromJSON(obj.rpId);
const userHandle = EncString.fromJSON(obj.userHandle);
const userName = EncString.fromJSON(obj.userName);
const counter = EncString.fromJSON(obj.counter);
const rpName = EncString.fromJSON(obj.rpName);
const userDisplayName = EncString.fromJSON(obj.userDisplayName);
@ -136,6 +141,7 @@ export class Fido2Credential extends Domain {
keyValue,
rpId,
userHandle,
userName,
counter,
rpName,
userDisplayName,

View File

@ -135,6 +135,7 @@ describe("Login DTO", () => {
keyValue: "keyValue" as EncryptedString,
rpId: "rpId" as EncryptedString,
userHandle: "userHandle" as EncryptedString,
userName: "userName" as EncryptedString,
counter: "counter" as EncryptedString,
rpName: "rpName" as EncryptedString,
userDisplayName: "userDisplayName" as EncryptedString,
@ -159,6 +160,7 @@ describe("Login DTO", () => {
keyValue: "keyValue_fromJSON",
rpId: "rpId_fromJSON",
userHandle: "userHandle_fromJSON",
userName: "userName_fromJSON",
counter: "counter_fromJSON",
rpName: "rpName_fromJSON",
userDisplayName: "userDisplayName_fromJSON",
@ -185,6 +187,7 @@ function initializeFido2Credential<T extends Fido2CredentialLike>(key: T): T {
key.keyValue = "keyValue";
key.rpId = "rpId";
key.userHandle = "userHandle";
key.userName = "userName";
key.counter = "counter";
key.rpName = "rpName";
key.userDisplayName = "userDisplayName";
@ -202,6 +205,7 @@ function encryptFido2Credential(key: Fido2CredentialLike): Fido2Credential {
encrypted.keyValue = { encryptedString: key.keyValue, encryptionType: 0 } as EncString;
encrypted.rpId = { encryptedString: key.rpId, encryptionType: 0 } as EncString;
encrypted.userHandle = { encryptedString: key.userHandle, encryptionType: 0 } as EncString;
encrypted.userName = { encryptedString: key.userName, encryptionType: 0 } as EncString;
encrypted.counter = { encryptedString: key.counter, encryptionType: 0 } as EncString;
encrypted.rpName = { encryptedString: key.rpName, encryptionType: 0 } as EncString;
encrypted.userDisplayName = {

View File

@ -81,6 +81,7 @@ export class CipherRequest {
keyApi.rpName = key.rpName != null ? key.rpName.encryptedString : null;
keyApi.counter = key.counter != null ? key.counter.encryptedString : null;
keyApi.userHandle = key.userHandle != null ? key.userHandle.encryptedString : null;
keyApi.userName = key.userName != null ? key.userName.encryptedString : null;
keyApi.userDisplayName =
key.userDisplayName != null ? key.userDisplayName.encryptedString : null;
keyApi.discoverable =

View File

@ -10,6 +10,7 @@ export class Fido2CredentialView extends ItemView {
keyValue: string;
rpId: string;
userHandle: string;
userName: string;
counter: number;
rpName: string;
userDisplayName: string;

View File

@ -1158,6 +1158,7 @@ export class CipherService implements CipherServiceAbstraction {
rpId: null,
rpName: null,
userHandle: null,
userName: null,
userDisplayName: null,
origin: null,
},

View File

@ -247,6 +247,7 @@ describe("FidoAuthenticatorService", () => {
rpId: params.rpEntity.id,
rpName: params.rpEntity.name,
userHandle: Fido2Utils.bufferToString(params.userEntity.id),
userName: params.userEntity.name,
counter: 0,
userDisplayName: params.userEntity.displayName,
discoverable: false,
@ -796,6 +797,7 @@ function createCipherView(
fido2CredentialView.counter = fido2Credential.counter ?? 0;
fido2CredentialView.userHandle =
fido2Credential.userHandle ?? Fido2Utils.bufferToString(randomBytes(16));
fido2CredentialView.userName = fido2Credential.userName;
fido2CredentialView.keyAlgorithm = fido2Credential.keyAlgorithm ?? "ECDSA";
fido2CredentialView.keyCurve = fido2Credential.keyCurve ?? "P-256";
fido2CredentialView.discoverable = fido2Credential.discoverable ?? true;

View File

@ -401,6 +401,7 @@ async function createKeyView(
fido2Credential.keyValue = Fido2Utils.bufferToString(pkcs8Key);
fido2Credential.rpId = params.rpEntity.id;
fido2Credential.userHandle = Fido2Utils.bufferToString(params.userEntity.id);
fido2Credential.userName = params.userEntity.name;
fido2Credential.counter = 0;
fido2Credential.rpName = params.rpEntity.name;
fido2Credential.userDisplayName = params.userEntity.displayName;

View File

@ -58,7 +58,7 @@ describe("FidoAuthenticatorService", () => {
// Spec: If the length of options.user.id is not between 1 and 64 bytes (inclusive) then return a TypeError.
it("should throw error if user.id is too small", async () => {
const params = createParams({ user: { id: "", displayName: "name" } });
const params = createParams({ user: { id: "", displayName: "displayName", name: "name" } });
const result = async () => await client.createCredential(params, tab);
@ -70,7 +70,8 @@ describe("FidoAuthenticatorService", () => {
const params = createParams({
user: {
id: "YWJzb2x1dGVseS13YXktd2F5LXRvby1sYXJnZS1iYXNlNjQtZW5jb2RlZC11c2VyLWlkLWJpbmFyeS1zZXF1ZW5jZQ",
displayName: "name",
displayName: "displayName",
name: "name",
},
});
@ -261,6 +262,7 @@ describe("FidoAuthenticatorService", () => {
user: params.user ?? {
id: "YmFzZTY0LWVuY29kZWQtdXNlci1pZA",
displayName: "User Name",
name: "name",
},
fallbackSupported: params.fallbackSupported ?? false,
timeout: params.timeout,

View File

@ -395,6 +395,7 @@ function mapToMakeCredentialParams({
userEntity: {
id: Fido2Utils.stringToBuffer(params.user.id),
displayName: params.user.displayName,
name: params.user.name,
},
fallbackSupported: params.fallbackSupported,
};