NCEntoToEndInterface.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. //
  2. // NCEntoToEndInterface.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/04/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class NCEntoToEndInterface : NSObject, OCNetworkingDelegate {
  25. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  26. let ASYMMETRIC_STRING_TEST = "Nextcloud a safe home for all your data"
  27. override init() {
  28. }
  29. // --------------------------------------------------------------------------------------------
  30. // MARK: Initialize
  31. // --------------------------------------------------------------------------------------------
  32. @objc func initEndToEndEncryption() {
  33. // Clear all keys
  34. CCUtility.clearAllKeysEnd(toEnd: appDelegate.activeAccount)
  35. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  36. metadataNet.action = actionGetEndToEndPublicKeys
  37. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  38. }
  39. func getPrivateKeyCipher() {
  40. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  41. metadataNet.action = actionGetEndToEndPrivateKeyCipher
  42. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  43. }
  44. func getPublicKeyServer() {
  45. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  46. metadataNet.action = actionGetEndToEndServerPublicKey
  47. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  48. }
  49. // --------------------------------------------------------------------------------------------
  50. // MARK: Manage PublicKey
  51. // --------------------------------------------------------------------------------------------
  52. func getEndToEndPublicKeysSuccess(_ metadataNet: CCMetadataNet!) {
  53. CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: metadataNet.key)
  54. // Request PrivateKey chiper to Server
  55. getPrivateKeyCipher()
  56. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPublicKeys, note: "E2E PublicKey present on Server and stored to keychain", type: k_activityTypeSuccess, verbose: false, activeUrl: "")
  57. }
  58. func getEndToEndPublicKeysFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  59. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPublicKeys, note: message as String!, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  60. switch errorCode {
  61. case 400:
  62. appDelegate.messageNotification("E2E publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  63. case 404:
  64. guard let csr = NCEndToEndEncryption.sharedManager().createCSR(appDelegate.activeUserID, directoryUser: appDelegate.directoryUser) else {
  65. appDelegate.messageNotification("E2E Csr", description: "Error to create Csr", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  66. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPublicKeys, note: "E2E Error to create Csr", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  67. return
  68. }
  69. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  70. metadataNet.action = actionSignEndToEndPublicKey;
  71. metadataNet.key = csr;
  72. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  73. case 409:
  74. appDelegate.messageNotification("E2E publicKey", description: "forbidden: the user can't access the public keys", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  75. default:
  76. appDelegate.messageNotification("E2E publicKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  77. }
  78. }
  79. func signEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
  80. guard let publicKey = metadataNet.key else {
  81. appDelegate.messageNotification("E2E publicKey", description: "Error : publicKey not present", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  82. return
  83. }
  84. CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: publicKey)
  85. // Request PrivateKey chiper to Server
  86. getPrivateKeyCipher()
  87. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionSignEndToEndPublicKey, note: "E2E Csr - publicKey sign on Server and stored publicKey locally", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  88. }
  89. func signEnd(toEndPublicKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  90. appDelegate.messageNotification("E2E sign Csr - publicKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  91. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionSignEndToEndPublicKey, note: message, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  92. }
  93. func deleteEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
  94. appDelegate.messageNotification("E2E delete publicKey", description: "Success", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.success, errorCode: 0)
  95. }
  96. func deleteEnd(toEndPublicKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  97. appDelegate.messageNotification("E2E delete publicKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  98. }
  99. // --------------------------------------------------------------------------------------------
  100. // MARK: Manage PrivateKey
  101. // --------------------------------------------------------------------------------------------
  102. func getEndToEndPrivateKeyCipherSuccess(_ metadataNet: CCMetadataNet!) {
  103. // request Passphrase
  104. var passphraseTextField: UITextField?
  105. let alertController = UIAlertController(title: NSLocalizedString("_e2e_passphrase_request_title_", comment: ""), message: NSLocalizedString("_e2e_passphrase_request_message_", comment: ""), preferredStyle: .alert)
  106. let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
  107. let passphrase = passphraseTextField?.text
  108. guard let privateKey = (NCEndToEndEncryption.sharedManager().decryptPrivateKey(metadataNet.key, passphrase: passphrase)) else {
  109. self.appDelegate.messageNotification("E2E decrypt privateKey", description: "Error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  110. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Error to decrypt PrivateKey", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  111. return
  112. }
  113. // --------- verify privateKey encrypt/decrypt asymmetric key ---------
  114. /*
  115. let publicKey = CCUtility.getEndToEndPublicKey(self.appDelegate.activeAccount)
  116. guard let encryptData = NCEndToEndEncryption.sharedManager().encryptAsymmetricString(self.ASYMMETRIC_STRING_TEST, publicKey: publicKey) else {
  117. self.appDelegate.messageNotification("E2E Verify privateKey", description: "Error to encrypt asymmetric key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  118. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Verify privateKey, error to encrypt asymmetric key", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  119. return
  120. }
  121. guard let decryptString = NCEndToEndEncryption.sharedManager().decryptAsymmetricData(encryptData, privateKey: privateKey) else {
  122. self.appDelegate.messageNotification("E2E Verify privateKey", description: "Error to decrypt asymmetric key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  123. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Verify privateKey, error to decrypt asymmetric key", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  124. return
  125. }
  126. if (decryptString != self.ASYMMETRIC_STRING_TEST) {
  127. self.appDelegate.messageNotification("E2E Verify privateKey", description: "Error verify data encrypt/decrypt", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  128. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Verify privateKey, error verify data encrypt/decrypt", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  129. return
  130. }
  131. */
  132. // Save to keychain
  133. CCUtility.setEndToEndPrivateKeyCipher(self.appDelegate.activeAccount, privateKeyCipher: metadataNet.key)
  134. CCUtility.setEndToEndPassphrase(self.appDelegate.activeAccount, passphrase:passphrase)
  135. // request publicKey Server()
  136. self.getPublicKeyServer()
  137. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E PrivateKey present on Server and stored to keychain", type: k_activityTypeSuccess, verbose: false, activeUrl: "")
  138. })
  139. let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
  140. }
  141. alertController.addAction(ok)
  142. alertController.addAction(cancel)
  143. alertController.addTextField { (textField) -> Void in
  144. passphraseTextField = textField
  145. passphraseTextField?.placeholder = "Enter passphrase (12 words)"
  146. }
  147. appDelegate.activeMain.present(alertController, animated: true)
  148. }
  149. func getEndToEndPrivateKeyCipherFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  150. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: message as String!, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  151. switch errorCode {
  152. case 400:
  153. appDelegate.messageNotification("E2E privateKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  154. case 404:
  155. // message
  156. let e2ePassphrase = NYMnemonic.generateString(128, language: "english")
  157. let message = "\n" + NSLocalizedString("_e2e_settings_view_passphrase_", comment: "") + "\n\n" + e2ePassphrase!
  158. let alertController = UIAlertController(title: NSLocalizedString("_e2e_settings_title_", comment: ""), message: NSLocalizedString(message, comment: ""), preferredStyle: .alert)
  159. let OKAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { action in
  160. guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().encryptPrivateKey(self.appDelegate.activeUserID, directoryUser: self.appDelegate.directoryUser, passphrase: e2ePassphrase) else {
  161. self.appDelegate.messageNotification("E2E privateKey", description: "Error to create PrivateKey chiper", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  162. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Error to create PrivateKey chiper", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  163. return
  164. }
  165. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: self.appDelegate.activeAccount)
  166. metadataNet.action = actionStoreEndToEndPrivateKeyCipher
  167. metadataNet.key = privateKeyChiper
  168. metadataNet.password = e2ePassphrase
  169. self.appDelegate.addNetworkingOperationQueue(self.appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  170. }
  171. alertController.addAction(OKAction)
  172. appDelegate.activeMain.present(alertController, animated: true)
  173. case 409:
  174. appDelegate.messageNotification("E2E privateKey", description: "forbidden: the user can't access the private key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  175. default:
  176. appDelegate.messageNotification("E2E privateKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  177. }
  178. }
  179. func storeEnd(toEndPrivateKeyCipherSuccess metadataNet: CCMetadataNet!) {
  180. guard let privateKeyCipher = metadataNet.key else {
  181. appDelegate.messageNotification("E2E privateKey", description: "Error : privateKey not present", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  182. return
  183. }
  184. CCUtility.setEndToEndPrivateKeyCipher(appDelegate.activeAccount, privateKeyCipher: privateKeyCipher)
  185. CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase:metadataNet.password)
  186. // request publicKey Server()
  187. self.getPublicKeyServer()
  188. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionStoreEndToEndPrivateKeyCipher, note: "E2E PrivateKey stored on Server and stored locally", type: k_activityTypeSuccess, verbose: false, activeUrl: "")
  189. }
  190. func storeEnd(toEndPrivateKeyCipherFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  191. appDelegate.messageNotification("E2E sign privateKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  192. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionStoreEndToEndPrivateKeyCipher, note: message, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  193. }
  194. func deleteEnd(toEndPrivateKeySuccess metadataNet: CCMetadataNet!) {
  195. appDelegate.messageNotification("E2E delete privateKey", description: "Success", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.success, errorCode: 0)
  196. }
  197. func deleteEnd(toEndPrivateKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  198. appDelegate.messageNotification("E2E delete privateKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  199. }
  200. // --------------------------------------------------------------------------------------------
  201. // MARK: Manage Server PublicKey
  202. // --------------------------------------------------------------------------------------------
  203. func getEndToEndServerPublicKeySuccess(_ metadataNet: CCMetadataNet!) {
  204. CCUtility.setEndToEndPublicKeyServer(appDelegate.activeAccount, publicKey: metadataNet.key)
  205. // OK Activated
  206. NotificationCenter.default.post(name: Notification.Name("reloadManageEndToEndEncryption"), object: nil)
  207. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndServerPublicKey, note: "E2E Server PublicKey present on Server and stored to keychain", type: k_activityTypeSuccess, verbose: false, activeUrl: "")
  208. }
  209. func getEndToEndServerPublicKeyFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  210. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndServerPublicKey, note: message as String!, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  211. switch (errorCode) {
  212. case 400:
  213. appDelegate.messageNotification("E2E Server publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  214. case 404:
  215. appDelegate.messageNotification("E2E Server publicKey", description: "Server publickey doesn't exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  216. case 409:
  217. appDelegate.messageNotification("E2E Server publicKey", description: "forbidden: the user can't access the Server publickey", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  218. default:
  219. appDelegate.messageNotification("E2E Server publicKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  220. }
  221. }
  222. // --------------------------------------------------------------------------------------------
  223. // MARK: Mark/Delete Encrypted Folder
  224. // --------------------------------------------------------------------------------------------
  225. func markEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  226. print("E2E mark folder success")
  227. }
  228. func markEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  229. // Unauthorized
  230. if (errorCode == kOCErrorServerUnauthorized) {
  231. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  232. }
  233. if (errorCode != kOCErrorServerUnauthorized) {
  234. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  235. }
  236. }
  237. @objc func markEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  238. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  239. metadataNet.action = actionMarkEndToEndFolderEncrypted;
  240. metadataNet.fileID = metadata.fileID;
  241. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  242. }
  243. func deletemarkEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  244. print("E2E delete mark folder success")
  245. }
  246. func deletemarkEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  247. // Unauthorized
  248. if (errorCode == kOCErrorServerUnauthorized) {
  249. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  250. }
  251. if (errorCode != kOCErrorServerUnauthorized) {
  252. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  253. }
  254. }
  255. @objc func deletemarkEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  256. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  257. metadataNet.action = actionDeletemarkEndToEndFolderEncrypted;
  258. metadataNet.fileID = metadata.fileID;
  259. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  260. }
  261. // --------------------------------------------------------------------------------------------
  262. // MARK: Lock/Unlock Encrypted Folder
  263. // --------------------------------------------------------------------------------------------
  264. func unlockEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  265. print("E2E lock file success")
  266. }
  267. func unlockEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  268. // Unauthorized
  269. if (errorCode == kOCErrorServerUnauthorized) {
  270. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  271. }
  272. if (errorCode != kOCErrorServerUnauthorized) {
  273. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  274. }
  275. }
  276. @objc func unlockEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  277. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  278. metadataNet.action = actionUnlockEndToEndFolderEncrypted;
  279. metadataNet.fileID = metadata.fileID;
  280. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  281. }
  282. func lockEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  283. print("E2E lock file success")
  284. }
  285. func lockEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  286. // Unauthorized
  287. if (errorCode == kOCErrorServerUnauthorized) {
  288. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  289. }
  290. if (errorCode != kOCErrorServerUnauthorized) {
  291. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  292. }
  293. }
  294. @objc func lockEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  295. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  296. metadataNet.action = actionLockEndToEndFolderEncrypted;
  297. metadataNet.fileID = metadata.fileID;
  298. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  299. }
  300. // --------------------------------------------------------------------------------------------
  301. // MARK: Manage Metadata
  302. // --------------------------------------------------------------------------------------------
  303. func getEndToEndMetadataSuccess(_ metadataNet: CCMetadataNet!) {
  304. print("E2E get metadata file success")
  305. }
  306. func getEndToEndMetadataFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  307. // Unauthorized
  308. if (errorCode == kOCErrorServerUnauthorized) {
  309. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  310. }
  311. if (errorCode != kOCErrorServerUnauthorized) {
  312. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  313. }
  314. }
  315. @objc func getEndToEndMetadata(_ metadata: tableMetadata) {
  316. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  317. metadataNet.action = actionGetEndToEndMetadata;
  318. metadataNet.fileID = metadata.fileID;
  319. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  320. }
  321. }