NCEntoToEndInterface.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. struct e2eMetadata: Codable {
  26. let files: [String:Element]
  27. struct Element: Codable {
  28. let key:String
  29. }
  30. }
  31. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  32. override init() {
  33. }
  34. // --------------------------------------------------------------------------------------------
  35. // MARK: Initialize
  36. // --------------------------------------------------------------------------------------------
  37. @objc func initEndToEndEncryption() {
  38. // Clear all keys
  39. CCUtility.clearAllKeysEnd(toEnd: appDelegate.activeAccount)
  40. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  41. metadataNet.action = actionGetEndToEndPublicKeys
  42. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  43. }
  44. func getPrivateKeyCipher() {
  45. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  46. metadataNet.action = actionGetEndToEndPrivateKeyCipher
  47. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  48. }
  49. func getPublicKeyServer() {
  50. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  51. metadataNet.action = actionGetEndToEndServerPublicKey
  52. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  53. }
  54. // --------------------------------------------------------------------------------------------
  55. // MARK: Manage PublicKey
  56. // --------------------------------------------------------------------------------------------
  57. func getEndToEndPublicKeysSuccess(_ metadataNet: CCMetadataNet!) {
  58. CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: metadataNet.key)
  59. // Request PrivateKey chiper to Server
  60. getPrivateKeyCipher()
  61. 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: "")
  62. }
  63. func getEndToEndPublicKeysFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  64. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPublicKeys, note: message as String!, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  65. switch errorCode {
  66. case 400:
  67. appDelegate.messageNotification("E2E publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  68. case 404:
  69. guard let csr = NCEndToEndEncryption.sharedManager().createCSR(appDelegate.activeUserID, directoryUser: appDelegate.directoryUser) else {
  70. appDelegate.messageNotification("E2E Csr", description: "Error to create Csr", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  71. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPublicKeys, note: "E2E Error to create Csr", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  72. return
  73. }
  74. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  75. metadataNet.action = actionSignEndToEndPublicKey;
  76. metadataNet.key = csr;
  77. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  78. case 409:
  79. 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)
  80. default:
  81. appDelegate.messageNotification("E2E publicKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  82. }
  83. }
  84. func signEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
  85. CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: metadataNet.key)
  86. // Request PrivateKey chiper to Server
  87. getPrivateKeyCipher()
  88. 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: "")
  89. }
  90. func signEnd(toEndPublicKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  91. appDelegate.messageNotification("E2E sign Csr - publicKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  92. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionSignEndToEndPublicKey, note: message, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  93. }
  94. func deleteEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
  95. appDelegate.messageNotification("E2E delete publicKey", description: "Success", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.success, errorCode: 0)
  96. }
  97. func deleteEnd(toEndPublicKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  98. appDelegate.messageNotification("E2E delete publicKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  99. }
  100. // --------------------------------------------------------------------------------------------
  101. // MARK: Manage PrivateKey
  102. // --------------------------------------------------------------------------------------------
  103. func getEndToEndPrivateKeyCipherSuccess(_ metadataNet: CCMetadataNet!) {
  104. // request Passphrase
  105. var passphraseTextField: UITextField?
  106. let alertController = UIAlertController(title: NSLocalizedString("_e2e_passphrase_request_title_", comment: ""), message: NSLocalizedString("_e2e_passphrase_request_message_", comment: ""), preferredStyle: .alert)
  107. //TEST
  108. /*
  109. if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
  110. let fileURL = dir.appendingPathComponent("privatekey.txt")
  111. //writing
  112. do {
  113. try metadataNet.key.write(to: fileURL, atomically: false, encoding: .utf8)
  114. }
  115. catch {/* error handling here */}
  116. }
  117. */
  118. //
  119. let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
  120. let passphrase = passphraseTextField?.text
  121. let publicKey = CCUtility.getEndToEndPublicKey(self.appDelegate.activeAccount)
  122. guard let privateKey = (NCEndToEndEncryption.sharedManager().decryptPrivateKey(metadataNet.key, passphrase: passphrase, publicKey: publicKey)) else {
  123. self.appDelegate.messageNotification("E2E decrypt privateKey", description: "Error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
  124. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Error to decrypt PrivateKey", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  125. return
  126. }
  127. // privateKey
  128. print(privateKey)
  129. // Save to keychain
  130. CCUtility.setEndToEndPrivateKeyCipher(self.appDelegate.activeAccount, privateKeyCipher: metadataNet.key)
  131. CCUtility.setEndToEndPassphrase(self.appDelegate.activeAccount, passphrase:passphrase)
  132. // request publicKey Server()
  133. self.getPublicKeyServer()
  134. 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: "")
  135. })
  136. let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
  137. }
  138. alertController.addAction(ok)
  139. alertController.addAction(cancel)
  140. alertController.addTextField { (textField) -> Void in
  141. passphraseTextField = textField
  142. passphraseTextField?.placeholder = "Enter passphrase (12 words)"
  143. }
  144. appDelegate.activeMain.present(alertController, animated: true)
  145. }
  146. func getEndToEndPrivateKeyCipherFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  147. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: message as String!, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  148. switch errorCode {
  149. case 400:
  150. appDelegate.messageNotification("E2E privateKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  151. case 404:
  152. // message
  153. let e2ePassphrase = NYMnemonic.generateString(128, language: "english")
  154. let message = "\n" + NSLocalizedString("_e2e_settings_view_passphrase_", comment: "") + "\n\n" + e2ePassphrase!
  155. let alertController = UIAlertController(title: NSLocalizedString("_e2e_settings_title_", comment: ""), message: NSLocalizedString(message, comment: ""), preferredStyle: .alert)
  156. let OKAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { action in
  157. guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().encryptPrivateKey(self.appDelegate.activeUserID, directoryUser: self.appDelegate.directoryUser, passphrase: e2ePassphrase) else {
  158. self.appDelegate.messageNotification("E2E privateKey", description: "Error to create PrivateKey chiper", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  159. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndPrivateKeyCipher, note: "E2E Error to create PrivateKey chiper", type: k_activityTypeFailure, verbose: false, activeUrl: "")
  160. return
  161. }
  162. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: self.appDelegate.activeAccount)
  163. metadataNet.action = actionStoreEndToEndPrivateKeyCipher
  164. metadataNet.key = privateKeyChiper
  165. metadataNet.password = e2ePassphrase
  166. self.appDelegate.addNetworkingOperationQueue(self.appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  167. }
  168. alertController.addAction(OKAction)
  169. appDelegate.activeMain.present(alertController, animated: true)
  170. case 409:
  171. 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)
  172. default:
  173. appDelegate.messageNotification("E2E privateKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  174. }
  175. }
  176. func storeEnd(toEndPrivateKeyCipherSuccess metadataNet: CCMetadataNet!) {
  177. CCUtility.setEndToEndPrivateKeyCipher(appDelegate.activeAccount, privateKeyCipher: metadataNet.key)
  178. CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase:metadataNet.password)
  179. // request publicKey Server()
  180. self.getPublicKeyServer()
  181. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionStoreEndToEndPrivateKeyCipher, note: "E2E PrivateKey stored on Server and stored locally", type: k_activityTypeSuccess, verbose: false, activeUrl: "")
  182. }
  183. func storeEnd(toEndPrivateKeyCipherFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  184. appDelegate.messageNotification("E2E sign privateKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  185. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionStoreEndToEndPrivateKeyCipher, note: message, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  186. }
  187. func deleteEnd(toEndPrivateKeySuccess metadataNet: CCMetadataNet!) {
  188. appDelegate.messageNotification("E2E delete privateKey", description: "Success", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.success, errorCode: 0)
  189. }
  190. func deleteEnd(toEndPrivateKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  191. appDelegate.messageNotification("E2E delete privateKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  192. }
  193. // --------------------------------------------------------------------------------------------
  194. // MARK: Manage Server PublicKey
  195. // --------------------------------------------------------------------------------------------
  196. func getEndToEndServerPublicKeySuccess(_ metadataNet: CCMetadataNet!) {
  197. CCUtility.setEndToEndPublicKeyServer(appDelegate.activeAccount, publicKey: metadataNet.key)
  198. // All OK Activated flsg on Manage EndToEnd Encryption
  199. NotificationCenter.default.post(name: Notification.Name("reloadManageEndToEndEncryption"), object: nil)
  200. 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: "")
  201. }
  202. func getEndToEndServerPublicKeyFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  203. NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionEndToEndEncryption, selector: actionGetEndToEndServerPublicKey, note: message as String!, type: k_activityTypeFailure, verbose: false, activeUrl: "")
  204. switch (errorCode) {
  205. case 400:
  206. appDelegate.messageNotification("E2E Server publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  207. case 404:
  208. appDelegate.messageNotification("E2E Server publicKey", description: "Server publickey doesn't exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  209. case 409:
  210. 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)
  211. default:
  212. appDelegate.messageNotification("E2E Server publicKey", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  213. }
  214. }
  215. // --------------------------------------------------------------------------------------------
  216. // MARK: Mark/Delete Encrypted Folder
  217. // --------------------------------------------------------------------------------------------
  218. func markEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  219. print("E2E mark folder success")
  220. }
  221. func markEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  222. // Unauthorized
  223. if (errorCode == kOCErrorServerUnauthorized) {
  224. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  225. }
  226. if (errorCode != kOCErrorServerUnauthorized) {
  227. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  228. }
  229. }
  230. @objc func markEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  231. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  232. metadataNet.action = actionMarkEndToEndFolderEncrypted;
  233. metadataNet.fileID = metadata.fileID;
  234. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  235. }
  236. func deletemarkEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  237. print("E2E delete mark folder success")
  238. }
  239. func deletemarkEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  240. // Unauthorized
  241. if (errorCode == kOCErrorServerUnauthorized) {
  242. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  243. }
  244. if (errorCode != kOCErrorServerUnauthorized) {
  245. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  246. }
  247. }
  248. @objc func deletemarkEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  249. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  250. metadataNet.action = actionDeletemarkEndToEndFolderEncrypted;
  251. metadataNet.fileID = metadata.fileID;
  252. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  253. }
  254. // --------------------------------------------------------------------------------------------
  255. // MARK: Lock/Unlock Encrypted Folder
  256. // --------------------------------------------------------------------------------------------
  257. func unlockEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  258. print("E2E lock file success")
  259. }
  260. func unlockEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  261. // Unauthorized
  262. if (errorCode == kOCErrorServerUnauthorized) {
  263. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  264. }
  265. if (errorCode != kOCErrorServerUnauthorized) {
  266. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  267. }
  268. }
  269. @objc func unlockEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  270. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  271. metadataNet.action = actionUnlockEndToEndFolderEncrypted;
  272. metadataNet.fileID = metadata.fileID;
  273. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  274. }
  275. func lockEnd(toEndFolderEncryptedSuccess metadataNet: CCMetadataNet!) {
  276. print("E2E lock file success")
  277. }
  278. func lockEnd(toEndFolderEncryptedFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  279. // Unauthorized
  280. if (errorCode == kOCErrorServerUnauthorized) {
  281. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  282. }
  283. if (errorCode != kOCErrorServerUnauthorized) {
  284. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  285. }
  286. }
  287. @objc func lockEndToEndFolderEncrypted(_ metadata: tableMetadata) {
  288. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  289. metadataNet.action = actionLockEndToEndFolderEncrypted;
  290. metadataNet.fileID = metadata.fileID;
  291. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  292. }
  293. // --------------------------------------------------------------------------------------------
  294. // MARK: Manage Metadata
  295. // --------------------------------------------------------------------------------------------
  296. func getEndToEndMetadataSuccess(_ metadataNet: CCMetadataNet!) {
  297. let decoder = JSONDecoder.init()
  298. let data = metadataNet.encryptedMetadata.data(using: .utf8)
  299. do {
  300. let response = try decoder.decode(e2eMetadata.self, from: data!)
  301. print(response)
  302. } catch let error {
  303. print("errore nella codifica dei dati", error)
  304. }
  305. print("E2E get metadata file success")
  306. }
  307. func getEndToEndMetadataFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
  308. // Unauthorized
  309. if (errorCode == kOCErrorServerUnauthorized) {
  310. appDelegate.openLoginView(appDelegate.activeMain, loginType: loginModifyPasswordUser)
  311. }
  312. if (errorCode != kOCErrorServerUnauthorized) {
  313. appDelegate.messageNotification("_error_", description: message as String!, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
  314. }
  315. }
  316. @objc func getEndToEndMetadata(_ metadata: tableMetadata) {
  317. let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
  318. metadataNet.action = actionGetEndToEndMetadata;
  319. metadataNet.fileID = metadata.fileID;
  320. appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
  321. }
  322. }