NCManageEndToEndEncryption.m 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // NCManageEndToEndEncryption.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 13/10/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 "NCManageEndToEndEncryption.h"
  24. #import "AppDelegate.h"
  25. #import "CCNetworking.h"
  26. #import "NYMnemonic.h"
  27. #import "NCBridgeSwift.h"
  28. @implementation NCManageEndToEndEncryption
  29. -(id)init
  30. {
  31. XLFormDescriptor *form ;
  32. XLFormSectionDescriptor *section;
  33. XLFormRowDescriptor *row;
  34. form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_e2e_settings_", nil)];
  35. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilites];
  36. if (capabilities.endToEndEncryption == NO) {
  37. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_not_available_", nil)];
  38. [form addFormSection:section];
  39. return [super initWithForm:form];
  40. }
  41. // Section INITIALIZE -------------------------------------------------
  42. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
  43. [form addFormSection:section];
  44. // Inizializze e2e
  45. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"initE2E" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
  46. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  47. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  48. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  49. row.action.formSelector = @selector(initE2E:);
  50. [section addFormRow:row];
  51. // Section INITIALIZE -------------------------------------------------
  52. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
  53. [form addFormSection:section];
  54. // Inizializze e2e
  55. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"initE2E" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_e2e_settings_initialize_", nil)];
  56. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  57. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  58. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  59. row.action.formSelector = @selector(initE2E:);
  60. [section addFormRow:row];
  61. #ifdef DEBUG
  62. // Section DELETE KEYS -------------------------------------------------
  63. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"Delete server keys ", nil)];
  64. [form addFormSection:section];
  65. // Delete publicKey
  66. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePublicKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete PublicKey", nil)];
  67. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  68. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  69. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  70. row.action.formSelector = @selector(deletePublicKey:);
  71. [section addFormRow:row];
  72. // Delete privateKey
  73. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"deletePrivateKey" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"Delete PrivateKey", nil)];
  74. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  75. [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
  76. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  77. row.action.formSelector = @selector(deletePrivateKey:);
  78. [section addFormRow:row];
  79. #endif
  80. return [super initWithForm:form];
  81. }
  82. - (void)deletePublicKey:(XLFormRowDescriptor *)sender
  83. {
  84. [self deselectFormRow:sender];
  85. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  86. metadataNet.action = actionDeleteEndToEndPublicKey;
  87. [app addNetworkingOperationQueue:app.netQueue delegate:app.endToEndInterface metadataNet:metadataNet];
  88. }
  89. - (void)deletePrivateKey:(XLFormRowDescriptor *)sender
  90. {
  91. [self deselectFormRow:sender];
  92. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  93. metadataNet.action = actionDeleteEndToEndPrivateKey;
  94. [app addNetworkingOperationQueue:app.netQueue delegate:app.endToEndInterface metadataNet:metadataNet];
  95. }
  96. - (void)initE2E:(XLFormRowDescriptor *)sender
  97. {
  98. NSString *message;
  99. [self deselectFormRow:sender];
  100. // select Passphrase
  101. //app.e2ePassphrase = k_passphrase_test;
  102. app.e2ePassphrase = [NYMnemonic generateMnemonicString:@128 language:@"english"];
  103. if ([CCUtility isEndToEndEnabled:app.activeAccount]) {
  104. message = [NSString stringWithFormat:@"%@\n\n%@\n\n%@", NSLocalizedString(@"_e2e_settings_initialize_already_request_", nil), NSLocalizedString(@"_e2e_settings_view_passphrase_", nil), app.e2ePassphrase];
  105. } else {
  106. message = [NSString stringWithFormat:@"%@\n\n%@\n\n%@", NSLocalizedString(@"_e2e_settings_initialize_request_", nil), NSLocalizedString(@"_e2e_settings_view_passphrase_", nil), app.e2ePassphrase];
  107. }
  108. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_initialization_", nil) message:message preferredStyle:UIAlertControllerStyleAlert];
  109. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  110. NSLog(@"Cancel action");
  111. }];
  112. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  113. [self deletePublicKey:sender];
  114. [self deletePrivateKey:sender];
  115. [CCUtility initEndToEnd:app.activeAccount];
  116. }];
  117. [alertController addAction:cancelAction];
  118. [alertController addAction:okAction];
  119. [self presentViewController:alertController animated:YES completion:nil];
  120. }
  121. @end