├── .gitignore ├── LICENSE ├── README.md ├── app ├── MarinoDeviceCheck.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── MarinoDeviceCheck │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift └── server ├── package.json └── sampleServer.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/swift 3 | 4 | ### Swift ### 5 | # Xcode 6 | # 7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 8 | 9 | ## Build generated 10 | build/ 11 | DerivedData/ 12 | 13 | ## Various settings 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata/ 23 | docs/ 24 | 25 | ## Other 26 | *.moved-aside 27 | *.xcuserstate 28 | 29 | ## Obj-C/Swift specific 30 | *.hmap 31 | *.ipa 32 | *.dSYM.zip 33 | *.dSYM 34 | 35 | ## Playgrounds 36 | timeline.xctimeline 37 | playground.xcworkspace 38 | 39 | # Swift Package Manager 40 | # 41 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 42 | # Packages/ 43 | .build/ 44 | 45 | # CocoaPods 46 | # 47 | # We recommend against adding the Pods directory to your .gitignore. However 48 | # you should judge for yourself, the pros and cons are mentioned at: 49 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 50 | # 51 | # Pods/ 52 | 53 | # Carthage 54 | # 55 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 56 | # Carthage/Checkouts 57 | 58 | Carthage/Build 59 | 60 | # fastlane 61 | # 62 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 63 | # screenshots whenever they are needed. 64 | # For more information about the recommended setup visit: 65 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 66 | 67 | fastlane/report.xml 68 | fastlane/Preview.html 69 | fastlane/screenshots 70 | fastlane/test_output 71 | 72 | # MacOS 73 | 74 | .DS_Store 75 | 76 | 77 | # NodeJS 78 | node_modules 79 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 marinosoftware 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DeviceCheck Sample 2 | DeviceCheck is a new iOS 11 API that gives you access to two bits of data per-device, per-developer that your associated server can use in its business logic. You can read more about DeviceCheck on [our blog](https://www.marinosoftware.com/insights/how-to-prevent-fraud-without-compromising-user-privacy-devicecheck-on-ios-11). 3 | 4 | This project contains a fully working sample app and server to demonstrate DeviceCheck on iOS 11. 5 | 6 | # Getting started 7 | All you have to do in the iOS project is change the host to your NodeJS server's IP. You can do this in ViewController.swift: 8 | ```` 9 | let host = "http://192.168.0.10:3000" // Change to your NodeJS server IP:port 10 | ```` 11 | 12 | 13 | # NodeJS server 14 | Getting the NodeJS server to work is a tiny bit more involved. 15 | The NodeJS server is dependent on a few NodeJS libraries namely: `'jsonwebtoken'`, `'uuid'`, `'express'`, `'body-parser'`. To install these dependencies you can use `npm install`, this will install the dependencies from the package.json. 16 | 17 | In sampleServer.js you'll find a few configurable variables. Fill in your own IDs and key. 18 | 19 | ```` 20 | /****************** Set your values ******************/ 21 | var keyFileName = 'AuthKey_###.p8'; // Download from https://developer.apple.com/account/ios/authkey/ 22 | var keyId = "###"; // Can be found at: https://developer.apple.com/account/ios/authkey/ 23 | var teamId = "###"; // Can be found at: https://developer.apple.com/account/#/membership/ 24 | 25 | var port = 3000; 26 | 27 | // Change this to true when your app is on the App Store 28 | var production = false; 29 | /****************** End set your values ******************/ 30 | ```` 31 | 32 | After you have configured your NodeJS server, you can run it with. 33 | 34 | ```` 35 | node sampleServer.js 36 | ```` 37 | 38 | After that your app will be able to talk to the NodeJS server. 39 | 40 | # Apple Docs 41 | iOS docs: 42 | 43 | 44 | Server side docs: 45 | 46 | 47 | WWDC 2017 - Session 702 - Privacy and Your Apps: 48 | 49 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1706FC861F6D6006009B9579 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1706FC851F6D6006009B9579 /* AppDelegate.swift */; }; 11 | 1706FC881F6D6006009B9579 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1706FC871F6D6006009B9579 /* ViewController.swift */; }; 12 | 1706FC8B1F6D6006009B9579 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1706FC891F6D6006009B9579 /* Main.storyboard */; }; 13 | 1706FC8D1F6D6006009B9579 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1706FC8C1F6D6006009B9579 /* Assets.xcassets */; }; 14 | 1706FC901F6D6006009B9579 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1706FC8E1F6D6006009B9579 /* LaunchScreen.storyboard */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 1706FC821F6D6006009B9579 /* MarinoDeviceCheck.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarinoDeviceCheck.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 1706FC851F6D6006009B9579 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | 1706FC871F6D6006009B9579 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 21 | 1706FC8A1F6D6006009B9579 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | 1706FC8C1F6D6006009B9579 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 1706FC8F1F6D6006009B9579 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 24 | 1706FC911F6D6006009B9579 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 1706FC7F1F6D6006009B9579 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 1706FC791F6D6006009B9579 = { 39 | isa = PBXGroup; 40 | children = ( 41 | 1706FC841F6D6006009B9579 /* MarinoDeviceCheck */, 42 | 1706FC831F6D6006009B9579 /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 1706FC831F6D6006009B9579 /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 1706FC821F6D6006009B9579 /* MarinoDeviceCheck.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 1706FC841F6D6006009B9579 /* MarinoDeviceCheck */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 1706FC851F6D6006009B9579 /* AppDelegate.swift */, 58 | 1706FC871F6D6006009B9579 /* ViewController.swift */, 59 | 1706FC891F6D6006009B9579 /* Main.storyboard */, 60 | 1706FC8C1F6D6006009B9579 /* Assets.xcassets */, 61 | 1706FC8E1F6D6006009B9579 /* LaunchScreen.storyboard */, 62 | 1706FC911F6D6006009B9579 /* Info.plist */, 63 | ); 64 | path = MarinoDeviceCheck; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 1706FC811F6D6006009B9579 /* MarinoDeviceCheck */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 1706FC941F6D6006009B9579 /* Build configuration list for PBXNativeTarget "MarinoDeviceCheck" */; 73 | buildPhases = ( 74 | 1706FC7E1F6D6006009B9579 /* Sources */, 75 | 1706FC7F1F6D6006009B9579 /* Frameworks */, 76 | 1706FC801F6D6006009B9579 /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = MarinoDeviceCheck; 83 | productName = MarinoDeviceCheck; 84 | productReference = 1706FC821F6D6006009B9579 /* MarinoDeviceCheck.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 1706FC7A1F6D6006009B9579 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0900; 94 | LastUpgradeCheck = 0900; 95 | ORGANIZATIONNAME = Marinosoftware; 96 | TargetAttributes = { 97 | 1706FC811F6D6006009B9579 = { 98 | CreatedOnToolsVersion = 9.0; 99 | ProvisioningStyle = Automatic; 100 | }; 101 | }; 102 | }; 103 | buildConfigurationList = 1706FC7D1F6D6006009B9579 /* Build configuration list for PBXProject "MarinoDeviceCheck" */; 104 | compatibilityVersion = "Xcode 8.0"; 105 | developmentRegion = en; 106 | hasScannedForEncodings = 0; 107 | knownRegions = ( 108 | en, 109 | Base, 110 | ); 111 | mainGroup = 1706FC791F6D6006009B9579; 112 | productRefGroup = 1706FC831F6D6006009B9579 /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | 1706FC811F6D6006009B9579 /* MarinoDeviceCheck */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | 1706FC801F6D6006009B9579 /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 1706FC901F6D6006009B9579 /* LaunchScreen.storyboard in Resources */, 127 | 1706FC8D1F6D6006009B9579 /* Assets.xcassets in Resources */, 128 | 1706FC8B1F6D6006009B9579 /* Main.storyboard in Resources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXResourcesBuildPhase section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | 1706FC7E1F6D6006009B9579 /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 1706FC881F6D6006009B9579 /* ViewController.swift in Sources */, 140 | 1706FC861F6D6006009B9579 /* AppDelegate.swift in Sources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXSourcesBuildPhase section */ 145 | 146 | /* Begin PBXVariantGroup section */ 147 | 1706FC891F6D6006009B9579 /* Main.storyboard */ = { 148 | isa = PBXVariantGroup; 149 | children = ( 150 | 1706FC8A1F6D6006009B9579 /* Base */, 151 | ); 152 | name = Main.storyboard; 153 | sourceTree = ""; 154 | }; 155 | 1706FC8E1F6D6006009B9579 /* LaunchScreen.storyboard */ = { 156 | isa = PBXVariantGroup; 157 | children = ( 158 | 1706FC8F1F6D6006009B9579 /* Base */, 159 | ); 160 | name = LaunchScreen.storyboard; 161 | sourceTree = ""; 162 | }; 163 | /* End PBXVariantGroup section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 1706FC921F6D6006009B9579 /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_ANALYZER_NONNULL = YES; 171 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_COMMA = YES; 179 | CLANG_WARN_CONSTANT_CONVERSION = YES; 180 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 181 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 182 | CLANG_WARN_EMPTY_BODY = YES; 183 | CLANG_WARN_ENUM_CONVERSION = YES; 184 | CLANG_WARN_INFINITE_RECURSION = YES; 185 | CLANG_WARN_INT_CONVERSION = YES; 186 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 187 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 190 | CLANG_WARN_STRICT_PROTOTYPES = YES; 191 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 192 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 193 | CLANG_WARN_UNREACHABLE_CODE = YES; 194 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 195 | CODE_SIGN_IDENTITY = "iPhone Developer"; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = dwarf; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu11; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_OPTIMIZATION_LEVEL = 0; 204 | GCC_PREPROCESSOR_DEFINITIONS = ( 205 | "DEBUG=1", 206 | "$(inherited)", 207 | ); 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 219 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 220 | }; 221 | name = Debug; 222 | }; 223 | 1706FC931F6D6006009B9579 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_ANALYZER_NONNULL = YES; 228 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 229 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 230 | CLANG_CXX_LIBRARY = "libc++"; 231 | CLANG_ENABLE_MODULES = YES; 232 | CLANG_ENABLE_OBJC_ARC = YES; 233 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 234 | CLANG_WARN_BOOL_CONVERSION = YES; 235 | CLANG_WARN_COMMA = YES; 236 | CLANG_WARN_CONSTANT_CONVERSION = YES; 237 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 238 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 239 | CLANG_WARN_EMPTY_BODY = YES; 240 | CLANG_WARN_ENUM_CONVERSION = YES; 241 | CLANG_WARN_INFINITE_RECURSION = YES; 242 | CLANG_WARN_INT_CONVERSION = YES; 243 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 244 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 245 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 246 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 247 | CLANG_WARN_STRICT_PROTOTYPES = YES; 248 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 249 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 250 | CLANG_WARN_UNREACHABLE_CODE = YES; 251 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 252 | CODE_SIGN_IDENTITY = "iPhone Developer"; 253 | COPY_PHASE_STRIP = NO; 254 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 255 | ENABLE_NS_ASSERTIONS = NO; 256 | ENABLE_STRICT_OBJC_MSGSEND = YES; 257 | GCC_C_LANGUAGE_STANDARD = gnu11; 258 | GCC_NO_COMMON_BLOCKS = YES; 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 266 | MTL_ENABLE_DEBUG_INFO = NO; 267 | SDKROOT = iphoneos; 268 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 269 | VALIDATE_PRODUCT = YES; 270 | }; 271 | name = Release; 272 | }; 273 | 1706FC951F6D6006009B9579 /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | CODE_SIGN_STYLE = Automatic; 278 | DEVELOPMENT_TEAM = 4QGK58U3J6; 279 | INFOPLIST_FILE = MarinoDeviceCheck/Info.plist; 280 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 281 | PRODUCT_BUNDLE_IDENTIFIER = com.marinosoftware.MarinoDeviceCheck; 282 | PRODUCT_NAME = "$(TARGET_NAME)"; 283 | SWIFT_VERSION = 4.0; 284 | TARGETED_DEVICE_FAMILY = "1,2"; 285 | }; 286 | name = Debug; 287 | }; 288 | 1706FC961F6D6006009B9579 /* Release */ = { 289 | isa = XCBuildConfiguration; 290 | buildSettings = { 291 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 292 | CODE_SIGN_STYLE = Automatic; 293 | DEVELOPMENT_TEAM = 4QGK58U3J6; 294 | INFOPLIST_FILE = MarinoDeviceCheck/Info.plist; 295 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 296 | PRODUCT_BUNDLE_IDENTIFIER = com.marinosoftware.MarinoDeviceCheck; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_VERSION = 4.0; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | }; 301 | name = Release; 302 | }; 303 | /* End XCBuildConfiguration section */ 304 | 305 | /* Begin XCConfigurationList section */ 306 | 1706FC7D1F6D6006009B9579 /* Build configuration list for PBXProject "MarinoDeviceCheck" */ = { 307 | isa = XCConfigurationList; 308 | buildConfigurations = ( 309 | 1706FC921F6D6006009B9579 /* Debug */, 310 | 1706FC931F6D6006009B9579 /* Release */, 311 | ); 312 | defaultConfigurationIsVisible = 0; 313 | defaultConfigurationName = Release; 314 | }; 315 | 1706FC941F6D6006009B9579 /* Build configuration list for PBXNativeTarget "MarinoDeviceCheck" */ = { 316 | isa = XCConfigurationList; 317 | buildConfigurations = ( 318 | 1706FC951F6D6006009B9579 /* Debug */, 319 | 1706FC961F6D6006009B9579 /* Release */, 320 | ); 321 | defaultConfigurationIsVisible = 0; 322 | defaultConfigurationName = Release; 323 | }; 324 | /* End XCConfigurationList section */ 325 | }; 326 | rootObject = 1706FC7A1F6D6006009B9579 /* Project object */; 327 | } 328 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MarinoDeviceCheck 4 | // 5 | // Created by Tim Colla on 16/09/2017. 6 | // Copyright © 2017 Marinosoftware. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /app/MarinoDeviceCheck/Base.lproj/LaunchScreen.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 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 47 | 48 | 49 | 50 | 57 | 64 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/MarinoDeviceCheck/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // MarinoDeviceCheck 4 | // 5 | // Created by Tim Colla on 16/09/2017. 6 | // Copyright © 2017 Marinosoftware. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import DeviceCheck 11 | 12 | class ViewController: UIViewController { 13 | @IBOutlet weak var bit0: UISwitch! 14 | @IBOutlet weak var bit1: UISwitch! 15 | @IBOutlet weak var activityIndicator: UIActivityIndicatorView! 16 | @IBOutlet weak var lastUpdated: UILabel! 17 | 18 | let host = "http://192.168.1.132:3000" // Change to your NodeJS server IP:port 19 | let curDevice = DCDevice.current 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | // Do any additional setup after loading the view, typically from a nib. 24 | 25 | } 26 | 27 | override func didReceiveMemoryWarning() { 28 | super.didReceiveMemoryWarning() 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | @IBAction func update(_ sender: UIButton) { 33 | startActivity() 34 | 35 | if curDevice.isSupported 36 | { 37 | 38 | curDevice.generateToken { (data, error) in 39 | if let data = data { 40 | let sesh = URLSession(configuration: .default) 41 | var req = URLRequest(url: URL(string:self.host+"/update_two_bits")!) 42 | req.addValue("application/json", forHTTPHeaderField: "Content-Type") 43 | req.httpMethod = "POST" 44 | 45 | DispatchQueue.main.sync { 46 | let bit0 = self.bit0.isOn 47 | let bit1 = self.bit1.isOn 48 | let data = try! JSONSerialization.data(withJSONObject: ["token": data.base64EncodedString(), 49 | "bit0": bit0, 50 | "bit1": bit1], options: []) 51 | 52 | req.httpBody = data 53 | let task = sesh.dataTask(with: req, completionHandler: { (data, response, error) in 54 | if let data = data, let jsonString = String(data: data, encoding: .utf8) { 55 | print(jsonString) 56 | 57 | DispatchQueue.main.async { 58 | self.updateUI(with: data) 59 | } 60 | } 61 | 62 | self.stopActivity() 63 | }) 64 | task.resume() 65 | } 66 | } 67 | if let error = error { 68 | print("Generate Token error:") 69 | print(error.localizedDescription) 70 | } 71 | } 72 | } else { 73 | print("Platform is not supported. Make sure you aren't running in an emulator.") 74 | self.stopActivity() 75 | 76 | } 77 | 78 | } 79 | 80 | @IBAction func query(_ sender: UIButton) { 81 | startActivity() 82 | if curDevice.isSupported 83 | { 84 | 85 | DCDevice.current.generateToken { (data, error) in 86 | if let data = data { 87 | let sesh = URLSession(configuration: .default) 88 | var req = URLRequest(url: URL(string:self.host+"/query_two_bits")!) 89 | req.addValue("application/json", forHTTPHeaderField: "Content-Type") 90 | req.httpMethod = "POST" 91 | 92 | let data = try! JSONSerialization.data(withJSONObject: ["token": data.base64EncodedString()], options: []) 93 | 94 | req.httpBody = data 95 | let task = sesh.dataTask(with: req, completionHandler: { (data, response, error) in 96 | if let data = data, let jsonString = String(data: data, encoding: .utf8) { 97 | print(jsonString) 98 | 99 | DispatchQueue.main.async { 100 | self.updateUI(with: data) 101 | } 102 | } 103 | 104 | self.stopActivity() 105 | }) 106 | task.resume() 107 | } 108 | if let error = error { 109 | print("Generate Token error:") 110 | print(error.localizedDescription) 111 | } 112 | } 113 | } else { 114 | print("Platform is not supported. Make sure you aren't running in an emulator.") 115 | self.stopActivity() 116 | 117 | } 118 | } 119 | 120 | func updateUI(with jsonData: Data) { 121 | do { 122 | let json = try JSONSerialization.jsonObject(with: jsonData, options: []) as! [String: Any] 123 | 124 | if let bit0 = json["bit0"] as? Bool, let bit1 = json["bit1"] as? Bool { 125 | self.bit0.isOn = bit0 126 | self.bit1.isOn = bit1 127 | } 128 | 129 | if let lastUpdated = json["lastUpdated"] as? String { 130 | self.lastUpdated.text = "Last Updated: "+lastUpdated 131 | } 132 | } catch { 133 | print(error.localizedDescription) 134 | } 135 | } 136 | 137 | func startActivity() { 138 | DispatchQueue.main.async { 139 | self.activityIndicator.startAnimating() 140 | 141 | self.view.isUserInteractionEnabled = false 142 | self.view.alpha = 0.5 143 | } 144 | } 145 | 146 | func stopActivity() { 147 | DispatchQueue.main.async { 148 | self.activityIndicator.stopAnimating() 149 | 150 | self.view.isUserInteractionEnabled = true 151 | self.view.alpha = 1.0 152 | } 153 | } 154 | } 155 | 156 | -------------------------------------------------------------------------------- /server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "marino-devicecheck", 3 | "version": "1.0.0", 4 | "description": "Sample server for iOS 11's DeviceCheck APIs", 5 | "main": "sampleServer.js", 6 | "dependencies": { 7 | "body-parser": "^1.17.2", 8 | "express": "^4.15.4", 9 | "jsonwebtoken": "^8.0.0", 10 | "uuid": "^3.1.0" 11 | }, 12 | "devDependencies": {}, 13 | "scripts": { 14 | "test": "echo \"Error: no test specified\" && exit 1", 15 | "start": "node sampleServer.js" 16 | }, 17 | "author": "Tim Colla, Marino Software", 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /server/sampleServer.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var jwt = require('jsonwebtoken'); 3 | var https = require('https'); 4 | const uuidv4 = require('uuid/v4'); 5 | 6 | var express = require('express'); 7 | var bodyParser = require('body-parser'); 8 | var app = express(); 9 | var http = require('http').createServer(app); 10 | var versionRouter = express(); 11 | 12 | 13 | versionRouter.set('view engine', 'ejs'); //tell Express we're using EJS 14 | versionRouter.use(bodyParser.json()); 15 | versionRouter.use(bodyParser.urlencoded({ extended: false })) 16 | var versionBuildPath = "/"; 17 | 18 | /****************** Set your values ******************/ 19 | var keyFileName = ""; // Download from https://developer.apple.com/account/ios/authkey/ 20 | var keyId = ""; // Can be found at: https://developer.apple.com/account/ios/authkey/ 21 | var teamId = ""; // Can be found at: https://developer.apple.com/account/#/membership/ 22 | 23 | var port = 3000; 24 | 25 | // Change this to true when you're app is on the App Store 26 | var production = false; 27 | /****************** End set your values ******************/ 28 | 29 | if(keyFileName == "") { 30 | console.log("Missing required parameters."); 31 | console.log("Make sure you've entered your keyFileName, keyId and teamId."); 32 | return; 33 | } 34 | 35 | var deviceCheckHost = production ? 'api.devicecheck.apple.com' : 'api.development.devicecheck.apple.com'; 36 | var cert = fs.readFileSync(keyFileName).toString(); 37 | 38 | versionRouter.post('/update_two_bits', function(req, response) { 39 | console.log("\n\n\n\n\n"); 40 | var dctoken = req.body.token; 41 | var bit0 = req.body.bit0; 42 | var bit1 = req.body.bit1; 43 | 44 | console.log("Updating two bits to:"); 45 | console.log("bit0: "+bit0); 46 | console.log("bit1: "+bit1); 47 | 48 | var jwToken = jwt.sign({}, cert, { algorithm: 'ES256', keyid: keyId, issuer: teamId}); 49 | 50 | // Build the post string from an object 51 | var post_data = { 52 | 'device_token' : dctoken, 53 | 'transaction_id': uuidv4(), 54 | 'timestamp': Date.now(), 55 | 'bit0': bit0, 56 | 'bit1': bit1 57 | } 58 | // An object of options to indicate where to post to 59 | var post_options = { 60 | host: deviceCheckHost, 61 | port: '443', 62 | path: '/v1/update_two_bits', 63 | method: 'POST', 64 | headers: { 65 | 'Authorization': 'Bearer '+jwToken 66 | } 67 | }; 68 | 69 | // Set up the request 70 | var post_req = https.request(post_options, function(res) { 71 | res.setEncoding('utf8'); 72 | 73 | console.log(res.headers); 74 | console.log("statusCode: "+res.statusCode); 75 | 76 | var data = ""; 77 | res.on('data', function (chunk) { 78 | data += chunk; 79 | }); 80 | res.on('end', function() { 81 | console.log(data); 82 | response.send({"status": res.statusCode}); 83 | }); 84 | 85 | res.on('error', function(data) { 86 | console.log('error'); 87 | console.log(data); 88 | response.send({"status": res.statusCode}); 89 | }); 90 | }); 91 | 92 | // post the data 93 | post_req.write(new Buffer.from(JSON.stringify(post_data))); 94 | post_req.end(); 95 | }); 96 | 97 | versionRouter.post('/query_two_bits', function(req, response) { 98 | console.log("\n\n\n\n\n"); 99 | console.log("Querying two bits"); 100 | var dctoken = req.body.token; 101 | 102 | var jwToken = jwt.sign({}, cert, { algorithm: 'ES256', keyid: keyId, issuer: teamId}); 103 | 104 | // Build the post string from an object 105 | var post_data = { 106 | 'device_token' : dctoken, 107 | 'transaction_id': uuidv4(), 108 | 'timestamp': Date.now() 109 | } 110 | // An object of options to indicate where to post to 111 | var post_options = { 112 | host: deviceCheckHost, 113 | port: '443', 114 | path: '/v1/query_two_bits', 115 | method: 'POST', 116 | headers: { 117 | 'Authorization': 'Bearer '+jwToken 118 | } 119 | }; 120 | 121 | // Set up the request 122 | var post_req = https.request(post_options, function(res) { 123 | res.setEncoding('utf8'); 124 | 125 | console.log(res.headers); 126 | console.log("statusCode: "+res.statusCode); 127 | 128 | var data = ""; 129 | res.on('data', function (chunk) { 130 | data += chunk; 131 | }); 132 | res.on('end', function() { 133 | try { 134 | var json = JSON.parse(data); 135 | console.log(json); 136 | response.send({"status": res.statusCode, 137 | "bit0": json.bit0, 138 | "bit1": json.bit1, 139 | "lastUpdated": json.last_update_time}); 140 | } catch (e) { 141 | console.log('error'); 142 | console.log(data); 143 | response.send({"status": res.statusCode}); 144 | } 145 | }); 146 | 147 | res.on('error', function(data) { 148 | console.log('error'); 149 | console.log(data); 150 | response.send({"status": res.statusCode}); 151 | }); 152 | }); 153 | 154 | // post the data 155 | post_req.write(new Buffer.from(JSON.stringify(post_data))); 156 | post_req.end(); 157 | }); 158 | 159 | app.use(versionBuildPath, versionRouter); 160 | // Start server on port 3000 161 | http.listen(port); --------------------------------------------------------------------------------