@vppos/react-native-nfc 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/NFCSDK.podspec +40 -0
- package/android/build.gradle +85 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +31 -0
- package/android/src/main/AndroidManifestNew.xml +30 -0
- package/android/src/main/java/com/nfcsdk/ChipReader.kt +237 -0
- package/android/src/main/java/com/nfcsdk/NFCSDKModule.kt +78 -0
- package/android/src/main/java/com/nfcsdk/NFCSDKPackage.kt +17 -0
- package/android/src/main/java/com/nfcsdk/NFCScanActivity.kt +299 -0
- package/android/src/main/java/com/nfcsdk/utils/Dg13Parser.kt +278 -0
- package/android/src/main/java/com/nfcsdk/utils/FaceExtractor.kt +40 -0
- package/android/src/main/java/com/nfcsdk/utils/MrzUtils.kt +75 -0
- package/android/src/main/res/drawable/bg_nfc_bottom_sheet.xml +13 -0
- package/android/src/main/res/drawable/bg_nfc_sheet_handle.xml +9 -0
- package/android/src/main/res/layout/activity_nfc.xml +110 -0
- package/android/src/main/res/values/styles.xml +10 -0
- package/android/src/main/res/xml/nfc_tech_filter.xml +8 -0
- package/ios/ChipReader.swift +258 -0
- package/ios/NFCSDK-Bridging-Header.h +2 -0
- package/ios/NFCSDK.mm +9 -0
- package/ios/NFCSDK.swift +112 -0
- package/ios/NFCSDKSession.swift +5 -0
- package/ios/utils/DG13Parser.swift +302 -0
- package/ios/utils/MrzUtils.swift +49 -0
- package/lib/module/errors.js +9 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/index.js +118 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/errors.d.ts +4 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +80 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +45 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +155 -0
- package/src/errors.ts +6 -0
- package/src/index.tsx +141 -0
- package/src/types.ts +45 -0
- package/vendor/ios-passport-reader/CHANGELOG +362 -0
- package/vendor/ios-passport-reader/CODE_OF_CONDUCT.md +77 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/AppDelegate.swift +39 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/Contents.json +158 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-40.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-72.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-76.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small-50.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small-50@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/ios-marketing.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon~ipad.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon~ipad@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/Contents.json +6 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/background.imageset/Contents.json +21 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/background.imageset/background.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/head.imageset/Contents.json +21 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Assets.xcassets/head.imageset/head.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Base.lproj/LaunchScreen.storyboard +25 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Extensions/FileManagerExt.swift +16 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Extensions/StringExt.swift +40 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Extensions/UIApplicationExt.swift +21 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Info.plist +77 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Model/PassportUtils.swift +76 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Model/SettingsStore.swift +107 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/NFCPassportReader.entitlements +10 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/SceneDelegate.swift +57 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/DetailsView.swift +197 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/ExportPassportView.swift +164 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/HelperViews/CheckBoxView.swift +48 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/HelperViews/ViewExt.swift +20 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/HelperViews/ViewModifiers.swift +41 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/MRZEntryView.swift +125 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/MRZScannerViewController.swift +90 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/MainView.swift +214 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/PassportSummaryView.swift +111 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/PassportView.swift +73 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/SettingsView.swift +63 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/Views/StoredPassportView.swift +152 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/masterList.pem +32 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp/readme.md +10 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp.xcodeproj/project.pbxproj +695 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp.xcodeproj/xcshareddata/xcschemes/NFCPassportReader.xcscheme +106 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp.xcworkspace/contents.xcworkspacedata +10 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderApp.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +8 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderAppTests/DataGroupParsingTests.swift +189 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderAppTests/Info.plist +22 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderAppTests/NFCPassportReaderTests.swift +260 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/NFCPassportReaderAppTests/PACETests.swift +112 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/Podfile +22 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/Podfile.lock +35 -0
- package/vendor/ios-passport-reader/Examples/Example_CocoaPods/README.md +2 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/AppDelegate.swift +39 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/Contents.json +158 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-40.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-40@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-40@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-60@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-60@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-72.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-72@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-76.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-76@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-83.5@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small-50.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small-50@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon-small@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/icon@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/ios-marketing.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon@3x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon~ipad.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/AppIcon.appiconset/notification-icon~ipad@2x.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/Contents.json +6 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/background.imageset/Contents.json +21 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/background.imageset/background.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/head.imageset/Contents.json +21 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Assets.xcassets/head.imageset/head.png +0 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Base.lproj/LaunchScreen.storyboard +25 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Extensions/FileManagerExt.swift +16 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Extensions/StringExt.swift +40 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Extensions/UIApplicationExt.swift +21 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Info.plist +79 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Model/PassportUtils.swift +99 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Model/SettingsStore.swift +98 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Model/SettingsStoreCAN.swift +75 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/MrzScanner/LICENSE +21 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/MrzScanner/PreviewView.swift +34 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/MrzScanner/StringUtils.swift +160 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/MrzScanner/ViewController.swift +320 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/MrzScanner/VisionViewController.swift +163 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/NFCPassportReader.entitlements +10 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/SceneDelegate.swift +58 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/CANViews/CanKeyView.swift +251 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/CANViews/MRZEntryViewCanKey.swift +65 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/CANViews/PassportViewCAN.swift +73 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/DetailsView.swift +193 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/ExportPassportView.swift +164 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/HelperViews/CheckBoxView.swift +48 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/HelperViews/ViewExt.swift +20 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/HelperViews/ViewModifiers.swift +41 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/MRZEntryView.swift +125 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/MRZScannerViewController.swift +90 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/MainView.swift +264 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/PassportSummaryView.swift +111 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/PassportView.swift +73 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/SettingsView.swift +47 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/Views/StoredPassportView.swift +149 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/masterList.pem +32 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp/readme.md +10 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp.xcodeproj/project.pbxproj +683 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +25 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderApp.xcodeproj/xcshareddata/xcschemes/NFCPassportReader.xcscheme +106 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderAppTests/DataGroupParsingTests.swift +190 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderAppTests/Info.plist +22 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderAppTests/NFCPassportReaderTests.swift +260 -0
- package/vendor/ios-passport-reader/Examples/Example_SPM/NFCPassportReaderAppTests/PACETests.swift +112 -0
- package/vendor/ios-passport-reader/LICENSE +21 -0
- package/vendor/ios-passport-reader/NFCPassportReader.podspec +27 -0
- package/vendor/ios-passport-reader/Package.swift +29 -0
- package/vendor/ios-passport-reader/README.md +141 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/AES_3DES_DESEncryption.swift +377 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/BACHandler.swift +194 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/ChipAuthenticationHandler.swift +224 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroupHash.swift +16 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroupParser.swift +36 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/ActiveAuthenticationInfo.swift +69 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/COM.swift +61 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/CardAccess.swift +38 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/ChipAuthenticationInfo.swift +135 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/ChipAuthenticationPublicKeyInfo.swift +53 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup.swift +103 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup1.swift +111 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup11.swift +66 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup12.swift +75 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup14.swift +37 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup15.swift +46 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup2.swift +163 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroup7.swift +46 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/DataGroupId.swift +105 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/NotImplementedDG.swift +16 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/PACEInfo.swift +415 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/SOD.swift +240 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/DataGroups/SecurityInfo.swift +136 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/Errors.swift +148 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/Logging.swift +32 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/Models/FaceImageInfo.swift +161 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/NFCPassportModel.swift +540 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/NFCViewDisplayMessage.swift +60 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/OpenSSLUtils.swift +705 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/PACEHandler.swift +627 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/PassportReader.swift +387 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/Resources/PrivacyInfo.xcprivacy +14 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/ResponseAPDU.swift +25 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/SecureMessaging.swift +301 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/SecureMessagingSessionKeyGenerator.swift +156 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/SimpleASN1DumpParser.swift +173 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/TagReader.swift +374 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/Utils.swift +430 -0
- package/vendor/ios-passport-reader/Sources/NFCPassportReader/X509Wrapper.swift +168 -0
- package/vendor/ios-passport-reader/scripts/README.md +45 -0
- package/vendor/ios-passport-reader/scripts/extract.py +197 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
//
|
|
2
|
+
// 3DES_DESEncryption.swift
|
|
3
|
+
// NFCTest
|
|
4
|
+
//
|
|
5
|
+
// Created by Andy Qua on 07/06/2019.
|
|
6
|
+
// Copyright © 2019 Andy Qua. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import OSLog
|
|
11
|
+
import CommonCrypto
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/// Encrypts a message using AES/CBC/NOPADDING with a specified key and initialisation vector
|
|
15
|
+
/// - Parameter key: Key use to encrypt
|
|
16
|
+
/// - Parameter message: Message to encrypt
|
|
17
|
+
/// - Parameter iv: Initialisation vector
|
|
18
|
+
@available(iOS 13, macOS 10.15, *)
|
|
19
|
+
public func AESEncrypt(key:[UInt8], message:[UInt8], iv:[UInt8]) -> [UInt8] {
|
|
20
|
+
|
|
21
|
+
let dataLength = message.count
|
|
22
|
+
|
|
23
|
+
let cryptLen = message.count + kCCBlockSizeAES128
|
|
24
|
+
var cryptData = Data(count: cryptLen)
|
|
25
|
+
|
|
26
|
+
let keyLength = size_t(key.count)
|
|
27
|
+
let operation: CCOperation = CCOperation(kCCEncrypt)
|
|
28
|
+
let algorithm: CCAlgorithm = CCAlgorithm(kCCAlgorithmAES)
|
|
29
|
+
let options: CCOptions = CCOptions(0)
|
|
30
|
+
|
|
31
|
+
var numBytesEncrypted = 0
|
|
32
|
+
|
|
33
|
+
var cryptStatus: CCCryptorStatus = CCCryptorStatus(kCCSuccess)
|
|
34
|
+
key.withUnsafeBytes {keyBytes in
|
|
35
|
+
message.withUnsafeBytes{ dataBytes in
|
|
36
|
+
iv.withUnsafeBytes{ ivBytes in
|
|
37
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
38
|
+
|
|
39
|
+
cryptStatus = CCCrypt(operation,
|
|
40
|
+
algorithm,
|
|
41
|
+
options,
|
|
42
|
+
keyBytes.baseAddress,
|
|
43
|
+
keyLength,
|
|
44
|
+
ivBytes.baseAddress,
|
|
45
|
+
dataBytes.baseAddress,
|
|
46
|
+
dataLength,
|
|
47
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
48
|
+
cryptLen,
|
|
49
|
+
&numBytesEncrypted)
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if cryptStatus == kCCSuccess {
|
|
57
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
58
|
+
|
|
59
|
+
return [UInt8](cryptData)
|
|
60
|
+
} else {
|
|
61
|
+
Logger.passportReader.error("AES Encrypt Error: \(cryptStatus)")
|
|
62
|
+
}
|
|
63
|
+
return []
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Decrypts a message using AES/CBC/NOPADDING with a specified key and initialisation vector
|
|
67
|
+
/// - Parameter key: Key use to decrypt
|
|
68
|
+
/// - Parameter message: Message to decrypt
|
|
69
|
+
/// - Parameter iv: Initialisation vector
|
|
70
|
+
@available(iOS 13, macOS 10.15, *)
|
|
71
|
+
public func AESDecrypt(key:[UInt8], message:[UInt8], iv:[UInt8]) -> [UInt8] {
|
|
72
|
+
var fixedKey = key
|
|
73
|
+
if key.count == 16 {
|
|
74
|
+
fixedKey += key[0..<8]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let data = Data(message)
|
|
78
|
+
let dataLength = message.count
|
|
79
|
+
|
|
80
|
+
let cryptLen = data.count + kCCBlockSizeAES128
|
|
81
|
+
var cryptData = Data(count: cryptLen)
|
|
82
|
+
|
|
83
|
+
let keyLength = size_t(key.count)
|
|
84
|
+
let operation: CCOperation = UInt32(kCCDecrypt)
|
|
85
|
+
let algorithm: CCAlgorithm = UInt32(kCCAlgorithmAES)
|
|
86
|
+
let options: CCOptions = UInt32(0)
|
|
87
|
+
|
|
88
|
+
var numBytesEncrypted = 0
|
|
89
|
+
|
|
90
|
+
let cryptStatus = fixedKey.withUnsafeBytes {keyBytes in
|
|
91
|
+
message.withUnsafeBytes{ dataBytes in
|
|
92
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
93
|
+
CCCrypt(operation,
|
|
94
|
+
algorithm,
|
|
95
|
+
options,
|
|
96
|
+
keyBytes.baseAddress,
|
|
97
|
+
keyLength,
|
|
98
|
+
iv,
|
|
99
|
+
dataBytes.baseAddress,
|
|
100
|
+
dataLength,
|
|
101
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
102
|
+
cryptLen,
|
|
103
|
+
&numBytesEncrypted)
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if cryptStatus == kCCSuccess {
|
|
110
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
111
|
+
|
|
112
|
+
return [UInt8](cryptData)
|
|
113
|
+
} else {
|
|
114
|
+
Logger.passportReader.error("AES Decrypt Error: \(cryptStatus)")
|
|
115
|
+
}
|
|
116
|
+
return []
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// Decrypts a message using AES/ECB/NOPADDING with a specified key and initialisation vector
|
|
120
|
+
/// - Parameter key: Key use to decrypt
|
|
121
|
+
/// - Parameter message: Message to decrypt
|
|
122
|
+
/// - Parameter iv: Initialisation vector
|
|
123
|
+
@available(iOS 13, macOS 10.15, *)
|
|
124
|
+
public func AESECBEncrypt(key:[UInt8], message:[UInt8]) -> [UInt8] {
|
|
125
|
+
|
|
126
|
+
let dataLength = message.count
|
|
127
|
+
|
|
128
|
+
let cryptLen = message.count + kCCBlockSizeAES128
|
|
129
|
+
var cryptData = Data(count: cryptLen)
|
|
130
|
+
|
|
131
|
+
let keyLength = size_t(key.count)
|
|
132
|
+
let operation: CCOperation = CCOperation(kCCEncrypt)
|
|
133
|
+
let algorithm: CCAlgorithm = CCAlgorithm(kCCAlgorithmAES)
|
|
134
|
+
let options: CCOptions = CCOptions(kCCOptionECBMode)
|
|
135
|
+
|
|
136
|
+
var numBytesEncrypted = 0
|
|
137
|
+
|
|
138
|
+
let cryptStatus = key.withUnsafeBytes {keyBytes in
|
|
139
|
+
message.withUnsafeBytes{ dataBytes in
|
|
140
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
141
|
+
|
|
142
|
+
CCCrypt(operation,
|
|
143
|
+
algorithm,
|
|
144
|
+
options,
|
|
145
|
+
keyBytes.baseAddress,
|
|
146
|
+
keyLength,
|
|
147
|
+
nil,
|
|
148
|
+
dataBytes.baseAddress,
|
|
149
|
+
dataLength,
|
|
150
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
151
|
+
cryptLen,
|
|
152
|
+
&numBytesEncrypted)
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if cryptStatus == kCCSuccess {
|
|
159
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
160
|
+
|
|
161
|
+
return [UInt8](cryptData)
|
|
162
|
+
} else {
|
|
163
|
+
Logger.passportReader.error("AESECBEncrypt Error: \(cryptStatus)")
|
|
164
|
+
}
|
|
165
|
+
return []
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Encrypts a message using DES3 with a specified key and initialisation vector
|
|
169
|
+
/// - Parameter key: Key use to encrypt
|
|
170
|
+
/// - Parameter message: Message to encrypt
|
|
171
|
+
/// - Parameter iv: Initialisation vector
|
|
172
|
+
@available(iOS 13, macOS 10.15, *)
|
|
173
|
+
public func tripleDESEncrypt(key:[UInt8], message:[UInt8], iv:[UInt8]) -> [UInt8] {
|
|
174
|
+
// Fix key data - if length is 16 then take the first 98 bytes and append them to the end to make 24 bytes
|
|
175
|
+
var fixedKey = key
|
|
176
|
+
if key.count == 16 {
|
|
177
|
+
fixedKey += key[0..<8]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let dataLength = message.count
|
|
181
|
+
|
|
182
|
+
let cryptLen = message.count + kCCBlockSize3DES
|
|
183
|
+
var cryptData = Data(count: cryptLen)
|
|
184
|
+
|
|
185
|
+
let keyLength = size_t(kCCKeySize3DES)
|
|
186
|
+
let operation: CCOperation = UInt32(kCCEncrypt)
|
|
187
|
+
let algorithm: CCAlgorithm = UInt32(kCCAlgorithm3DES)
|
|
188
|
+
let options: CCOptions = UInt32(0)
|
|
189
|
+
|
|
190
|
+
var numBytesEncrypted = 0
|
|
191
|
+
|
|
192
|
+
let cryptStatus = fixedKey.withUnsafeBytes {keyBytes in
|
|
193
|
+
message.withUnsafeBytes{ dataBytes in
|
|
194
|
+
iv.withUnsafeBytes{ ivBytes in
|
|
195
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
196
|
+
CCCrypt(operation,
|
|
197
|
+
algorithm,
|
|
198
|
+
options,
|
|
199
|
+
keyBytes.baseAddress,
|
|
200
|
+
keyLength,
|
|
201
|
+
ivBytes.baseAddress,
|
|
202
|
+
dataBytes.baseAddress,
|
|
203
|
+
dataLength,
|
|
204
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
205
|
+
cryptLen,
|
|
206
|
+
&numBytesEncrypted)
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if cryptStatus == kCCSuccess {
|
|
214
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
215
|
+
|
|
216
|
+
return [UInt8](cryptData)
|
|
217
|
+
} else {
|
|
218
|
+
Logger.passportReader.error("Error: \(cryptStatus)")
|
|
219
|
+
}
|
|
220
|
+
return []
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// Decrypts a message using DES3 with a specified key and initialisation vector
|
|
224
|
+
/// - Parameter key: Key use to decrypt
|
|
225
|
+
/// - Parameter message: Message to decrypt
|
|
226
|
+
/// - Parameter iv: Initialisation vector
|
|
227
|
+
@available(iOS 13, macOS 10.15, *)
|
|
228
|
+
public func tripleDESDecrypt(key:[UInt8], message:[UInt8], iv:[UInt8]) -> [UInt8] {
|
|
229
|
+
var fixedKey = key
|
|
230
|
+
if key.count == 16 {
|
|
231
|
+
fixedKey += key[0..<8]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
let data = Data(message)
|
|
235
|
+
let dataLength = message.count
|
|
236
|
+
|
|
237
|
+
let cryptLen = data.count + kCCBlockSize3DES
|
|
238
|
+
var cryptData = Data(count: cryptLen)
|
|
239
|
+
|
|
240
|
+
let keyLength = size_t(kCCKeySize3DES)
|
|
241
|
+
let operation: CCOperation = UInt32(kCCDecrypt)
|
|
242
|
+
let algorithm: CCAlgorithm = UInt32(kCCAlgorithm3DES)
|
|
243
|
+
let options: CCOptions = UInt32(0)
|
|
244
|
+
|
|
245
|
+
var numBytesEncrypted = 0
|
|
246
|
+
|
|
247
|
+
let cryptStatus = fixedKey.withUnsafeBytes {keyBytes in
|
|
248
|
+
message.withUnsafeBytes{ dataBytes in
|
|
249
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
250
|
+
CCCrypt(operation,
|
|
251
|
+
algorithm,
|
|
252
|
+
options,
|
|
253
|
+
keyBytes.baseAddress,
|
|
254
|
+
keyLength,
|
|
255
|
+
iv,
|
|
256
|
+
dataBytes.baseAddress,
|
|
257
|
+
dataLength,
|
|
258
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
259
|
+
cryptLen,
|
|
260
|
+
&numBytesEncrypted)
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if cryptStatus == kCCSuccess {
|
|
267
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
268
|
+
|
|
269
|
+
return [UInt8](cryptData)
|
|
270
|
+
} else {
|
|
271
|
+
Logger.passportReader.error("Error: \(cryptStatus)")
|
|
272
|
+
}
|
|
273
|
+
return []
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
/// Encrypts a message using DES with a specified key and initialisation vector
|
|
278
|
+
/// - Parameter key: Key use to encrypt
|
|
279
|
+
/// - Parameter message: Message to encrypt
|
|
280
|
+
/// - Parameter iv: Initialisation vector
|
|
281
|
+
/// - Parameter options: Encryption options to use
|
|
282
|
+
@available(iOS 13, macOS 10.15, *)
|
|
283
|
+
public func DESEncrypt(key:[UInt8], message:[UInt8], iv:[UInt8], options:UInt32 = 0) -> [UInt8] {
|
|
284
|
+
|
|
285
|
+
let dataLength = message.count
|
|
286
|
+
|
|
287
|
+
let cryptLen = message.count + kCCBlockSizeDES
|
|
288
|
+
var cryptData = Data(count: cryptLen)
|
|
289
|
+
|
|
290
|
+
let keyLength = size_t(kCCKeySizeDES)
|
|
291
|
+
let operation: CCOperation = UInt32(kCCEncrypt)
|
|
292
|
+
let algorithm: CCAlgorithm = UInt32(kCCAlgorithmDES)
|
|
293
|
+
let options: CCOptions = options
|
|
294
|
+
|
|
295
|
+
var numBytesEncrypted = 0
|
|
296
|
+
|
|
297
|
+
let cryptStatus = key.withUnsafeBytes {keyBytes in
|
|
298
|
+
message.withUnsafeBytes{ dataBytes in
|
|
299
|
+
iv.withUnsafeBytes{ ivBytes in
|
|
300
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
301
|
+
CCCrypt(operation,
|
|
302
|
+
algorithm,
|
|
303
|
+
options,
|
|
304
|
+
keyBytes.baseAddress,
|
|
305
|
+
keyLength,
|
|
306
|
+
ivBytes.baseAddress,
|
|
307
|
+
dataBytes.baseAddress,
|
|
308
|
+
dataLength,
|
|
309
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
310
|
+
cryptLen,
|
|
311
|
+
&numBytesEncrypted)
|
|
312
|
+
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if cryptStatus == kCCSuccess {
|
|
319
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
320
|
+
|
|
321
|
+
return [UInt8](cryptData)
|
|
322
|
+
} else {
|
|
323
|
+
Logger.passportReader.error("Error: \(cryptStatus)")
|
|
324
|
+
}
|
|
325
|
+
return []
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/// Decrypts a message using DES with a specified key and initialisation vector
|
|
329
|
+
/// - Parameter key: Key use to decrypt
|
|
330
|
+
/// - Parameter message: Message to decrypt
|
|
331
|
+
/// - Parameter iv: Initialisation vector
|
|
332
|
+
/// - Parameter options: Decryption options to use
|
|
333
|
+
@available(iOS 13, macOS 10.15, *)
|
|
334
|
+
public func DESDecrypt(key:[UInt8], message:[UInt8], iv:[UInt8], options:UInt32 = 0) -> [UInt8] {
|
|
335
|
+
|
|
336
|
+
let dataLength = message.count
|
|
337
|
+
|
|
338
|
+
let cryptLen = message.count + kCCBlockSizeDES
|
|
339
|
+
var cryptData = Data(count: cryptLen)
|
|
340
|
+
|
|
341
|
+
let keyLength = size_t(kCCKeySizeDES)
|
|
342
|
+
let operation: CCOperation = UInt32(kCCDecrypt)
|
|
343
|
+
let algorithm: CCAlgorithm = UInt32(kCCAlgorithmDES)
|
|
344
|
+
let options: CCOptions = options
|
|
345
|
+
|
|
346
|
+
var numBytesEncrypted = 0
|
|
347
|
+
|
|
348
|
+
let cryptStatus = key.withUnsafeBytes {keyBytes in
|
|
349
|
+
message.withUnsafeBytes{ dataBytes in
|
|
350
|
+
iv.withUnsafeBytes{ ivBytes in
|
|
351
|
+
cryptData.withUnsafeMutableBytes{ cryptBytes in
|
|
352
|
+
CCCrypt(operation,
|
|
353
|
+
algorithm,
|
|
354
|
+
options,
|
|
355
|
+
keyBytes.baseAddress,
|
|
356
|
+
keyLength,
|
|
357
|
+
nil,
|
|
358
|
+
dataBytes.baseAddress,
|
|
359
|
+
dataLength,
|
|
360
|
+
cryptBytes.bindMemory(to: UInt8.self).baseAddress,
|
|
361
|
+
cryptLen,
|
|
362
|
+
&numBytesEncrypted)
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if cryptStatus == kCCSuccess {
|
|
370
|
+
cryptData.count = Int(numBytesEncrypted)
|
|
371
|
+
|
|
372
|
+
return [UInt8](cryptData)
|
|
373
|
+
} else {
|
|
374
|
+
Logger.passportReader.error("Error: \(cryptStatus)")
|
|
375
|
+
}
|
|
376
|
+
return []
|
|
377
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BACHandler.swift
|
|
3
|
+
// NFCTest
|
|
4
|
+
//
|
|
5
|
+
// Created by Andy Qua on 07/06/2019.
|
|
6
|
+
// Copyright © 2019 Andy Qua. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import OSLog
|
|
11
|
+
|
|
12
|
+
#if !os(macOS)
|
|
13
|
+
import CoreNFC
|
|
14
|
+
|
|
15
|
+
@available(iOS 15, *)
|
|
16
|
+
public class BACHandler {
|
|
17
|
+
let KENC : [UInt8] = [0,0,0,1]
|
|
18
|
+
let KMAC : [UInt8] = [0,0,0,2]
|
|
19
|
+
|
|
20
|
+
public var ksenc : [UInt8] = []
|
|
21
|
+
public var ksmac : [UInt8] = []
|
|
22
|
+
|
|
23
|
+
var rnd_icc : [UInt8] = []
|
|
24
|
+
var rnd_ifd : [UInt8] = []
|
|
25
|
+
public var kifd : [UInt8] = []
|
|
26
|
+
|
|
27
|
+
var tagReader : TagReader?
|
|
28
|
+
|
|
29
|
+
public init() {
|
|
30
|
+
// For testing only
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public init(tagReader: TagReader) {
|
|
34
|
+
self.tagReader = tagReader
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public func performBACAndGetSessionKeys( mrzKey : String ) async throws {
|
|
38
|
+
guard let tagReader = self.tagReader else {
|
|
39
|
+
throw NFCPassportReaderError.NoConnectedTag
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Logger.bac.debug( "BACHandler - deriving Document Basic Access Keys" )
|
|
43
|
+
_ = try self.deriveDocumentBasicAccessKeys(mrz: mrzKey)
|
|
44
|
+
|
|
45
|
+
// Make sure we clear secure messaging (could happen if we read an invalid DG or we hit a secure error
|
|
46
|
+
tagReader.secureMessaging = nil
|
|
47
|
+
|
|
48
|
+
// get Challenge
|
|
49
|
+
Logger.bac.debug( "BACHandler - Getting initial challenge" )
|
|
50
|
+
let response = try await tagReader.getChallenge()
|
|
51
|
+
|
|
52
|
+
Logger.bac.debug( "DATA - \(response.data)" )
|
|
53
|
+
|
|
54
|
+
Logger.bac.debug( "BACHandler - Doing mutual authentication" )
|
|
55
|
+
let cmd_data = self.authentication(rnd_icc: [UInt8](response.data))
|
|
56
|
+
let maResponse = try await tagReader.doMutualAuthentication(cmdData: Data(cmd_data))
|
|
57
|
+
Logger.bac.debug( "DATA - \(maResponse.data)" )
|
|
58
|
+
guard maResponse.data.count > 0 else {
|
|
59
|
+
throw NFCPassportReaderError.InvalidMRZKey
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let (KSenc, KSmac, ssc) = try self.sessionKeys(data: [UInt8](maResponse.data))
|
|
63
|
+
tagReader.secureMessaging = SecureMessaging(ksenc: KSenc, ksmac: KSmac, ssc: ssc)
|
|
64
|
+
Logger.bac.debug( "BACHandler - complete" )
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
func deriveDocumentBasicAccessKeys(mrz: String) throws -> ([UInt8], [UInt8]) {
|
|
69
|
+
let kseed = generateInitialKseed(kmrz:mrz)
|
|
70
|
+
|
|
71
|
+
Logger.bac.debug("Calculate the Basic Access Keys (Kenc and Kmac) using TR-SAC 1.01, 4.2")
|
|
72
|
+
let smskg = SecureMessagingSessionKeyGenerator()
|
|
73
|
+
self.ksenc = try smskg.deriveKey(keySeed: kseed, mode: .ENC_MODE)
|
|
74
|
+
self.ksmac = try smskg.deriveKey(keySeed: kseed, mode: .MAC_MODE)
|
|
75
|
+
|
|
76
|
+
return (ksenc, ksmac)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
///
|
|
80
|
+
/// Calculate the kseed from the kmrz:
|
|
81
|
+
/// - Calculate a SHA-1 hash of the kmrz
|
|
82
|
+
/// - Take the most significant 16 bytes to form the Kseed.
|
|
83
|
+
/// @param kmrz: The MRZ information
|
|
84
|
+
/// @type kmrz: a string
|
|
85
|
+
/// @return: a 16 bytes string
|
|
86
|
+
///
|
|
87
|
+
/// - Parameter kmrz: mrz key
|
|
88
|
+
/// - Returns: first 16 bytes of the mrz SHA1 hash
|
|
89
|
+
///
|
|
90
|
+
func generateInitialKseed(kmrz : String ) -> [UInt8] {
|
|
91
|
+
|
|
92
|
+
Logger.bac.debug("Calculate the SHA-1 hash of MRZ_information")
|
|
93
|
+
Logger.bac.debug("\tMRZ KEY - \(kmrz)")
|
|
94
|
+
let hash = calcSHA1Hash( [UInt8](kmrz.data(using:.utf8)!) )
|
|
95
|
+
|
|
96
|
+
Logger.bac.debug("\tsha1(MRZ_information): \(binToHexRep(hash))")
|
|
97
|
+
|
|
98
|
+
let subHash = Array(hash[0..<16])
|
|
99
|
+
Logger.bac.debug("Take the most significant 16 bytes to form the Kseed")
|
|
100
|
+
Logger.bac.debug("\tKseed: \(binToHexRep(subHash))" )
|
|
101
|
+
|
|
102
|
+
return Array(subHash)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
/// Construct the command data for the mutual authentication.
|
|
107
|
+
/// - Request an 8 byte random number from the MRTD's chip (rnd.icc)
|
|
108
|
+
/// - Generate an 8 byte random (rnd.ifd) and a 16 byte random (kifd)
|
|
109
|
+
/// - Concatenate rnd.ifd, rnd.icc and kifd (s = rnd.ifd + rnd.icc + kifd)
|
|
110
|
+
/// - Encrypt it with TDES and the Kenc key (eifd = TDES(s, Kenc))
|
|
111
|
+
/// - Compute the MAC over eifd with TDES and the Kmax key (mifd = mac(pad(eifd))
|
|
112
|
+
/// - Construct the APDU data for the mutualAuthenticate command (cmd_data = eifd + mifd)
|
|
113
|
+
///
|
|
114
|
+
/// @param rnd_icc: The challenge received from the ICC.
|
|
115
|
+
/// @type rnd_icc: A 8 bytes binary string
|
|
116
|
+
/// @return: The APDU binary data for the mutual authenticate command
|
|
117
|
+
func authentication( rnd_icc : [UInt8]) -> [UInt8] {
|
|
118
|
+
self.rnd_icc = rnd_icc
|
|
119
|
+
|
|
120
|
+
Logger.bac.debug("Request an 8 byte random number from the MRTD's chip")
|
|
121
|
+
Logger.bac.debug("\tRND.ICC: '(binToHexRep(self.rnd_icc))")
|
|
122
|
+
|
|
123
|
+
self.rnd_icc = rnd_icc
|
|
124
|
+
|
|
125
|
+
let rnd_ifd = generateRandomUInt8Array(8)
|
|
126
|
+
let kifd = generateRandomUInt8Array(16)
|
|
127
|
+
|
|
128
|
+
Logger.bac.debug("Generate an 8 byte random and a 16 byte random")
|
|
129
|
+
Logger.bac.debug("\tRND.IFD: \(binToHexRep(rnd_ifd))" )
|
|
130
|
+
Logger.bac.debug("\tRND.Kifd: \(binToHexRep(kifd))")
|
|
131
|
+
|
|
132
|
+
let s = rnd_ifd + rnd_icc + kifd
|
|
133
|
+
|
|
134
|
+
Logger.bac.debug("Concatenate RND.IFD, RND.ICC and Kifd")
|
|
135
|
+
Logger.bac.debug("\tS: \(binToHexRep(s))")
|
|
136
|
+
|
|
137
|
+
let iv : [UInt8] = [0, 0, 0, 0, 0, 0, 0, 0]
|
|
138
|
+
let eifd = tripleDESEncrypt(key: ksenc,message: s, iv: iv)
|
|
139
|
+
|
|
140
|
+
Logger.bac.debug("Encrypt S with TDES key Kenc as calculated in Appendix 5.2")
|
|
141
|
+
Logger.bac.debug("\tEifd: \(binToHexRep(eifd))")
|
|
142
|
+
|
|
143
|
+
let mifd = mac(algoName: .DES, key: ksmac, msg: pad(eifd, blockSize:8))
|
|
144
|
+
|
|
145
|
+
Logger.bac.debug("Compute MAC over eifd with TDES key Kmac as calculated in-Appendix 5.2")
|
|
146
|
+
Logger.bac.debug("\tMifd: \(binToHexRep(mifd))")
|
|
147
|
+
// Construct APDU
|
|
148
|
+
|
|
149
|
+
let cmd_data = eifd + mifd
|
|
150
|
+
Logger.bac.debug("Construct command data for MUTUAL AUTHENTICATE")
|
|
151
|
+
Logger.bac.debug("\tcmd_data: \(binToHexRep(cmd_data))")
|
|
152
|
+
|
|
153
|
+
self.rnd_ifd = rnd_ifd
|
|
154
|
+
self.kifd = kifd
|
|
155
|
+
|
|
156
|
+
return cmd_data
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// Calculate the session keys (KSenc, KSmac) and the SSC from the data
|
|
160
|
+
/// received by the mutual authenticate command.
|
|
161
|
+
|
|
162
|
+
/// @param data: the data received from the mutual authenticate command send to the chip.
|
|
163
|
+
/// @type data: a binary string
|
|
164
|
+
/// @return: A set of two 16 bytes keys (KSenc, KSmac) and the SSC
|
|
165
|
+
public func sessionKeys(data : [UInt8] ) throws -> ([UInt8], [UInt8], [UInt8]) {
|
|
166
|
+
Logger.bac.debug("Decrypt and verify received data and compare received RND.IFD with generated RND.IFD \(binToHexRep(self.ksmac))" )
|
|
167
|
+
|
|
168
|
+
let response = tripleDESDecrypt(key: self.ksenc, message: [UInt8](data[0..<32]), iv: [0,0,0,0,0,0,0,0] )
|
|
169
|
+
|
|
170
|
+
let response_kicc = [UInt8](response[16..<32])
|
|
171
|
+
let Kseed = xor(self.kifd, response_kicc)
|
|
172
|
+
Logger.bac.debug("Calculate XOR of Kifd and Kicc")
|
|
173
|
+
Logger.bac.debug("\tKseed: \(binToHexRep(Kseed))" )
|
|
174
|
+
|
|
175
|
+
let smskg = SecureMessagingSessionKeyGenerator()
|
|
176
|
+
let KSenc = try smskg.deriveKey(keySeed: Kseed, mode: .ENC_MODE)
|
|
177
|
+
let KSmac = try smskg.deriveKey(keySeed: Kseed, mode: .MAC_MODE)
|
|
178
|
+
|
|
179
|
+
// let KSenc = self.keyDerivation(kseed: Kseed,c: KENC)
|
|
180
|
+
// let KSmac = self.keyDerivation(kseed: Kseed,c: KMAC)
|
|
181
|
+
|
|
182
|
+
Logger.bac.debug("Calculate Session Keys (KSenc and KSmac) using Appendix 5.1")
|
|
183
|
+
Logger.bac.debug("\tKSenc: \(binToHexRep(KSenc))" )
|
|
184
|
+
Logger.bac.debug("\tKSmac: \(binToHexRep(KSmac))" )
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
let ssc = [UInt8](self.rnd_icc.suffix(4) + self.rnd_ifd.suffix(4))
|
|
188
|
+
Logger.bac.debug("Calculate Send Sequence Counter")
|
|
189
|
+
Logger.bac.debug("\tSSC: \(binToHexRep(ssc))" )
|
|
190
|
+
return (KSenc, KSmac, ssc)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
#endif
|