Skip to content

Commit e89c1ee

Browse files
ylangiscchenkins
authored andcommitted
Prepare for UVFVault implementation.
1 parent a69d55d commit e89c1ee

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

hub/src/main/java/ch/iterate/hub/crypto/uvf/UvfMetadataPayload.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public static UvfMetadataPayload fromJWE(final String jwe) throws JsonProcessing
9393
return mapper.readValue(jwe, UvfMetadataPayload.class);
9494
}
9595

96+
public String toJSON() throws JsonProcessingException {
97+
ObjectMapper mapper = new ObjectMapper();
98+
mapper.registerModule(new JsonNullableModule());
99+
return mapper.writeValueAsString(this);
100+
}
101+
96102
public static UvfMetadataPayload create() {
97103
final String kid = new AlphanumericRandomStringService(4).random();
98104
final byte[] rawSeed = new byte[32];

hub/src/main/java/ch/iterate/hub/protocols/hub/HubCryptoVault.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Cryptomator vault implementation for Cipherduck (without masterkey file).
3434
*/
35-
public class HubCryptoVault extends CryptoVault {
35+
public class HubCryptoVault extends CryptoVault { // TODO extend from UVFVault
3636
private static final Logger log = LogManager.getLogger(HubCryptoVault.class);
3737

3838
// See https://github.com/cryptomator/hub/blob/develop/frontend/src/common/vaultconfig.ts
@@ -55,7 +55,7 @@ public HubCryptoVault(final Path home) {
5555
}
5656

5757
public HubCryptoVault(final Path home, final String masterkey, final String config, final byte[] pepper) {
58-
super(home);
58+
super(home, masterkey, config, pepper);
5959
}
6060

6161
/**

hub/src/main/java/ch/iterate/hub/protocols/s3/S3AutoLoadVaultSession.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import ch.cyberduck.core.HostPasswordStore;
1414
import ch.cyberduck.core.LocaleFactory;
1515
import ch.cyberduck.core.LoginCallback;
16-
import ch.cyberduck.core.LoginOptions;
1716
import ch.cyberduck.core.PasswordStoreFactory;
1817
import ch.cyberduck.core.Path;
1918
import ch.cyberduck.core.exception.BackgroundException;
@@ -27,13 +26,11 @@
2726
import ch.cyberduck.core.ssl.X509KeyManager;
2827
import ch.cyberduck.core.ssl.X509TrustManager;
2928
import ch.cyberduck.core.threading.CancelCallback;
30-
import ch.cyberduck.core.vault.VaultCredentials;
3129
import ch.cyberduck.core.vault.VaultFactory;
3230

3331
import org.apache.logging.log4j.LogManager;
3432
import org.apache.logging.log4j.Logger;
3533

36-
import java.util.Base64;
3734
import java.util.UUID;
3835

3936
import ch.iterate.hub.client.ApiException;
@@ -44,8 +41,7 @@
4441
import ch.iterate.hub.workflows.VaultServiceImpl;
4542
import ch.iterate.hub.workflows.exceptions.AccessException;
4643
import ch.iterate.hub.workflows.exceptions.SecurityFailure;
47-
import com.google.common.primitives.Bytes;
48-
import com.nimbusds.jose.util.Base64URL;
44+
import com.fasterxml.jackson.core.JsonProcessingException;
4945

5046
public class S3AutoLoadVaultSession extends S3AssumeRoleSession {
5147
private static final Logger log = LogManager.getLogger(S3AutoLoadVaultSession.class);
@@ -83,23 +79,13 @@ public void login(final LoginCallback prompt, final CancelCallback cancel) throw
8379
super.login(prompt, cancel);
8480
final Path home = new DelegatingHomeFeature(new DefaultPathHomeFeature(host)).find();
8581
log.debug("Attempting to locate vault in {}", home);
86-
final Vault vault = VaultFactory.get(home);
87-
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MUST NEVER BE RELEASED LIKE THIS
88-
// TODO https://github.com/shift7-ch/cipherduck-hub/issues/19 use rawFileKey,rawNameKey as vault key for now (going into cryptolib's Masterkey)
8982
final UvfMetadataPayload vaultMetadata = new VaultServiceImpl(backend).getVaultMetadataJWE(
9083
UUID.fromString(host.getUuid()), new UserKeysServiceImpl(backend).getUserKeys(backend.getHost(), FirstLoginDeviceSetupCallbackFactory.get()));
91-
final byte[] rawFileKey = Base64URL.from(vaultMetadata.seeds().get(vaultMetadata.latestSeed())).decode();
92-
final byte[] rawNameKey = Base64URL.from(vaultMetadata.seeds().get(vaultMetadata.latestSeed())).decode();
93-
final byte[] vaultKey = Bytes.concat(rawFileKey, rawNameKey);
94-
registry.add(vault.load(this, new DisabledPasswordCallback() {
95-
@Override
96-
public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
97-
return new VaultCredentials(Base64.getEncoder().encodeToString(vaultKey));
98-
}
99-
}));
84+
final Vault vault = VaultFactory.get(home, vaultMetadata.toJSON(), null, null);
85+
vault.load(this, new DisabledPasswordCallback());
10086
backend.close();
10187
}
102-
catch(ApiException | SecurityFailure | AccessException e) {
88+
catch(ApiException | SecurityFailure | AccessException | JsonProcessingException e) {
10389
throw new LoginFailureException(LocaleFactory.localizedString("Login failed", "Credentials"), e);
10490
}
10591
}

0 commit comments

Comments
 (0)