Skip to content

Commit e8a56b9

Browse files
reverted bcd3b05: only allow access to header claims
1 parent bcd3b05 commit e8a56b9

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
requires com.google.common;
1313
requires org.slf4j;
1414
requires dagger;
15-
requires transitive com.auth0.jwt;
15+
requires com.auth0.jwt;
1616

1717
// filename-based module required by dagger
1818
// we will probably need to live with this for a while:

src/main/java/org/cryptomator/cryptofs/VaultConfig.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,34 @@ public URI getKeyId() {
141141
return URI.create(unverifiedConfig.getKeyId());
142142
}
143143

144-
public Claim get(String key) {
145-
return unverifiedConfig.getClaim(key);
144+
/**
145+
* Gets a value from the tokens header
146+
* @param key Which key to read
147+
* @param clazz Type of the value
148+
* @param <T> Type of the value
149+
* @return The value or <code>null</code> if the key doesn't exist
150+
*/
151+
public <T> T getHeader(String key, Class<T> clazz) {
152+
var claim = unverifiedConfig.getHeaderClaim(key);
153+
try {
154+
return unverifiedConfig.getHeaderClaim(key).as(clazz);
155+
} catch (JWTDecodeException e) {
156+
throw new IllegalArgumentException("Can't convert " + claim + " to type " + clazz.getName(), e);
157+
}
146158
}
147159

148160
/**
149161
* @return The unverified vault version (signature not verified)
150162
*/
151163
public int allegedVaultVersion() {
152-
return get(JSON_KEY_VAULTVERSION).asInt();
164+
return unverifiedConfig.getClaim(JSON_KEY_VAULTVERSION).asInt();
153165
}
154166

155167
/**
156168
* @return The unverified shortening threshold (signature not verified)
157169
*/
158170
public int allegedShorteningThreshold() {
159-
return get(JSON_KEY_SHORTENING_THRESHOLD).asInt();
171+
return unverifiedConfig.getClaim(JSON_KEY_SHORTENING_THRESHOLD).asInt();
160172
}
161173

162174
/**

0 commit comments

Comments
 (0)