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

Use hub subscription header #333

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving
webAppURL: webAppURL)

let encryptedVaultKey: String
let unlockHeader: [AnyHashable: Any]
switch retrieveMasterkeyResponse {
case let .success(key):
case let .success(key, header):
encryptedVaultKey = key
unlockHeader = header
case .accessNotGranted:
return .accessNotGranted
case .licenseExceeded:
Expand All @@ -93,7 +95,7 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving
let encryptedUserKeyJWE = try JWE(compactSerialization: encryptedUserKey)
let encryptedVaultKeyJWE = try JWE(compactSerialization: encryptedVaultKey)

return .success(.init(encryptedUserKey: encryptedUserKeyJWE, encryptedVaultKey: encryptedVaultKeyJWE, header: [:]))
return .success(.init(encryptedUserKey: encryptedUserKeyJWE, encryptedVaultKey: encryptedVaultKeyJWE, header: unlockHeader))
}

/**
Expand Down Expand Up @@ -240,7 +242,7 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving
guard let body = String(data: data, encoding: .utf8) else {
throw CryptomatorHubAuthenticatorError.unexpectedResponse
}
return .success(encryptedVaultKey: body)
return .success(encryptedVaultKey: body, header: httpResponse?.allHeaderFields ?? [:])
case 402:
return .licenseExceeded
case 403, 410:
Expand Down Expand Up @@ -299,7 +301,7 @@ public class CryptomatorHubAuthenticator: HubDeviceRegistering, HubKeyReceiving

private enum RetrieveVaultMasterkeyEncryptedForUserResponse {
// 200
case success(encryptedVaultKey: String)
case success(encryptedVaultKey: String, header: [AnyHashable: Any])
// 403, 410
case accessNotGranted
// 402
Expand Down