@@ -32,7 +32,6 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
32
32
33
33
// Initialize Nitro native code loader
34
34
init {
35
- Log .d(logTag, " Initializing SecureEnclaveOperations" )
36
35
secureenclaveoperationsOnLoad.initializeNative()
37
36
}
38
37
@@ -54,8 +53,6 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
54
53
override fun prepareIntegrityTokenAndroid (cloudProjectNumber : String ): Promise <Boolean > {
55
54
return Promise .async {
56
55
try {
57
- Log .d(logTag, " Preparing integrity token with cloud project number: $cloudProjectNumber " )
58
-
59
56
// Convert string to long
60
57
val cpn = cloudProjectNumber.toLong()
61
58
@@ -76,12 +73,10 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
76
73
standardIntegrityManager.prepareIntegrityToken(prepareRequest)
77
74
.addOnSuccessListener { provider ->
78
75
integrityTokenProvider = provider
79
- Log .d(logTag, " Integrity token provider prepared successfully" )
80
76
result = true
81
77
isComplete = true
82
78
}
83
79
.addOnFailureListener { ex ->
84
- Log .e(logTag, " Failed to prepare integrity token" , ex)
85
80
throw RuntimeException (" Failed to prepare integrity token: ${ex.message} " , ex)
86
81
}
87
82
@@ -92,10 +87,8 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
92
87
93
88
return @async result
94
89
} catch (e: NumberFormatException ) {
95
- Log .e(logTag, " Invalid cloud project number format" , e)
96
90
throw RuntimeException (" Invalid cloud project number format" , e)
97
91
} catch (e: Exception ) {
98
- Log .e(logTag, " Error preparing integrity token" , e)
99
92
throw RuntimeException (" Error preparing integrity token: ${e.message} " , e)
100
93
}
101
94
}
@@ -105,12 +98,9 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
105
98
return Promise .async {
106
99
try {
107
100
if (integrityTokenProvider == null ) {
108
- Log .e(logTag, " Integrity token provider not initialized" )
109
101
throw RuntimeException (" Integrity token provider not initialized" )
110
102
}
111
103
112
- Log .d(logTag, " Requesting integrity token with hash: $requestHash " )
113
-
114
104
val request = StandardIntegrityManager .StandardIntegrityTokenRequest .builder()
115
105
.setRequestHash(requestHash)
116
106
.build()
@@ -120,12 +110,10 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
120
110
121
111
integrityTokenProvider?.request(request)
122
112
?.addOnSuccessListener { response ->
123
- Log .d(logTag, " Integrity token received successfully" )
124
113
token = response.token()
125
114
isComplete = true
126
115
}
127
116
?.addOnFailureListener { ex ->
128
- Log .e(logTag, " Failed to get integrity token" , ex)
129
117
throw RuntimeException (" Failed to get integrity token: ${ex.message} " , ex)
130
118
}
131
119
@@ -137,13 +125,11 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
137
125
attempts++
138
126
}
139
127
if (! isComplete) {
140
- Log .e(logTag, " Timeout while waiting for integrity token" )
141
128
throw RuntimeException (" Timeout while waiting for integrity token" )
142
129
}
143
130
144
131
return @async token
145
132
} catch (e: Exception ) {
146
- Log .e(logTag, " Error requesting integrity token" , e)
147
133
throw RuntimeException (" Error requesting integrity token: ${e.message} " , e)
148
134
}
149
135
}
@@ -198,7 +184,6 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
198
184
val concatenatedAttestations = attestations.joinToString(" |" )
199
185
return @async Base64 .encodeToString(concatenatedAttestations.toByteArray(), Base64 .NO_WRAP )
200
186
} catch (e: Exception ) {
201
- Log .e(logTag, " Error attesting key" , e)
202
187
throw RuntimeException (" Error attesting key: ${e.message} " , e)
203
188
}
204
189
}
@@ -227,13 +212,11 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
227
212
return Promise .async {
228
213
try {
229
214
// Generate a unique key ID
230
- Log .d(logTag, " Generating key with ID: $keyId " )
231
215
val keyStore = KeyStore .getInstance(" AndroidKeyStore" ).apply { load(null ) }
232
216
233
217
234
218
// Create a key pair generator for EC keys
235
219
val keyPairGenerator = KeyPairGenerator .getInstance(" EC" , " AndroidKeyStore" )
236
- Log .d(logTag, " Created key pair generator for EC/AndroidKeyStore" )
237
220
238
221
// Configure the key pair generator with hardware-backed security
239
222
val parameterSpec =
@@ -257,29 +240,22 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
257
240
258
241
if (securityLevel == PackageManager .FEATURE_STRONGBOX_KEYSTORE && Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
259
242
parameterSpec.setIsStrongBoxBacked(true )
260
- Log .d(logTag, " KeyGenParameterSpec backed by hardware strongbox" )
261
243
}
262
244
263
245
val buildSpec = parameterSpec.build()
264
246
265
- Log .d(logTag, " KeyGenParameterSpec built" )
266
-
267
247
// Generate the key pair with EC algorithm
268
248
keyPairGenerator.initialize(buildSpec)
269
249
keyPairGenerator.generateKeyPair()
270
- Log .d(logTag, " Key pair generated" )
271
250
272
251
val entry = keyStore.getEntry(keyId, null ) as ? KeyStore .PrivateKeyEntry
273
252
if (entry == null ) {
274
- Log .e(logTag, " Failed to retrieve key entry from KeyStore" )
275
253
throw RuntimeException (" Failed to generate key" )
276
254
}
277
- Log .d(logTag, " Key successfully verified in KeyStore" )
278
255
279
256
// Return the key ID to be used for future operations
280
257
return @async keyId
281
258
} catch (e: Exception ) {
282
- Log .e(logTag, " Error generating key" , e)
283
259
throw RuntimeException (" Error generating key: ${e.message} " , e)
284
260
}
285
261
}
@@ -288,21 +264,17 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
288
264
private fun isHardwareBackedKeyGenerationSupported (): Promise <Boolean > {
289
265
return Promise .async {
290
266
try {
291
- Log .d(logTag, " Checking if attestation is supported" )
292
-
293
267
// Get application context from NitroModules
294
268
val context = NitroModules .applicationContext ? : reactContext
295
269
296
270
val isStrongBoxSupported =
297
271
context.packageManager.hasSystemFeature(
298
272
" android.hardware.strongbox_keystore"
299
273
)
300
- Log .d(logTag, " StrongBox support: $isStrongBoxSupported " )
301
274
302
275
// We'll just check hardware features for now, without requiring Play Services
303
276
return @async isStrongBoxSupported
304
277
} catch (e: Exception ) {
305
- Log .e(logTag, " Error checking attestation support" , e)
306
278
return @async false
307
279
}
308
280
}
@@ -311,17 +283,14 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
311
283
// Helper method to check if a key is hardware-backed
312
284
private fun isHardwareBacked (keyId : String ): Boolean {
313
285
try {
314
- Log .d(logTag, " Checking if key is hardware-backed: $keyId " )
315
286
val keyStore = KeyStore .getInstance(" AndroidKeyStore" ).apply { load(null ) }
316
287
val entry = keyStore.getEntry(keyId, null ) as ? KeyStore .PrivateKeyEntry
317
288
if (entry != null ) {
318
289
val privateKey = entry.privateKey
319
290
val isHardwareBacked = privateKey.toString().contains(" AndroidKeyStore" )
320
- Log .d(logTag, " Key hardware backing check result: $isHardwareBacked " )
321
291
return isHardwareBacked
322
292
}
323
293
} catch (e: Exception ) {
324
- Log .e(logTag, " Error checking if key is hardware-backed" , e)
325
294
}
326
295
Log .w(logTag, " Could not determine if key is hardware-backed, assuming false" )
327
296
return false
@@ -330,7 +299,6 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
330
299
// Check weather the device has biometric enabled
331
300
private fun isBiometricEnabled (): Boolean {
332
301
return try {
333
- Log .d(logTag, " Checking if biometrics are enabled" )
334
302
// Get application context from NitroModules
335
303
val context = NitroModules .applicationContext ? : reactContext
336
304
@@ -339,29 +307,24 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
339
307
if (packageManager.hasSystemFeature(PackageManager .FEATURE_FACE ) ||
340
308
packageManager.hasSystemFeature(PackageManager .FEATURE_IRIS )
341
309
) {
342
- Log .d(logTag, " Face or iris recognition hardware is available" )
343
310
return true
344
311
}
345
312
}
346
313
347
314
val packageManager = context.packageManager
348
315
if (packageManager.hasSystemFeature(PackageManager .FEATURE_FINGERPRINT )) {
349
- Log .d(logTag, " Fingerprint hardware is available" )
350
316
return true
351
317
}
352
318
353
- Log .d(logTag, " No biometric hardware features detected" )
354
319
false
355
320
} catch (e: Exception ) {
356
- Log .e(logTag, " Error checking biometric availability" , e)
357
321
false
358
322
}
359
323
}
360
324
361
325
// Check if user has set up biometrics on the device
362
326
private fun isBiometricEnrolled (): Boolean {
363
327
return try {
364
- Log .d(logTag, " Checking if biometrics are enrolled" )
365
328
val context = NitroModules .applicationContext ? : reactContext
366
329
367
330
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
@@ -372,48 +335,38 @@ class SecureEnclaveOperations(private val reactContext: ReactApplicationContext)
372
335
biometricManager?.canAuthenticate(android.hardware.biometrics.BiometricManager .Authenticators .BIOMETRIC_STRONG )
373
336
374
337
if (canAuthenticate == android.hardware.biometrics.BiometricManager .BIOMETRIC_SUCCESS ) {
375
- Log .d(logTag, " Biometrics are enrolled and available" )
376
338
return true
377
339
}
378
- Log .d(logTag, " Biometric status code: $canAuthenticate " )
379
340
} else {
380
341
// For Android M (API 23) to P (API 28), check keyguard secure
381
342
val keyguardManager =
382
343
context.getSystemService(android.content.Context .KEYGUARD_SERVICE ) as android.app.KeyguardManager
383
344
if (keyguardManager.isKeyguardSecure) {
384
345
// If keyguard is secure, biometric or pin/pattern is set up
385
- Log .d(logTag, " Device is secured with PIN/pattern/biometric" )
386
346
return true
387
347
}
388
348
}
389
349
390
- Log .d(logTag, " No enrolled biometrics detected" )
391
350
false
392
351
} catch (e: Exception ) {
393
- Log .e(logTag, " Error checking biometric enrollment" , e)
394
352
false
395
353
}
396
354
}
397
355
398
356
// Helper method to get the security level
399
357
private fun getSecurityLevel (): String {
400
358
return try {
401
- Log .d(logTag, " Getting security level" )
402
359
// Get application context from NitroModules
403
360
val context = NitroModules .applicationContext ? : reactContext
404
361
405
362
if (context.packageManager.hasSystemFeature(PackageManager .FEATURE_STRONGBOX_KEYSTORE ) && Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
406
- Log .d(logTag, " StrongBox is available" )
407
363
PackageManager .FEATURE_STRONGBOX_KEYSTORE
408
364
} else if (context.packageManager.hasSystemFeature(PackageManager .FEATURE_HARDWARE_KEYSTORE ) && Build .VERSION .SDK_INT >= Build .VERSION_CODES .S ) {
409
- Log .d(logTag, " TEE is available" )
410
365
PackageManager .FEATURE_HARDWARE_KEYSTORE
411
366
} else {
412
- Log .d(logTag, " No hardware security features detected" )
413
367
" Software"
414
368
}
415
369
} catch (e: Exception ) {
416
- Log .e(logTag, " Error determining security level" , e)
417
370
" Unknown"
418
371
}
419
372
}
0 commit comments