1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

Move sm code to new encrypt service interface (#14545)

This commit is contained in:
Bernd Schoolmann
2025-05-09 00:36:07 +02:00
committed by GitHub
parent 00a37d9d0a
commit 9b85123acf
9 changed files with 38 additions and 35 deletions

View File

@@ -93,7 +93,7 @@ export class ProjectService {
): Promise<ProjectRequest> {
const orgKey = await this.getOrganizationKey(organizationId);
const request = new ProjectRequest();
request.name = await this.encryptService.encrypt(projectView.name, orgKey);
request.name = await this.encryptService.encryptString(projectView.name, orgKey);
return request;
}
@@ -108,7 +108,7 @@ export class ProjectService {
projectView.revisionDate = projectResponse.revisionDate;
projectView.read = projectResponse.read;
projectView.write = projectResponse.write;
projectView.name = await this.encryptService.decryptToUtf8(
projectView.name = await this.encryptService.decryptString(
new EncString(projectResponse.name),
orgKey,
);
@@ -127,7 +127,7 @@ export class ProjectService {
projectListView.organizationId = s.organizationId;
projectListView.read = s.read;
projectListView.write = s.write;
projectListView.name = await this.encryptService.decryptToUtf8(
projectListView.name = await this.encryptService.decryptString(
new EncString(s.name),
orgKey,
);

View File

@@ -24,10 +24,10 @@ describe("SecretService", () => {
sut = new SecretService(keyService, apiService, encryptService, accessPolicyService);
encryptService.encrypt.mockResolvedValue({
encryptService.encryptString.mockResolvedValue({
encryptedString: "mockEncryptedString",
} as EncString);
encryptService.decryptToUtf8.mockResolvedValue(mockUnencryptedData);
encryptService.decryptString.mockResolvedValue(mockUnencryptedData);
});
it("instantiates", () => {

View File

@@ -166,9 +166,9 @@ export class SecretService {
const orgKey = await this.getOrganizationKey(organizationId);
const request = new SecretRequest();
const [key, value, note] = await Promise.all([
this.encryptService.encrypt(secretView.name, orgKey),
this.encryptService.encrypt(secretView.value, orgKey),
this.encryptService.encrypt(secretView.note, orgKey),
this.encryptService.encryptString(secretView.name, orgKey),
this.encryptService.encryptString(secretView.value, orgKey),
this.encryptService.encryptString(secretView.note, orgKey),
]);
request.key = key.encryptedString;
request.value = value.encryptedString;
@@ -193,9 +193,9 @@ export class SecretService {
secretView.revisionDate = secretResponse.revisionDate;
const [name, value, note] = await Promise.all([
this.encryptService.decryptToUtf8(new EncString(secretResponse.name), orgKey),
this.encryptService.decryptToUtf8(new EncString(secretResponse.value), orgKey),
this.encryptService.decryptToUtf8(new EncString(secretResponse.note), orgKey),
this.encryptService.decryptString(new EncString(secretResponse.name), orgKey),
this.encryptService.decryptString(new EncString(secretResponse.value), orgKey),
this.encryptService.decryptString(new EncString(secretResponse.note), orgKey),
]);
secretView.name = name;
secretView.value = value;
@@ -230,7 +230,7 @@ export class SecretService {
const secretListView = new SecretListView();
secretListView.id = s.id;
secretListView.organizationId = s.organizationId;
secretListView.name = await this.encryptService.decryptToUtf8(
secretListView.name = await this.encryptService.decryptString(
new EncString(s.name),
orgKey,
);
@@ -259,7 +259,7 @@ export class SecretService {
const projectsMappedToSecretView = new SecretProjectView();
projectsMappedToSecretView.id = s.id;
projectsMappedToSecretView.name = s.name
? await this.encryptService.decryptToUtf8(new EncString(s.name), orgKey)
? await this.encryptService.decryptString(new EncString(s.name), orgKey)
: null;
return projectsMappedToSecretView;
}),

View File

@@ -102,12 +102,12 @@ export class AccessService {
const organizationKey = await this.getOrganizationKey(organizationId);
const accessTokenRequest = new AccessTokenRequest();
const [name, encryptedPayload, key] = await Promise.all([
await this.encryptService.encrypt(accessTokenView.name, organizationKey),
await this.encryptService.encrypt(
await this.encryptService.encryptString(accessTokenView.name, organizationKey),
await this.encryptService.encryptString(
JSON.stringify({ encryptionKey: organizationKey.keyB64 }),
encryptionKey,
),
await this.encryptService.encrypt(encryptionKey.keyB64, organizationKey),
await this.encryptService.encryptString(encryptionKey.keyB64, organizationKey),
]);
accessTokenRequest.name = name;
@@ -130,7 +130,7 @@ export class AccessService {
accessTokenResponses.map(async (s) => {
const view = new AccessTokenView();
view.id = s.id;
view.name = await this.encryptService.decryptToUtf8(new EncString(s.name), orgKey);
view.name = await this.encryptService.decryptString(new EncString(s.name), orgKey);
view.scopes = s.scopes;
view.expireAt = s.expireAt ? new Date(s.expireAt) : null;
view.creationDate = new Date(s.creationDate);

View File

@@ -130,7 +130,10 @@ export class ServiceAccountService {
serviceAccountView: ServiceAccountView,
) {
const request = new ServiceAccountRequest();
request.name = await this.encryptService.encrypt(serviceAccountView.name, organizationKey);
request.name = await this.encryptService.encryptString(
serviceAccountView.name,
organizationKey,
);
return request;
}
@@ -144,7 +147,7 @@ export class ServiceAccountService {
serviceAccountView.creationDate = serviceAccountResponse.creationDate;
serviceAccountView.revisionDate = serviceAccountResponse.revisionDate;
serviceAccountView.name = serviceAccountResponse.name
? await this.encryptService.decryptToUtf8(
? await this.encryptService.decryptString(
new EncString(serviceAccountResponse.name),
organizationKey,
)
@@ -163,7 +166,7 @@ export class ServiceAccountService {
view.revisionDate = response.revisionDate;
view.accessToSecrets = response.accessToSecrets;
view.name = response.name
? await this.encryptService.decryptToUtf8(new EncString(response.name), organizationKey)
? await this.encryptService.decryptString(new EncString(response.name), organizationKey)
: null;
return view;
}

View File

@@ -28,8 +28,8 @@ describe("SecretsManagerPortingApiService", () => {
sut = new SecretsManagerPortingApiService(apiService, encryptService, keyService);
encryptService.encrypt.mockResolvedValue(mockEncryptedString);
encryptService.decryptToUtf8.mockResolvedValue(mockUnencryptedString);
encryptService.encryptString.mockResolvedValue(mockEncryptedString);
encryptService.decryptString.mockResolvedValue(mockUnencryptedString);
const mockRandomBytes = new Uint8Array(64) as CsprngArray;
const mockOrgKey = new SymmetricCryptoKey(mockRandomBytes) as OrgKey;

View File

@@ -86,7 +86,7 @@ export class SecretsManagerPortingApiService {
importData.projects.map(async (p: any) => {
const project = new SecretsManagerImportedProjectRequest();
project.id = p.id;
project.name = await this.encryptService.encrypt(p.name, orgKey);
project.name = await this.encryptService.encryptString(p.name, orgKey);
return project;
}),
);
@@ -96,9 +96,9 @@ export class SecretsManagerPortingApiService {
const secret = new SecretsManagerImportedSecretRequest();
[secret.key, secret.value, secret.note] = await Promise.all([
this.encryptService.encrypt(s.key, orgKey),
this.encryptService.encrypt(s.value, orgKey),
this.encryptService.encrypt(s.note, orgKey),
this.encryptService.encryptString(s.key, orgKey),
this.encryptService.encryptString(s.value, orgKey),
this.encryptService.encryptString(s.note, orgKey),
]);
secret.id = s.id;
@@ -129,7 +129,7 @@ export class SecretsManagerPortingApiService {
exportData.projects.map(async (p) => {
const project = new SecretsManagerExportProject();
project.id = p.id;
project.name = await this.encryptService.decryptToUtf8(new EncString(p.name), orgKey);
project.name = await this.encryptService.decryptString(new EncString(p.name), orgKey);
return project;
}),
);
@@ -139,9 +139,9 @@ export class SecretsManagerPortingApiService {
const secret = new SecretsManagerExportSecret();
[secret.key, secret.value, secret.note] = await Promise.all([
this.encryptService.decryptToUtf8(new EncString(s.key), orgKey),
this.encryptService.decryptToUtf8(new EncString(s.value), orgKey),
this.encryptService.decryptToUtf8(new EncString(s.note), orgKey),
this.encryptService.decryptString(new EncString(s.key), orgKey),
this.encryptService.decryptString(new EncString(s.value), orgKey),
this.encryptService.decryptString(new EncString(s.note), orgKey),
]);
secret.id = s.id;

View File

@@ -138,7 +138,7 @@ describe("AccessPolicyService", () => {
const mockRandomBytes = new Uint8Array(64) as CsprngArray;
const mockOrgKey = new SymmetricCryptoKey(mockRandomBytes) as OrgKey;
keyService.getOrgKey.mockResolvedValue(mockOrgKey);
encryptService.decryptToUtf8.mockImplementation((c) => Promise.resolve(c.encryptedString));
encryptService.decryptString.mockImplementation((c) => Promise.resolve(c.encryptedString));
const organizationId = Utils.newGuid();
const serviceAccountId = Utils.newGuid();
@@ -175,7 +175,7 @@ describe("AccessPolicyService", () => {
const mockRandomBytes = new Uint8Array(64) as CsprngArray;
const mockOrgKey = new SymmetricCryptoKey(mockRandomBytes) as OrgKey;
keyService.getOrgKey.mockResolvedValue(mockOrgKey);
encryptService.decryptToUtf8.mockImplementation((c) => Promise.resolve(c.encryptedString));
encryptService.decryptString.mockImplementation((c) => Promise.resolve(c.encryptedString));
const organizationId = Utils.newGuid();
const projectId = Utils.newGuid();

View File

@@ -350,7 +350,7 @@ export class AccessPolicyService {
...this.createBaseAccessPolicyView(response),
grantedProjectId: response.grantedProjectId,
grantedProjectName: response.grantedProjectName
? await this.encryptService.decryptToUtf8(
? await this.encryptService.decryptString(
new EncString(response.grantedProjectName),
organizationKey,
)
@@ -394,7 +394,7 @@ export class AccessPolicyService {
...this.createBaseAccessPolicyView(response),
serviceAccountId: response.serviceAccountId,
serviceAccountName: response.serviceAccountName
? await this.encryptService.decryptToUtf8(
? await this.encryptService.decryptString(
new EncString(response.serviceAccountName),
orgKey,
)
@@ -420,7 +420,7 @@ export class AccessPolicyService {
if (r.type === "serviceAccount" || r.type === "project") {
view.name = r.name
? await this.encryptService.decryptToUtf8(new EncString(r.name), orgKey)
? await this.encryptService.decryptString(new EncString(r.name), orgKey)
: null;
} else {
view.name = r.name;