1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-26 09:33:22 +00:00
Files
browser/libs/common/src/vault/models/domain/ssh-key.ts
Bernd Schoolmann 395e4f2c05 [PM-27591] Remove orgid in vault decryption code (#17099)
* Remove orgid in vault decryption code

* Remove folder usage without provided key

* Fix folder test

* Fix build

* Fix build

* Fix build

* Fix tests

* Update spec to not use EncString decrypt

* Fix tests

* Fix test

* Fix test

* Remove comment

* Remove org id parameter
2025-12-08 07:09:43 -07:00

90 lines
2.4 KiB
TypeScript

import { Jsonify } from "type-fest";
import { SshKey as SdkSshKey } from "@bitwarden/sdk-internal";
import { EncString } from "../../../key-management/crypto/models/enc-string";
import Domain from "../../../platform/models/domain/domain-base";
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
import { SshKeyData } from "../data/ssh-key.data";
import { SshKeyView } from "../view/ssh-key.view";
export class SshKey extends Domain {
privateKey!: EncString;
publicKey!: EncString;
keyFingerprint!: EncString;
constructor(obj?: SshKeyData) {
super();
if (obj == null) {
return;
}
this.privateKey = new EncString(obj.privateKey);
this.publicKey = new EncString(obj.publicKey);
this.keyFingerprint = new EncString(obj.keyFingerprint);
}
decrypt(encKey: SymmetricCryptoKey, context = "No Cipher Context"): Promise<SshKeyView> {
return this.decryptObj<SshKey, SshKeyView>(
this,
new SshKeyView(),
["privateKey", "publicKey", "keyFingerprint"],
encKey,
"DomainType: SshKey; " + context,
);
}
toSshKeyData(): SshKeyData {
const c = new SshKeyData();
this.buildDataModel(this, c, {
privateKey: null,
publicKey: null,
keyFingerprint: null,
});
return c;
}
static fromJSON(obj: Jsonify<SshKey> | undefined): SshKey | undefined {
if (obj == null) {
return undefined;
}
const sshKey = new SshKey();
sshKey.privateKey = EncString.fromJSON(obj.privateKey);
sshKey.publicKey = EncString.fromJSON(obj.publicKey);
sshKey.keyFingerprint = EncString.fromJSON(obj.keyFingerprint);
return sshKey;
}
/**
* Maps SSH key to SDK format.
*
* @returns {SdkSshKey} The SDK SSH key object.
*/
toSdkSshKey(): SdkSshKey {
return {
privateKey: this.privateKey.toSdk(),
publicKey: this.publicKey.toSdk(),
fingerprint: this.keyFingerprint.toSdk(),
};
}
/**
* Maps an SDK SshKey object to a SshKey
* @param obj - The SDK SshKey object
*/
static fromSdkSshKey(obj?: SdkSshKey): SshKey | undefined {
if (obj == null) {
return undefined;
}
const sshKey = new SshKey();
sshKey.privateKey = EncString.fromJSON(obj.privateKey);
sshKey.publicKey = EncString.fromJSON(obj.publicKey);
sshKey.keyFingerprint = EncString.fromJSON(obj.fingerprint);
return sshKey;
}
}