Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UVF support #274

Draft
wants to merge 88 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
2d080ea
add `"alg": "A256KW"` support for JWEs
overheadhunter Mar 2, 2024
d109cff
uvf metadata (WiP).
chenkins Feb 28, 2024
55633f1
remove dead code from `backend.ts` for now
overheadhunter Apr 13, 2024
fe7ff3d
disentangle v8 and uvf based vaults
overheadhunter Apr 13, 2024
be8803c
move vault format 8 code to separate file
overheadhunter Apr 13, 2024
b51cc59
move UVF code to separate file
overheadhunter Apr 13, 2024
a9f12d4
adjust UVF payload to latest spec
overheadhunter Apr 13, 2024
cdf5571
Merge branch 'develop' into feature/uvf
overheadhunter Apr 20, 2024
3f77d16
new JWE API supporting compact and JSON format
overheadhunter Apr 25, 2024
3646379
use correct `AlgorithmID` for Concat KDF
overheadhunter Apr 26, 2024
f1c14fd
added tests
overheadhunter Apr 26, 2024
e0a7ab1
Merge branch 'develop' into feature/uvf
overheadhunter Apr 28, 2024
aa1690f
type cleanup
overheadhunter Apr 28, 2024
e6e028a
include recovery key in UVF metadata
overheadhunter Apr 28, 2024
a85cf3c
create UVF-based vault
overheadhunter Apr 28, 2024
32f2743
store uvf metadata and recovery key in vault table
overheadhunter May 2, 2024
a63ef34
adjusted to DTO model
overheadhunter May 2, 2024
6ce1569
Merge branch 'develop' into feature/uvf
overheadhunter May 2, 2024
01c8a06
grant permission to UVF vault
overheadhunter May 2, 2024
36eb79c
fix autocompletion mistake
overheadhunter May 2, 2024
3cf9c8e
use common interfaces for VF8 and UVF
overheadhunter May 2, 2024
69f0360
fix linter errors
overheadhunter May 2, 2024
7bddc62
experimental implementation of `serializePrivateKey()`
overheadhunter May 2, 2024
ba05d8b
make config.ts usable during tests
overheadhunter May 2, 2024
3d1db01
deduplicate "encrypt for user"
overheadhunter May 3, 2024
6b46862
store recovery key among vault key in access token
overheadhunter May 3, 2024
cb4e53a
reordered fields
overheadhunter May 3, 2024
b294f55
store recovery key as PKCS8 instead of words
overheadhunter May 9, 2024
a3fc184
adjusted parameter order
overheadhunter May 9, 2024
aeafffe
fix mocha test explorer: `document is not defined`
overheadhunter May 9, 2024
17c7099
fix method signature
overheadhunter May 9, 2024
f3f3e02
relax linter
overheadhunter May 9, 2024
aa49371
add tests
overheadhunter May 9, 2024
eda2621
add tests
overheadhunter May 9, 2024
815199f
reduce public API surface
overheadhunter May 9, 2024
037157f
add tests
overheadhunter May 9, 2024
2a40d01
speed up tests by reducing KDF iteration count
overheadhunter May 9, 2024
5118876
Merge branch 'develop' into feature/uvf
overheadhunter May 9, 2024
e4f9865
renamed files
overheadhunter May 10, 2024
e27d20a
clean up tests
overheadhunter May 10, 2024
657598a
fix uneffective test
overheadhunter May 10, 2024
88a95eb
clean up test
overheadhunter May 10, 2024
c229fdd
remove outdated TODOs
overheadhunter May 10, 2024
b46f55e
restore recovery key from human-readable form
overheadhunter May 10, 2024
b0790aa
store JWK Set in backend
overheadhunter May 10, 2024
98cd173
expose `jwks.json` and `vault.uvf` endpoints
overheadhunter May 10, 2024
00641e4
switch to MemberDto
overheadhunter May 16, 2024
4f3e969
cleanup
overheadhunter May 16, 2024
8320786
include role-depending data in access token
overheadhunter May 16, 2024
458e98a
Merge branch 'develop' into feature/uvf
overheadhunter May 16, 2024
8cb9af6
add `UniversalVaultFormat.recover(...)`
overheadhunter May 16, 2024
aad13fa
Merge branch 'develop' into feature/uvf
overheadhunter May 17, 2024
686713b
Merge branch 'develop' into feature/uvf
overheadhunter May 17, 2024
994d7b3
Merge branch 'develop' into feature/uvf
overheadhunter May 17, 2024
155d640
remove unnecessary guard
overheadhunter May 17, 2024
9b4f5ba
fix weird error message in unit tests
overheadhunter May 21, 2024
388426f
pass in URL during vault template generation
overheadhunter May 21, 2024
52b97b5
improve test
overheadhunter May 21, 2024
7224b46
add root directory to vault template
overheadhunter May 21, 2024
81e9ab4
split up `computeDirId` and `computeDirIdHash`
overheadhunter May 21, 2024
9c3ab12
add `dir.uvf` file to vault template
overheadhunter May 21, 2024
ec4415d
refine test
overheadhunter May 22, 2024
2947b80
show also uvf recovery key in vault details
infeo May 22, 2024
2d03e39
fix linter hints
infeo May 22, 2024
bf85c2a
(unfinished) rework recover Vault dialog
infeo May 27, 2024
8d86446
Do not erase uploaded file on failed upload
infeo May 28, 2024
57cfd0a
improve error handling
infeo May 28, 2024
b1f9fc4
define event listeners as functions
infeo May 28, 2024
a667e0d
remove unused Error class
infeo May 28, 2024
871b6de
set vault type during recovery
infeo May 28, 2024
3368768
minor adjustments
infeo May 28, 2024
b43a946
add additional verification to vaultformat 8 module
infeo May 29, 2024
ea77daf
Add negative test for vaultFormat8 verfiy and recover
infeo May 30, 2024
c2fe768
reduce diff
infeo May 30, 2024
b2cb75d
add doc string
infeo Jun 3, 2024
64d8ff6
add tests for simple jwt parsing
infeo Jun 3, 2024
eaaad24
improve error handling
infeo Jun 3, 2024
597b2cc
add error translations
infeo Jun 3, 2024
b7a0687
more wording/translations
infeo Jun 5, 2024
afd370f
fix display bug
infeo Jun 5, 2024
0de22c9
Merge branch 'develop' into feature/uvf
overheadhunter Jun 6, 2024
917fedc
use new JWE parser in `userdata.ts`
overheadhunter Jun 6, 2024
847ecc4
dedup
overheadhunter Jun 6, 2024
26369a5
adjust DTO to carry both EC keys
overheadhunter Jun 6, 2024
e77ca7a
Merge branch 'develop' into feature/uvf
overheadhunter Jul 12, 2024
3e30a00
Merge branch 'develop' into feature/uvf
overheadhunter Nov 3, 2024
fd0add4
fixed test
overheadhunter Nov 3, 2024
68eb5d9
fixed linter warnings
overheadhunter Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions backend/src/main/java/org/cryptomator/hub/api/VaultResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,18 @@ public Response removeAuthority(@PathParam("vaultId") UUID vaultId, @PathParam("
@VaultRole(VaultAccess.Role.OWNER) // may throw 403
@Transactional
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "list devices requiring access rights", description = "lists all devices owned by vault members, that don't have a device-specific masterkey yet")
@Operation(summary = "list members requiring access tokens", description = "lists all members, that have permissions but lack an access token")
@APIResponse(responseCode = "200")
@APIResponse(responseCode = "403", description = "not a vault owner")
public List<UserDto> getUsersRequiringAccessGrant(@PathParam("vaultId") UUID vaultId) {
return userRepo.findRequiringAccessGrant(vaultId).map(UserDto::justPublicInfo).toList();
public List<MemberDto> getUsersRequiringAccessGrant(@PathParam("vaultId") UUID vaultId) {
return effectiveVaultAccessRepo.findMembersWithoutAccessTokens(vaultId).map(access -> {
if (access.getAuthority() instanceof User u) {
return MemberDto.fromEntity(u, access.getRole());
} else {
// findMembersWithoutAccessTokens() should only return users, not groups.
throw new IllegalStateException();
}
}).toList();
}

@Deprecated(forRemoval = true)
Expand Down Expand Up @@ -332,6 +339,38 @@ public Response unlock(@PathParam("vaultId") UUID vaultId, @QueryParam("evenIfAr
}
}

@GET
@Path("/{vaultId}/uvf/vault.uvf")
@RolesAllowed("user")
@Transactional
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "get the vault.uvf file")
@APIResponse(responseCode = "200")
@APIResponse(responseCode = "404", description = "unknown vault")
public String getUvfMetadata(@PathParam("vaultId") UUID vaultId) {
var vault = vaultRepo.findById(vaultId);
if (vault == null || vault.getUvfMetadataFile() == null) {
throw new NotFoundException();
}
return vault.getUvfMetadataFile();
}

@GET
@Path("/{vaultId}/uvf/jwks.json")
@RolesAllowed("user")
@Transactional
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "get public vault keys", description = "retrieves a JWK Set containing public keys related to this vault")
@APIResponse(responseCode = "200")
@APIResponse(responseCode = "404", description = "unknown vault")
public String getUvfKeys(@PathParam("vaultId") UUID vaultId) {
var vault = vaultRepo.findById(vaultId);
if (vault == null || vault.getUvfMetadataFile() == null) {
throw new NotFoundException();
}
return vault.getUvfKeySet();
}

@POST
@Path("/{vaultId}/access-tokens")
@RolesAllowed("user")
Expand Down Expand Up @@ -419,7 +458,9 @@ public Response createOrUpdate(@PathParam("vaultId") UUID vaultId, @Valid @NotNu
// set regardless of whether vault is new or existing:
vault.setName(vaultDto.name);
vault.setDescription(vaultDto.description);
vault.setArchived(existingVault.isEmpty() ? false : vaultDto.archived);
vault.setArchived(existingVault.isPresent() && vaultDto.archived);
vault.setUvfMetadataFile(vaultDto.uvfMetadataFile);
vault.setUvfKeySet(vaultDto.uvfKeySet);

vaultRepo.persistAndFlush(vault); // trigger PersistenceException before we continue with
if (existingVault.isEmpty()) {
Expand Down Expand Up @@ -500,14 +541,18 @@ public record VaultDto(@JsonProperty("id") UUID id,
@JsonProperty("description") @NoHtmlOrScriptChars String description,
@JsonProperty("archived") boolean archived,
@JsonProperty("creationTime") Instant creationTime,
@JsonProperty("uvfMetadataFile") String uvfMetadataFile,
@JsonProperty("uvfKeySet") String uvfKeySet,
// Legacy properties ("Vault Admin Password"):
@JsonProperty("masterkey") @OnlyBase64Chars String masterkey, @JsonProperty("iterations") Integer iterations,
@JsonProperty("salt") @OnlyBase64Chars String salt,
@JsonProperty("masterkey") @OnlyBase64Chars String masterkey, @JsonProperty("iterations") Integer iterations, @JsonProperty("salt") @OnlyBase64Chars String salt,
@JsonProperty("authPublicKey") @OnlyBase64Chars String authPublicKey, @JsonProperty("authPrivateKey") @OnlyBase64Chars String authPrivateKey

) {

public static VaultDto fromEntity(Vault entity) {
return new VaultDto(entity.getId(), entity.getName(), entity.getDescription(), entity.isArchived(), entity.getCreationTime().truncatedTo(ChronoUnit.MILLIS), entity.getMasterkey(), entity.getIterations(), entity.getSalt(), entity.getAuthenticationPublicKey(), entity.getAuthenticationPrivateKey());
return new VaultDto(entity.getId(), entity.getName(), entity.getDescription(), entity.isArchived(), entity.getCreationTime().truncatedTo(ChronoUnit.MILLIS), entity.getUvfMetadataFile(), entity.getUvfKeySet(),
// legacy properties:
entity.getMasterkey(), entity.getIterations(), entity.getSalt(), entity.getAuthenticationPublicKey(), entity.getAuthenticationPrivateKey());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table;
import org.hibernate.annotations.Immutable;
Expand All @@ -19,6 +22,7 @@
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Entity
@Immutable
Expand Down Expand Up @@ -62,11 +66,29 @@ SELECT count(DISTINCT u)
FROM EffectiveVaultAccess eva
WHERE eva.id.vaultId = :vaultId AND eva.id.authorityId = :authorityId
""")
@NamedQuery(name = "EffectiveVaultAccess.findMembersWithoutAccessTokens", query = """
SELECT eva
FROM EffectiveVaultAccess eva
INNER JOIN User u ON u.id = eva.id.authorityId
LEFT JOIN AccessToken token ON token.id.vaultId = eva.id.vaultId AND token.id.userId = eva.id.authorityId
WHERE eva.id.vaultId = :vaultId AND token.vault IS NULL AND u.ecdhPublicKey IS NOT NULL
"""
)
public class EffectiveVaultAccess {

@EmbeddedId
private EffectiveVaultAccess.Id id;

@ManyToOne
@MapsId("vaultId")
@JoinColumn(name = "vault_id")
private Vault vault;

@ManyToOne
@MapsId("authorityId")
@JoinColumn(name = "authority_id")
private Authority authority;

public Id getId() {
return id;
}
Expand All @@ -75,6 +97,30 @@ public void setId(Id id) {
this.id = id;
}

public Vault getVault() {
return vault;
}

public void setVault(Vault vault) {
this.vault = vault;
}

public Authority getAuthority() {
return authority;
}

public void setAuthority(Authority authority) {
this.authority = authority;
}

public VaultAccess.Role getRole() {
return id.role;
}

public void setRole(VaultAccess.Role role) {
this.id.role = role;
}

@Embeddable
public static class Id implements Serializable {

Expand Down Expand Up @@ -170,8 +216,12 @@ public long countSeatOccupyingUsersOfGroup(String groupId) {

public Collection<VaultAccess.Role> listRoles(UUID vaultId, String authorityId) {
return find("#EffectiveVaultAccess.findByAuthorityAndVault", Parameters.with("vaultId", vaultId).and("authorityId", authorityId)).stream()
.map(eva -> eva.getId().getRole())
.map(EffectiveVaultAccess::getRole)
.collect(Collectors.toUnmodifiableSet());
}

public Stream<EffectiveVaultAccess> findMembersWithoutAccessTokens(UUID vaultId) {
return find("#EffectiveVaultAccess.findMembersWithoutAccessTokens", Parameters.with("vaultId", vaultId)).stream();
}
}
}
13 changes: 0 additions & 13 deletions backend/src/main/java/org/cryptomator/hub/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
@Entity
@Table(name = "user_details")
@DiscriminatorValue("USER")
@NamedQuery(name = "User.requiringAccessGrant",
query = """
SELECT u
FROM User u
INNER JOIN EffectiveVaultAccess perm ON u.id = perm.id.authorityId
LEFT JOIN u.accessTokens token ON token.id.vaultId = :vaultId AND token.id.userId = u.id
WHERE perm.id.vaultId = :vaultId AND token.vault IS NULL AND u.ecdhPublicKey IS NOT NULL
"""
)
@NamedQuery(name = "User.getEffectiveGroupUsers", query = """
SELECT DISTINCT u
FROM User u
Expand Down Expand Up @@ -149,10 +140,6 @@ public int hashCode() {
@ApplicationScoped
public static class Repository implements PanacheRepositoryBase<User, String> {

public Stream<User> findRequiringAccessGrant(UUID vaultId) {
return find("#User.requiringAccessGrant", Parameters.with("vaultId", vaultId)).stream();
}

public long countEffectiveGroupUsers(String groupdId) {
return count("#User.countEffectiveGroupUsers", Parameters.with("groupId", groupdId));
}
Expand Down
34 changes: 29 additions & 5 deletions backend/src/main/java/org/cryptomator/hub/entities/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public class Vault {
@Column(name = "archived", nullable = false)
private boolean archived;

@Column(name = "uvf_metadata_file")
private String uvfMetadataFile;

@Column(name = "uvf_jwks")
private String uvfKeySet;

public Optional<ECPublicKey> getAuthenticationPublicKeyOptional() {
if (authenticationPublicKey == null) {
return Optional.empty();
Expand Down Expand Up @@ -230,6 +236,22 @@ public void setArchived(boolean archived) {
this.archived = archived;
}

public String getUvfMetadataFile() {
return uvfMetadataFile;
}

public void setUvfMetadataFile(String uvfMetadataFile) {
this.uvfMetadataFile = uvfMetadataFile;
}

public String getUvfKeySet() {
return uvfKeySet;
}

public void setUvfKeySet(String uvfKeySet) {
this.uvfKeySet = uvfKeySet;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -240,12 +262,14 @@ public boolean equals(Object o) {
&& Objects.equals(salt, vault.salt)
&& Objects.equals(iterations, vault.iterations)
&& Objects.equals(masterkey, vault.masterkey)
&& Objects.equals(archived, vault.archived);
&& Objects.equals(archived, vault.archived)
&& Objects.equals(uvfMetadataFile, vault.uvfMetadataFile)
&& Objects.equals(uvfKeySet, vault.uvfKeySet);
}

@Override
public int hashCode() {
return Objects.hash(id, name, salt, iterations, masterkey, archived);
return Objects.hash(id, name, salt, iterations, masterkey, archived, uvfMetadataFile, uvfKeySet);
}

@Override
Expand All @@ -255,12 +279,12 @@ public String toString() {
", members=" + directMembers.stream().map(Authority::getId).collect(Collectors.joining(", ")) +
", accessToken=" + accessTokens.stream().map(a -> a.getId().toString()).collect(Collectors.joining(", ")) +
", name='" + name + '\'' +
", archived='" + archived + '\'' +
", salt='" + salt + '\'' +
", iterations='" + iterations + '\'' +
", masterkey='" + masterkey + '\'' +
", authenticationPublicKey='" + authenticationPublicKey + '\'' +
", authenticationPrivateKey='" + authenticationPrivateKey + '\'' +
", archived='" + archived + '\'' +
", uvfMetadataFile='" + uvfMetadataFile + '\'' +
", uvfKeySet='" + uvfKeySet + '\'' +
'}';
}

Expand Down
Binary file modified backend/src/main/resources/org/cryptomator/hub/flyway/ERM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE vault ADD uvf_metadata_file VARCHAR UNIQUE; -- vault.uvf file, encrypted as JWE
ALTER TABLE vault ADD uvf_jwks VARCHAR UNIQUE; -- encoded as JWKs
Loading