|
@@ -46,253 +46,257 @@ class NCEndToEndInitialize : NSObject {
|
|
|
// Clear all keys
|
|
|
CCUtility.clearAllKeysEnd(toEnd: appDelegate.activeAccount)
|
|
|
|
|
|
-
|
|
|
- //metadataNet.action = actionGetEndToEndPublicKeys
|
|
|
+ self.getPublicKey()
|
|
|
}
|
|
|
|
|
|
- func getPrivateKeyCipher() {
|
|
|
-
|
|
|
-
|
|
|
- //metadataNet.action = actionGetEndToEndPrivateKeyCipher
|
|
|
- }
|
|
|
-
|
|
|
- func getPublicKeyServer() {
|
|
|
-
|
|
|
-
|
|
|
- //metadataNet.action = actionGetEndToEndServerPublicKey
|
|
|
- }
|
|
|
-
|
|
|
- // --------------------------------------------------------------------------------------------
|
|
|
- // MARK: Manage PublicKey
|
|
|
- // --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- func getEndToEndPublicKeysSuccess(_ metadataNet: CCMetadataNet!) {
|
|
|
-
|
|
|
- CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: metadataNet.key)
|
|
|
-
|
|
|
- // Request PrivateKey chiper to Server
|
|
|
- getPrivateKeyCipher()
|
|
|
- }
|
|
|
+ func getPublicKey() {
|
|
|
|
|
|
- func getEndToEndPublicKeysFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
|
|
|
-
|
|
|
- switch errorCode {
|
|
|
-
|
|
|
- case 400:
|
|
|
- appDelegate.messageNotification("E2E get publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ NCNetworkingEndToEnd.sharedManager()?.getPublicKey(withAccount: appDelegate.activeAccount, completion: { (account, publicKey, message, errorCode) in
|
|
|
|
|
|
- case 404:
|
|
|
- guard let csr = NCEndToEndEncryption.sharedManager().createCSR(appDelegate.activeUserID, directory: CCUtility.getDirectoryUserData()) else {
|
|
|
+ if (errorCode == 0 && account == self.appDelegate.activeAccount) {
|
|
|
|
|
|
- appDelegate.messageNotification("E2E Csr", description: "Error to create Csr", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ CCUtility.setEndToEndPublicKey(account, publicKey: publicKey)
|
|
|
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- //let metadataNet: CCMetadataNet = CCMetadataNet.init(account: appDelegate.activeAccount)
|
|
|
-
|
|
|
- //metadataNet.action = actionSignEndToEndPublicKey;
|
|
|
- //metadataNet.key = csr;
|
|
|
-
|
|
|
- //appDelegate.addNetworkingOperationQueue(appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
|
|
|
-
|
|
|
- case 409:
|
|
|
- appDelegate.messageNotification("E2E get publicKey", description: "forbidden: the user can't access the public keys", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- default:
|
|
|
- appDelegate.messageNotification("E2E get publicKey", description: message as String, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func signEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
|
|
|
-
|
|
|
- CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: metadataNet.key)
|
|
|
-
|
|
|
- // Request PrivateKey chiper to Server
|
|
|
- getPrivateKeyCipher()
|
|
|
- }
|
|
|
-
|
|
|
- func signEnd(toEndPublicKeyFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
|
|
|
-
|
|
|
- switch errorCode {
|
|
|
-
|
|
|
- case 400:
|
|
|
- appDelegate.messageNotification("E2E sign publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- case 409:
|
|
|
- appDelegate.messageNotification("E2E sign publicKey", description: "conflict: a public key for the user already exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- default:
|
|
|
- appDelegate.messageNotification("E2E sign publicKey", description: message as String, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // --------------------------------------------------------------------------------------------
|
|
|
- // MARK: Manage PrivateKey
|
|
|
- // --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- func getEndToEndPrivateKeyCipherSuccess(_ metadataNet: CCMetadataNet!) {
|
|
|
-
|
|
|
- // request Passphrase
|
|
|
-
|
|
|
- var passphraseTextField: UITextField?
|
|
|
-
|
|
|
- let alertController = UIAlertController(title: NSLocalizedString("_e2e_passphrase_request_title_", comment: ""), message: NSLocalizedString("_e2e_passphrase_request_message_", comment: ""), preferredStyle: .alert)
|
|
|
-
|
|
|
- //TEST
|
|
|
- /*
|
|
|
- if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
|
|
|
-
|
|
|
- let fileURL = dir.appendingPathComponent("privatekey.txt")
|
|
|
-
|
|
|
- //writing
|
|
|
- do {
|
|
|
- try metadataNet.key.write(to: fileURL, atomically: false, encoding: .utf8)
|
|
|
- }
|
|
|
- catch {/* error handling here */}
|
|
|
- }
|
|
|
- */
|
|
|
- //
|
|
|
-
|
|
|
- let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
|
|
|
-
|
|
|
- let passphrase = passphraseTextField?.text
|
|
|
-
|
|
|
- let publicKey = CCUtility.getEndToEndPublicKey(self.appDelegate.activeAccount)
|
|
|
-
|
|
|
- guard let privateKey = (NCEndToEndEncryption.sharedManager().decryptPrivateKey(metadataNet.key, passphrase: passphrase, publicKey: publicKey)) else {
|
|
|
+ // Request PrivateKey chiper to Server
|
|
|
+ self.getPrivateKeyCipher()
|
|
|
|
|
|
- self.appDelegate.messageNotification("E2E decrypt privateKey", description: "Serious internal error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
|
|
|
+ } else if errorCode != 0 {
|
|
|
|
|
|
- return
|
|
|
+ switch errorCode {
|
|
|
+
|
|
|
+ case 400:
|
|
|
+ self.appDelegate.messageNotification("E2E get publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 404:
|
|
|
+ guard let csr = NCEndToEndEncryption.sharedManager().createCSR(self.appDelegate.activeUserID, directory: CCUtility.getDirectoryUserData()) else {
|
|
|
+
|
|
|
+ self.appDelegate.messageNotification("E2E Csr", description: "Error to create Csr", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ NCNetworkingEndToEnd.sharedManager()?.signPublicKey(withAccount: account, publicKey: csr, completion: { (account, publicKey, message, errorCode) in
|
|
|
+
|
|
|
+ if (errorCode == 0 && account == self.appDelegate.activeAccount) {
|
|
|
+
|
|
|
+ CCUtility.setEndToEndPublicKey(account, publicKey: publicKey)
|
|
|
+
|
|
|
+ // Request PrivateKey chiper to Server
|
|
|
+ self.getPrivateKeyCipher()
|
|
|
+
|
|
|
+ } else if errorCode != 0 {
|
|
|
+
|
|
|
+ switch errorCode {
|
|
|
+
|
|
|
+ case 400:
|
|
|
+ self.appDelegate.messageNotification("E2E sign publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 409:
|
|
|
+ self.appDelegate.messageNotification("E2E sign publicKey", description: "conflict: a public key for the user already exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ default:
|
|
|
+ self.appDelegate.messageNotification("E2E sign publicKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ case 409:
|
|
|
+ self.appDelegate.messageNotification("E2E get publicKey", description: "forbidden: the user can't access the public keys", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ default:
|
|
|
+ self.appDelegate.messageNotification("E2E get publicKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- // privateKey
|
|
|
- print(privateKey)
|
|
|
-
|
|
|
- // Save to keychain
|
|
|
- CCUtility.setEndToEndPrivateKey(self.appDelegate.activeAccount, privateKey: privateKey)
|
|
|
- CCUtility.setEndToEndPassphrase(self.appDelegate.activeAccount, passphrase:passphrase)
|
|
|
-
|
|
|
- // request publicKey Server()
|
|
|
- self.getPublicKeyServer()
|
|
|
})
|
|
|
-
|
|
|
- let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
|
|
|
- }
|
|
|
-
|
|
|
- alertController.addAction(ok)
|
|
|
- alertController.addAction(cancel)
|
|
|
- alertController.addTextField { (textField) -> Void in
|
|
|
- passphraseTextField = textField
|
|
|
- passphraseTextField?.placeholder = "Enter passphrase (12 words)"
|
|
|
- }
|
|
|
-
|
|
|
- appDelegate.activeMain.present(alertController, animated: true)
|
|
|
}
|
|
|
|
|
|
- func getEndToEndPrivateKeyCipherFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
|
|
|
+ func getPrivateKeyCipher() {
|
|
|
|
|
|
- switch errorCode {
|
|
|
-
|
|
|
- case 400:
|
|
|
- appDelegate.messageNotification("E2E get privateKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- case 404:
|
|
|
- // message
|
|
|
- let e2ePassphrase = NYMnemonic.generateString(128, language: "english")
|
|
|
- let message = "\n" + NSLocalizedString("_e2e_settings_view_passphrase_", comment: "") + "\n\n" + e2ePassphrase!
|
|
|
-
|
|
|
- let alertController = UIAlertController(title: NSLocalizedString("_e2e_settings_title_", comment: ""), message: NSLocalizedString(message, comment: ""), preferredStyle: .alert)
|
|
|
+ // Request PrivateKey chiper to Server
|
|
|
+ NCNetworkingEndToEnd.sharedManager()?.getPrivateKeyCipher(withAccount: appDelegate.activeAccount, completion: { (account, privateKeyChiper, message, errorCode) in
|
|
|
|
|
|
- let OKAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { action in
|
|
|
+ if (errorCode == 0 && account == self.appDelegate.activeAccount) {
|
|
|
|
|
|
- var privateKey: NSString?
|
|
|
+ // request Passphrase
|
|
|
|
|
|
- guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().encryptPrivateKey(self.appDelegate.activeUserID, directory: CCUtility.getDirectoryUserData(), passphrase: e2ePassphrase, privateKey: &privateKey) else {
|
|
|
+ var passphraseTextField: UITextField?
|
|
|
+
|
|
|
+ let alertController = UIAlertController(title: NSLocalizedString("_e2e_passphrase_request_title_", comment: ""), message: NSLocalizedString("_e2e_passphrase_request_message_", comment: ""), preferredStyle: .alert)
|
|
|
+
|
|
|
+ //TEST
|
|
|
+ /*
|
|
|
+ if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
|
|
|
+
|
|
|
+ let fileURL = dir.appendingPathComponent("privatekey.txt")
|
|
|
+
|
|
|
+ //writing
|
|
|
+ do {
|
|
|
+ try metadataNet.key.write(to: fileURL, atomically: false, encoding: .utf8)
|
|
|
+ }
|
|
|
+ catch {/* error handling here */}
|
|
|
+ }
|
|
|
+ */
|
|
|
+ //
|
|
|
+
|
|
|
+ let ok = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
|
|
|
+
|
|
|
+ let passphrase = passphraseTextField?.text
|
|
|
+
|
|
|
+ let publicKey = CCUtility.getEndToEndPublicKey(self.appDelegate.activeAccount)
|
|
|
+
|
|
|
+ guard let privateKey = (NCEndToEndEncryption.sharedManager().decryptPrivateKey(privateKeyChiper, passphrase: passphrase, publicKey: publicKey)) else {
|
|
|
+
|
|
|
+ self.appDelegate.messageNotification("E2E decrypt privateKey", description: "Serious internal error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: Int(k_CCErrorInternalError))
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // privateKey
|
|
|
+ print(privateKey)
|
|
|
|
|
|
- self.appDelegate.messageNotification("E2E privateKey", description: "Serious internal error to create PrivateKey chiper", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ // Save to keychain
|
|
|
+ CCUtility.setEndToEndPrivateKey(self.appDelegate.activeAccount, privateKey: privateKey)
|
|
|
+ CCUtility.setEndToEndPassphrase(self.appDelegate.activeAccount, passphrase:passphrase)
|
|
|
|
|
|
- return
|
|
|
+ // request publicKey Server()
|
|
|
+ NCNetworkingEndToEnd.sharedManager()?.getServerPublicKey(withAccount: account, completion: { (account, publicKey, message, errorCode) in
|
|
|
+
|
|
|
+ if (errorCode == 0 && account == self.appDelegate.activeAccount) {
|
|
|
+
|
|
|
+ CCUtility.setEndToEndPublicKeyServer(account, publicKey: publicKey)
|
|
|
+
|
|
|
+ // Clear Table
|
|
|
+ NCManageDatabase.sharedInstance.clearTable(tableDirectory.self, account: account)
|
|
|
+ NCManageDatabase.sharedInstance.clearTable(tableE2eEncryption.self, account: account)
|
|
|
+
|
|
|
+ self.delegate?.endToEndInitializeSuccess()
|
|
|
+
|
|
|
+ } else if errorCode != 0 {
|
|
|
+
|
|
|
+ switch (errorCode) {
|
|
|
+
|
|
|
+ case 400:
|
|
|
+ self.appDelegate.messageNotification("E2E Server publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 404:
|
|
|
+ self.appDelegate.messageNotification("E2E Server publicKey", description: "Server publickey doesn't exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 409:
|
|
|
+ self.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)
|
|
|
+
|
|
|
+ default:
|
|
|
+ self.appDelegate.messageNotification("E2E Server publicKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) -> Void in
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- let metadataNet: CCMetadataNet = CCMetadataNet.init(account: self.appDelegate.activeAccount)
|
|
|
-
|
|
|
- metadataNet.action = actionStoreEndToEndPrivateKeyCipher
|
|
|
- metadataNet.key = privateKey! as String
|
|
|
- metadataNet.keyCipher = privateKeyChiper
|
|
|
- metadataNet.password = e2ePassphrase
|
|
|
+ alertController.addAction(ok)
|
|
|
+ alertController.addAction(cancel)
|
|
|
+ alertController.addTextField { (textField) -> Void in
|
|
|
+ passphraseTextField = textField
|
|
|
+ passphraseTextField?.placeholder = "Enter passphrase (12 words)"
|
|
|
+ }
|
|
|
+
|
|
|
+ self.appDelegate.activeMain.present(alertController, animated: true)
|
|
|
+
|
|
|
+ } else if errorCode != 0 {
|
|
|
+
|
|
|
+ switch errorCode {
|
|
|
+
|
|
|
+ case 400:
|
|
|
+ self.appDelegate.messageNotification("E2E get privateKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 404:
|
|
|
+ // message
|
|
|
+ let e2ePassphrase = NYMnemonic.generateString(128, language: "english")
|
|
|
+ let message = "\n" + NSLocalizedString("_e2e_settings_view_passphrase_", comment: "") + "\n\n" + e2ePassphrase!
|
|
|
+
|
|
|
+ let alertController = UIAlertController(title: NSLocalizedString("_e2e_settings_title_", comment: ""), message: NSLocalizedString(message, comment: ""), preferredStyle: .alert)
|
|
|
+
|
|
|
+ let OKAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { action in
|
|
|
+
|
|
|
+ var privateKey: NSString?
|
|
|
+
|
|
|
+ guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().encryptPrivateKey(self.appDelegate.activeUserID, directory: CCUtility.getDirectoryUserData(), passphrase: e2ePassphrase, privateKey: &privateKey) else {
|
|
|
+
|
|
|
+ self.appDelegate.messageNotification("E2E privateKey", description: "Serious internal error to create PrivateKey chiper", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ NCNetworkingEndToEnd.sharedManager()?.storePrivateKeyCipher(withAccount: account, privateKeyChiper: privateKeyChiper, completion: { (account, privateKey, message, errorCode) in
|
|
|
+
|
|
|
+ if (errorCode == 0 && account == self.appDelegate.activeAccount) {
|
|
|
+
|
|
|
+ CCUtility.setEndToEndPrivateKey(account, privateKey: privateKey)
|
|
|
+ CCUtility.setEndToEndPassphrase(account, passphrase: e2ePassphrase)
|
|
|
+
|
|
|
+ // request publicKey Server()
|
|
|
+ NCNetworkingEndToEnd.sharedManager()?.getServerPublicKey(withAccount: account, completion: { (account, publicKey, message, errorCode) in
|
|
|
+
|
|
|
+ if (errorCode == 0 && account == self.appDelegate.activeAccount) {
|
|
|
+
|
|
|
+ CCUtility.setEndToEndPublicKeyServer(account, publicKey: publicKey)
|
|
|
+
|
|
|
+ // Clear Table
|
|
|
+ NCManageDatabase.sharedInstance.clearTable(tableDirectory.self, account: account)
|
|
|
+ NCManageDatabase.sharedInstance.clearTable(tableE2eEncryption.self, account: account)
|
|
|
+
|
|
|
+ self.delegate?.endToEndInitializeSuccess()
|
|
|
+
|
|
|
+ } else if errorCode != 0 {
|
|
|
+
|
|
|
+ switch (errorCode) {
|
|
|
+
|
|
|
+ case 400:
|
|
|
+ self.appDelegate.messageNotification("E2E Server publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 404:
|
|
|
+ self.appDelegate.messageNotification("E2E Server publicKey", description: "Server publickey doesn't exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 409:
|
|
|
+ self.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)
|
|
|
+
|
|
|
+ default:
|
|
|
+ self.appDelegate.messageNotification("E2E Server publicKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ } else if errorCode != 0 {
|
|
|
+
|
|
|
+ switch errorCode {
|
|
|
+
|
|
|
+ case 400:
|
|
|
+ self.appDelegate.messageNotification("E2E store privateKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ case 409:
|
|
|
+ self.appDelegate.messageNotification("E2E store privateKey", description: "conflict: a private key for the user already exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ default:
|
|
|
+ self.appDelegate.messageNotification("E2E store privateKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ alertController.addAction(OKAction)
|
|
|
+ self.appDelegate.activeMain.present(alertController, animated: true)
|
|
|
|
|
|
- self.appDelegate.addNetworkingOperationQueue(self.appDelegate.netQueue, delegate: self, metadataNet: metadataNet)
|
|
|
- */
|
|
|
+ case 409:
|
|
|
+ self.appDelegate.messageNotification("E2E get privateKey", description: "forbidden: the user can't access the private key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+
|
|
|
+ default:
|
|
|
+ self.appDelegate.messageNotification("E2E get privateKey", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- alertController.addAction(OKAction)
|
|
|
- appDelegate.activeMain.present(alertController, animated: true)
|
|
|
-
|
|
|
- case 409:
|
|
|
- appDelegate.messageNotification("E2E get privateKey", description: "forbidden: the user can't access the private key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- default:
|
|
|
- appDelegate.messageNotification("E2E get privateKey", description: message as String, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func storeEnd(toEndPrivateKeyCipherSuccess metadataNet: CCMetadataNet!) {
|
|
|
-
|
|
|
- CCUtility.setEndToEndPrivateKey(appDelegate.activeAccount, privateKey: metadataNet.key)
|
|
|
- CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase:metadataNet.password)
|
|
|
-
|
|
|
- // request publicKey Server()
|
|
|
- self.getPublicKeyServer()
|
|
|
- }
|
|
|
-
|
|
|
- func storeEnd(toEndPrivateKeyCipherFailure metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
|
|
|
-
|
|
|
- switch errorCode {
|
|
|
-
|
|
|
- case 400:
|
|
|
- appDelegate.messageNotification("E2E store privateKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- case 409:
|
|
|
- appDelegate.messageNotification("E2E store privateKey", description: "conflict: a private key for the user already exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
+ })
|
|
|
|
|
|
- default:
|
|
|
- appDelegate.messageNotification("E2E store privateKey", description: message as String, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- // --------------------------------------------------------------------------------------------
|
|
|
- // MARK: Manage Server PublicKey
|
|
|
- // --------------------------------------------------------------------------------------------
|
|
|
-
|
|
|
- func getEndToEndServerPublicKeySuccess(_ metadataNet: CCMetadataNet!) {
|
|
|
-
|
|
|
- CCUtility.setEndToEndPublicKeyServer(appDelegate.activeAccount, publicKey: metadataNet.key)
|
|
|
-
|
|
|
- // Clear Table
|
|
|
- NCManageDatabase.sharedInstance.clearTable(tableDirectory.self, account: appDelegate.activeAccount)
|
|
|
- NCManageDatabase.sharedInstance.clearTable(tableE2eEncryption.self, account: appDelegate.activeAccount)
|
|
|
-
|
|
|
- self.delegate?.endToEndInitializeSuccess()
|
|
|
- }
|
|
|
|
|
|
- func getEndToEndServerPublicKeyFailure(_ metadataNet: CCMetadataNet!, message: String!, errorCode: Int) {
|
|
|
-
|
|
|
- switch (errorCode) {
|
|
|
-
|
|
|
- case 400:
|
|
|
- appDelegate.messageNotification("E2E Server publicKey", description: "bad request: unpredictable internal error", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- case 404:
|
|
|
- appDelegate.messageNotification("E2E Server publicKey", description: "Server publickey doesn't exists", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
-
|
|
|
- case 409:
|
|
|
- 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)
|
|
|
-
|
|
|
- default:
|
|
|
- appDelegate.messageNotification("E2E Server publicKey", description: message as String, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
|
|
|
- }
|
|
|
- }
|
|
|
}
|