Skip to content

Commit 5f53e6d

Browse files
committed
fix: check has property namespace for Android
1 parent 9423ffe commit 5f53e6d

13 files changed

Lines changed: 94 additions & 78 deletions

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 1.0.12
2+
3+
* Check biometric changed for iOS
4+
5+
## 1.0.11
6+
7+
* Check has property namespace for Android
8+
19
## 1.0.10
210

311
* Add function isBiometricChanged

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Generate key pair and signing (NIST P-256 EC key pair using ECDSA) using Local A
1111
It is really easy to use! You should ensure that you add the `local_auth_signature` as a dependency in your flutter project.
1212

1313
```yaml
14-
local_auth_signature: "^1.0.8"
14+
local_auth_signature: "^1.0.12"
1515
```
1616
1717
## Usage
@@ -30,10 +30,26 @@ final _localAuthSignature = LocalAuthSignature.instance;
3030
final _key = 'com.prongbang.signx.key';
3131
```
3232

33-
#### Key Changed
33+
#### Check Fingerprint or Biometric changed
34+
35+
- Android, iOS
36+
37+
```dart
38+
final status = await _localAuthSignature.isBiometricChanged(_key);
39+
```
40+
41+
- iOS
3442

3543
```dart
36-
final status = await _localAuthSignature.keyChanged(_key, publicKey);
44+
await _localAuthSignature.resetBiometricChanged();
45+
```
46+
47+
```dart
48+
try {
49+
final signature = await _localAuthSignature.sign(_key, androidPrompt, iosPrompt);
50+
} on PlatformException catch (e) {
51+
// TODO check from exception code
52+
}
3753
```
3854

3955
#### Create KeyPair

android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ apply plugin: 'com.android.library'
2727
apply plugin: 'kotlin-android'
2828

2929
android {
30+
if (project.android.hasProperty("namespace")) {
31+
namespace 'com.prongbang.local_auth_signature'
32+
}
33+
3034
compileSdk 33
3135

3236
compileOptions {

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
platform :ios, '11.0'
2+
platform :ios, '12.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ PODS:
22
- Flutter (1.0.0)
33
- local_auth_signature (1.0.1):
44
- Flutter
5-
- SignatureBiometricSwift (~> 1.0.9)
6-
- SignatureBiometricSwift (1.0.9)
5+
- SignatureBiometricSwift (~> 1.0.10)
6+
- SignatureBiometricSwift (1.0.10)
77

88
DEPENDENCIES:
99
- Flutter (from `Flutter`)
@@ -21,9 +21,9 @@ EXTERNAL SOURCES:
2121

2222
SPEC CHECKSUMS:
2323
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
24-
local_auth_signature: 6a1aab72015b8de7f30c7e394e9f110a2e1a7d98
25-
SignatureBiometricSwift: d67ad0a5b8ecf0e88b454bf2bc1a9a6c528bea83
24+
local_auth_signature: 5526cf4d92cc893cefc6368926aefb34f124a07d
25+
SignatureBiometricSwift: e8f35299350fe33b93e7a1342ccb88448c80ff98
2626

27-
PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d
27+
PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048
2828

29-
COCOAPODS: 1.11.3
29+
COCOAPODS: 1.15.2

example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class _MyAppState extends State<MyApp> {
1919
final _key = 'com.prongbang.test.key';
2020
final _payload = 'Hello';
2121
String? _publicKey = '';
22-
String? _signature = '';
22+
String? _signature = 'MEUCIBIcOQng5BqDg9tOjayHDMPgiZT48bWJ0AzkSM0WGVcmAiEAkEGVzlZeJuJCz2IUnqJ/c1zzla1TErcnyU1nzkkN/dA=';
2323
String? _verified = '';
2424
String? _status = '';
2525

@@ -42,6 +42,7 @@ class _MyAppState extends State<MyApp> {
4242
),
4343
IOSPromptInfo(reason: 'Please allow biometric'),
4444
);
45+
await _localAuthSignature.resetBiometricChanged();
4546
setState(() {
4647
_publicKey = publicKey;
4748
});

example/pubspec.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,26 @@ packages:
7979
dependency: transitive
8080
description:
8181
name: leak_tracker
82-
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
82+
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
8383
url: "https://pub.dev"
8484
source: hosted
85-
version: "10.0.4"
85+
version: "10.0.0"
8686
leak_tracker_flutter_testing:
8787
dependency: transitive
8888
description:
8989
name: leak_tracker_flutter_testing
90-
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
90+
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
9191
url: "https://pub.dev"
9292
source: hosted
93-
version: "3.0.3"
93+
version: "2.0.1"
9494
leak_tracker_testing:
9595
dependency: transitive
9696
description:
9797
name: leak_tracker_testing
98-
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
98+
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
9999
url: "https://pub.dev"
100100
source: hosted
101-
version: "3.0.1"
101+
version: "2.0.1"
102102
lints:
103103
dependency: transitive
104104
description:
@@ -113,7 +113,7 @@ packages:
113113
path: ".."
114114
relative: true
115115
source: path
116-
version: "1.0.9"
116+
version: "1.0.12"
117117
matcher:
118118
dependency: transitive
119119
description:
@@ -134,10 +134,10 @@ packages:
134134
dependency: transitive
135135
description:
136136
name: meta
137-
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
137+
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
138138
url: "https://pub.dev"
139139
source: hosted
140-
version: "1.12.0"
140+
version: "1.11.0"
141141
path:
142142
dependency: transitive
143143
description:
@@ -195,10 +195,10 @@ packages:
195195
dependency: transitive
196196
description:
197197
name: test_api
198-
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
198+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
199199
url: "https://pub.dev"
200200
source: hosted
201-
version: "0.7.0"
201+
version: "0.6.1"
202202
vector_math:
203203
dependency: transitive
204204
description:
@@ -211,10 +211,10 @@ packages:
211211
dependency: transitive
212212
description:
213213
name: vm_service
214-
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
214+
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
215215
url: "https://pub.dev"
216216
source: hosted
217-
version: "14.2.1"
217+
version: "13.0.0"
218218
sdks:
219-
dart: ">=3.3.0 <4.0.0"
220-
flutter: ">=3.18.0-18.0.pre.54"
219+
dart: ">=3.2.0-0 <4.0.0"
220+
flutter: ">=2.5.0"

ios/Classes/SwiftLocalAuthSignatureMethod.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ class SwiftLocalAuthSignatureMethod {
1212
static let Sign = "sign"
1313
static let Verify = "verify"
1414
static let isBiometricChanged = "isBiometricChanged"
15+
static let resetBiometricChanged = "resetBiometricChanged"
1516
}

ios/Classes/SwiftLocalAuthSignaturePlugin.swift

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,35 @@ import LocalAuthentication
55

66
public class SwiftLocalAuthSignaturePlugin: NSObject, FlutterPlugin {
77

8-
private var signatureBiometricManager: SignatureBiometricManager?=nil
9-
108
public static func register(with registrar: FlutterPluginRegistrar) {
119
let channel = FlutterMethodChannel(name: "local_auth_signature", binaryMessenger: registrar.messenger())
1210
let instance = SwiftLocalAuthSignaturePlugin()
1311
registrar.addMethodCallDelegate(instance, channel: channel)
1412
}
1513

16-
func isBiometricChanged(name: String) -> Bool {
17-
let context = LAContext()
18-
var error: NSError?
14+
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
1915

20-
// Check if biometric authentication is available
21-
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
22-
// Biometric authentication is not available
23-
return true
16+
if call.method == SwiftLocalAuthSignatureMethod.isBiometricChanged {
17+
let keyConfig = KeyConfig(name: "")
18+
let signatureBiometricManager = LocalSignatureBiometricManager.newInstance(keyConfig: keyConfig)
19+
20+
let isChanged = signatureBiometricManager.biometricsChanged()
21+
if isChanged {
22+
result("changed")
23+
} else {
24+
result("unchanged")
25+
}
26+
return
27+
} else if call.method == SwiftLocalAuthSignatureMethod.resetBiometricChanged {
28+
let keyConfig = KeyConfig(name: "")
29+
let signatureBiometricManager = LocalSignatureBiometricManager.newInstance(keyConfig: keyConfig)
30+
31+
signatureBiometricManager.biometricsPolicyStateReset()
32+
33+
result(true)
34+
return
2435
}
2536

26-
let tag = name.data(using: .utf8)!
27-
let query: [String: Any] = [
28-
kSecClass as String: kSecClassKey,
29-
kSecAttrKeyType as String: kSecAttrKeyTypeECSECPrimeRandom,
30-
kSecAttrApplicationTag as String: tag,
31-
kSecReturnRef as String: true,
32-
kSecUseAuthenticationUI as String: kSecUseAuthenticationUIFail
33-
]
34-
35-
var item: CFTypeRef?
36-
let status = SecItemCopyMatching(query as CFDictionary, &item)
37-
38-
switch status {
39-
case errSecSuccess:
40-
// Key exists and is accessible without authentication
41-
return false
42-
case errSecItemNotFound:
43-
// Key doesn't exist anymore, biometrics likely changed
44-
return true
45-
case errSecUserCanceled, errSecAuthFailed:
46-
// Key exists but requires authentication (which we've disabled)
47-
// Biometrics are still valid
48-
return false
49-
default:
50-
// Any other error suggests the key is not accessible, biometrics likely changed
51-
print("Unexpected error checking biometric state: \(status)")
52-
return true
53-
}
54-
}
55-
56-
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
5737
guard let args = call.arguments as? Dictionary<String, String> else {
5838
result(
5939
FlutterError(
@@ -77,16 +57,6 @@ public class SwiftLocalAuthSignaturePlugin: NSObject, FlutterPlugin {
7757
}
7858

7959
switch call.method {
80-
case SwiftLocalAuthSignatureMethod.isBiometricChanged:
81-
82-
let isChanged = isBiometricChanged(name: key)
83-
if isChanged {
84-
result("changed")
85-
} else {
86-
result("unchanged")
87-
}
88-
89-
break
9060
case SwiftLocalAuthSignatureMethod.CreateKeyPair:
9161
guard let reason = args[SwiftLocalAuthSignatureArgs.Reason] else {
9262
result(

ios/local_auth_signature.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Generate key pair and signing using Local Authentication for Android and iOS.
1616
s.source = { :path => '.' }
1717
s.source_files = 'Classes/**/*'
1818
s.dependency 'Flutter'
19-
s.dependency 'SignatureBiometricSwift', '~> 1.0.9'
19+
s.dependency 'SignatureBiometricSwift', '~> 1.0.10'
2020
s.platform = :ios, '11.0'
2121
s.swift_version = ["4.0", "4.1", "4.2", "5.0", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "5.7", "5.8", "5.9"]
2222
end

0 commit comments

Comments
 (0)