Sfoglia il codice sorgente

Check that we are actually connected to an SQLCipher db

jason 6 anni fa
parent
commit
d92d1285ce
1 ha cambiato i file con 17 aggiunte e 0 eliminazioni
  1. 17 0
      src/fmdb/FMDatabase.m

+ 17 - 0
src/fmdb/FMDatabase.m

@@ -497,12 +497,29 @@ - (BOOL)goodConnection {
         return NO;
     }
     
+#ifdef SQLITE_HAS_CODEC
+    // Starting with Xcode8 / iOS 10 we check to make sure we really are linked with
+    // SQLCipher because there is no longer a linker error if we accidently link
+    // with unencrypted sqlite library.
+    //
+    // https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688
+    
+    FMResultSet *rs = [self executeQuery:@"PRAGMA cipher_version"];
+
+    if ([rs next]) {
+        NSLog(@"SQLCipher version: %@", rs.resultDictionary[@"cipher_version"]);
+        
+        [rs close];
+        return YES;
+    }
+#else
     FMResultSet *rs = [self executeQuery:@"select name from sqlite_master where type='table'"];
     
     if (rs) {
         [rs close];
         return YES;
     }
+#endif
     
     return NO;
 }