mirror of
https://github.com/bitwarden/browser
synced 2025-12-24 04:04:24 +00:00
* [PM-3660] chore: simplify object assignment * [PM-3660] fix: remove unused origin field * [PM-3660] feat: add Fido2Key tests * [PM-3660] chore: convert popOut to async func * [PM-3660] chore: refactor if-statements * [PM-3660] chore: simplify closePopOut * [PM-3660] fix: remove confusing comment * [PM-3660] chore: move guid utils away from platform utils * [PM-3660] chore: use null instead of undefined * [PM-3660] chore: use `switch` instead of `if`
125 lines
3.0 KiB
TypeScript
125 lines
3.0 KiB
TypeScript
import { Jsonify } from "type-fest";
|
|
|
|
import Domain from "../../../platform/models/domain/domain-base";
|
|
import { EncString } from "../../../platform/models/domain/enc-string";
|
|
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
|
|
import { Fido2KeyData } from "../data/fido2-key.data";
|
|
import { Fido2KeyView } from "../view/fido2-key.view";
|
|
|
|
export class Fido2Key extends Domain {
|
|
nonDiscoverableId: EncString | null = null;
|
|
keyType: EncString;
|
|
keyAlgorithm: EncString;
|
|
keyCurve: EncString;
|
|
keyValue: EncString;
|
|
rpId: EncString;
|
|
userHandle: EncString;
|
|
counter: EncString;
|
|
rpName: EncString;
|
|
userDisplayName: EncString;
|
|
|
|
constructor(obj?: Fido2KeyData) {
|
|
super();
|
|
if (obj == null) {
|
|
return;
|
|
}
|
|
|
|
this.buildDomainModel(
|
|
this,
|
|
obj,
|
|
{
|
|
nonDiscoverableId: null,
|
|
keyType: null,
|
|
keyAlgorithm: null,
|
|
keyCurve: null,
|
|
keyValue: null,
|
|
rpId: null,
|
|
userHandle: null,
|
|
counter: null,
|
|
rpName: null,
|
|
userDisplayName: null,
|
|
},
|
|
[]
|
|
);
|
|
}
|
|
|
|
async decrypt(orgId: string, encKey?: SymmetricCryptoKey): Promise<Fido2KeyView> {
|
|
const view = await this.decryptObj(
|
|
new Fido2KeyView(),
|
|
{
|
|
nonDiscoverableId: null,
|
|
keyType: null,
|
|
keyAlgorithm: null,
|
|
keyCurve: null,
|
|
keyValue: null,
|
|
rpId: null,
|
|
userHandle: null,
|
|
rpName: null,
|
|
userDisplayName: null,
|
|
},
|
|
orgId,
|
|
encKey
|
|
);
|
|
|
|
const { counter } = await this.decryptObj(
|
|
{ counter: "" },
|
|
{
|
|
counter: null,
|
|
},
|
|
orgId,
|
|
encKey
|
|
);
|
|
// Counter will end up as NaN if this fails
|
|
view.counter = parseInt(counter);
|
|
|
|
return view;
|
|
}
|
|
|
|
toFido2KeyData(): Fido2KeyData {
|
|
const i = new Fido2KeyData();
|
|
this.buildDataModel(this, i, {
|
|
nonDiscoverableId: null,
|
|
keyType: null,
|
|
keyAlgorithm: null,
|
|
keyCurve: null,
|
|
keyValue: null,
|
|
rpId: null,
|
|
userHandle: null,
|
|
counter: null,
|
|
rpName: null,
|
|
userDisplayName: null,
|
|
});
|
|
return i;
|
|
}
|
|
|
|
static fromJSON(obj: Jsonify<Fido2Key>): Fido2Key {
|
|
if (obj == null) {
|
|
return null;
|
|
}
|
|
|
|
const nonDiscoverableId = EncString.fromJSON(obj.nonDiscoverableId);
|
|
const keyType = EncString.fromJSON(obj.keyType);
|
|
const keyAlgorithm = EncString.fromJSON(obj.keyAlgorithm);
|
|
const keyCurve = EncString.fromJSON(obj.keyCurve);
|
|
const keyValue = EncString.fromJSON(obj.keyValue);
|
|
const rpId = EncString.fromJSON(obj.rpId);
|
|
const userHandle = EncString.fromJSON(obj.userHandle);
|
|
const counter = EncString.fromJSON(obj.counter);
|
|
const rpName = EncString.fromJSON(obj.rpName);
|
|
const userDisplayName = EncString.fromJSON(obj.userDisplayName);
|
|
|
|
return Object.assign(new Fido2Key(), obj, {
|
|
nonDiscoverableId,
|
|
keyType,
|
|
keyAlgorithm,
|
|
keyCurve,
|
|
keyValue,
|
|
rpId,
|
|
userHandle,
|
|
counter,
|
|
rpName,
|
|
userDisplayName,
|
|
});
|
|
}
|
|
}
|