Search in sources :

Example 1 with Vault

use of org.cryptomator.common.vaults.Vault in project cryptomator by cryptomator.

the class VaultListController method initialize.

public void initialize() {
    vaultList.setItems(vaults);
    vaultList.setCellFactory(cellFactory);
    selectedVault.bind(vaultList.getSelectionModel().selectedItemProperty());
    vaults.addListener((ListChangeListener.Change<? extends Vault> c) -> {
        while (c.next()) {
            if (c.wasAdded()) {
                Vault anyAddedVault = c.getAddedSubList().get(0);
                vaultList.getSelectionModel().select(anyAddedVault);
            }
        }
    });
    vaultList.addEventFilter(MouseEvent.MOUSE_RELEASED, this::deselect);
    vaultList.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, request -> {
        if (selectedVault.get() == null) {
            request.consume();
        }
    });
    vaultList.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> {
        if (keyEvent.getCode() == KeyCode.DELETE) {
            pressedShortcutToRemoveVault();
            keyEvent.consume();
        }
    });
    if (SystemUtils.IS_OS_MAC) {
        vaultList.addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> {
            if (keyEvent.getCode() == KeyCode.BACK_SPACE) {
                pressedShortcutToRemoveVault();
                keyEvent.consume();
            }
        });
    }
    // register vault selection shortcut to the main window
    mainWindow.addEventFilter(KeyEvent.KEY_RELEASED, keyEvent -> {
        if (keyEvent.isShortcutDown() && keyEvent.getCode().isDigitKey()) {
            vaultList.getSelectionModel().select(Integer.parseInt(keyEvent.getText()) - 1);
            keyEvent.consume();
        }
    });
}
Also used : Vault(org.cryptomator.common.vaults.Vault)

Example 2 with Vault

use of org.cryptomator.common.vaults.Vault in project cryptomator by cryptomator.

the class TrayMenuController method rebuildMenu.

private void rebuildMenu() {
    menu.removeAll();
    MenuItem showMainWindowItem = new MenuItem(resourceBundle.getString("traymenu.showMainWindow"));
    showMainWindowItem.addActionListener(this::showMainWindow);
    menu.add(showMainWindowItem);
    MenuItem showPreferencesItem = new MenuItem(resourceBundle.getString("traymenu.showPreferencesWindow"));
    showPreferencesItem.addActionListener(this::showPreferencesWindow);
    menu.add(showPreferencesItem);
    menu.addSeparator();
    for (Vault v : vaults) {
        MenuItem submenu = buildSubmenu(v);
        menu.add(submenu);
    }
    menu.addSeparator();
    MenuItem lockAllItem = new MenuItem(resourceBundle.getString("traymenu.lockAllVaults"));
    lockAllItem.addActionListener(this::lockAllVaults);
    lockAllItem.setEnabled(!vaults.filtered(Vault::isUnlocked).isEmpty());
    menu.add(lockAllItem);
    MenuItem quitApplicationItem = new MenuItem(resourceBundle.getString("traymenu.quitApplication"));
    quitApplicationItem.addActionListener(this::quitApplication);
    menu.add(quitApplicationItem);
}
Also used : MenuItem(java.awt.MenuItem) Vault(org.cryptomator.common.vaults.Vault)

Example 3 with Vault

use of org.cryptomator.common.vaults.Vault in project cryptomator by cryptomator.

the class CreateNewVaultPasswordController method initializationSucceeded.

private void initializationSucceeded(Path pathToVault) {
    try {
        Vault newVault = vaultListManager.add(pathToVault);
        vaultProperty.set(newVault);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) Vault(org.cryptomator.common.vaults.Vault) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 4 with Vault

use of org.cryptomator.common.vaults.Vault in project cryptomator by cryptomator.

the class CreateNewVaultPasswordController method showRecoveryKeyScene.

private void showRecoveryKeyScene() {
    Path pathToVault = vaultPathProperty.get();
    processing.set(true);
    Tasks.create(() -> {
        initializeVault(pathToVault);
        return recoveryKeyFactory.createRecoveryKey(pathToVault, newPasswordSceneController.passwordField.getCharacters());
    }).onSuccess(recoveryKey -> {
        initializationSucceeded(pathToVault);
        recoveryKeyProperty.set(recoveryKey);
        window.setScene(recoveryKeyScene.get());
    }).onError(IOException.class, e -> {
        LOG.error("Failed to initialize vault.", e);
        errorComponent.cause(e).window(window).returnToScene(window.getScene()).build().showErrorScene();
    }).andFinally(() -> {
        processing.set(false);
    }).runOnce(executor);
}
Also used : Path(java.nio.file.Path) Scene(javafx.scene.Scene) CryptoFileSystemProperties(org.cryptomator.cryptofs.CryptoFileSystemProperties) VaultListManager(org.cryptomator.common.vaults.VaultListManager) LoggerFactory(org.slf4j.LoggerFactory) CryptoFileSystemProvider(org.cryptomator.cryptofs.CryptoFileSystemProvider) CryptoException(org.cryptomator.cryptolib.api.CryptoException) Bindings(javafx.beans.binding.Bindings) FxmlFile(org.cryptomator.ui.common.FxmlFile) NewPasswordController(org.cryptomator.ui.common.NewPasswordController) Inject(javax.inject.Inject) SecureRandom(java.security.SecureRandom) Masterkey(org.cryptomator.cryptolib.api.Masterkey) MasterkeyFileAccess(org.cryptomator.cryptolib.common.MasterkeyFileAccess) ResourceBundle(java.util.ResourceBundle) Vault(org.cryptomator.common.vaults.Vault) ErrorComponent(org.cryptomator.ui.common.ErrorComponent) Named(javax.inject.Named) URI(java.net.URI) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Tasks(org.cryptomator.ui.common.Tasks) ObjectProperty(javafx.beans.property.ObjectProperty) MASTERKEY_FILENAME(org.cryptomator.common.Constants.MASTERKEY_FILENAME) Logger(org.slf4j.Logger) Files(java.nio.file.Files) FxController(org.cryptomator.ui.common.FxController) ObjectBinding(javafx.beans.binding.ObjectBinding) StandardOpenOption(java.nio.file.StandardOpenOption) CryptorProvider(org.cryptomator.cryptolib.api.CryptorProvider) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) Lazy(dagger.Lazy) FxmlScene(org.cryptomator.ui.common.FxmlScene) RecoveryKeyFactory(org.cryptomator.ui.recoverykey.RecoveryKeyFactory) FXML(javafx.fxml.FXML) UncheckedIOException(java.io.UncheckedIOException) US_ASCII(java.nio.charset.StandardCharsets.US_ASCII) MasterkeyLoader(org.cryptomator.cryptolib.api.MasterkeyLoader) BooleanProperty(javafx.beans.property.BooleanProperty) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) MasterkeyFileLoadingStrategy(org.cryptomator.ui.keyloading.masterkeyfile.MasterkeyFileLoadingStrategy) Stage(javafx.stage.Stage) WritableByteChannel(java.nio.channels.WritableByteChannel) Toggle(javafx.scene.control.Toggle) StringProperty(javafx.beans.property.StringProperty) ContentDisplay(javafx.scene.control.ContentDisplay)

Example 5 with Vault

use of org.cryptomator.common.vaults.Vault in project cryptomator by cryptomator.

the class CreateNewVaultPasswordController method initializeVault.

private void initializeVault(Path path) throws IOException {
    // 1. write masterkey:
    Path masterkeyFilePath = path.resolve(MASTERKEY_FILENAME);
    try (Masterkey masterkey = Masterkey.generate(csprng)) {
        masterkeyFileAccess.persist(masterkey, masterkeyFilePath, newPasswordSceneController.passwordField.getCharacters());
        // 2. initialize vault:
        try {
            MasterkeyLoader loader = ignored -> masterkey.copy();
            CryptoFileSystemProperties fsProps = CryptoFileSystemProperties.cryptoFileSystemProperties().withCipherCombo(CryptorProvider.Scheme.SIV_CTRMAC).withKeyLoader(loader).build();
            CryptoFileSystemProvider.initialize(path, fsProps, DEFAULT_KEY_ID);
            // 3. write vault-internal readme file:
            String vaultReadmeFileName = resourceBundle.getString("addvault.new.readme.accessLocation.fileName");
            try (// 
            FileSystem fs = CryptoFileSystemProvider.newFileSystem(path, fsProps);
                WritableByteChannel ch = Files.newByteChannel(fs.getPath("/", vaultReadmeFileName), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) {
                ch.write(US_ASCII.encode(readmeGenerator.createVaultAccessLocationReadmeRtf()));
            }
        } catch (CryptoException e) {
            throw new IOException("Failed initialize vault.", e);
        }
    }
    // 4. write vault-external readme file:
    String storagePathReadmeFileName = resourceBundle.getString("addvault.new.readme.storageLocation.fileName");
    try (WritableByteChannel ch = Files.newByteChannel(path.resolve(storagePathReadmeFileName), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) {
        ch.write(US_ASCII.encode(readmeGenerator.createVaultStorageLocationReadmeRtf()));
    }
    LOG.info("Created vault at {}", path);
}
Also used : Path(java.nio.file.Path) Scene(javafx.scene.Scene) CryptoFileSystemProperties(org.cryptomator.cryptofs.CryptoFileSystemProperties) VaultListManager(org.cryptomator.common.vaults.VaultListManager) LoggerFactory(org.slf4j.LoggerFactory) CryptoFileSystemProvider(org.cryptomator.cryptofs.CryptoFileSystemProvider) CryptoException(org.cryptomator.cryptolib.api.CryptoException) Bindings(javafx.beans.binding.Bindings) FxmlFile(org.cryptomator.ui.common.FxmlFile) NewPasswordController(org.cryptomator.ui.common.NewPasswordController) Inject(javax.inject.Inject) SecureRandom(java.security.SecureRandom) Masterkey(org.cryptomator.cryptolib.api.Masterkey) MasterkeyFileAccess(org.cryptomator.cryptolib.common.MasterkeyFileAccess) ResourceBundle(java.util.ResourceBundle) Vault(org.cryptomator.common.vaults.Vault) ErrorComponent(org.cryptomator.ui.common.ErrorComponent) Named(javax.inject.Named) URI(java.net.URI) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Tasks(org.cryptomator.ui.common.Tasks) ObjectProperty(javafx.beans.property.ObjectProperty) MASTERKEY_FILENAME(org.cryptomator.common.Constants.MASTERKEY_FILENAME) Logger(org.slf4j.Logger) Files(java.nio.file.Files) FxController(org.cryptomator.ui.common.FxController) ObjectBinding(javafx.beans.binding.ObjectBinding) StandardOpenOption(java.nio.file.StandardOpenOption) CryptorProvider(org.cryptomator.cryptolib.api.CryptorProvider) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) Lazy(dagger.Lazy) FxmlScene(org.cryptomator.ui.common.FxmlScene) RecoveryKeyFactory(org.cryptomator.ui.recoverykey.RecoveryKeyFactory) FXML(javafx.fxml.FXML) UncheckedIOException(java.io.UncheckedIOException) US_ASCII(java.nio.charset.StandardCharsets.US_ASCII) MasterkeyLoader(org.cryptomator.cryptolib.api.MasterkeyLoader) BooleanProperty(javafx.beans.property.BooleanProperty) ToggleGroup(javafx.scene.control.ToggleGroup) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) MasterkeyFileLoadingStrategy(org.cryptomator.ui.keyloading.masterkeyfile.MasterkeyFileLoadingStrategy) Stage(javafx.stage.Stage) WritableByteChannel(java.nio.channels.WritableByteChannel) Toggle(javafx.scene.control.Toggle) StringProperty(javafx.beans.property.StringProperty) ContentDisplay(javafx.scene.control.ContentDisplay) Masterkey(org.cryptomator.cryptolib.api.Masterkey) FileSystem(java.nio.file.FileSystem) WritableByteChannel(java.nio.channels.WritableByteChannel) CryptoFileSystemProperties(org.cryptomator.cryptofs.CryptoFileSystemProperties) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) CryptoException(org.cryptomator.cryptolib.api.CryptoException) MasterkeyLoader(org.cryptomator.cryptolib.api.MasterkeyLoader)

Aggregations

Vault (org.cryptomator.common.vaults.Vault)7 IOException (java.io.IOException)4 UncheckedIOException (java.io.UncheckedIOException)4 Lazy (dagger.Lazy)3 FXML (javafx.fxml.FXML)3 Inject (javax.inject.Inject)3 FxmlFile (org.cryptomator.ui.common.FxmlFile)3 URI (java.net.URI)2 WritableByteChannel (java.nio.channels.WritableByteChannel)2 US_ASCII (java.nio.charset.StandardCharsets.US_ASCII)2 FileSystem (java.nio.file.FileSystem)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 StandardOpenOption (java.nio.file.StandardOpenOption)2 SecureRandom (java.security.SecureRandom)2 ResourceBundle (java.util.ResourceBundle)2 ExecutorService (java.util.concurrent.ExecutorService)2 Bindings (javafx.beans.binding.Bindings)2 ObjectBinding (javafx.beans.binding.ObjectBinding)2 BooleanProperty (javafx.beans.property.BooleanProperty)2