react-native-instantpay-code-push 1.2.5 → 1.2.6
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.
|
@@ -328,7 +328,7 @@ RCT_EXPORT_MODULE();
|
|
|
328
328
|
.APP_VERSION = [IpayCodePushImpl appVersion],
|
|
329
329
|
.CHANNEL = [impl getChannel],
|
|
330
330
|
.FINGERPRINT_HASH = [impl getFingerprintHash],
|
|
331
|
-
.KEYSTORE_PUBLIC_KEY =
|
|
331
|
+
.KEYSTORE_PUBLIC_KEY = [IpayCodePushImpl getKeyChainPublickey],
|
|
332
332
|
});
|
|
333
333
|
}
|
|
334
334
|
|
|
@@ -300,7 +300,7 @@ public class SignatureVerifier {
|
|
|
300
300
|
*/
|
|
301
301
|
private static func createPublicKey(from publicKeyPEM: String) -> Result<SecKey, SignatureVerificationError> {
|
|
302
302
|
// Remove PEM headers/footers and whitespace
|
|
303
|
-
|
|
303
|
+
let keyString = publicKeyPEM
|
|
304
304
|
.replacingOccurrences(of: "-----BEGIN PUBLIC KEY-----", with: "")
|
|
305
305
|
.replacingOccurrences(of: "-----END PUBLIC KEY-----", with: "")
|
|
306
306
|
.replacingOccurrences(of: "\\n", with: "")
|
|
@@ -354,5 +354,73 @@ public class SignatureVerifier {
|
|
|
354
354
|
return data
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
private static let KEY_ALIAS = "com.ipaycodepush.security.rsa"
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Get Device Public Key of generated KeyChain
|
|
361
|
+
*/
|
|
362
|
+
public static func getDevicePublicKeyBase64() -> String? {
|
|
363
|
+
|
|
364
|
+
if let existingKey = getPrivateKey() {
|
|
365
|
+
return exportPublicKeyBase64(from: existingKey)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// If not exists → generate
|
|
369
|
+
generateKeyChain()
|
|
370
|
+
guard let newKey = getPrivateKey() else { return nil }
|
|
371
|
+
return exportPublicKeyBase64(from: newKey)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Generate a new EC key pair entry in the Ios Keychain by
|
|
376
|
+
* using the KeyPairGenerator API.
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
private static func generateKeyChain() -> Void {
|
|
380
|
+
|
|
381
|
+
let tagData = KEY_ALIAS.data(using: .utf8)!
|
|
382
|
+
|
|
383
|
+
let attributes: [String: Any] = [
|
|
384
|
+
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
|
|
385
|
+
kSecAttrKeySizeInBits as String: 2048,
|
|
386
|
+
kSecAttrTokenID as String: kSecAttrTokenIDSecureEnclave,
|
|
387
|
+
kSecPrivateKeyAttrs as String: [
|
|
388
|
+
kSecAttrIsPermanent as String: true,
|
|
389
|
+
kSecAttrApplicationTag as String: tagData
|
|
390
|
+
]
|
|
391
|
+
]
|
|
392
|
+
|
|
393
|
+
SecKeyCreateRandomKey(attributes as CFDictionary, nil)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Get Private Key of device keychain
|
|
398
|
+
*/
|
|
399
|
+
private static func getPrivateKey() -> SecKey? {
|
|
400
|
+
|
|
401
|
+
let tagData = KEY_ALIAS.data(using: .utf8)!
|
|
402
|
+
|
|
403
|
+
let query: [String: Any] = [
|
|
404
|
+
kSecClass as String: kSecClassKey,
|
|
405
|
+
kSecAttrApplicationTag as String: tagData,
|
|
406
|
+
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
|
|
407
|
+
kSecReturnRef as String: true
|
|
408
|
+
]
|
|
409
|
+
|
|
410
|
+
var item: CFTypeRef?
|
|
411
|
+
SecItemCopyMatching(query as CFDictionary, &item)
|
|
412
|
+
return (item as! SecKey?)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Get Public key of generated Private Key
|
|
417
|
+
*/
|
|
418
|
+
private static func exportPublicKeyBase64(from privateKey: SecKey) -> String? {
|
|
419
|
+
|
|
420
|
+
guard let publicKey = SecKeyCopyPublicKey(privateKey) else { return nil }
|
|
421
|
+
guard let data = SecKeyCopyExternalRepresentation(publicKey, nil) as Data? else { return nil }
|
|
422
|
+
|
|
423
|
+
return data.base64EncodedString()
|
|
424
|
+
}
|
|
357
425
|
|
|
358
426
|
}
|