Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix][Android] Unsupported RSA key size for StrongBox #577

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

frw
Copy link
Contributor

@frw frw commented Nov 13, 2022

Upon app startup, I'm noticing this error showing up

11-13 19:16:28.052   711   711 E [email protected]: GenerateKey : device response error code: UNSUPPORTED_KEY_SIZE
11-13 19:16:28.052   749   779 E keystore2: keystore2::error: In generate_key.
11-13 19:16:28.052   749   779 E keystore2:
11-13 19:16:28.052   749   779 E keystore2: Caused by:
11-13 19:16:28.052   749   779 E keystore2:     0: While generating Key without explicit attestation key.
11-13 19:16:28.052   749   779 E keystore2:     1: Error::Km(ErrorCode(-6))
11-13 19:16:28.059 27168 27303 W CipherStorageBase: StrongBox security storage is not available.
11-13 19:16:28.059 27168 27303 W CipherStorageBase: java.security.ProviderException: Failed to generate key pair.
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at android.security.keystore2.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPairHelper(AndroidKeyStoreKeyPairGeneratorSpi.java:620)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at android.security.keystore2.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:545)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:746)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.cipherStorage.CipherStorageKeystoreRsaEcb.generateKey(CipherStorageKeystoreRsaEcb.java:249)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.cipherStorage.CipherStorageBase.tryGenerateStrongBoxSecurityKey(CipherStorageBase.java:475)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.cipherStorage.CipherStorageBase.tryGenerateStrongBoxSecurityKey(CipherStorageBase.java:460)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.cipherStorage.CipherStorageBase.generateKeyAndStoreUnderAlias(CipherStorageBase.java:413)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.KeychainModule.internalWarmingBestCipher(KeychainModule.java:175)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.KeychainModule.$r8$lambda$DYujhqpjRgfFQ_gyuwMwyxxqDlk(Unknown Source:0)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at com.oblador.keychain.KeychainModule$$ExternalSyntheticLambda0.run(Unknown Source:2)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at java.lang.Thread.run(Thread.java:1012)
11-13 19:16:28.059 27168 27303 W CipherStorageBase: Caused by: android.security.KeyStoreException: Unsupported key size
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at android.security.KeyStore2.getKeyStoreException(KeyStore2.java:356)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at android.security.KeyStoreSecurityLevel.handleExceptions(KeyStoreSecurityLevel.java:57)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at android.security.KeyStoreSecurityLevel.generateKey(KeyStoreSecurityLevel.java:145)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     at android.security.keystore2.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPairHelper(AndroidKeyStoreKeyPairGeneratorSpi.java:587)
11-13 19:16:28.059 27168 27303 W CipherStorageBase:     ... 10 more

It seems like RSA 3072 is not supported for StrongBox but 2048 is (reference: https://developer.android.com/training/articles/keystore). Changing it to 2048 makes the error disappear.

@@ -50,7 +50,7 @@ public class CipherStorageKeystoreRsaEcb extends CipherStorageBase {
public static final String TRANSFORMATION_RSA_ECB_PKCS1 =
ALGORITHM_RSA + "/" + BLOCK_MODE_ECB + "/" + PADDING_PKCS1;
/** Selected encryption key size. */
public static final int ENCRYPTION_KEY_SIZE = 3072;
public static final int ENCRYPTION_KEY_SIZE = 2048;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed correct! I can confirm. What about the other scenarions with normal (non-strongbox) key generation? It will also change to 2048.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strength of RSA encryption is based on the difficulty of factoring large numbers that are the product of two large prime numbers. A 2048-bit RSA key is believed to be secure against foreseeable cryptographic attacks, including brute force attacks, with the computational power available today and in the near future. The National Institute of Standards and Technology (NIST) and other cryptographic authorities have provided guidelines indicating that 2048-bit RSA keys are expected to be secure until at least 2030.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although StrongBox is a little slower and resource constrained (meaning that it supports fewer concurrent operations) compared to TEE, StrongBox provides better security guarantees against physical and side-channel attacks. If you want to prioritize higher security guarantees over app resource efficiency, we recommend using StrongBox on the devices where it is available. Wherever StrongBox isn't available, your app can always fall back to TEE to store key materials.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's go for 2048 key size and fix the strongbox issue

@androideveloper androideveloper merged commit 75171f7 into oblador:master Feb 15, 2024
3 checks passed
renovate bot referenced this pull request in valora-inc/wallet Feb 21, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[react-native-keychain](https://togithub.com/oblador/react-native-keychain)
| [`^8.1.2` ->
`^8.1.3`](https://renovatebot.com/diffs/npm/react-native-keychain/8.1.2/8.1.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/react-native-keychain/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/react-native-keychain/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/react-native-keychain/8.1.2/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-native-keychain/8.1.2/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>oblador/react-native-keychain (react-native-keychain)</summary>

###
[`v8.1.3`](https://togithub.com/oblador/react-native-keychain/releases/tag/v8.1.3)

[Compare
Source](https://togithub.com/oblador/react-native-keychain/compare/v8.1.2...v8.1.3)

#### What's Changed

- use setUserAuthenticationParameters for android >= 11 by
[@&#8203;AntoineThibi](https://togithub.com/AntoineThibi) in
[https://github.com/oblador/react-native-keychain/pull/613](https://togithub.com/oblador/react-native-keychain/pull/613)
- \[Fix]\[Android] Bugfix for lambda functions not workin in older
projects. by
[@&#8203;sohail-shrestha](https://togithub.com/sohail-shrestha) in
[https://github.com/oblador/react-native-keychain/pull/585](https://togithub.com/oblador/react-native-keychain/pull/585)
- \[Fix]\[Android] Unsupported RSA key size for StrongBox by
[@&#8203;frw](https://togithub.com/frw) in
[https://github.com/oblador/react-native-keychain/pull/577](https://togithub.com/oblador/react-native-keychain/pull/577)

#### New Contributors

- [@&#8203;AntoineThibi](https://togithub.com/AntoineThibi) made their
first contribution in
[https://github.com/oblador/react-native-keychain/pull/613](https://togithub.com/oblador/react-native-keychain/pull/613)
- [@&#8203;sohail-shrestha](https://togithub.com/sohail-shrestha) made
their first contribution in
[https://github.com/oblador/react-native-keychain/pull/585](https://togithub.com/oblador/react-native-keychain/pull/585)
- [@&#8203;frw](https://togithub.com/frw) made their first contribution
in
[https://github.com/oblador/react-native-keychain/pull/577](https://togithub.com/oblador/react-native-keychain/pull/577)

**Full Changelog**:
oblador/react-native-keychain@v8.1.2...v8.1.3

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone
America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone
America/Los_Angeles.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/valora-inc/wallet).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMDAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: valora-bot <[email protected]>
shottah referenced this pull request in zed-io/kolektivo May 15, 2024
…inc#4947)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[react-native-keychain](https://togithub.com/oblador/react-native-keychain)
| [`^8.1.2` ->
`^8.1.3`](https://renovatebot.com/diffs/npm/react-native-keychain/8.1.2/8.1.3)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/react-native-keychain/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/react-native-keychain/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/react-native-keychain/8.1.2/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/react-native-keychain/8.1.2/8.1.3?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>oblador/react-native-keychain (react-native-keychain)</summary>

###
[`v8.1.3`](https://togithub.com/oblador/react-native-keychain/releases/tag/v8.1.3)

[Compare
Source](https://togithub.com/oblador/react-native-keychain/compare/v8.1.2...v8.1.3)

#### What's Changed

- use setUserAuthenticationParameters for android >= 11 by
[@&#8203;AntoineThibi](https://togithub.com/AntoineThibi) in
[https://github.com/oblador/react-native-keychain/pull/613](https://togithub.com/oblador/react-native-keychain/pull/613)
- \[Fix]\[Android] Bugfix for lambda functions not workin in older
projects. by
[@&#8203;sohail-shrestha](https://togithub.com/sohail-shrestha) in
[https://github.com/oblador/react-native-keychain/pull/585](https://togithub.com/oblador/react-native-keychain/pull/585)
- \[Fix]\[Android] Unsupported RSA key size for StrongBox by
[@&#8203;frw](https://togithub.com/frw) in
[https://github.com/oblador/react-native-keychain/pull/577](https://togithub.com/oblador/react-native-keychain/pull/577)

#### New Contributors

- [@&#8203;AntoineThibi](https://togithub.com/AntoineThibi) made their
first contribution in
[https://github.com/oblador/react-native-keychain/pull/613](https://togithub.com/oblador/react-native-keychain/pull/613)
- [@&#8203;sohail-shrestha](https://togithub.com/sohail-shrestha) made
their first contribution in
[https://github.com/oblador/react-native-keychain/pull/585](https://togithub.com/oblador/react-native-keychain/pull/585)
- [@&#8203;frw](https://togithub.com/frw) made their first contribution
in
[https://github.com/oblador/react-native-keychain/pull/577](https://togithub.com/oblador/react-native-keychain/pull/577)

**Full Changelog**:
oblador/react-native-keychain@v8.1.2...v8.1.3

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone
America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone
America/Los_Angeles.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/valora-inc/wallet).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMDAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: valora-bot <[email protected]>
SamuelScheit pushed a commit to respondchat/react-native-keychain that referenced this pull request Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants