|
@@ -34,8 +34,7 @@ extension NCEndToEndMetadata {
|
|
|
func encoderMetadataV20(account: String, serverUrl: String, ocIdServerUrl: String, userId: String, addUserId: String?, addCertificate: String?) -> (metadata: String?, signature: String?) {
|
|
|
|
|
|
guard let keyGenerated = NCEndToEndEncryption.sharedManager()?.generateKey() as? Data,
|
|
|
- let directoryTop = NCUtility.shared.getDirectoryE2EETop(serverUrl: serverUrl, account: account),
|
|
|
- let ownerId = NCManageDatabase.shared.getMetadataFromOcId(ocIdServerUrl)?.ownerId else {
|
|
|
+ let directoryTop = NCUtility.shared.getDirectoryE2EETop(serverUrl: serverUrl, account: account) else {
|
|
|
return (nil, nil)
|
|
|
}
|
|
|
|
|
@@ -50,38 +49,31 @@ extension NCEndToEndMetadata {
|
|
|
|
|
|
// USERS
|
|
|
|
|
|
- func addUser(userId: String, certificate: String, privateKey: String? = nil) {
|
|
|
+ func addUser(userId: String?, certificate: String?) {
|
|
|
|
|
|
+ guard let userId, let certificate else { return }
|
|
|
let decryptedMetadataKey = keyGenerated
|
|
|
let metadataKey = keyGenerated.base64EncodedString()
|
|
|
|
|
|
- if let metadataKeyEncrypted = NCEndToEndEncryption.sharedManager().encryptAsymmetricData(keyGenerated, certificate: certificate, privateKey: privateKey) {
|
|
|
+ if let metadataKeyEncrypted = NCEndToEndEncryption.sharedManager().encryptAsymmetricData(keyGenerated, certificate: certificate) {
|
|
|
|
|
|
let encryptedMetadataKey = metadataKeyEncrypted.base64EncodedString()
|
|
|
NCManageDatabase.shared.addE2EUsersV2(account: account, serverUrl: serverUrl, ocIdServerUrl: ocIdServerUrl, userId: userId, certificate: certificate, encryptedFiledropKey: nil, encryptedMetadataKey: encryptedMetadataKey, decryptedFiledropKey: nil, decryptedMetadataKey: decryptedMetadataKey, filedropKey: nil, metadataKey: metadataKey)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if userId == ownerId {
|
|
|
- addUser(userId: userId, certificate: CCUtility.getEndToEndCertificate(account), privateKey: CCUtility.getEndToEndPrivateKey(account))
|
|
|
- }
|
|
|
-
|
|
|
if isDirectoryTop {
|
|
|
|
|
|
- if let addUserId, let addCertificate {
|
|
|
- addUser(userId: addUserId, certificate: addCertificate)
|
|
|
- }
|
|
|
+ addUser(userId: userId, certificate: CCUtility.getEndToEndCertificate(account))
|
|
|
+ addUser(userId: addUserId, certificate: addCertificate)
|
|
|
|
|
|
if let users = NCManageDatabase.shared.getE2EUsersV2(account: account, ocIdServerUrl: ocIdServerUrl) {
|
|
|
for user in users {
|
|
|
- if user.userId != ownerId {
|
|
|
- addUser(userId: user.userId, certificate: user.certificate)
|
|
|
- }
|
|
|
+ addUser(userId: user.userId, certificate: user.certificate)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Create E2eeV20.Users
|
|
|
if let e2eUsers = NCManageDatabase.shared.getE2EUsersV2(account: account, ocIdServerUrl: directoryTop.ocId) {
|
|
|
for user in e2eUsers {
|
|
|
if isDirectoryTop {
|
|
@@ -90,10 +82,8 @@ extension NCEndToEndMetadata {
|
|
|
if let hash = NCEndToEndEncryption.sharedManager().createSHA256(user.decryptedMetadataKey) {
|
|
|
keyChecksums.append(hash)
|
|
|
}
|
|
|
- if let addUserId {
|
|
|
- if user.userId == addUserId {
|
|
|
- metadataKey = user.metadataKey
|
|
|
- }
|
|
|
+ if let addUserId, user.userId == addUserId {
|
|
|
+ metadataKey = user.metadataKey
|
|
|
} else if user.userId == userId {
|
|
|
metadataKey = user.metadataKey
|
|
|
}
|