-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PM-12700] Add private key regeneration process #11829
Changes from 38 commits
6f16953
fc65449
3a709cb
e0647a2
7c32f5c
65b5fae
04b78e9
654ae05
5c090ce
630eb14
c6ce0c1
42ce721
9f1f8cf
ac1e08a
8ac7d64
c049384
0596c25
3a70a6b
e877375
4769f86
6d2e7ee
7fa765c
fccf892
d3e9610
112a239
77b525c
8b79a4d
960ece2
eb2a400
03bab1c
b0cd1e2
e587062
36322f7
9abc0ce
b6637fa
4779dc7
4e39e01
b6f9272
d677b9e
5466be0
5736d40
d775217
c827822
26ee44f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { UserId } from "@bitwarden/common/types/guid"; | ||
|
||
export abstract class LoginSuccessHandlerService { | ||
/** | ||
* Runs any service calls required after a successful login. | ||
* Service calls that should be included in this method are only those required to be awaited after successful login. | ||
* @param userId The user id. | ||
*/ | ||
abstract run: (userId: UserId) => Promise<void>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { SyncService } from "@bitwarden/common/platform/sync"; | ||
import { UserId } from "@bitwarden/common/types/guid"; | ||
import { UserAsymmetricKeysRegenerationService } from "@bitwarden/key-management"; | ||
|
||
import { LoginSuccessHandlerService } from "../../abstractions/login-success-handler.service"; | ||
|
||
export class DefaultLoginSuccessHandlerService implements LoginSuccessHandlerService { | ||
constructor( | ||
private syncService: SyncService, | ||
private userAsymmetricKeysRegenerationService: UserAsymmetricKeysRegenerationService, | ||
Check warning on line 10 in libs/auth/src/common/services/login-success-handler/default-login-success-handler.service.ts Codecov / codecov/patchlibs/auth/src/common/services/login-success-handler/default-login-success-handler.service.ts#L9-L10
|
||
) {} | ||
async run(userId: UserId): Promise<void> { | ||
await this.syncService.fullSync(true); | ||
await this.userAsymmetricKeysRegenerationService.regenerateIfNeeded(userId); | ||
Check warning on line 14 in libs/auth/src/common/services/login-success-handler/default-login-success-handler.service.ts Codecov / codecov/patchlibs/auth/src/common/services/login-success-handler/default-login-success-handler.service.ts#L13-L14
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; | ||
|
||
export abstract class UserAsymmetricKeysRegenerationApiService { | ||
Check warning on line 3 in libs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration-api.service.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration-api.service.ts#L3
|
||
abstract regenerateUserAsymmetricKeys: ( | ||
Thomas-Avery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
userPublicKey: string, | ||
userKeyEncryptedUserPrivateKey: EncString, | ||
) => Promise<void>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { UserId } from "@bitwarden/common/types/guid"; | ||
|
||
export abstract class UserAsymmetricKeysRegenerationService { | ||
Check warning on line 3 in libs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration.service.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/abstractions/user-asymmetric-key-regeneration.service.ts#L3
|
||
/** | ||
* Attempts to regenerate the user's asymmetric keys if they are invalid. | ||
* Requires the PrivateKeyRegeneration feature flag to be enabled if not the method will do nothing. | ||
* @param userId The user id. | ||
*/ | ||
abstract regenerateIfNeeded: (userId: UserId) => Promise<void>; | ||
Thomas-Avery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { UserAsymmetricKeysRegenerationService } from "./abstractions/user-asymmetric-key-regeneration.service"; | ||
export { DefaultUserAsymmetricKeysRegenerationService } from "./services/default-user-asymmetric-key-regeneration.service"; | ||
|
||
export { UserAsymmetricKeysRegenerationApiService } from "./abstractions/user-asymmetric-key-regeneration-api.service"; | ||
export { DefaultUserAsymmetricKeysRegenerationApiService } from "./services/default-user-asymmetric-key-regeneration-api.service"; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; | ||
|
||
export class KeyRegenerationRequest { | ||
Check warning on line 3 in libs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts#L3
|
||
userPublicKey: string; | ||
userKeyEncryptedUserPrivateKey: EncString; | ||
|
||
constructor(userPublicKey: string, userKeyEncryptedUserPrivateKey: EncString) { | ||
this.userPublicKey = userPublicKey; | ||
this.userKeyEncryptedUserPrivateKey = userKeyEncryptedUserPrivateKey; | ||
Check warning on line 9 in libs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/models/requests/key-regeneration.request.ts#L8-L9
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ApiService } from "@bitwarden/common/abstractions/api.service"; | ||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string"; | ||
|
||
import { UserAsymmetricKeysRegenerationApiService } from "../abstractions/user-asymmetric-key-regeneration-api.service"; | ||
import { KeyRegenerationRequest } from "../models/requests/key-regeneration.request"; | ||
|
||
export class DefaultUserAsymmetricKeysRegenerationApiService | ||
Check warning on line 7 in libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts#L7
|
||
implements UserAsymmetricKeysRegenerationApiService | ||
{ | ||
constructor(private apiService: ApiService) {} | ||
Check warning on line 10 in libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts#L10
|
||
|
||
async regenerateUserAsymmetricKeys( | ||
userPublicKey: string, | ||
userKeyEncryptedUserPrivateKey: EncString, | ||
): Promise<void> { | ||
const request: KeyRegenerationRequest = { | ||
Check warning on line 16 in libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts#L16
|
||
userPublicKey, | ||
userKeyEncryptedUserPrivateKey, | ||
}; | ||
|
||
await this.apiService.send( | ||
Check warning on line 21 in libs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts Codecov / codecov/patchlibs/key-management/src/user-asymmetric-key-regeneration/services/default-user-asymmetric-key-regeneration-api.service.ts#L21
|
||
"POST", | ||
"/accounts/key-management/regenerate-keys", | ||
request, | ||
true, | ||
true, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 function instead of property ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is what you're asking for ? 5466be0
It looks like KM follows a standard, so I swapped to that. In the rest of the code base, they're both used.
Not sure what the difference is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods declared as arrow functions in an abstract class are treated as properties in TypeScript, not as traditional methods. Generally, we would want actual functions to be treated as functions. It makes things like testing easier as well.