Skip to content

Commit 2c2e45d

Browse files
committed
Move validation function.
1 parent bdb09a3 commit 2c2e45d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

hub/src/main/java/ch/iterate/hub/crypto/UserKeys.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
import java.util.Base64;
1616
import java.util.Objects;
1717

18-
import ch.iterate.hub.client.model.UserDto;
18+
import static ch.iterate.hub.crypto.KeyHelper.decodeKeyPair;
19+
import static ch.iterate.hub.crypto.UserKeyPayload.createFromPayload;
20+
1921
import ch.iterate.hub.crypto.uvf.UvfAccessTokenPayload;
2022
import com.fasterxml.jackson.core.JsonProcessingException;
2123
import com.nimbusds.jose.JOSEException;
2224

23-
import static ch.iterate.hub.crypto.KeyHelper.decodeKeyPair;
24-
import static ch.iterate.hub.crypto.UserKeyPayload.createFromPayload;
25-
2625
/**
2726
* Represents Cryptomator Hub <a href="https://docs.cryptomator.org/en/latest/security/hub/#user-key-pair>User Keys</a>.
2827
* Counterpart of <a href="https://github.com/cryptomator/hub/blob/develop/frontend/src/common/crypto.ts"><code>UserKeys</code></a>.
@@ -86,10 +85,6 @@ public static UserKeys create() {
8685
return new UserKeys(P384KeyPair.generate(), P384KeyPair.generate());
8786
}
8887

89-
public static boolean validate(final UserDto me) {
90-
return me.getEcdhPublicKey() != null && me.getPrivateKey() != null;
91-
}
92-
9388
private UserKeyPayload prepareForEncryption() {
9489
return new UserKeyPayload(Base64.getEncoder().encodeToString(ecdhKeyPair().getPrivate().getEncoded()), Base64.getEncoder().encodeToString(ecdsaKeyPair().getPrivate().getEncoded()));
9590
}

hub/src/main/java/ch/iterate/hub/workflows/UserKeysServiceImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public UserKeys getUserKeys(final Host hub, final UserDto me, final DeviceKeys d
6868

6969
@Override
7070
public UserKeys getOrCreateUserKeys(final Host hub, final UserDto me, final DeviceKeys deviceKeyPair, final DeviceSetupCallback prompt) throws ApiException, AccessException, SecurityFailure {
71-
if(UserKeys.validate(me)) {
71+
if(validate(me)) {
7272
try {
7373
return this.getUserKeys(hub, me, deviceKeyPair);
7474
}
@@ -83,7 +83,7 @@ public UserKeys getOrCreateUserKeys(final Host hub, final UserDto me, final Devi
8383
}
8484
}
8585
}
86-
else if(UserKeys.validate(me)) {
86+
else if(validate(me)) {
8787
// No device keys
8888
log.info("Setting up new device w/ Account Key for existing user keys.");
8989
return this.recover(me, deviceKeyPair, prompt.askForAccountKeyAndDeviceName(hub, COMPUTER_NAME));
@@ -143,4 +143,8 @@ private UserKeys uploadDeviceKeys(final String deviceName, final UserKeys userKe
143143
}
144144
return userKeys;
145145
}
146+
147+
private static boolean validate(final UserDto me) {
148+
return me.getEcdhPublicKey() != null && me.getPrivateKey() != null;
149+
}
146150
}

0 commit comments

Comments
 (0)