├── .gitignore ├── .travis.yml ├── Example ├── IOCipher.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ ├── IOCipherServer.xcscheme │ │ └── IOCipherTests.xcscheme ├── IOCipher.xcworkspace │ └── contents.xcworkspacedata ├── IOCipherServer │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── SQLVirtualFile.h │ ├── SQLVirtualFile.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── Podfile ├── Tests │ ├── IOCipherTests.m │ ├── Tests-Info.plist │ ├── Tests-Prefix.pch │ └── en.lproj │ │ └── InfoPlist.strings └── samples │ └── README.txt ├── IOCipher.podspec ├── IOCipher ├── GCDWebServer │ ├── GCDWebServerVirtualFileResponse.h │ └── GCDWebServerVirtualFileResponse.m ├── IOCipher.h └── IOCipher.m ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | # We recommend against adding the Pods directory to your .gitignore. However 26 | # you should judge for yourself, the pros and cons are mentioned at: 27 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 28 | # 29 | # Note: if you ignore the Pods directory, make sure to uncomment 30 | # `pod install` in .travis.yml 31 | # 32 | Example/Pods/ 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # references: 2 | # * http://www.objc.io/issue-6/travis-ci.html 3 | # * https://github.com/supermarin/xcpretty#usage 4 | 5 | language: objective-c 6 | # cache: cocoapods 7 | # podfile: Example/Podfile 8 | # before_install: 9 | # - gem install cocoapods # Since Travis is not always on latest version 10 | # - pod install --project-directory=Example 11 | # install: 12 | # - gem install xcpretty --no-rdoc --no-ri --no-document --quiet 13 | xcode_workspace: Example/IOCipher.xcworkspace 14 | xcode_scheme: IOCipherTests 15 | podfile: Example/Podfile 16 | script: 17 | - pod lib lint --quick 18 | - xcodebuild -workspace Example/IOCipher.xcworkspace -scheme IOCipherTests -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=latest' test 19 | 20 | -------------------------------------------------------------------------------- /Example/IOCipher.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; }; 11 | 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 12 | 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; 13 | 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; }; 14 | 695A358EE80A777D9D25C50F /* libPods-IOCipherServer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5736EA9D33097C7791A9EC12 /* libPods-IOCipherServer.a */; }; 15 | D9111DBA1A71B9C2004AFD08 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D9111DB91A71B9C2004AFD08 /* main.m */; }; 16 | D9111DBD1A71B9C2004AFD08 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D9111DBC1A71B9C2004AFD08 /* AppDelegate.m */; }; 17 | D9111DC01A71B9C2004AFD08 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D9111DBF1A71B9C2004AFD08 /* ViewController.m */; }; 18 | D9111DC31A71B9C2004AFD08 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D9111DC11A71B9C2004AFD08 /* Main.storyboard */; }; 19 | D9111DC51A71B9C2004AFD08 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D9111DC41A71B9C2004AFD08 /* Images.xcassets */; }; 20 | D9111DC81A71B9C2004AFD08 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D9111DC61A71B9C2004AFD08 /* LaunchScreen.xib */; }; 21 | D9111E221A71BDA4004AFD08 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D9111E211A71BDA4004AFD08 /* libz.dylib */; }; 22 | D9111E241A71C014004AFD08 /* samples in Resources */ = {isa = PBXBuildFile; fileRef = D9111E231A71C014004AFD08 /* samples */; }; 23 | D9111E291A71C0B6004AFD08 /* SQLVirtualFile.m in Sources */ = {isa = PBXBuildFile; fileRef = D9111E281A71C0B6004AFD08 /* SQLVirtualFile.m */; }; 24 | D9111E2E1A71EA0B004AFD08 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9111E2D1A71EA0B004AFD08 /* MediaPlayer.framework */; }; 25 | D964F2A41A83EE3D00CFF26D /* libPods-IOCipherTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D964F2A31A83EE3D00CFF26D /* libPods-IOCipherTests.a */; }; 26 | D9C89F3C1A6F0624001C8ECA /* IOCipherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D9C89F3B1A6F0624001C8ECA /* IOCipherTests.m */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 0227BFB7F7600F87F4962B21 /* Pods-IOCipherServer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IOCipherServer.debug.xcconfig"; path = "Pods/Target Support Files/Pods-IOCipherServer/Pods-IOCipherServer.debug.xcconfig"; sourceTree = ""; }; 31 | 5736EA9D33097C7791A9EC12 /* libPods-IOCipherServer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-IOCipherServer.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 6003F58A195388D20070C39A /* IOCipher.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IOCipher.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 34 | 6003F58F195388D20070C39A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 35 | 6003F591195388D20070C39A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 36 | 6003F5AE195388D20070C39A /* IOCipherTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IOCipherTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 6003F5AF195388D20070C39A /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 38 | 6003F5B7195388D20070C39A /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; }; 39 | 6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 40 | 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; 41 | 618E01500FDC49A3023C0894 /* Pods-IOCipherTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IOCipherTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-IOCipherTests/Pods-IOCipherTests.release.xcconfig"; sourceTree = ""; }; 42 | 622E0FDC898D852AC3992DDC /* IOCipher.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = IOCipher.podspec; path = ../IOCipher.podspec; sourceTree = ""; }; 43 | 702208B5DE99E6265864829B /* libPods-IOCipher.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-IOCipher.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 8AB2EF51F465253A30F46D88 /* libPods-IOCipherTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-IOCipherTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 8E0A4C5E4572D469BBA87962 /* Pods-IOCipherServer.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IOCipherServer.release.xcconfig"; path = "Pods/Target Support Files/Pods-IOCipherServer/Pods-IOCipherServer.release.xcconfig"; sourceTree = ""; }; 46 | C8240088979CCA2033A1C9CB /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 47 | D9111DB51A71B9C1004AFD08 /* IOCipherServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IOCipherServer.app; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | D9111DB81A71B9C2004AFD08 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | D9111DB91A71B9C2004AFD08 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 50 | D9111DBB1A71B9C2004AFD08 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 51 | D9111DBC1A71B9C2004AFD08 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 52 | D9111DBE1A71B9C2004AFD08 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 53 | D9111DBF1A71B9C2004AFD08 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 54 | D9111DC21A71B9C2004AFD08 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 55 | D9111DC41A71B9C2004AFD08 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 56 | D9111DC71A71B9C2004AFD08 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 57 | D9111E1D1A71BBAA004AFD08 /* IOCipher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOCipher.h; sourceTree = ""; }; 58 | D9111E1E1A71BBAA004AFD08 /* IOCipher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOCipher.m; sourceTree = ""; }; 59 | D9111E211A71BDA4004AFD08 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 60 | D9111E231A71C014004AFD08 /* samples */ = {isa = PBXFileReference; lastKnownFileType = folder; path = samples; sourceTree = SOURCE_ROOT; }; 61 | D9111E271A71C0B6004AFD08 /* SQLVirtualFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLVirtualFile.h; sourceTree = ""; }; 62 | D9111E281A71C0B6004AFD08 /* SQLVirtualFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SQLVirtualFile.m; sourceTree = ""; }; 63 | D9111E2D1A71EA0B004AFD08 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; 64 | D964F2A31A83EE3D00CFF26D /* libPods-IOCipherTests.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-IOCipherTests.a"; path = "Pods/build/Debug-iphoneos/libPods-IOCipherTests.a"; sourceTree = ""; }; 65 | D964F2A81A83EF0E00CFF26D /* Pods-IOCipherTests.debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "Pods-IOCipherTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-IOCipherTests/Pods-IOCipherTests.debug.xcconfig"; sourceTree = ""; }; 66 | D9C89F3B1A6F0624001C8ECA /* IOCipherTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOCipherTests.m; sourceTree = ""; }; 67 | ED48EF81DCE538EA97AB038E /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 68 | /* End PBXFileReference section */ 69 | 70 | /* Begin PBXFrameworksBuildPhase section */ 71 | 6003F5AB195388D20070C39A /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | D964F2A41A83EE3D00CFF26D /* libPods-IOCipherTests.a in Frameworks */, 76 | 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */, 77 | 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */, 78 | 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */, 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | D9111DB21A71B9C1004AFD08 /* Frameworks */ = { 83 | isa = PBXFrameworksBuildPhase; 84 | buildActionMask = 2147483647; 85 | files = ( 86 | D9111E2E1A71EA0B004AFD08 /* MediaPlayer.framework in Frameworks */, 87 | D9111E221A71BDA4004AFD08 /* libz.dylib in Frameworks */, 88 | 695A358EE80A777D9D25C50F /* libPods-IOCipherServer.a in Frameworks */, 89 | ); 90 | runOnlyForDeploymentPostprocessing = 0; 91 | }; 92 | /* End PBXFrameworksBuildPhase section */ 93 | 94 | /* Begin PBXGroup section */ 95 | 0D337C4650E6AF9FF11EDFEC /* Pods */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 0227BFB7F7600F87F4962B21 /* Pods-IOCipherServer.debug.xcconfig */, 99 | 8E0A4C5E4572D469BBA87962 /* Pods-IOCipherServer.release.xcconfig */, 100 | 618E01500FDC49A3023C0894 /* Pods-IOCipherTests.release.xcconfig */, 101 | D964F2A81A83EF0E00CFF26D /* Pods-IOCipherTests.debug.xcconfig */, 102 | ); 103 | name = Pods; 104 | sourceTree = ""; 105 | }; 106 | 6003F581195388D10070C39A = { 107 | isa = PBXGroup; 108 | children = ( 109 | 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */, 110 | 6003F5B5195388D20070C39A /* Tests */, 111 | D9111DB61A71B9C1004AFD08 /* IOCipherServer */, 112 | 6003F58C195388D20070C39A /* Frameworks */, 113 | 6003F58B195388D20070C39A /* Products */, 114 | 0D337C4650E6AF9FF11EDFEC /* Pods */, 115 | ); 116 | sourceTree = ""; 117 | }; 118 | 6003F58B195388D20070C39A /* Products */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 6003F58A195388D20070C39A /* IOCipher.app */, 122 | 6003F5AE195388D20070C39A /* IOCipherTests.xctest */, 123 | D9111DB51A71B9C1004AFD08 /* IOCipherServer.app */, 124 | ); 125 | name = Products; 126 | sourceTree = ""; 127 | }; 128 | 6003F58C195388D20070C39A /* Frameworks */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | D964F2A31A83EE3D00CFF26D /* libPods-IOCipherTests.a */, 132 | D9111E2D1A71EA0B004AFD08 /* MediaPlayer.framework */, 133 | D9111E211A71BDA4004AFD08 /* libz.dylib */, 134 | 6003F58D195388D20070C39A /* Foundation.framework */, 135 | 6003F58F195388D20070C39A /* CoreGraphics.framework */, 136 | 6003F591195388D20070C39A /* UIKit.framework */, 137 | 6003F5AF195388D20070C39A /* XCTest.framework */, 138 | 702208B5DE99E6265864829B /* libPods-IOCipher.a */, 139 | 5736EA9D33097C7791A9EC12 /* libPods-IOCipherServer.a */, 140 | 8AB2EF51F465253A30F46D88 /* libPods-IOCipherTests.a */, 141 | ); 142 | name = Frameworks; 143 | sourceTree = ""; 144 | }; 145 | 6003F5B5195388D20070C39A /* Tests */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | D9C89F3B1A6F0624001C8ECA /* IOCipherTests.m */, 149 | 6003F5B6195388D20070C39A /* Supporting Files */, 150 | ); 151 | path = Tests; 152 | sourceTree = ""; 153 | }; 154 | 6003F5B6195388D20070C39A /* Supporting Files */ = { 155 | isa = PBXGroup; 156 | children = ( 157 | 6003F5B7195388D20070C39A /* Tests-Info.plist */, 158 | 6003F5B8195388D20070C39A /* InfoPlist.strings */, 159 | 606FC2411953D9B200FFA9A0 /* Tests-Prefix.pch */, 160 | ); 161 | name = "Supporting Files"; 162 | sourceTree = ""; 163 | }; 164 | 60FF7A9C1954A5C5007DD14C /* Podspec Metadata */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | 622E0FDC898D852AC3992DDC /* IOCipher.podspec */, 168 | C8240088979CCA2033A1C9CB /* README.md */, 169 | ED48EF81DCE538EA97AB038E /* LICENSE */, 170 | ); 171 | name = "Podspec Metadata"; 172 | sourceTree = ""; 173 | }; 174 | D9111DB61A71B9C1004AFD08 /* IOCipherServer */ = { 175 | isa = PBXGroup; 176 | children = ( 177 | D9111E271A71C0B6004AFD08 /* SQLVirtualFile.h */, 178 | D9111E281A71C0B6004AFD08 /* SQLVirtualFile.m */, 179 | D9111E231A71C014004AFD08 /* samples */, 180 | D9111E1B1A71BBAA004AFD08 /* IOCipher */, 181 | D9111DBB1A71B9C2004AFD08 /* AppDelegate.h */, 182 | D9111DBC1A71B9C2004AFD08 /* AppDelegate.m */, 183 | D9111DBE1A71B9C2004AFD08 /* ViewController.h */, 184 | D9111DBF1A71B9C2004AFD08 /* ViewController.m */, 185 | D9111DC11A71B9C2004AFD08 /* Main.storyboard */, 186 | D9111DC41A71B9C2004AFD08 /* Images.xcassets */, 187 | D9111DC61A71B9C2004AFD08 /* LaunchScreen.xib */, 188 | D9111DB71A71B9C2004AFD08 /* Supporting Files */, 189 | ); 190 | path = IOCipherServer; 191 | sourceTree = ""; 192 | }; 193 | D9111DB71A71B9C2004AFD08 /* Supporting Files */ = { 194 | isa = PBXGroup; 195 | children = ( 196 | D9111DB81A71B9C2004AFD08 /* Info.plist */, 197 | D9111DB91A71B9C2004AFD08 /* main.m */, 198 | ); 199 | name = "Supporting Files"; 200 | sourceTree = ""; 201 | }; 202 | D9111E1B1A71BBAA004AFD08 /* IOCipher */ = { 203 | isa = PBXGroup; 204 | children = ( 205 | D9111E1D1A71BBAA004AFD08 /* IOCipher.h */, 206 | D9111E1E1A71BBAA004AFD08 /* IOCipher.m */, 207 | ); 208 | name = IOCipher; 209 | path = ../../Pod/Classes; 210 | sourceTree = ""; 211 | }; 212 | /* End PBXGroup section */ 213 | 214 | /* Begin PBXNativeTarget section */ 215 | 6003F5AD195388D20070C39A /* IOCipherTests */ = { 216 | isa = PBXNativeTarget; 217 | buildConfigurationList = 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "IOCipherTests" */; 218 | buildPhases = ( 219 | C31B71F0D1A4C411D81C3AED /* Check Pods Manifest.lock */, 220 | 6003F5AA195388D20070C39A /* Sources */, 221 | 6003F5AB195388D20070C39A /* Frameworks */, 222 | 6003F5AC195388D20070C39A /* Resources */, 223 | BD2C90F05A6F7AA001CFB651 /* Copy Pods Resources */, 224 | ); 225 | buildRules = ( 226 | ); 227 | dependencies = ( 228 | ); 229 | name = IOCipherTests; 230 | productName = IOCipherTests; 231 | productReference = 6003F5AE195388D20070C39A /* IOCipherTests.xctest */; 232 | productType = "com.apple.product-type.bundle.unit-test"; 233 | }; 234 | D9111DB41A71B9C1004AFD08 /* IOCipherServer */ = { 235 | isa = PBXNativeTarget; 236 | buildConfigurationList = D9111DD91A71B9C2004AFD08 /* Build configuration list for PBXNativeTarget "IOCipherServer" */; 237 | buildPhases = ( 238 | 0679B82330BAFD070978CB90 /* Check Pods Manifest.lock */, 239 | D9111DB11A71B9C1004AFD08 /* Sources */, 240 | D9111DB21A71B9C1004AFD08 /* Frameworks */, 241 | D9111DB31A71B9C1004AFD08 /* Resources */, 242 | E754D09D31589E1C53DC9C30 /* Copy Pods Resources */, 243 | ); 244 | buildRules = ( 245 | ); 246 | dependencies = ( 247 | ); 248 | name = IOCipherServer; 249 | productName = IOCipherServer; 250 | productReference = D9111DB51A71B9C1004AFD08 /* IOCipherServer.app */; 251 | productType = "com.apple.product-type.application"; 252 | }; 253 | /* End PBXNativeTarget section */ 254 | 255 | /* Begin PBXProject section */ 256 | 6003F582195388D10070C39A /* Project object */ = { 257 | isa = PBXProject; 258 | attributes = { 259 | CLASSPREFIX = SQL; 260 | LastUpgradeCheck = 0510; 261 | ORGANIZATIONNAME = "Chris Ballinger"; 262 | TargetAttributes = { 263 | 6003F5AD195388D20070C39A = { 264 | TestTargetID = 6003F589195388D20070C39A; 265 | }; 266 | D9111DB41A71B9C1004AFD08 = { 267 | CreatedOnToolsVersion = 6.1.1; 268 | }; 269 | }; 270 | }; 271 | buildConfigurationList = 6003F585195388D10070C39A /* Build configuration list for PBXProject "IOCipher" */; 272 | compatibilityVersion = "Xcode 3.2"; 273 | developmentRegion = English; 274 | hasScannedForEncodings = 0; 275 | knownRegions = ( 276 | en, 277 | Base, 278 | ); 279 | mainGroup = 6003F581195388D10070C39A; 280 | productRefGroup = 6003F58B195388D20070C39A /* Products */; 281 | projectDirPath = ""; 282 | projectRoot = ""; 283 | targets = ( 284 | 6003F5AD195388D20070C39A /* IOCipherTests */, 285 | D9111DB41A71B9C1004AFD08 /* IOCipherServer */, 286 | ); 287 | }; 288 | /* End PBXProject section */ 289 | 290 | /* Begin PBXResourcesBuildPhase section */ 291 | 6003F5AC195388D20070C39A /* Resources */ = { 292 | isa = PBXResourcesBuildPhase; 293 | buildActionMask = 2147483647; 294 | files = ( 295 | 6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */, 296 | ); 297 | runOnlyForDeploymentPostprocessing = 0; 298 | }; 299 | D9111DB31A71B9C1004AFD08 /* Resources */ = { 300 | isa = PBXResourcesBuildPhase; 301 | buildActionMask = 2147483647; 302 | files = ( 303 | D9111E241A71C014004AFD08 /* samples in Resources */, 304 | D9111DC31A71B9C2004AFD08 /* Main.storyboard in Resources */, 305 | D9111DC81A71B9C2004AFD08 /* LaunchScreen.xib in Resources */, 306 | D9111DC51A71B9C2004AFD08 /* Images.xcassets in Resources */, 307 | ); 308 | runOnlyForDeploymentPostprocessing = 0; 309 | }; 310 | /* End PBXResourcesBuildPhase section */ 311 | 312 | /* Begin PBXShellScriptBuildPhase section */ 313 | 0679B82330BAFD070978CB90 /* Check Pods Manifest.lock */ = { 314 | isa = PBXShellScriptBuildPhase; 315 | buildActionMask = 2147483647; 316 | files = ( 317 | ); 318 | inputPaths = ( 319 | ); 320 | name = "Check Pods Manifest.lock"; 321 | outputPaths = ( 322 | ); 323 | runOnlyForDeploymentPostprocessing = 0; 324 | shellPath = /bin/sh; 325 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 326 | showEnvVarsInLog = 0; 327 | }; 328 | BD2C90F05A6F7AA001CFB651 /* Copy Pods Resources */ = { 329 | isa = PBXShellScriptBuildPhase; 330 | buildActionMask = 2147483647; 331 | files = ( 332 | ); 333 | inputPaths = ( 334 | ); 335 | name = "Copy Pods Resources"; 336 | outputPaths = ( 337 | ); 338 | runOnlyForDeploymentPostprocessing = 0; 339 | shellPath = /bin/sh; 340 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-IOCipherTests/Pods-IOCipherTests-resources.sh\"\n"; 341 | showEnvVarsInLog = 0; 342 | }; 343 | C31B71F0D1A4C411D81C3AED /* Check Pods Manifest.lock */ = { 344 | isa = PBXShellScriptBuildPhase; 345 | buildActionMask = 2147483647; 346 | files = ( 347 | ); 348 | inputPaths = ( 349 | ); 350 | name = "Check Pods Manifest.lock"; 351 | outputPaths = ( 352 | ); 353 | runOnlyForDeploymentPostprocessing = 0; 354 | shellPath = /bin/sh; 355 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 356 | showEnvVarsInLog = 0; 357 | }; 358 | E754D09D31589E1C53DC9C30 /* Copy Pods Resources */ = { 359 | isa = PBXShellScriptBuildPhase; 360 | buildActionMask = 2147483647; 361 | files = ( 362 | ); 363 | inputPaths = ( 364 | ); 365 | name = "Copy Pods Resources"; 366 | outputPaths = ( 367 | ); 368 | runOnlyForDeploymentPostprocessing = 0; 369 | shellPath = /bin/sh; 370 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-IOCipherServer/Pods-IOCipherServer-resources.sh\"\n"; 371 | showEnvVarsInLog = 0; 372 | }; 373 | /* End PBXShellScriptBuildPhase section */ 374 | 375 | /* Begin PBXSourcesBuildPhase section */ 376 | 6003F5AA195388D20070C39A /* Sources */ = { 377 | isa = PBXSourcesBuildPhase; 378 | buildActionMask = 2147483647; 379 | files = ( 380 | D9C89F3C1A6F0624001C8ECA /* IOCipherTests.m in Sources */, 381 | ); 382 | runOnlyForDeploymentPostprocessing = 0; 383 | }; 384 | D9111DB11A71B9C1004AFD08 /* Sources */ = { 385 | isa = PBXSourcesBuildPhase; 386 | buildActionMask = 2147483647; 387 | files = ( 388 | D9111E291A71C0B6004AFD08 /* SQLVirtualFile.m in Sources */, 389 | D9111DC01A71B9C2004AFD08 /* ViewController.m in Sources */, 390 | D9111DBD1A71B9C2004AFD08 /* AppDelegate.m in Sources */, 391 | D9111DBA1A71B9C2004AFD08 /* main.m in Sources */, 392 | ); 393 | runOnlyForDeploymentPostprocessing = 0; 394 | }; 395 | /* End PBXSourcesBuildPhase section */ 396 | 397 | /* Begin PBXVariantGroup section */ 398 | 6003F5B8195388D20070C39A /* InfoPlist.strings */ = { 399 | isa = PBXVariantGroup; 400 | children = ( 401 | 6003F5B9195388D20070C39A /* en */, 402 | ); 403 | name = InfoPlist.strings; 404 | sourceTree = ""; 405 | }; 406 | D9111DC11A71B9C2004AFD08 /* Main.storyboard */ = { 407 | isa = PBXVariantGroup; 408 | children = ( 409 | D9111DC21A71B9C2004AFD08 /* Base */, 410 | ); 411 | name = Main.storyboard; 412 | sourceTree = ""; 413 | }; 414 | D9111DC61A71B9C2004AFD08 /* LaunchScreen.xib */ = { 415 | isa = PBXVariantGroup; 416 | children = ( 417 | D9111DC71A71B9C2004AFD08 /* Base */, 418 | ); 419 | name = LaunchScreen.xib; 420 | sourceTree = ""; 421 | }; 422 | /* End PBXVariantGroup section */ 423 | 424 | /* Begin XCBuildConfiguration section */ 425 | 6003F5BE195388D20070C39A /* Release */ = { 426 | isa = XCBuildConfiguration; 427 | buildSettings = { 428 | ALWAYS_SEARCH_USER_PATHS = NO; 429 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 430 | CLANG_CXX_LIBRARY = "libc++"; 431 | CLANG_ENABLE_MODULES = YES; 432 | CLANG_ENABLE_OBJC_ARC = YES; 433 | CLANG_WARN_BOOL_CONVERSION = YES; 434 | CLANG_WARN_CONSTANT_CONVERSION = YES; 435 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 436 | CLANG_WARN_EMPTY_BODY = YES; 437 | CLANG_WARN_ENUM_CONVERSION = YES; 438 | CLANG_WARN_INT_CONVERSION = YES; 439 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 440 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 441 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 442 | COPY_PHASE_STRIP = YES; 443 | ENABLE_NS_ASSERTIONS = NO; 444 | GCC_C_LANGUAGE_STANDARD = gnu99; 445 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 446 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 447 | GCC_WARN_UNDECLARED_SELECTOR = YES; 448 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 449 | GCC_WARN_UNUSED_FUNCTION = YES; 450 | GCC_WARN_UNUSED_VARIABLE = YES; 451 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 452 | SDKROOT = iphoneos; 453 | TARGETED_DEVICE_FAMILY = "1,2"; 454 | VALIDATE_PRODUCT = YES; 455 | }; 456 | name = Release; 457 | }; 458 | 6003F5C4195388D20070C39A /* Release */ = { 459 | isa = XCBuildConfiguration; 460 | baseConfigurationReference = 618E01500FDC49A3023C0894 /* Pods-IOCipherTests.release.xcconfig */; 461 | buildSettings = { 462 | FRAMEWORK_SEARCH_PATHS = ( 463 | "$(SDKROOT)/Developer/Library/Frameworks", 464 | "$(inherited)", 465 | "$(DEVELOPER_FRAMEWORKS_DIR)", 466 | ); 467 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 468 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; 469 | INFOPLIST_FILE = "Tests/Tests-Info.plist"; 470 | LIBRARY_SEARCH_PATHS = ( 471 | "$(inherited)", 472 | "$(PROJECT_DIR)/Pods/build/Debug-iphoneos", 473 | ); 474 | PRODUCT_NAME = "$(TARGET_NAME)"; 475 | TEST_HOST = "$(BUNDLE_LOADER)"; 476 | WRAPPER_EXTENSION = xctest; 477 | }; 478 | name = Release; 479 | }; 480 | D9111DD61A71B9C2004AFD08 /* Release */ = { 481 | isa = XCBuildConfiguration; 482 | baseConfigurationReference = 8E0A4C5E4572D469BBA87962 /* Pods-IOCipherServer.release.xcconfig */; 483 | buildSettings = { 484 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 485 | CLANG_WARN_UNREACHABLE_CODE = YES; 486 | ENABLE_STRICT_OBJC_MSGSEND = YES; 487 | INFOPLIST_FILE = IOCipherServer/Info.plist; 488 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 489 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 490 | MTL_ENABLE_DEBUG_INFO = NO; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | }; 493 | name = Release; 494 | }; 495 | D964F2A51A83EE5600CFF26D /* Debug */ = { 496 | isa = XCBuildConfiguration; 497 | buildSettings = { 498 | ALWAYS_SEARCH_USER_PATHS = NO; 499 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 500 | CLANG_CXX_LIBRARY = "libc++"; 501 | CLANG_ENABLE_MODULES = YES; 502 | CLANG_ENABLE_OBJC_ARC = YES; 503 | CLANG_WARN_BOOL_CONVERSION = YES; 504 | CLANG_WARN_CONSTANT_CONVERSION = YES; 505 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 506 | CLANG_WARN_EMPTY_BODY = YES; 507 | CLANG_WARN_ENUM_CONVERSION = YES; 508 | CLANG_WARN_INT_CONVERSION = YES; 509 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 510 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 511 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 512 | COPY_PHASE_STRIP = YES; 513 | ENABLE_NS_ASSERTIONS = NO; 514 | GCC_C_LANGUAGE_STANDARD = gnu99; 515 | GCC_OPTIMIZATION_LEVEL = 0; 516 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 517 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 518 | GCC_WARN_UNDECLARED_SELECTOR = YES; 519 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 520 | GCC_WARN_UNUSED_FUNCTION = YES; 521 | GCC_WARN_UNUSED_VARIABLE = YES; 522 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 523 | SDKROOT = iphoneos; 524 | TARGETED_DEVICE_FAMILY = "1,2"; 525 | VALIDATE_PRODUCT = YES; 526 | }; 527 | name = Debug; 528 | }; 529 | D964F2A61A83EE5600CFF26D /* Debug */ = { 530 | isa = XCBuildConfiguration; 531 | baseConfigurationReference = D964F2A81A83EF0E00CFF26D /* Pods-IOCipherTests.debug.xcconfig */; 532 | buildSettings = { 533 | FRAMEWORK_SEARCH_PATHS = ( 534 | "$(SDKROOT)/Developer/Library/Frameworks", 535 | "$(inherited)", 536 | "$(DEVELOPER_FRAMEWORKS_DIR)", 537 | ); 538 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 539 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; 540 | INFOPLIST_FILE = "Tests/Tests-Info.plist"; 541 | LIBRARY_SEARCH_PATHS = ( 542 | "$(inherited)", 543 | "$(PROJECT_DIR)/Pods/build/Debug-iphoneos", 544 | ); 545 | ONLY_ACTIVE_ARCH = YES; 546 | PRODUCT_NAME = "$(TARGET_NAME)"; 547 | TEST_HOST = "$(BUNDLE_LOADER)"; 548 | WRAPPER_EXTENSION = xctest; 549 | }; 550 | name = Debug; 551 | }; 552 | D964F2A71A83EE5600CFF26D /* Debug */ = { 553 | isa = XCBuildConfiguration; 554 | baseConfigurationReference = 0227BFB7F7600F87F4962B21 /* Pods-IOCipherServer.debug.xcconfig */; 555 | buildSettings = { 556 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 557 | CLANG_WARN_UNREACHABLE_CODE = YES; 558 | ENABLE_STRICT_OBJC_MSGSEND = YES; 559 | INFOPLIST_FILE = IOCipherServer/Info.plist; 560 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 561 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 562 | MTL_ENABLE_DEBUG_INFO = NO; 563 | ONLY_ACTIVE_ARCH = YES; 564 | PRODUCT_NAME = "$(TARGET_NAME)"; 565 | }; 566 | name = Debug; 567 | }; 568 | /* End XCBuildConfiguration section */ 569 | 570 | /* Begin XCConfigurationList section */ 571 | 6003F585195388D10070C39A /* Build configuration list for PBXProject "IOCipher" */ = { 572 | isa = XCConfigurationList; 573 | buildConfigurations = ( 574 | 6003F5BE195388D20070C39A /* Release */, 575 | D964F2A51A83EE5600CFF26D /* Debug */, 576 | ); 577 | defaultConfigurationIsVisible = 0; 578 | defaultConfigurationName = Release; 579 | }; 580 | 6003F5C2195388D20070C39A /* Build configuration list for PBXNativeTarget "IOCipherTests" */ = { 581 | isa = XCConfigurationList; 582 | buildConfigurations = ( 583 | 6003F5C4195388D20070C39A /* Release */, 584 | D964F2A61A83EE5600CFF26D /* Debug */, 585 | ); 586 | defaultConfigurationIsVisible = 0; 587 | defaultConfigurationName = Release; 588 | }; 589 | D9111DD91A71B9C2004AFD08 /* Build configuration list for PBXNativeTarget "IOCipherServer" */ = { 590 | isa = XCConfigurationList; 591 | buildConfigurations = ( 592 | D9111DD61A71B9C2004AFD08 /* Release */, 593 | D964F2A71A83EE5600CFF26D /* Debug */, 594 | ); 595 | defaultConfigurationIsVisible = 0; 596 | defaultConfigurationName = Release; 597 | }; 598 | /* End XCConfigurationList section */ 599 | }; 600 | rootObject = 6003F582195388D10070C39A /* Project object */; 601 | } 602 | -------------------------------------------------------------------------------- /Example/IOCipher.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/IOCipher.xcodeproj/xcshareddata/xcschemes/IOCipherServer.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Example/IOCipher.xcodeproj/xcshareddata/xcschemes/IOCipherTests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Example/IOCipher.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/IOCipherServer/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // IOCipherServer 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Example/IOCipherServer/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // IOCipherServer 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Example/IOCipherServer/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Example/IOCipherServer/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/IOCipherServer/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Example/IOCipherServer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.chrisballinger.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Example/IOCipherServer/SQLVirtualFile.h: -------------------------------------------------------------------------------- 1 | // 2 | // SQLVirtualFile.h 3 | // IOCipher 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SQLVirtualFile : NSObject 12 | 13 | /** dynamic accessor for @"/$uuid/$fileName" */ 14 | @property (nonatomic, strong, readonly) NSString *virtualPath; 15 | 16 | /** file name, not neccessarily unique */ 17 | @property (nonatomic, strong, readonly) NSString *fileName; 18 | 19 | /** unique UUID created for every file. used as unique directory */ 20 | @property (nonatomic, strong, readonly) NSString *uuid; 21 | 22 | /** dynamic accessor for HTTP URL for use with GCDWebServerVirtualFileResponse */ 23 | @property (nonatomic, strong, readonly) NSURL *url; 24 | 25 | /** port number of running HTTP server */ 26 | @property (nonatomic) uint16_t portNumber; 27 | 28 | /** creates a unique directory / uuid for each file to prevent filename collisions */ 29 | - (instancetype) initWithFileName:(NSString*)fileName; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /Example/IOCipherServer/SQLVirtualFile.m: -------------------------------------------------------------------------------- 1 | // 2 | // SQLVirtualFile.m 3 | // IOCipher 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import "SQLVirtualFile.h" 10 | 11 | @implementation SQLVirtualFile 12 | @dynamic virtualPath; 13 | @dynamic url; 14 | 15 | - (instancetype) initWithFileName:(NSString*)fileName { 16 | if (self = [super init]) { 17 | _uuid = [[NSUUID UUID] UUIDString]; 18 | _fileName = fileName; 19 | _portNumber = 80; 20 | } 21 | return self; 22 | } 23 | 24 | - (NSString*) virtualPath { 25 | return [NSString stringWithFormat:@"/%@/%@", self.uuid, self.fileName]; 26 | } 27 | 28 | - (NSString*) description { 29 | NSString *description = [[super description] stringByAppendingFormat:@": %@", self.virtualPath]; 30 | return description; 31 | } 32 | 33 | - (NSURL*) url { 34 | NSString *path = self.virtualPath; 35 | NSString *urlString = [NSString stringWithFormat:@"http://localhost:%d%@", self.portNumber, path]; 36 | NSURL *url = [NSURL URLWithString:urlString]; 37 | return url; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Example/IOCipherServer/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // IOCipherServer 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Example/IOCipherServer/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // IOCipherServer 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "GCDWebServer.h" 11 | #import "IOCipher.h" 12 | #import "SQLVirtualFile.h" 13 | #import "GCDWebServerVirtualFileResponse.h" 14 | #import 15 | 16 | static NSString * const CellIdentifier = @"CellIdentifier"; 17 | 18 | @interface ViewController () 19 | @property (nonatomic, strong) IOCipher *iocipher; 20 | @property (nonatomic, strong) GCDWebServer *server; 21 | @property (nonatomic, strong) NSMutableArray *virtualFiles; 22 | @property (nonatomic, strong) UITableView *tableView; 23 | @end 24 | 25 | @implementation ViewController 26 | 27 | - (void)viewDidLoad { 28 | [super viewDidLoad]; 29 | // Do any additional setup after loading the view, typically from a nib. 30 | [self setupServer]; 31 | [self setupIOCipher]; 32 | self.virtualFiles = [NSMutableArray array]; 33 | 34 | [self setupTableView]; 35 | 36 | 37 | NSArray *files = [[NSBundle mainBundle] pathsForResourcesOfType:nil inDirectory:@"samples"]; 38 | [files enumerateObjectsUsingBlock:^(NSString *filePath, NSUInteger idx, BOOL *stop) { 39 | [self addLocalFileToEncryptedStore:filePath]; 40 | }]; 41 | [self.tableView reloadData]; 42 | } 43 | 44 | - (void) setupTableView { 45 | self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; 46 | self.tableView.delegate = self; 47 | self.tableView.dataSource = self; 48 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier]; 49 | [self.view addSubview:self.tableView]; 50 | } 51 | 52 | - (void) viewWillAppear:(BOOL)animated { 53 | [super viewWillAppear:animated]; 54 | self.tableView.frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height); 55 | } 56 | 57 | 58 | - (NSString *) applicationDocumentsDirectory 59 | { 60 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 61 | NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 62 | return basePath; 63 | } 64 | 65 | - (void) setupIOCipher { 66 | NSString *dbDirectory = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"IOCipher"]; 67 | NSString *dbPath = [dbDirectory stringByAppendingPathComponent:@"vfs.sqlite"]; 68 | 69 | if ([[NSFileManager defaultManager] fileExistsAtPath:dbDirectory isDirectory:NULL]) { 70 | [[NSFileManager defaultManager] removeItemAtPath:dbDirectory error:nil]; 71 | } 72 | [[NSFileManager defaultManager] createDirectoryAtPath:dbDirectory withIntermediateDirectories:YES attributes:nil error:nil]; 73 | self.iocipher = [[IOCipher alloc] initWithPath:dbPath password:@"test"]; 74 | } 75 | 76 | - (void) addLocalFileToEncryptedStore:(NSString*)localFilePath { 77 | NSString *fileName = [localFilePath lastPathComponent]; 78 | SQLVirtualFile *virtualFile = [[SQLVirtualFile alloc] initWithFileName:fileName]; 79 | virtualFile.portNumber = self.server.port; 80 | NSError *error = nil; 81 | 82 | if (![self.iocipher fileExistsAtPath:virtualFile.uuid isDirectory:NULL]) { 83 | [self.iocipher createFolderAtPath:virtualFile.uuid error:&error]; 84 | if (error) { 85 | NSLog(@"Error creating folder: %@", error); 86 | return; 87 | } 88 | } 89 | 90 | NSData *fileData = [NSData dataWithContentsOfFile:localFilePath]; 91 | [self.iocipher writeDataToFileAtPath:virtualFile.virtualPath data:fileData offset:0 error:&error]; 92 | if (error) { 93 | NSLog(@"Error writing file data"); 94 | return; 95 | } 96 | 97 | IOCipher *iocipher = self.iocipher; 98 | [self.server addHandlerForMethod:@"GET" path:virtualFile.virtualPath requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) { 99 | NSRange range = request.byteRange; 100 | 101 | NSLog(@"GET: (%d,%d) %@ %@", (int)range.location, (int)range.length, request.URL, request.headers); 102 | GCDWebServerResponse* response = [GCDWebServerVirtualFileResponse responseWithFile:virtualFile.virtualPath byteRange:request.byteRange isAttachment:NO ioCipher:iocipher]; 103 | [response setValue:@"bytes" forAdditionalHeader:@"Accept-Ranges"]; 104 | return response; 105 | }]; 106 | 107 | [self.virtualFiles addObject:virtualFile]; 108 | } 109 | 110 | - (void) setupServer { 111 | self.server = [[GCDWebServer alloc] init]; 112 | self.server.delegate = self; 113 | NSError *error = nil; 114 | [self.server startWithOptions:nil error:&error]; 115 | if (error) { 116 | NSLog(@"Error starting server: %@", error); 117 | } 118 | 119 | } 120 | 121 | - (void)didReceiveMemoryWarning { 122 | [super didReceiveMemoryWarning]; 123 | // Dispose of any resources that can be recreated. 124 | } 125 | 126 | - (SQLVirtualFile *) virtualFileAtIndexPath:(NSIndexPath*)indexPath { 127 | return [self.virtualFiles objectAtIndex:indexPath.row]; 128 | } 129 | 130 | - (void) playFileWithURL:(NSURL*)url { 131 | NSParameterAssert(url != nil); 132 | MPMoviePlayerViewController *movie = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 133 | [self presentMoviePlayerViewControllerAnimated:movie]; 134 | } 135 | 136 | #pragma mark UITableViewDelegate 137 | 138 | - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 139 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 140 | SQLVirtualFile *file = [self virtualFileAtIndexPath:indexPath]; 141 | NSURL *url = file.url; 142 | NSLog(@"Playing file at URL: %@", url); 143 | [self playFileWithURL:url]; 144 | } 145 | 146 | #pragma mark UITableViewDataSource 147 | 148 | - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 149 | return self.virtualFiles.count; 150 | } 151 | 152 | - (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 153 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 154 | SQLVirtualFile *file = [self virtualFileAtIndexPath:indexPath]; 155 | cell.textLabel.text = file.fileName; 156 | return cell; 157 | } 158 | 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /Example/IOCipherServer/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // IOCipherServer 4 | // 5 | // Created by Christopher Ballinger on 1/22/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | source 'https://github.com/CocoaPods/Specs.git' 2 | 3 | platform :ios, "8.0" 4 | 5 | use_modular_headers! 6 | 7 | target 'IOCipherTests' do 8 | pod "IOCipher", :path => "../" 9 | pod 'libsqlfs/SQLCipher', :git => 'https://github.com/ChatSecure/libsqlfs.git', :branch => '1.3.2-chatsecure' 10 | pod 'SQLCipher', :git => 'https://github.com/ChatSecure/sqlcipher.git', :branch => 'v4.3.0-catalyst' 11 | end 12 | 13 | target 'IOCipherServer' do 14 | pod "IOCipher/GCDWebServer", :path => "../" 15 | end 16 | 17 | -------------------------------------------------------------------------------- /Example/Tests/IOCipherTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // IOCipherTests.m 3 | // IOCipher 4 | // 5 | // Created by Christopher Ballinger on 1/20/15. 6 | // Copyright (c) 2015 Chris Ballinger. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "IOCipher.h" 12 | 13 | @interface IOCipherTests : XCTestCase 14 | @property (nonatomic, strong) IOCipher *ioCipher; 15 | @end 16 | 17 | NSString *const IOCipherTestPassword = @"test"; 18 | 19 | @implementation IOCipherTests 20 | 21 | - (NSString *) applicationDocumentsDirectory 22 | { 23 | return [[NSFileManager defaultManager] currentDirectoryPath];; 24 | } 25 | 26 | - (NSString*) dbPath { 27 | NSString *path = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"test.sqlite"]; 28 | return path; 29 | } 30 | 31 | - (NSData *)dataOfLength:(NSUInteger)length 32 | { 33 | NSMutableData* data = [NSMutableData dataWithCapacity:length]; 34 | for (NSUInteger index = 0; index < length/4; index++) { 35 | u_int32_t randomBits = arc4random(); 36 | [data appendBytes:(void*)&randomBits length:4]; 37 | } 38 | return data; 39 | } 40 | 41 | - (void)removeAllFilesInDirectory:(NSString *)directory 42 | { 43 | NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:directory]; 44 | NSString *file = nil; 45 | while (file = [enumerator nextObject]) { 46 | [[NSFileManager defaultManager] removeItemAtPath:[directory stringByAppendingPathComponent:file] error:nil]; 47 | } 48 | } 49 | 50 | - (void)setUp { 51 | [super setUp]; 52 | 53 | NSString *path = [self dbPath]; 54 | [self removeAllFilesInDirectory:[path stringByDeletingLastPathComponent]]; 55 | BOOL isDirectory = NO; 56 | NSString *directory = [path stringByDeletingLastPathComponent]; 57 | BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:directory isDirectory:&isDirectory]; 58 | XCTAssertTrue(exists,@"Directory does not exist: %@",directory); 59 | XCTAssertTrue(isDirectory,@"Directory is not directory"); 60 | 61 | self.ioCipher = [[IOCipher alloc] initWithPath:path password:IOCipherTestPassword]; 62 | } 63 | 64 | - (void)tearDown { 65 | // Put teardown code here. This method is called after the invocation of each test method in the class. 66 | [super tearDown]; 67 | self.ioCipher = nil; 68 | [self removeAllFilesInDirectory:[[self dbPath] stringByDeletingLastPathComponent]]; 69 | } 70 | 71 | - (void)testWriteToDocuments 72 | { 73 | NSString *path = [[[self dbPath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"test.txt"]; 74 | NSData *data = [@"test" dataUsingEncoding:NSUTF8StringEncoding]; 75 | 76 | [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil]; 77 | NSData *newData = [[NSFileManager defaultManager] contentsAtPath:path]; 78 | XCTAssertTrue([data isEqualToData:newData]); 79 | } 80 | 81 | - (void)testCreateFile { 82 | NSString *filePath = @"file.txt"; 83 | NSError *error = nil; 84 | BOOL success = [self.ioCipher fileExistsAtPath:filePath isDirectory:NULL]; 85 | XCTAssertFalse(success); 86 | success = [self.ioCipher createFileAtPath:filePath error:&error]; 87 | XCTAssertTrue(success, @"error: %@", error); 88 | success = [self.ioCipher createFileAtPath:filePath error:&error]; 89 | BOOL isDirectory = YES; 90 | success = [self.ioCipher fileExistsAtPath:filePath isDirectory:&isDirectory]; 91 | XCTAssertFalse(isDirectory); 92 | XCTAssertTrue(success, @"error: %@", error); 93 | } 94 | 95 | - (void)testCreateFolder { 96 | NSString *folder = @"folder"; 97 | NSError *error = nil; 98 | BOOL success = [self.ioCipher createFolderAtPath:folder error:&error]; 99 | XCTAssertTrue(success, @"error: %@", error); 100 | BOOL isDirectory = NO; 101 | success = [self.ioCipher fileExistsAtPath:folder isDirectory:&isDirectory]; 102 | XCTAssertTrue(isDirectory); 103 | XCTAssertTrue(success); 104 | } 105 | 106 | - (void)testRemoveFilesAndFolders { 107 | NSString *folder = @"/folder"; 108 | NSString *file = @"file.txt"; 109 | 110 | NSString *path = [folder stringByAppendingPathComponent:file]; 111 | NSError *error = nil; 112 | BOOL success = [self.ioCipher createFolderAtPath:folder error:&error]; 113 | XCTAssertTrue(success, @"error: %@", error); 114 | success = [self.ioCipher createFileAtPath:path error:&error]; 115 | XCTAssertTrue(success, @"error: %@", error); 116 | success = [self.ioCipher removeItemAtPath:path error:&error]; 117 | XCTAssertTrue(success, @"error: %@", error); 118 | success = [self.ioCipher fileExistsAtPath:path isDirectory:NULL]; 119 | XCTAssertFalse(success); 120 | success = [self.ioCipher removeItemAtPath:folder error:&error]; 121 | XCTAssertTrue(success, @"error: %@", error); 122 | success = [self.ioCipher fileExistsAtPath:path isDirectory:NULL]; 123 | XCTAssertFalse(success); 124 | } 125 | 126 | - (void) testReadWriteData { 127 | NSString *filePath = @"file.txt"; 128 | NSData *fileData = [@"test" dataUsingEncoding:NSUTF8StringEncoding]; 129 | NSError *error = nil; 130 | BOOL success = [self.ioCipher createFileAtPath:filePath error:&error]; 131 | XCTAssertTrue(success, @"error: %@", error); 132 | NSUInteger bytesWritten = [self.ioCipher writeDataToFileAtPath:filePath data:fileData offset:0 error:&error]; 133 | XCTAssert(bytesWritten == fileData.length, @"error: %@", error); 134 | NSData *readData = [self.ioCipher readDataFromFileAtPath:filePath length:fileData.length offset:0 error:&error]; 135 | XCTAssertNotNil(readData, @"error: %@", error); 136 | XCTAssertEqualObjects(fileData, readData); 137 | } 138 | 139 | - (void) testFileAttributes { 140 | NSString *filePath = @"file.txt"; 141 | NSData *fileData = [@"test" dataUsingEncoding:NSUTF8StringEncoding]; 142 | NSError *error = nil; 143 | BOOL success = [self.ioCipher createFileAtPath:filePath error:&error]; 144 | XCTAssertTrue(success, @"error: %@", error); 145 | NSUInteger bytesWritten = [self.ioCipher writeDataToFileAtPath:filePath data:fileData offset:0 error:&error]; 146 | XCTAssert(bytesWritten == fileData.length, @"error: %@", error); 147 | NSDictionary *fileAttributes = [self.ioCipher fileAttributesAtPath:filePath error:&error]; 148 | XCTAssertNotNil(fileAttributes, @"error: %@", error); 149 | NSNumber *fileSize = fileAttributes[NSFileSize]; 150 | NSDate *dateModified = fileAttributes[NSFileModificationDate]; 151 | XCTAssert(fileSize.unsignedIntegerValue == fileData.length, @"File size doesn't match"); 152 | XCTAssertNotNil(dateModified); 153 | } 154 | 155 | - (void) testTruncateFile { 156 | NSString *filePath = @"file.txt"; 157 | NSData *fileData = [@"test" dataUsingEncoding:NSUTF8StringEncoding]; 158 | NSError *error = nil; 159 | BOOL success = [self.ioCipher createFileAtPath:filePath error:&error]; 160 | XCTAssertTrue(success, @"error: %@", error); 161 | NSUInteger bytesWritten = [self.ioCipher writeDataToFileAtPath:filePath data:fileData offset:0 error:&error]; 162 | XCTAssert(bytesWritten == fileData.length, @"error: %@", error); 163 | 164 | NSUInteger newFileLength = 3; 165 | success = [self.ioCipher truncateFileAtPath:filePath length:newFileLength error:&error]; 166 | 167 | XCTAssertTrue(success, @"error: %@", error); 168 | 169 | NSDictionary *fileAttributes = [self.ioCipher fileAttributesAtPath:filePath error:&error]; 170 | XCTAssertNotNil(fileAttributes, @"error: %@", error); 171 | NSNumber *fileSize = fileAttributes[NSFileSize]; 172 | XCTAssert(fileSize.unsignedIntegerValue == newFileLength, @"New file size doesn't match"); 173 | } 174 | 175 | - (void) testFileSystemCopy { 176 | 177 | NSData *data = [self dataOfLength:20000000]; 178 | 179 | XCTAssert([data length] > 0); 180 | 181 | NSString *path = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"random"]; 182 | BOOL createdFile = [[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil]; 183 | 184 | XCTAssertTrue(createdFile, @"Unable to create file in documents path"); 185 | 186 | NSString *encryptedPath = @"/test/random"; 187 | 188 | NSError *error = nil; 189 | BOOL succes = [self.ioCipher copyItemAtFileSystemPath:path toEncryptedPath:encryptedPath error:&error]; 190 | 191 | XCTAssertNil(error,@"Error copying file"); 192 | XCTAssertTrue(succes, @"Error unable to copy"); 193 | 194 | NSData *originalData = [[NSFileManager defaultManager] contentsAtPath:path]; 195 | NSDictionary *attributes = [self.ioCipher fileAttributesAtPath:encryptedPath error:&error]; 196 | XCTAssertNil(error,@"Error getting file attributes"); 197 | XCTAssertGreaterThan([[attributes allKeys] count], 0, @"No attributes retrieved"); 198 | NSNumber *fileSize = attributes[NSFileSize]; 199 | NSData *encryptedData = [self.ioCipher readDataFromFileAtPath:encryptedPath length:fileSize.unsignedIntegerValue offset:0 error:&error]; 200 | XCTAssertNil(error,@"Error getting encrypted data"); 201 | XCTAssertNotNil(encryptedData,@"No encrypted file data"); 202 | XCTAssertNotNil(originalData,@"No original file data"); 203 | 204 | XCTAssertTrue([originalData isEqualToData:encryptedData], @"Data not the same"); 205 | } 206 | - (void) testReadFile { 207 | NSString *filePath = @"file.txt"; 208 | NSData *fileData = [@"test" dataUsingEncoding:NSUTF8StringEncoding]; 209 | NSError *error = nil; 210 | BOOL success = [self.ioCipher createFileAtPath:filePath error:&error]; 211 | XCTAssertTrue(success, @"error: %@", error); 212 | NSUInteger bytesWritten = [self.ioCipher writeDataToFileAtPath:filePath data:fileData offset:0 error:&error]; 213 | XCTAssertNil(error, @"Error writing file"); 214 | XCTAssert(bytesWritten == fileData.length, @"error: %@", error); 215 | 216 | NSError *readError = nil; 217 | NSData *readData = [self.ioCipher readDataFromFileAtPath:filePath error:&readError]; 218 | XCTAssertNil(readError, @"Error reading Data"); 219 | XCTAssertTrue([readData isEqualToData:fileData], @"File data is not equal"); 220 | } 221 | 222 | - (void)testChangePassword 223 | { 224 | NSString *filePath = @"file.txt"; 225 | NSData *fileData = [@"test" dataUsingEncoding:NSUTF8StringEncoding]; 226 | [self.ioCipher createFileAtPath:filePath error:nil]; 227 | [self.ioCipher writeDataToFileAtPath:filePath data:fileData offset:0 error:nil]; 228 | BOOL changePasswordResult = [self.ioCipher changePassword:@"newPassword" oldPassword:IOCipherTestPassword]; 229 | XCTAssertTrue(changePasswordResult,@"Unable to change password"); 230 | NSData *data = [self.ioCipher readDataFromFileAtPath:filePath error:nil]; 231 | XCTAssertNotNil(data, @"No data found"); 232 | XCTAssertTrue([data isEqualToData:fileData],@"Data is not equal"); 233 | } 234 | 235 | 236 | @end 237 | -------------------------------------------------------------------------------- /Example/Tests/Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Example/Tests/Tests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every test case source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | 9 | 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /Example/Tests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Example/samples/README.txt: -------------------------------------------------------------------------------- 1 | Populate this folder with the following files: 2 | 3 | 1. 480p_15sec.mov 4 | 2. image.jpg 5 | 3. test.m4a 6 | 4. test.mp3 -------------------------------------------------------------------------------- /IOCipher.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "IOCipher" 3 | s.version = "0.1.0" 4 | s.summary = "Objective-C wrapper for libsqlfs and SQLCipher to create virtual encrypted file systems." 5 | s.homepage = "https://github.com/chrisballinger/IOCipher" 6 | s.license = 'LGPLv2.1+' 7 | s.author = { "Chris Ballinger" => "chris@chatsecure.org" } 8 | s.source = { :git => "https://github.com/chrisballinger/IOCipher.git", :tag => s.version.to_s } 9 | s.social_media_url = 'https://twitter.com/ChatSecure' 10 | 11 | s.ios.deployment_target = '7.0' 12 | s.osx.deployment_target = '10.8' 13 | s.requires_arc = true 14 | 15 | s.default_subspec = 'standard' 16 | 17 | s.subspec 'common' do |ss| 18 | ss.source_files = 'IOCipher/*.{h,m}' 19 | ss.xcconfig = { 'OTHER_CFLAGS' => '$(inherited) -DHAVE_LIBSQLCIPHER -DSQLITE_HAS_CODEC' } 20 | ss.dependency 'libsqlfs/SQLCipher' 21 | ss.dependency 'CocoaLumberjack' 22 | end 23 | 24 | s.subspec 'standard' do |ss| 25 | ss.dependency 'IOCipher/common' 26 | end 27 | 28 | s.subspec 'GCDWebServer' do |ss| 29 | ss.source_files = 'IOCipher/GCDWebServer/*.{h,m}' 30 | ss.dependency 'IOCipher/common' 31 | ss.dependency 'GCDWebServer' 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /IOCipher/GCDWebServer/GCDWebServerVirtualFileResponse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2014, Pierre-Olivier Latour 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * The name of Pierre-Olivier Latour may not be used to endorse 13 | or promote products derived from this software without specific 14 | prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #import 29 | #import "IOCipher.h" 30 | 31 | /** 32 | * The GCDWebServerFileResponse subclass of GCDWebServerResponse reads the body 33 | * of the HTTP response from a file on disk. 34 | * 35 | * It will automatically set the contentType, lastModifiedDate and eTag 36 | * properties of the GCDWebServerResponse according to the file extension and 37 | * metadata. 38 | */ 39 | @interface GCDWebServerVirtualFileResponse : GCDWebServerResponse 40 | 41 | /** Used internally for virtual file system */ 42 | @property (nonatomic, strong, readonly) IOCipher *ioCipher; 43 | 44 | /** 45 | * Creates a response with the contents of a file. 46 | */ 47 | + (instancetype)responseWithFile:(NSString*)path ioCipher:(IOCipher*)ioCipher; 48 | 49 | /** 50 | * Creates a response like +responseWithFile: and sets the "Content-Disposition" 51 | * HTTP header for a download if the "attachment" argument is YES. 52 | */ 53 | + (instancetype)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher; 54 | 55 | /** 56 | * Creates a response like +responseWithFile: but restricts the file contents 57 | * to a specific byte range. 58 | * 59 | * See -initWithFile:byteRange: for details. 60 | */ 61 | + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range ioCipher:(IOCipher*)ioCipher; 62 | 63 | /** 64 | * Creates a response like +responseWithFile:byteRange: and sets the 65 | * "Content-Disposition" HTTP header for a download if the "attachment" 66 | * argument is YES. 67 | */ 68 | + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher; 69 | 70 | /** 71 | * Initializes a response with the contents of a file. 72 | */ 73 | - (instancetype)initWithFile:(NSString*)path ioCipher:(IOCipher*)ioCipher; 74 | 75 | /** 76 | * Initializes a response like +responseWithFile: and sets the 77 | * "Content-Disposition" HTTP header for a download if the "attachment" 78 | * argument is YES. 79 | */ 80 | - (instancetype)initWithFile:(NSString*)path isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher; 81 | 82 | /** 83 | * Initializes a response like -initWithFile: but restricts the file contents 84 | * to a specific byte range. This range should be set to (NSUIntegerMax, 0) for 85 | * the full file, (offset, length) if expressed from the beginning of the file, 86 | * or (NSUIntegerMax, length) if expressed from the end of the file. The "offset" 87 | * and "length" values will be automatically adjusted to be compatible with the 88 | * actual size of the file. 89 | * 90 | * This argument would typically be set to the value of the byteRange property 91 | * of the current GCDWebServerRequest. 92 | */ 93 | - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range ioCipher:(IOCipher*)ioCipher; 94 | 95 | /** 96 | * This method is the designated initializer for the class. 97 | */ 98 | - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher; 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /IOCipher/GCDWebServer/GCDWebServerVirtualFileResponse.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012-2014, Pierre-Olivier Latour 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * The name of Pierre-Olivier Latour may not be used to endorse 13 | or promote products derived from this software without specific 14 | prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if !__has_feature(objc_arc) 29 | #error GCDWebServer requires ARC 30 | #endif 31 | 32 | #import 33 | 34 | #import 35 | #import 36 | #import "GCDWebServerVirtualFileResponse.h" 37 | 38 | #define kFileReadBufferSize (32 * 1024) 39 | 40 | static inline BOOL GCDWebServerIsValidByteRange(NSRange range) { 41 | return ((range.location != NSUIntegerMax) || (range.length > 0)); 42 | } 43 | 44 | static inline NSError* GCDWebServerMakePosixError(int code) { 45 | return [NSError errorWithDomain:NSPOSIXErrorDomain code:code userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithUTF8String:strerror(code)]}]; 46 | } 47 | 48 | @interface GCDWebServerVirtualFileResponse () { 49 | @private 50 | NSString* _path; 51 | NSUInteger _offset; 52 | NSUInteger _size; 53 | } 54 | @end 55 | 56 | @implementation GCDWebServerVirtualFileResponse 57 | 58 | + (instancetype)responseWithFile:(NSString*)path ioCipher:(IOCipher*)ioCipher { 59 | return [[[self class] alloc] initWithFile:path ioCipher:ioCipher]; 60 | } 61 | 62 | + (instancetype)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher { 63 | return [[[self class] alloc] initWithFile:path isAttachment:attachment ioCipher:ioCipher]; 64 | } 65 | 66 | + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range ioCipher:(IOCipher*)ioCipher { 67 | return [[[self class] alloc] initWithFile:path byteRange:range ioCipher:ioCipher]; 68 | } 69 | 70 | + (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher { 71 | return [[[self class] alloc] initWithFile:path byteRange:range isAttachment:attachment ioCipher:ioCipher]; 72 | } 73 | 74 | - (instancetype)initWithFile:(NSString*)path ioCipher:(IOCipher*)ioCipher { 75 | return [self initWithFile:path byteRange:NSMakeRange(NSUIntegerMax, 0) isAttachment:NO ioCipher:ioCipher]; 76 | } 77 | 78 | - (instancetype)initWithFile:(NSString*)path isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher { 79 | return [self initWithFile:path byteRange:NSMakeRange(NSUIntegerMax, 0) isAttachment:attachment ioCipher:ioCipher]; 80 | } 81 | 82 | - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range ioCipher:(IOCipher*)ioCipher { 83 | return [self initWithFile:path byteRange:range isAttachment:NO ioCipher:ioCipher]; 84 | } 85 | 86 | - (instancetype)initWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment ioCipher:(IOCipher*)ioCipher { 87 | _ioCipher = ioCipher; 88 | NSError *error = nil; 89 | NSDictionary *fileAttributes = [self.ioCipher fileAttributesAtPath:path error:&error]; 90 | NSUInteger fileSize = [fileAttributes[NSFileSize] unsignedIntegerValue]; 91 | 92 | BOOL hasByteRange = GCDWebServerIsValidByteRange(range); 93 | if (hasByteRange) { 94 | if (range.location != NSUIntegerMax) { 95 | range.location = MIN(range.location, fileSize); 96 | range.length = MIN(range.length, fileSize - range.location); 97 | } else { 98 | range.length = MIN(range.length, fileSize); 99 | range.location = fileSize - range.length; 100 | } 101 | if (range.length == 0) { 102 | return nil; // TODO: Return 416 status code and "Content-Range: bytes */{file length}" header 103 | } 104 | } else { 105 | range.location = 0; 106 | range.length = fileSize; 107 | } 108 | 109 | if ((self = [super init])) { 110 | _path = [path copy]; 111 | _offset = range.location; 112 | _size = range.length; 113 | if (hasByteRange) { 114 | [self setStatusCode:kGCDWebServerHTTPStatusCode_PartialContent]; 115 | [self setValue:[NSString stringWithFormat:@"bytes %lu-%lu/%lu", (unsigned long)_offset, (unsigned long)(_offset + _size - 1), (unsigned long)fileSize] forAdditionalHeader:@"Content-Range"]; 116 | } 117 | 118 | if (attachment) { 119 | NSString* fileName = [path lastPathComponent]; 120 | NSData* data = [[fileName stringByReplacingOccurrencesOfString:@"\"" withString:@""] dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:YES]; 121 | NSString* lossyFileName = data ? [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding] : nil; 122 | if (lossyFileName) { 123 | NSString* value = [NSString stringWithFormat:@"attachment; filename=\"%@\"; filename*=UTF-8''%@", lossyFileName, GCDWebServerEscapeURLString(fileName)]; 124 | [self setValue:value forAdditionalHeader:@"Content-Disposition"]; 125 | } 126 | } 127 | 128 | self.contentType = GCDWebServerGetMimeTypeForExtension([_path pathExtension], nil); 129 | self.contentLength = _size; 130 | self.lastModifiedDate = fileAttributes[NSFileModificationDate]; 131 | //self.eTag = [NSString stringWithFormat:@"%llu/%li/%li", info.st_ino, info.st_mtimespec.tv_sec, info.st_mtimespec.tv_nsec]; 132 | } 133 | return self; 134 | } 135 | 136 | - (BOOL)open:(NSError**)error { 137 | BOOL fileExists = [self.ioCipher fileExistsAtPath:_path isDirectory:NULL]; 138 | if (!fileExists) { 139 | if (error) { 140 | *error = GCDWebServerMakePosixError(ENOENT); 141 | } 142 | return NO; 143 | } 144 | return YES; 145 | } 146 | 147 | - (NSData*)readData:(NSError**)error { 148 | size_t length = MIN((NSUInteger)kFileReadBufferSize, _size); 149 | if (length == 0) { 150 | return [NSData data]; 151 | } 152 | NSData *data = [self.ioCipher readDataFromFileAtPath:_path length:length offset:_offset error:error]; 153 | if (!data) { 154 | if (error) { 155 | *error = GCDWebServerMakePosixError(EIO); 156 | } 157 | return nil; 158 | } 159 | if (data.length > 0) { 160 | _size -= data.length; 161 | _offset += data.length; 162 | } 163 | return data; 164 | } 165 | 166 | - (void)close { 167 | // sqlfs has no "close" operation 168 | } 169 | 170 | - (NSString*)description { 171 | NSMutableString* description = [NSMutableString stringWithString:[super description]]; 172 | [description appendFormat:@"\n\n{%@}", _path]; 173 | return description; 174 | } 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /IOCipher/IOCipher.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOCipher.h 3 | // Pods 4 | // 5 | // Created by Christopher Ballinger on 1/20/15. 6 | // 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** Due to limitations of libsqlfs you can only have one instance of this class */ 14 | @interface IOCipher : NSObject 15 | 16 | @property (nonatomic, strong, readonly) NSString *path; 17 | 18 | /** password should be UTF-8 and have non-zero length */ 19 | - (nullable instancetype) initWithPath:(NSString*)path password:(NSString*)password; 20 | 21 | /** key should be 32-bytes and have non-zero length */ 22 | - (nullable instancetype) initWithPath:(NSString*)path key:(NSData*)key; 23 | 24 | /** 25 | * Changes the passwod of the current store. This method closes and reopones the store so no writes or reads can occur. 26 | * 27 | * 28 | * @param newPassword the new password that will be used after the change 29 | * @param oldPassword the old password that was used previously 30 | * 31 | * @return Whether changing the password was successful 32 | */ 33 | - (BOOL)changePassword:(NSString *)newPassword oldPassword:(NSString *)oldPassword; 34 | 35 | /** 36 | * Changes the key of the current store. This method closes and reopones the store so no writes or reads can occur. 37 | * Keys should be 32-bytes 38 | * 39 | * @param newKey the new key that will be used after the change 40 | * @param oldKey the old key that was used previously 41 | * 42 | * @return Whether changing the key was successful 43 | */ 44 | - (BOOL)changeKey:(NSData *)newKey oldKey:(NSData *)oldKey; 45 | 46 | /** 47 | * Databases created with SQLCipher 3.0 are not compatible with SQLCipher 4.0. 48 | * Setting this flag will set "PRAGMA cipher_compatibility = %i" on the current database. 49 | * This must be called after the database is keyed. 50 | * 51 | * For more information see https://www.zetetic.net/sqlcipher/sqlcipher-api/#cipher_compatibility 52 | **/ 53 | - (BOOL)setCipherCompatibility:(NSInteger)version; 54 | 55 | - (BOOL)vacuum; 56 | @end 57 | 58 | @interface IOCipher (FileManagement) 59 | 60 | /** Creates file at path */ 61 | - (BOOL) createFileAtPath:(NSString*)path error:(NSError**)error; 62 | 63 | /** Creates folder at path */ 64 | - (BOOL) createFolderAtPath:(NSString*)path error:(NSError**)error; 65 | 66 | /** Removes file or folder at path */ 67 | - (BOOL) removeItemAtPath:(NSString*)path error:(NSError**)error; 68 | 69 | /** Checks if file exists at path */ 70 | - (BOOL) fileExistsAtPath:(NSString *)path 71 | isDirectory:(BOOL * _Nullable)isDirectory; 72 | 73 | /** 74 | * Returns NSDictionary of file attributes similar to NSFileManager 75 | * 76 | * Supported keys: 77 | * * NSFileSize (NSNumber) 78 | * * NSFileModificationDate (NSDate) 79 | * 80 | * @param path file path 81 | * 82 | * @return file attribute keys or nil if error 83 | */ 84 | - (nullable NSDictionary *) fileAttributesAtPath:(NSString*)path 85 | error:(NSError**)error; 86 | 87 | @end 88 | 89 | @interface IOCipher (FileData) 90 | 91 | /** 92 | * Reads data from file at path. 93 | * 94 | * @param path file path 95 | * @param error error 96 | * 97 | * @return Data read from file, or nil if there was an error. 98 | */ 99 | 100 | - (nullable NSData*) readDataFromFileAtPath:(NSString*)path 101 | error:(NSError**)error; 102 | 103 | /** 104 | * Reads data from file at path. 105 | * 106 | * @param path file path 107 | * @param length length of data to read in bytes 108 | * @param offset byte offset in file 109 | * @param error error 110 | * 111 | * @return Data read from file, or nil if there was an error. May be less than length. 112 | */ 113 | - (nullable NSData*) readDataFromFileAtPath:(NSString*)path 114 | length:(NSUInteger)length 115 | offset:(NSUInteger)offset 116 | error:(NSError**)error; 117 | 118 | /** 119 | * Writes data to file at path at offset. 120 | * 121 | * @param path file path 122 | * @param data data to write 123 | * @param offset byte offset in file 124 | * @param error error 125 | * 126 | * @return number of bytes written, or -1 if error 127 | */ 128 | - (NSInteger) writeDataToFileAtPath:(NSString*)path 129 | data:(NSData*)data 130 | offset:(NSUInteger)offset 131 | error:(NSError**)error; 132 | 133 | /** 134 | * Truncates file at path to new length. 135 | * 136 | * @param path file path 137 | * @param length new file length in bytes 138 | * @param error error 139 | * 140 | * @return success or failure 141 | */ 142 | - (BOOL) truncateFileAtPath:(NSString*)path 143 | length:(NSUInteger)length 144 | error:(NSError**)error; 145 | 146 | 147 | /** 148 | * Asynchronously copy file from file system to encrypted storage 149 | * 150 | * @param fileSystemPath file path of the normal file system 151 | * @param encryptedPath file path in encrypted store 152 | */ 153 | - (BOOL) copyItemAtFileSystemPath:(NSString *)fileSystemPath 154 | toEncryptedPath:(NSString *)encryptedPath 155 | error:(NSError **)error; 156 | 157 | @end 158 | 159 | NS_ASSUME_NONNULL_END 160 | -------------------------------------------------------------------------------- /IOCipher/IOCipher.m: -------------------------------------------------------------------------------- 1 | // 2 | // IOCipher.m 3 | // Pods 4 | // 5 | // Created by Christopher Ballinger on 1/20/15. 6 | // 7 | // 8 | 9 | #import "IOCipher.h" 10 | @import SQLCipher; 11 | #import 12 | 13 | /** Switches sign on sqlfs result codes */ 14 | static inline NSError* IOCipherPOSIXError(int code) { 15 | return [NSError errorWithDomain:NSPOSIXErrorDomain code:-code userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithUTF8String:strerror(code)]}]; 16 | } 17 | 18 | @interface IOCipher() 19 | @property (nonatomic, readonly) sqlfs_t *sqlfs; 20 | @end 21 | 22 | @implementation IOCipher 23 | 24 | - (void) dealloc { 25 | if (_sqlfs) { 26 | sqlfs_close(_sqlfs); 27 | _sqlfs = NULL; 28 | } 29 | } 30 | 31 | /** password should be UTF-8 */ 32 | - (instancetype) initWithPath:(NSString*)path password:(NSString*)password { 33 | NSParameterAssert(path != nil); 34 | NSAssert(password.length > 0, @"password should have a non-zero length!"); 35 | if (password.length == 0) { 36 | return nil; 37 | } 38 | if (self = [super init]) { 39 | [self cleanUpWalFile:path password:password]; 40 | sqlfs_open_password([path UTF8String], [password UTF8String], &_sqlfs); 41 | _path = path; 42 | if (!_sqlfs) { 43 | return nil; 44 | } 45 | } 46 | 47 | return self; 48 | } 49 | 50 | - (void)cleanUpWalFile:(NSString *)path password:(NSString *)password { 51 | NSError *error = nil; 52 | NSString *walPath = [path stringByAppendingString:@"-wal"]; 53 | NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:walPath error:&error]; 54 | 55 | if (error == nil && ((NSNumber *) attributes[NSFileSize]).longLongValue > 1 * 1024 * 1024) { 56 | // Quote from the SQLite documentation: "The only safe way to remove a WAL file is to open the database file 57 | // using one of the sqlite3_open() interfaces then immediately close the database using sqlite3_close()" 58 | sqlfs_open_password([path UTF8String], [password UTF8String], &_sqlfs); 59 | sqlfs_close(_sqlfs); 60 | } 61 | } 62 | 63 | /** key should be 32-bytes */ 64 | - (instancetype) initWithPath:(NSString*)path key:(NSData*)key { 65 | NSParameterAssert(path != nil); 66 | NSAssert(key.length == 32, @"key must be 32 bytes"); 67 | if (key.length != 32) { 68 | return nil; 69 | } 70 | if (self = [super init]) { 71 | sqlfs_open_key([path UTF8String], [key bytes], key.length, &_sqlfs); 72 | _path = path; 73 | if (!_sqlfs) { 74 | return nil; 75 | } 76 | } 77 | return self; 78 | } 79 | 80 | - (BOOL) setCipherCompatibility:(NSInteger)version { 81 | return sqlfs_set_cipher_compatibility(_sqlfs, version); 82 | } 83 | 84 | - (BOOL) changePassword:(NSString *)newPassword oldPassword:(NSString *)oldPassword 85 | { 86 | NSParameterAssert(oldPassword != nil); 87 | if (sqlfs_close(self.sqlfs)) { 88 | _sqlfs = nil; 89 | int changeResult = sqlfs_change_password([self.path UTF8String], [oldPassword UTF8String], [newPassword UTF8String]); 90 | if (changeResult) { 91 | sqlfs_open_password([self.path UTF8String], [newPassword UTF8String], &_sqlfs); 92 | if (_sqlfs) { 93 | return YES; 94 | } 95 | } 96 | } 97 | return NO; 98 | } 99 | 100 | - (BOOL) changeKey:(NSData *)newKey oldKey:(NSData *)oldkey 101 | { 102 | NSAssert(newKey.length == 32, @"key must be 32 bytes"); 103 | NSParameterAssert(oldkey != nil); 104 | if (sqlfs_close(self.sqlfs)) { 105 | _sqlfs = nil; 106 | int changeResult = sqlfs_rekey([self.path UTF8String], [oldkey bytes], oldkey.length, [newKey bytes], newKey.length); 107 | if (changeResult) { 108 | sqlfs_open_key([self.path UTF8String], [newKey bytes], newKey.length, &_sqlfs); 109 | if (_sqlfs) { 110 | return YES; 111 | } 112 | } 113 | } 114 | return NO; 115 | } 116 | 117 | /** Creates file at path */ 118 | - (BOOL) createFileAtPath:(NSString*)path error:(NSError**)error { 119 | struct fuse_file_info ffi; 120 | ffi.direct_io = 0; 121 | int result = sqlfs_proc_create(NULL, [path UTF8String], 0, &ffi); 122 | if (result == SQLITE_OK) { 123 | return YES; 124 | } else if (error) { 125 | *error = IOCipherPOSIXError(result); 126 | } 127 | return NO; 128 | } 129 | 130 | /** Creates folder at path */ 131 | - (BOOL) createFolderAtPath:(NSString*)path error:(NSError**)error { 132 | NSParameterAssert(path != nil); 133 | if (!path) { 134 | return NO; 135 | } 136 | int result = sqlfs_proc_mkdir(NULL, [path UTF8String], 0); 137 | if (result == SQLITE_OK) { 138 | return YES; 139 | } else if (error) { 140 | *error = IOCipherPOSIXError(result); 141 | } 142 | return NO; 143 | } 144 | 145 | /** Removes file or folder at path */ 146 | - (BOOL) removeItemAtPath:(NSString*)path error:(NSError**)error { 147 | NSParameterAssert(path != nil); 148 | if (!path) { 149 | return NO; 150 | } 151 | const char * cPath = [path UTF8String]; 152 | int result = -1; 153 | if (sqlfs_is_dir(NULL, cPath)) { 154 | result = sqlfs_proc_rmdir(NULL, cPath); 155 | } else { 156 | result = sqlfs_proc_unlink(NULL, cPath); 157 | } 158 | if (result == SQLITE_OK) { 159 | return YES; 160 | } else if (error) { 161 | *error = IOCipherPOSIXError(result); 162 | } 163 | return NO; 164 | } 165 | 166 | 167 | - (BOOL) fileExistsAtPath:(NSString *)path 168 | isDirectory:(BOOL *)isDirectory { 169 | NSParameterAssert(path != nil); 170 | if (!path) { 171 | return NO; 172 | } 173 | const char * cPath = [path UTF8String]; 174 | if (isDirectory) { 175 | *isDirectory = sqlfs_is_dir(NULL, cPath); 176 | } 177 | int result = sqlfs_proc_access(NULL, cPath, 0); 178 | if (result == SQLITE_OK) { 179 | return YES; 180 | } 181 | return NO; 182 | } 183 | 184 | /** 185 | * Returns NSDictionary of file attributes similar to NSFileManager 186 | * 187 | * Supported keys: 188 | * * NSFileSize (NSNumber) 189 | * * NSFileModificationDate (NSDate) 190 | * 191 | * @param path file path 192 | * 193 | * @return file attribute keys or nil if error 194 | */ 195 | - (NSDictionary*) fileAttributesAtPath:(NSString*)path error:(NSError**)error { 196 | NSParameterAssert(path != nil); 197 | struct stat sb; 198 | const char * cPath = [path UTF8String]; 199 | int result = sqlfs_proc_getattr(NULL, cPath, &sb); 200 | if (result < 0) { 201 | if (error) { 202 | *error = IOCipherPOSIXError(result); 203 | } 204 | return nil; 205 | } 206 | NSNumber *fileSize = @(sb.st_size); 207 | NSDate *lastModified = [NSDate dateWithTimeIntervalSince1970:((NSTimeInterval)sb.st_mtimespec.tv_sec + (NSTimeInterval)sb.st_mtimespec.tv_nsec / 1000000000.0)]; 208 | NSDictionary *fileAttributes = @{NSFileSize: fileSize, 209 | NSFileModificationDate: lastModified}; 210 | return fileAttributes; 211 | } 212 | 213 | - (NSData*) readDataFromFileAtPath:(NSString *)path 214 | error:(NSError **)error 215 | { 216 | NSError *err = nil; 217 | NSDictionary *attributes = [self fileAttributesAtPath:path error:&err]; 218 | if (err) { 219 | if (error) { 220 | *error = err; 221 | } 222 | return nil; 223 | } 224 | NSNumber *fileSize = attributes[NSFileSize]; 225 | return [self readDataFromFileAtPath:path length:fileSize.unsignedIntegerValue offset:0 error:error]; 226 | } 227 | 228 | /** 229 | * Reads data from file at path. 230 | * 231 | * @param path file path 232 | * @param length length of data to read in bytes 233 | * @param offset byte offset in file 234 | * @param error error 235 | * 236 | * @return Data read from file, or nil if there was an error. May be less than length. 237 | */ 238 | - (NSData*) readDataFromFileAtPath:(NSString*)path 239 | length:(NSUInteger)length 240 | offset:(NSUInteger)offset 241 | error:(NSError**)error { 242 | NSParameterAssert(path != nil); 243 | if (!path) { 244 | return nil; 245 | } 246 | struct fuse_file_info ffi; 247 | const char * cPath = [path UTF8String]; 248 | uint8_t *bytes = malloc(sizeof(uint8_t) * length); 249 | if (!bytes) { 250 | return nil; 251 | } 252 | int result = sqlfs_proc_read(NULL, 253 | cPath, 254 | (char*)bytes, 255 | length, 256 | offset, 257 | &ffi); 258 | if (result < 0) { 259 | free(bytes); 260 | if (result != -EIO) { // sqlfs_proc_open returns EIO on end-of-file 261 | if (error) { 262 | *error = IOCipherPOSIXError(result); 263 | } 264 | } 265 | return nil; 266 | } else { 267 | NSData *data = [NSData dataWithBytesNoCopy:bytes length:result freeWhenDone:YES]; 268 | return data; 269 | } 270 | return nil; 271 | } 272 | 273 | /** 274 | * Writes data to file at path at offset. 275 | * 276 | * @param path file path 277 | * @param data data to write 278 | * @param offset byte offset in file 279 | * @param error error 280 | * 281 | * @return number of bytes written, or -1 if error 282 | */ 283 | - (NSInteger) writeDataToFileAtPath:(NSString*)path 284 | data:(NSData*)data 285 | offset:(NSUInteger)offset 286 | error:(NSError**)error { 287 | NSParameterAssert(path != nil); 288 | NSParameterAssert(data != nil); 289 | if (!path || !data) { 290 | return NO; 291 | } 292 | struct fuse_file_info ffi; 293 | const char * cPath = [path UTF8String]; 294 | int result = sqlfs_proc_write(NULL, 295 | cPath, 296 | data.bytes, 297 | data.length, 298 | offset, 299 | &ffi); 300 | if (result < 0) { 301 | if (error) { 302 | *error = IOCipherPOSIXError(result); 303 | } 304 | return -1; 305 | } else { 306 | return result; 307 | } 308 | } 309 | 310 | /** 311 | * Truncates file at path to new length. 312 | * 313 | * @param path file path 314 | * @param length new file length in bytes 315 | * @param error error 316 | * 317 | * @return success or failure 318 | */ 319 | - (BOOL) truncateFileAtPath:(NSString*)path 320 | length:(NSUInteger)length 321 | error:(NSError**)error { 322 | NSParameterAssert(path != nil); 323 | const char *cPath = [path UTF8String]; 324 | int result = sqlfs_proc_truncate(NULL, cPath, (off_t)length); 325 | if (result < 0) { 326 | if (error) { 327 | *error = IOCipherPOSIXError(result); 328 | } 329 | return NO; 330 | } 331 | return YES; 332 | } 333 | 334 | - (BOOL)vacuum { 335 | return sqlfs_vacuum(NULL) == SQLITE_OK; 336 | } 337 | 338 | #pragma - mark File Copying 339 | 340 | 341 | - (BOOL)copyItemAtFileSystemPath:(NSString *)fileSystemPath toEncryptedPath:(NSString *)encryptedPath error:(NSError *__autoreleasing *)error 342 | { 343 | 344 | NSInputStream *inputStream = [[NSInputStream alloc] initWithFileAtPath:fileSystemPath]; 345 | [inputStream open]; 346 | 347 | NSUInteger bytesWritten = 0; 348 | 349 | BOOL success = YES; 350 | while (inputStream.hasBytesAvailable && success) { 351 | int bufferLength = 4096; 352 | uint8_t buf[bufferLength]; 353 | NSInteger length = 0; 354 | length = [inputStream read:buf maxLength:bufferLength]; 355 | if(length) { 356 | NSData *data = [NSData dataWithBytes:(const void *)buf length:length]; 357 | NSUInteger wroteBytes = [self writeDataToFileAtPath:encryptedPath 358 | data:data 359 | offset:bytesWritten 360 | error:error]; 361 | if (wroteBytes > 0 && !*error) { 362 | bytesWritten += wroteBytes; 363 | } 364 | else { 365 | success = NO; 366 | } 367 | } 368 | } 369 | return success; 370 | } 371 | 372 | 373 | @end 374 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | 505 | 506 | 507 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [IOCipher-ObjC](https://github.com/ChatSecure/IOCipher-ObjC) 2 | 3 | [![Build Status](https://travis-ci.org/ChatSecure/IOCipher-ObjC.svg?branch=master)](https://travis-ci.org/ChatSecure/IOCipher-ObjC) 4 | [![Version](https://img.shields.io/cocoapods/v/IOCipher.svg?style=flat)](http://cocoadocs.org/docsets/IOCipher) 5 | [![License](https://img.shields.io/cocoapods/l/IOCipher.svg?style=flat)](http://cocoadocs.org/docsets/IOCipher) 6 | [![Platform](https://img.shields.io/cocoapods/p/IOCipher.svg?style=flat)](http://cocoadocs.org/docsets/IOCipher) 7 | 8 | IOCipher allows you to create an encrypted virtual file store within a SQLite/SQLCipher database. The Obj-C version mirrors the NSFileManager API as much as possible for familiarity and easy of use. 9 | 10 | ## Usage 11 | 12 | To run the example project, clone the repo, and run `pod install` from the Example directory first. 13 | 14 | The `IOCipher` class contains all of the required functionality for working with encrypted files. The `GCDWebServerVirtualFileResponse` class is for usage with an embedded HTTP server for decypting files on the fly to better integrate with the stock iOS media playback APIs. 15 | 16 | ## Installation 17 | 18 | IOCipher is available through [CocoaPods](http://cocoapods.org). To install 19 | it, simply add the following line to your Podfile: 20 | 21 | pod 'IOCipher' 22 | 23 | You can also use the `'IOCipher/GCDWebServer'` subspec if you want to support decryption on-the-fly via an embedded HTTP server ([GCDWebServer](https://github.com/swisspol/GCDWebServer)). This allows you to support playback in the default iOS media player by decrypting everything as it's requested. Details on how to implement this are available in the Example project. 24 | 25 | ## Author 26 | 27 | [Chris Ballinger](https://github.com/chrisballinger), chris@chatsecure.org 28 | 29 | ## License 30 | 31 | IOCipher is available under the LGPLv2.1+ license. See the LICENSE file for more info. --------------------------------------------------------------------------------