Kaynağa Gözat

change name of keychain for privateKeyChiper

Marino Faggiana 7 yıl önce
ebeveyn
işleme
6848b64e71

+ 7 - 13
iOSClient/Security/NCEntoToEndInterface.swift

@@ -85,8 +85,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
             
         case 404:
             
-            // public keys couldn't be found
-            // remove keychain
+            // public keys couldn't be found, remove keychain
             CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: nil)
             
             guard let csr = NCEndToEndEncryption.sharedManager().createCSR(appDelegate.activeUserID, directoryUser: appDelegate.directoryUser) else {
@@ -117,7 +116,6 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
 
     func signEnd(toEndPublicKeySuccess metadataNet: CCMetadataNet!) {
 
-        // Insert publicKey To Cheychain end delete
         guard let publicKey = metadataNet.key else {
             
             appDelegate.messageNotification("E2E publicKey", description: "Error : publicKey not present", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
@@ -125,7 +123,6 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
             return
         }
         
-        // OK signed key locally keychain
         CCUtility.setEndToEndPublicKey(appDelegate.activeAccount, publicKey: publicKey)
         
         getSignPublicKey = true
@@ -170,7 +167,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
             
             let passphrase = passphraseTextField?.text
             
-            guard let privateKey = NCEndToEndEncryption.sharedManager().decryptPrivateKey(metadataNet.key, passphrase: passphrase) else {
+            guard (NCEndToEndEncryption.sharedManager().decryptPrivateKey(metadataNet.key, passphrase: passphrase)) != nil else {
                 
                 self.appDelegate.messageNotification("E2E decrypt privateKey", description: "E2E Error to decrypt Private Key", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
                 
@@ -180,8 +177,7 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
             }
             
             // Save to keychain
-            CCUtility.setEndToEndPrivateKey(self.appDelegate.activeAccount, privateKey: privateKey)
-            // Save passphrase to keychain
+            CCUtility.setEndToEndPrivateKeyCipher(self.appDelegate.activeAccount, privateKeyCipher: metadataNet.key)
             CCUtility.setEndToEndPassphrase(self.appDelegate.activeAccount, passphrase:passphrase)
             
             self.getStorePrivateKey = true
@@ -220,9 +216,8 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
             
         case 404:
             
-            // private key couldn't be found
-            // remove keychain
-            CCUtility.setEndToEndPrivateKey(appDelegate.activeAccount, privateKey: nil)
+            // private key couldn't be found, remove keychain
+            CCUtility.setEndToEndPrivateKeyCipher(appDelegate.activeAccount, privateKeyCipher: nil)
             CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase: nil)
             
             // message
@@ -266,15 +261,14 @@ class NCEntoToEndInterface : NSObject, OCNetworkingDelegate  {
     
     func storeEnd(toEndPrivateKeyCipherSuccess metadataNet: CCMetadataNet!) {
         
-        // Insert PrivateKey (end delete) and passphrase to Cheychain
-        guard let privateKey = metadataNet.key else {
+        guard let privateKeyCipher = metadataNet.key else {
             
             appDelegate.messageNotification("E2E privateKey", description: "Error : privateKey not present", visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: 0)
             
             return
         }
         
-        CCUtility.setEndToEndPrivateKey(appDelegate.activeAccount, privateKey: privateKey)
+        CCUtility.setEndToEndPrivateKeyCipher(appDelegate.activeAccount, privateKeyCipher: privateKeyCipher)
         CCUtility.setEndToEndPassphrase(appDelegate.activeAccount, passphrase:metadataNet.password)
         
         getStorePrivateKey = true

+ 2 - 2
iOSClient/Utility/CCUtility.h

@@ -92,7 +92,7 @@
 + (void)setShowHiddenFiles:(BOOL)show;
 
 + (void)setEndToEndPublicKey:(NSString *)account publicKey:(NSString *)publicKey;
-+ (void)setEndToEndPrivateKey:(NSString *)account privateKey:(NSString *)privateKey;
++ (void)setEndToEndPrivateKeyCipher:(NSString *)account privateKeyCipher:(NSString *)privateKeyCipher;
 + (void)setEndToEndPassphrase:(NSString *)account passphrase:(NSString *)passphrase;
 + (void)initEndToEnd:(NSString *)account;
 
@@ -142,7 +142,7 @@
 + (BOOL)getShowHiddenFiles;
 
 + (NSString *)getEndToEndPublicKey:(NSString *)account;
-+ (NSString *)getEndToEndPrivateKey:(NSString *)account;
++ (NSString *)getEndToEndPrivateKeyCipher:(NSString *)account;
 + (NSString *)getEndToEndPassphrase:(NSString *)account;
 + (BOOL)isEndToEndEnabled:(NSString *)account;
 

+ 8 - 8
iOSClient/Utility/CCUtility.m

@@ -34,7 +34,7 @@
 #define INTRO_MessageType       @"MessageType_"
 
 #define E2E_PublicKey           @"EndToEndPublicKey_"
-#define E2E_PrivateKey          @"EndToEndPrivateKey_"
+#define E2E_PrivateKeyCipher    @"EndToEndPrivateKeyCipher_"
 #define E2E_Passphrase          @"EndToEndPassphrase_"
 
 
@@ -237,10 +237,10 @@
     [UICKeyChainStore setString:publicKey forKey:key service:k_serviceShareKeyChain];
 }
 
-+ (void)setEndToEndPrivateKey:(NSString *)account privateKey:(NSString *)privateKey
++ (void)setEndToEndPrivateKeyCipher:(NSString *)account privateKeyCipher:(NSString *)privateKeyCipher
 {
-    NSString *key = [E2E_PrivateKey stringByAppendingString:account];
-    [UICKeyChainStore setString:privateKey forKey:key service:k_serviceShareKeyChain];
+    NSString *key = [E2E_PrivateKeyCipher stringByAppendingString:account];
+    [UICKeyChainStore setString:privateKeyCipher forKey:key service:k_serviceShareKeyChain];
 }
 
 + (void)setEndToEndPassphrase:(NSString *)account passphrase:(NSString *)passphrase
@@ -252,7 +252,7 @@
 + (void)initEndToEnd:(NSString *)account
 {
     [self setEndToEndPublicKey:account publicKey:nil];
-    [self setEndToEndPrivateKey:account privateKey:nil];
+    [self setEndToEndPrivateKeyCipher:account privateKeyCipher:nil];
     [self setEndToEndPassphrase:account passphrase:nil];
 }
 
@@ -458,9 +458,9 @@
     return [UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain];
 }
 
-+ (NSString *)getEndToEndPrivateKey:(NSString *)account
++ (NSString *)getEndToEndPrivateKeyCipher:(NSString *)account
 {
-    NSString *key = [E2E_PrivateKey stringByAppendingString:account];
+    NSString *key = [E2E_PrivateKeyCipher stringByAppendingString:account];
     return [UICKeyChainStore stringForKey:key service:k_serviceShareKeyChain];
 }
 
@@ -473,7 +473,7 @@
 + (BOOL)isEndToEndEnabled:(NSString *)account
 {
     NSString *publicKey = [self getEndToEndPublicKey:account];
-    NSString *privateKey = [self getEndToEndPrivateKey:account];
+    NSString *privateKey = [self getEndToEndPrivateKeyCipher:account];
     NSString *passphrase = [self getEndToEndPassphrase:account];
     
     if (passphrase.length > 0 && privateKey.length > 0 && publicKey.length > 0) {