Skip to content

Commit f2fc9b8

Browse files
committed
Implemented secure data storage on macos
1 parent 5f374f8 commit f2fc9b8

File tree

4 files changed

+513
-97
lines changed

4 files changed

+513
-97
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ log = "0.4"
2222
objc2 = "0.5"
2323
objc2-foundation = "0.2"
2424
objc2-local-authentication = { version = "0.2", features = ["LAContext", "LAError", "block2"] }
25+
objc2-security = "0.3"
26+
objc2-core-foundation = "0.3"
2527
block2 = "0.5"
2628

2729
[target.'cfg(target_os = "windows")'.dependencies]

README.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
# Tauri Plugin Biometry
66

7-
A Tauri plugin for biometric authentication
8-
(Touch ID, Face ID, fingerprint, etc.) on macOS, iOS, and Android.
7+
A Tauri plugin for biometric authentication (Touch ID, Face ID, Windows Hello, fingerprint, etc.) with support for macOS, Windows, iOS, and Android.
98

109
## Features
1110

12-
- 🔐 Biometric authentication (Touch ID, Face ID, fingerprint)
13-
- 📱 Support for iOS and Android
14-
- 🖥️ Desktop support planned
15-
- 🔑 Secure data storage with biometric protection
11+
- 🔐 Biometric authentication (Touch ID, Face ID, Windows Hello, fingerprint)
12+
- 📱 Full support for iOS and Android
13+
- 🖥️ Desktop support for macOS (Touch ID) and Windows (Windows Hello)
14+
- 🔑 Secure data storage with biometric protection (Android/iOS/macOS only)
1615
- 🎛️ Fallback to device passcode/password
1716
- 🛡️ Native security best practices
17+
- ⚡ Proper error handling with detailed error codes
1818

1919
## Installation
2020

@@ -24,7 +24,7 @@ Add the plugin to your `Cargo.toml`:
2424

2525
```toml
2626
[dependencies]
27-
tauri-plugin-biometry = "0.1"
27+
tauri-plugin-biometry = "0.2"
2828
```
2929

3030
### JavaScript/TypeScript
@@ -69,7 +69,7 @@ The plugin automatically handles the necessary permissions for Android.
6969

7070
### Permissions
7171

72-
Add the biometry permission to your `capabilities` in `default.json`:
72+
Configure the plugin permissions in your `capabilities/default.json`:
7373

7474
```json
7575
{
@@ -88,7 +88,12 @@ import { checkStatus } from '@choochmeque/tauri-plugin-biometry-api';
8888

8989
const status = await checkStatus();
9090
console.log('Biometry available:', status.isAvailable);
91-
console.log('Biometry type:', status.biometryType); // 0: None, 1: TouchID, 2: FaceID
91+
console.log('Biometry type:', status.biometryType); // 0: None, 1: TouchID, 2: FaceID, 3: Iris, 4: Auto (Windows Hello)
92+
93+
if (status.error) {
94+
console.error('Error:', status.error);
95+
console.error('Error code:', status.errorCode);
96+
}
9297
```
9398

9499
### Authenticate
@@ -111,7 +116,7 @@ try {
111116
}
112117
```
113118

114-
### Store Secure Data
119+
### Store Secure Data (macOS/iOS only)
115120

116121
```typescript
117122
import { setData, getData, hasData, removeData } from '@choochmeque/tauri-plugin-biometry-api';
@@ -134,8 +139,7 @@ if (exists) {
134139
const response = await getData({
135140
domain: 'com.myapp',
136141
name: 'api_key',
137-
reason: 'Access your API key',
138-
cancelTitle: 'Cancel'
142+
reason: 'Access your API key'
139143
});
140144
console.log('Retrieved data:', response.data);
141145
}
@@ -147,6 +151,8 @@ await removeData({
147151
});
148152
```
149153

154+
**Note:** Data storage methods are not supported on Windows and will return a `notSupported` error.
155+
150156
## API Reference
151157

152158
### Types
@@ -156,7 +162,8 @@ enum BiometryType {
156162
None = 0,
157163
TouchID = 1,
158164
FaceID = 2,
159-
Iris = 3
165+
Iris = 3,
166+
Auto = 4 // Windows Hello (auto-detects available biometry)
160167
}
161168

162169
interface Status {
@@ -216,10 +223,20 @@ Removes secure data.
216223
- Dialog appearance can be customized with `title` and `subtitle`
217224
- Supports `confirmationRequired` for additional security
218225

219-
### Desktop
226+
### macOS
227+
228+
- Supports Touch ID
229+
- Full keychain integration for secure data storage
230+
- Same API as iOS for consistency
231+
- Requires user authentication for data access
232+
- **Important:** The app must be properly code-signed to use keychain data storage. Without proper signing, data storage operations may fail with errors
233+
234+
### Windows
220235

221-
- Currently returns an error indicating biometry is not supported
222-
- Desktop support may be added in future versions
236+
- Supports Windows Hello (fingerprint, face, PIN)
237+
- Authentication only (data storage methods return "not supported" error)
238+
- Automatically focuses Windows Hello dialog
239+
- Returns `BiometryType.Auto` as it uses Windows Hello's automatic selection
223240

224241
## Error Codes
225242

@@ -230,14 +247,26 @@ Common error codes returned by the plugin:
230247
- `biometryNotAvailable` - Biometry is not available on device
231248
- `biometryNotEnrolled` - No biometric data is enrolled
232249
- `biometryLockout` - Too many failed attempts, biometry is locked
250+
- `systemCancel` - System cancelled the operation (device busy)
251+
- `appCancel` - Application cancelled the operation
252+
- `invalidContext` - Invalid authentication context
253+
- `notInteractive` - Non-interactive authentication not allowed
254+
- `passcodeNotSet` - Device passcode not set
255+
- `userFallback` - User chose to use fallback authentication
256+
- `itemNotFound` - Keychain item not found (macOS/iOS)
257+
- `authenticationRequired` - Authentication required but UI interaction not allowed
258+
- `keychainError` - Generic keychain operation error
259+
- `internalError` - Internal plugin error
260+
- `notSupported` - Operation not supported on this platform
233261

234262
## Security Considerations
235263

236-
- All secure data is stored in the system keychain (iOS) or Android Keystore
264+
- All secure data is stored in the system keychain (macOS/iOS) or Android Keystore
237265
- Data is encrypted and can only be accessed after successful biometric authentication
238266
- The plugin follows platform-specific security best practices
239-
- Consider implementing additional application-level encryption
240-
for highly sensitive data
267+
- Windows currently supports authentication only, not secure data storage
268+
- **macOS Code Signing:** Your app must be properly code-signed to use keychain storage on macOS. Development builds may work with ad-hoc signing, but production apps require valid Developer ID or App Store signing
269+
- Consider implementing additional application-level encryption for highly sensitive data
241270

242271
## Contributing
243272

0 commit comments

Comments
 (0)