Skip to content

Commit c981056

Browse files
committed
Cleanup.
1 parent 2e157f4 commit c981056

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

hub/src/main/java/cloud/katta/crypto/uvf/UvfMetadataPayload.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,27 @@
5757
/**
5858
* Represents payload of <a href="https://github.com/encryption-alliance/unified-vault-format/blob/develop/vault%20metadata/README.md"><code>vault.uvf</code> metadata</a>.
5959
* Counterpart of <a href="https://github.com/shift7-ch/katta-server/blob/feature/cipherduck-uvf/frontend/src/common/universalVaultFormat.ts"><code>MetadataPayload</code></a>.
60+
* <p>
61+
* It has two custom fields:
62+
* <ul>
63+
* <li>org.cryptomator.automaticAccessGrant (upstream)</li>
64+
* <li>cloud.katta.storage</li>
65+
* </ul>
66+
* It has at two recipients:
67+
* <ul>
68+
* <li>org.cryptomator.hub.memberkey shared with vault members (having access to the member key)</li>
69+
* <li>org.cryptomator.hub.recoverykey. shared with vault owners (having access to the recovery key)</li>
70+
* </ul>
6071
*/
6172
@JsonIgnoreProperties(ignoreUnknown = true)
6273
public class UvfMetadataPayload extends JWEPayload {
74+
private static final String UVF_SPEC_VERSION_KEY_PARAM = "uvf.spec.version";
75+
76+
private static final String KID_MEMBERKEY = "org.cryptomator.hub.memberkey";
77+
private static final String KID_RECOVERYKEY_PREFIX = "org.cryptomator.hub.recoverykey.%s";
78+
79+
private static final String UVF_FILEFORMAT = "AES-256-GCM-32k";
80+
private static final String UVF_NAME_FORMAT = "AES-SIV-512-B64URL";
6381

6482
@JsonProperty(value = "fileFormat", required = true)
6583
String fileFormat;
@@ -107,9 +125,11 @@ public static UvfMetadataPayload create() {
107125
FastSecureRandomProvider.get().provide().nextBytes(rawSeed);
108126
final byte[] kdfSalt = new byte[32];
109127
FastSecureRandomProvider.get().provide().nextBytes(kdfSalt);
128+
129+
110130
return new UvfMetadataPayload()
111-
.withFileFormat("AES-256-GCM-32k")
112-
.withNameFormat("AES-SIV-512-B64URL")
131+
.withFileFormat(UVF_FILEFORMAT)
132+
.withNameFormat(UVF_NAME_FORMAT)
113133
.withSeeds(new HashMap<String, String>() {{
114134
put(kid, Base64.getUrlEncoder().encodeToString(rawSeed));
115135
}})
@@ -152,7 +172,7 @@ public OctetSequenceKey memberKey() {
152172

153173
private UniversalVaultFormatJWKS() throws JOSEException {
154174
memberKey = new OctetSequenceKeyGenerator(256)
155-
.keyID("org.cryptomator.hub.memberkey")
175+
.keyID(KID_MEMBERKEY)
156176
.algorithm(JWEAlgorithm.A256KW)
157177
.generate();
158178

@@ -162,10 +182,11 @@ private UniversalVaultFormatJWKS() throws JOSEException {
162182
recoveryKey.getPublic())
163183
.build();
164184

185+
165186
recoveryKeyJWK = new ECKey.Builder(Curve.P_384,
166187
recoveryKey.getPublic())
167188
.algorithm(JWEAlgorithm.ECDH_ES_A256KW)
168-
.keyID(String.format("org.cryptomator.hub.recoverykey.%s", recoveryKeyJWKWithoutThumbprint.computeThumbprint()))
189+
.keyID(String.format("%s%s", KID_RECOVERYKEY_PREFIX, recoveryKeyJWKWithoutThumbprint.computeThumbprint()))
169190
.privateKey(recoveryKey.getPrivate())
170191
.build();
171192
}
@@ -189,8 +210,9 @@ public UvfAccessTokenPayload toOwnerAccessToken() {
189210
}
190211

191212
public static OctetSequenceKey memberKeyFromRawKey(final byte[] raw) {
213+
192214
return new OctetSequenceKey.Builder(raw)
193-
.keyID("org.cryptomator.hub.memberkey")
215+
.keyID(KID_MEMBERKEY)
194216
.algorithm(JWEAlgorithm.A256KW)
195217
.build();
196218
}
@@ -297,7 +319,7 @@ public UvfMetadataPayload withStorage(final VaultMetadataJWEBackendDto backend)
297319
*/
298320
public static UvfMetadataPayload decryptWithJWK(final String jwe, final JWK jwk) throws ParseException, JOSEException, JsonProcessingException {
299321
final JWEObjectJSON jweObject = JWEObjectJSON.parse(jwe);
300-
jweObject.decrypt(new MultiDecrypter(jwk, Collections.singleton("uvf.spec.version")));
322+
jweObject.decrypt(new MultiDecrypter(jwk, Collections.singleton(UVF_SPEC_VERSION_KEY_PARAM)));
301323
final Payload payload = jweObject.getPayload();
302324
return UvfMetadataPayload.fromJWE(payload.toString());
303325
}
@@ -318,8 +340,8 @@ public String encrypt(final String apiURL, final UUID vaultId, final JWKSet keys
318340
.customParam("origin", String.format("%s/vaults/%s/uvf/vault.uvf", apiURL, vaultId.toString()))
319341
.jwkURL(URI.create("jwks.json"))
320342
.contentType("json")
321-
.criticalParams(Collections.singleton("uvf.spec.version"))
322-
.customParam("uvf.spec.version", "1")
343+
.criticalParams(Collections.singleton(UVF_SPEC_VERSION_KEY_PARAM))
344+
.customParam(UVF_SPEC_VERSION_KEY_PARAM, "1")
323345
.build(),
324346
new Payload(new HashMap<String, Object>() {{
325347
put("fileFormat", fileFormat);

0 commit comments

Comments
 (0)