@ -4,6 +4,8 @@ import * as jsdom from 'jsdom';
@@ -4,6 +4,8 @@ import * as jsdom from 'jsdom';
import * as path from 'path' ;
import { LogLevelType } from 'jslib-common/enums/logLevelType' ;
import { StorageKey } from 'jslib-common/enums/storageKey' ;
import { AuthService } from 'jslib-common/services/auth.service' ;
@ -12,12 +14,16 @@ import { NodeEnvSecureStorageService } from './services/nodeEnvSecureStorage.ser
@@ -12,12 +14,16 @@ import { NodeEnvSecureStorageService } from './services/nodeEnvSecureStorage.ser
import { CliPlatformUtilsService } from 'jslib-node/cli/services/cliPlatformUtils.service' ;
import { ConsoleLogService } from 'jslib-node/cli/services/consoleLog.service' ;
import { LowdbStorageService } from 'jslib-node/services/lowdbStorage.service' ;
import { NodeApiService } from 'jslib-node/services/nodeApi.service' ;
import { NodeCryptoFunctionService } from 'jslib-node/services/nodeCryptoFunction.service' ;
import { AccountsManagementService } from 'jslib-common/services/accountsManagement.service' ;
import { ActiveAccountService } from 'jslib-common/services/activeAccount.service' ;
import { AppIdService } from 'jslib-common/services/appId.service' ;
import { AuditService } from 'jslib-common/services/audit.service' ;
import { CipherService } from 'jslib-common/services/cipher.service' ;
import { CollectionService } from 'jslib-common/services/collection.service' ;
import { ConstantsService } from 'jslib-common/services/constants.service' ;
import { ContainerService } from 'jslib-common/services/container.service' ;
import { CryptoService } from 'jslib-common/services/crypto.service' ;
import { EnvironmentService } from 'jslib-common/services/environment.service' ;
@ -26,19 +32,18 @@ import { FileUploadService } from 'jslib-common/services/fileUpload.service';
@@ -26,19 +32,18 @@ import { FileUploadService } from 'jslib-common/services/fileUpload.service';
import { FolderService } from 'jslib-common/services/folder.service' ;
import { ImportService } from 'jslib-common/services/import.service' ;
import { NoopMessagingService } from 'jslib-common/services/noopMessaging.service' ;
import { OrganizationService } from 'jslib-common/services/organization.service' ;
import { PasswordGenerationService } from 'jslib-common/services/passwordGeneration.service' ;
import { PolicyService } from 'jslib-common/services/policy.service' ;
import { ProviderService } from 'jslib-common/services/provider.service' ;
import { SearchService } from 'jslib-common/services/search.service' ;
import { SendService } from 'jslib-common/services/send.service' ;
import { SettingsService } from 'jslib-common/services/settings.service' ;
import { StoreService } from 'jslib-common/services/store.service' ;
import { SyncService } from 'jslib-common/services/sync.service' ;
import { TokenService } from 'jslib-common/services/token.service' ;
import { TotpService } from 'jslib-common/services/totp.service' ;
import { UserService } from 'jslib-common/services/user.service' ;
import { VaultTimeoutService } from 'jslib-common/services/vaultTimeout.service' ;
import { LowdbStorageService } from 'jslib-node/services/lowdbStorage.service' ;
import { NodeApiService } from 'jslib-node/services/nodeApi.service' ;
import { NodeCryptoFunctionService } from 'jslib-node/services/nodeCryptoFunction.service' ;
import { Program } from './program' ;
import { SendProgram } from './send.program' ;
@ -56,13 +61,11 @@ export class Main {
@@ -56,13 +61,11 @@ export class Main {
secureStorageService : NodeEnvSecureStorageService ;
i18nService : I18nService ;
platformUtilsService : CliPlatformUtilsService ;
constantsService : ConstantsService ;
cryptoService : CryptoService ;
tokenService : TokenService ;
appIdService : AppIdService ;
apiService : NodeApiService ;
environmentService : EnvironmentService ;
userService : UserService ;
settingsService : SettingsService ;
cipherService : CipherService ;
folderService : FolderService ;
@ -85,6 +88,11 @@ export class Main {
@@ -85,6 +88,11 @@ export class Main {
logService : ConsoleLogService ;
sendService : SendService ;
fileUploadService : FileUploadService ;
activeAccount : ActiveAccountService ;
accountsManagementService : AccountsManagementService ;
organizationService : OrganizationService ;
providerService : ProviderService ;
storeService : StoreService ;
constructor ( ) {
let p = null ;
@ -111,49 +119,54 @@ export class Main {
@@ -111,49 +119,54 @@ export class Main {
this . storageService = new LowdbStorageService ( this . logService , null , p , true ) ;
this . secureStorageService = new NodeEnvSecureStorageService ( this . storageService , this . logService ,
( ) = > this . cryptoService ) ;
this . cryptoService = new CryptoService ( this . storageService , this . secureStorageService ,
this . cryptoFunctionService , this . platformUtilsService , this . logService ) ;
this . storeService = new StoreService ( this . storageService , this . secureStorageService ) ;
this . accountsManagementService = new AccountsManagementService ( this . storageService , this . secureStorageService ) ;
this . activeAccount = new ActiveAccountService ( this . accountsManagementService , this . storeService ) ;
this . organizationService = new OrganizationService ( this . activeAccount ) ;
this . providerService = new ProviderService ( this . activeAccount ) ;
this . cryptoService = new CryptoService ( this . cryptoFunctionService , this . platformUtilsService ,
this . logService , this . activeAccount ) ;
this . appIdService = new AppIdService ( this . storageService ) ;
this . tokenService = new TokenService ( this . storageService ) ;
this . tokenService = new TokenService ( this . activeAccount ) ;
this . messagingService = new NoopMessagingService ( ) ;
this . environmentService = new EnvironmentService ( this . storageService ) ;
this . environmentService = new EnvironmentService ( this . activeAccount ) ;
this . apiService = new NodeApiService ( this . tokenService , this . platformUtilsService , this . environmentService ,
async ( expired : boolean ) = > await this . logout ( ) ,
'Bitwarden_CLI/' + this . platformUtilsService . getApplicationVersion ( ) +
' (' + this . platformUtilsService . getDeviceString ( ) . toUpperCase ( ) + ')' , ( clientId , clientSecret ) = >
this . authService . logInApiKey ( clientId , clientSecret ) ) ;
this . userService = new UserService ( this . tokenService , this . storageService ) ;
this . containerService = new ContainerService ( this . cryptoService ) ;
this . settingsService = new SettingsService ( this . userService , this . storageService ) ;
this . settingsService = new SettingsService ( this . activeAccount ) ;
this . fileUploadService = new FileUploadService ( this . logService , this . apiService ) ;
this . cipherService = new CipherService ( this . cryptoService , this . userService , this . settingsService ,
this . apiService , this . fileUploadService , this . storageService , this . i18nService , null ) ;
this . folderService = new FolderService ( this . cryptoService , this . userService , this . apiService ,
this . storageService , this . i18nService , this . cipherService ) ;
this . collectionService = new CollectionService ( this . cryptoService , this . userService , this . storageService ,
this . i18nService ) ;
this . cipherService = new CipherService ( this . cryptoService , this . settingsService ,
this . apiService , this . fileUploadService , this . i18nService , null ,
this . activeAccount ) ;
this . folderService = new FolderService ( this . cryptoService , this . apiService ,
this . i18nService , this . cipherService , this . activeAccount ) ;
this . collectionService = new CollectionService ( this . cryptoService , this . i18nService ,
this . activeAccount ) ;
this . searchService = new SearchService ( this . cipherService , this . logService , this . i18nService ) ;
this . policyService = new PolicyService ( this . userService , this . storage Service) ;
this . sendService = new SendService ( this . cryptoService , this . userService , this . apiService , this . fileUpload Service ,
this . storage Service, this . i18nService , this . cryptoFunctionService ) ;
this . policyService = new PolicyService ( this . activeAccount , this . organization Service) ;
this . sendService = new SendService ( this . cryptoService , this . apiService ,
this . fileUpload Service, this . i18nService , this . cryptoFunctionService , this . activeAccount ) ;
this . vaultTimeoutService = new VaultTimeoutService ( this . cipherService , this . folderService ,
this . collectionService , this . cryptoService , this . platformUtilsService , this . storage Service,
this . messagingService , this . searchService , this . user Service , this . tokenService , this . policyService ,
this . collectionService , this . cryptoService , this . platformUtilsService , this . messaging Service,
this . searchService , this . tokenService , this . policyService , this . activeAccount ,
async ( ) = > await this . cryptoService . clearStoredKey ( 'auto' ) , null ) ;
this . syncService = new SyncService ( this . userService , this . apiService , this . settingsService ,
this . syncService = new SyncService ( this . apiService , this . settingsService ,
this . folderService , this . cipherService , this . cryptoService , this . collectionService ,
this . storageService , this . messagingService , this . policyService , this . sendService ,
async ( expired : boolean ) = > await this . logout ( ) ) ;
this . passwordGenerationService = new PasswordGenerationService ( this . cryptoService , this . storage Service,
this . policyService ) ;
this . totpService = new TotpService ( this . storage Service, this . cryp toF unc tionService ) ;
this . messagingService , this . policyService , this . sendService , async ( ) = > await this . logout ( ) ,
this . activeAccount , this . organizationService , this . providerService ) ;
this . passwordGenerationService = new PasswordGenerationService ( this . cryptoService , this . policy Service,
this . activeAccount ) ;
this . totpService = new TotpService ( this . cryptoFunction Service, this . a ctiveAcc ount) ;
this . importService = new ImportService ( this . cipherService , this . folderService , this . apiService ,
this . i18nService , this . collectionService , this . platformUtilsService , this . cryptoService ) ;
this . exportService = new ExportService ( this . folderService , this . cipherService , this . apiService ,
this . cryptoService ) ;
this . authService = new AuthService ( this . cryptoService , this . apiService , this . userService , this . tokenService ,
this . authService = new AuthService ( this . cryptoService , this . apiService , this . tokenService ,
this . appIdService , this . i18nService , this . platformUtilsService , this . messagingService ,
this . vaultTimeoutService , this . logService , true ) ;
this . vaultTimeoutService , this . logService , this . activeAccount , this . accountsManagementService , true ) ;
this . auditService = new AuditService ( this . cryptoFunctionService , this . apiService ) ;
this . program = new Program ( this ) ;
this . vaultProgram = new VaultProgram ( this ) ;
@ -177,17 +190,15 @@ export class Main {
@@ -177,17 +190,15 @@ export class Main {
}
async logout() {
const userId = await this . userService . getUserId ( ) ;
await Promise . all ( [
this . syncService . setLastSync ( new Date ( 0 ) ) ,
this . tokenService . clearToken ( ) ,
this . cryptoService . clearKeys ( ) ,
this . userService . clear ( ) ,
this . settingsService . clear ( userId ) ,
this . cipherService . clear ( userId ) ,
this . folderService . clear ( userId ) ,
this . collectionService . clear ( userId ) ,
this . policyService . clear ( userId ) ,
this . settingsService . clear ( ) ,
this . cipherService . clear ( ) ,
this . folderService . clear ( ) ,
this . collectionService . clear ( ) ,
this . policyService . clear ( ) ,
this . passwordGenerationService . clear ( ) ,
] ) ;
process . env . BW_SESSION = null ;
@ -203,14 +214,14 @@ export class Main {
@@ -203,14 +214,14 @@ export class Main {
// api: 'http://localhost:4000',
// identity: 'http://localhost:33656',
// });
const locale = await this . storageService . get < string > ( ConstantsService . localeKey ) ;
const locale = await this . storageService . get < string > ( StorageKey . Locale ) ;
await this . i18nService . init ( locale ) ;
this . authService . init ( ) ;
const installedVersion = await this . storageService . get < string > ( ConstantsService . installedVersionKey ) ;
const installedVersion = await this . storageService . get < string > ( StorageKey . InstalledVersion ) ;
const currentVersion = await this . platformUtilsService . getApplicationVersion ( ) ;
if ( installedVersion == null || installedVersion !== currentVersion ) {
await this . storageService . save ( ConstantsService . installedVersionKey , currentVersion ) ;
await this . storageService . save ( StorageKey . InstalledVersion , currentVersion ) ;
}
}
}