NCEntoToEndInterface.swift 26 KB

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