mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-18 10:41:26 +00:00
applied suggestions from code review
This commit is contained in:
@@ -98,16 +98,12 @@ public class ReceiveKeyController implements FxController {
|
||||
*/
|
||||
private void receivedVaultMasterkey(HttpResponse<String> response) {
|
||||
LOG.debug("GET {} -> Status Code {}", response.request().uri(), response.statusCode());
|
||||
try {
|
||||
switch (response.statusCode()) {
|
||||
case 200 -> requestUserKey(response.body());
|
||||
case 402 -> licenseExceeded();
|
||||
case 403, 410 -> accessNotGranted(); // or vault has been archived, effectively disallowing access - TODO: add specific dialog?
|
||||
case 404 -> requestLegacyAccessToken();
|
||||
default -> throw new IOException("Unexpected response " + response.statusCode());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
switch (response.statusCode()) {
|
||||
case 200 -> requestUserKey(response.body());
|
||||
case 402 -> licenseExceeded();
|
||||
case 403, 410 -> accessNotGranted(); // or vault has been archived, effectively disallowing access - TODO: add specific dialog?
|
||||
case 404 -> requestLegacyAccessToken();
|
||||
default -> throw new IllegalStateException("Unexpected response " + response.statusCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +111,7 @@ public class ReceiveKeyController implements FxController {
|
||||
* STEP 2 (Request): GET user key for this device
|
||||
*/
|
||||
private void requestUserKey(String encryptedVaultKey) {
|
||||
var deviceTokenUri = appendPath(URI.create(hubConfig.devicesResourceUrl), "/%s".formatted(deviceId));
|
||||
var deviceTokenUri = appendPath(URI.create(hubConfig.devicesResourceUrl), "/" + deviceId);
|
||||
var request = HttpRequest.newBuilder(deviceTokenUri) //
|
||||
.header("Authorization", "Bearer " + bearerToken) //
|
||||
.GET() //
|
||||
@@ -139,7 +135,7 @@ public class ReceiveKeyController implements FxController {
|
||||
receivedBothEncryptedKeys(encryptedVaultKey, device.userPrivateKey);
|
||||
}
|
||||
case 404 -> needsDeviceSetup(); // TODO: using the setup code, we can theoretically immediately unlock
|
||||
default -> throw new IOException("Unexpected response " + response.statusCode());
|
||||
default -> throw new IllegalStateException("Unexpected response " + response.statusCode());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
@@ -166,7 +162,7 @@ public class ReceiveKeyController implements FxController {
|
||||
*/
|
||||
@Deprecated
|
||||
private void requestLegacyAccessToken() {
|
||||
var legacyAccessTokenUri = appendPath(vaultBaseUri, "/keys/%s".formatted(deviceId));
|
||||
var legacyAccessTokenUri = appendPath(vaultBaseUri, "/keys/" + deviceId);
|
||||
var request = HttpRequest.newBuilder(legacyAccessTokenUri) //
|
||||
.header("Authorization", "Bearer " + bearerToken) //
|
||||
.GET() //
|
||||
|
||||
@@ -17,7 +17,7 @@ interface ReceivedKey {
|
||||
Masterkey decryptMasterkey(ECPrivateKey deviceKey);
|
||||
|
||||
/**
|
||||
* Creates an unlock response object from the received legacy "access token" JWE.
|
||||
* Creates an unlock response object from the user key + vault key.
|
||||
*
|
||||
* @param vaultKeyJwe a JWE containing the symmetric vault key, encrypted for this device's user.
|
||||
* @param userKeyJwe a JWE containing the user's private key, encrypted for this device.
|
||||
|
||||
@@ -85,11 +85,13 @@ public class SetupDeviceController implements FxController {
|
||||
|
||||
public void initialize() {
|
||||
deviceNameField.setText(determineHostname());
|
||||
deviceNameField.textProperty().addListener(observable -> deviceNameAlreadyExists.set(false));
|
||||
deviceNameField.textProperty().addListener(_ -> deviceNameAlreadyExists.set(false));
|
||||
deviceNameField.disableProperty().bind(workInProgress);
|
||||
setupCodeField.textProperty().addListener(observable -> invalidSetupCode.set(false));
|
||||
setupCodeField.textProperty().addListener(_ -> invalidSetupCode.set(false));
|
||||
setupCodeField.disableProperty().bind(workInProgress);
|
||||
registerBtn.disableProperty().bind(workInProgress.or(setupCodeField.textProperty().isEmpty()).or(deviceNameField.textProperty().isEmpty()));
|
||||
var missingSetupCode = setupCodeField.textProperty().isEmpty();
|
||||
var missingDeviceName = deviceNameField.textProperty().isEmpty();
|
||||
registerBtn.disableProperty().bind(workInProgress.or(missingSetupCode).or(missingDeviceName));
|
||||
registerBtn.contentDisplayProperty().bind(Bindings.when(workInProgress).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user