Beispiel #1
0
 def __init__(self):
     self.storageService = StorageService()
     self.cryptoService = CryptoService(self.storageService)
     self.secureStorageService = SecureStorageService(
         self.storageService, self.cryptoService)
     self.userService = UserService(self.storageService)
     self.cipherService = CipherService(self.storageService,
                                        self.userService)
     self.containerService = ContainerService()
     self.containerService.add_service(self.cryptoService)
     self.containerService.add_service(self.secureStorageService)
Beispiel #2
0
class Bitwarden:
    containerService: ContainerService
    cryptoService: CryptoService
    secureStorageService: SecureStorageService
    storageService: StorageService

    def __init__(self):
        self.storageService = StorageService()
        self.cryptoService = CryptoService(self.storageService)
        self.secureStorageService = SecureStorageService(
            self.storageService, self.cryptoService)
        self.userService = UserService(self.storageService)
        self.cipherService = CipherService(self.storageService,
                                           self.userService)
        self.containerService = ContainerService()
        self.containerService.add_service(self.cryptoService)
        self.containerService.add_service(self.secureStorageService)

    def _exit_if_no_session(self):
        if not environ.get('BW_SESSION'):
            print('Environement variable BW_SESSION is not set.')
            exit(1)
        if not self.cryptoService.has_key():
            print('Vault is locked.')
            exit(1)

    def get(self, uuid, field):
        self._exit_if_no_session()
        cipher = self.cipherService.get(uuid)
        if cipher is None:
            raise ManagedException('Unable to find entry with id: ' + uuid)
        decrypted_value = cipher.decrypt_field(field)
        if type(decrypted_value).__name__ == 'bytes':
            print(str(decrypted_value, 'utf-8'), end='')
            return decrypted_value
        elif type(decrypted_value).__name__ == 'list':
            for item in decrypted_value:
                print(str(item, 'utf-8'))
            return decrypted_value
        else:
            print(decrypted_value, file=stderr)

    def list(self):
        self._exit_if_no_session()
        ciphers = self.storageService.list_ciphers(
            self.userService.get_user_id())
        for cipher in ciphers:
            print(cipher['id'] + ' ' +
                  str(cipher['name'].decrypt(cipher['org_id']), 'utf-8'))
Beispiel #3
0
def test_container_service():
    storage_service = StorageService()
    crypto_service = CryptoService(storage_service)
    secure_storage_service = SecureStorageService(storage_service,
                                                  crypto_service)
    container_service = ContainerService()
    container_service.add_service(crypto_service)
    container_service.add_service(secure_storage_service)
    container_service2 = ContainerService()
    assert container_service.get_crypto_service() == crypto_service
    assert container_service.get_secure_storage_service(
    ) == secure_storage_service
    assert container_service2.get_crypto_service() == crypto_service
    assert container_service2.get_secure_storage_service(
    ) == secure_storage_service
Beispiel #4
0
class Bitwarden:
    containerService: ContainerService
    cryptoService: CryptoService
    secureStorageService: SecureStorageService
    storageService: StorageService

    def __init__(self):
        self.storageService = StorageService()
        self.cryptoService = CryptoService(self.storageService)
        self.secureStorageService = SecureStorageService(
            self.storageService, self.cryptoService)
        self.userService = UserService(self.storageService)
        self.cipherService = CipherService(self.storageService,
                                           self.userService)
        self.containerService = ContainerService()
        self.containerService.add_service(self.cryptoService)
        self.containerService.add_service(self.secureStorageService)

    def _exit_if_no_session(self):
        if not environ.get('BW_SESSION'):
            print('Environement variable BW_SESSION is not set.')
            exit(1)
        if not self.cryptoService.has_key():
            print('Vault is locked.')
            exit(1)

    def get(self, uuid, field):
        self._exit_if_no_session()
        cipher = self.cipherService.get(uuid)
        if cipher is None:
            raise ManagedException('Unable to find entry with id: ' + uuid)
        return cipher.decrypt_field(field)

    def list(self):
        self._exit_if_no_session()
        ciphers = self.storageService.list_ciphers(
            self.userService.get_user_id())
        return ciphers
def storage_service():
    return StorageService(
        path.join(path.dirname(__file__),
                  common_data('test_database_filename')))
def cipher_service():
    storage_service = StorageService(
        path.join(path.dirname(__file__),
                  common_data('test_database_filename')))
    user_service = UserService(storage_service)
    return CipherService(storage_service, user_service)
def crypto_service():
    storage_service = StorageService(
        path.join(path.dirname(__file__),
                  common_data('test_database_filename')))
    return CryptoService(storage_service)
def test_storage_service_init_without_db_path():
    storage_service = StorageService()
    assert os.path.isfile(storage_service.database_path)