Skip to content

Commit

Permalink
feat: private key without biometrics
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Aug 25, 2024
1 parent 323d66d commit 9d0e46b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
7 changes: 5 additions & 2 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
},
"ios": {
"supportsTablet": true,
"bundleIdentifier": "id.animo.secure.environment.example"
"bundleIdentifier": "id.animo.secure.environment.example",
"infoPlist": {
"NSFaceIDUsageDescription": "FaceID is used to securely sign data"
}
},
"android": {
"adaptiveIcon": {
Expand All @@ -26,4 +29,4 @@
"favicon": "./assets/favicon.png"
}
}
}
}
19 changes: 10 additions & 9 deletions ios/SecureEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ struct SecureEnvironment {
kSecAttrApplicationTag as String: Bundle.main.bundleIdentifier.unsafelyUnwrapped,
],
]


var flags: SecAccessControlCreateFlags = [.privateKeyUsage]
if biometricsBacked {
let accessControl = SecAccessControlCreateWithFlags(
kCFAllocatorDefault,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
[.privateKeyUsage, .biometryCurrentSet],
nil
)

attributes[kSecAttrAccessControl as String] = accessControl
flags.insert(.biometryCurrentSet)
}

attributes[kSecAttrAccessControl as String] = SecAccessControlCreateWithFlags(
kCFAllocatorDefault,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
flags,
nil
)

var error: Unmanaged<CFError>?
guard SecKeyCreateRandomKey(attributes as CFDictionary, &error) != nil else {
throw error!.takeRetainedValue() as Error
Expand Down

0 comments on commit 9d0e46b

Please sign in to comment.