Skip to content

Commit 943fc16

Browse files
authored
Removing unnecessary attributes from keystore wrap operation, Fixes AB#3137956 (#2578)
In an older [PR](#2558), I replaced the deprecated Keystore API for Android 28+ But it did not fix the issue of unwrap keystore operation failing on some Pixel 5 devices. Since it is not reproducing on other devices, I am removing the unnecessary attributes from the keystore wrap operation to see if it fixes the issue. certificate parameters are no longer actively used in other parts of the code. Hence removed those. I have already shared the test build with 2 customers and the issue has NOT reproduced on their devices so far with this fix. Fixes [AB#3137956](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3137956)
1 parent 83158f9 commit 943fc16

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ vNext
44
- [MINOR] Organize browser selection classes and change signature for get AuthorizationStrategy (#2564)
55
- [MINOR] Add support for OneBox Environment (#2559)
66
- [MINOR] Add support for claims requests for native authentication (#2572)
7+
- [MINOR] Removing unnecessary attributes from keystore wrap operation (#2578)
78

89
Version 19.0.0
910
----------

common/src/main/java/com/microsoft/identity/common/crypto/AndroidWrappedKeyLoader.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
import java.security.KeyStore;
4747
import java.security.spec.AlgorithmParameterSpec;
4848
import java.util.Calendar;
49-
import java.util.Date;
5049
import java.util.Locale;
51-
import java.util.concurrent.TimeUnit;
5250

5351
import javax.crypto.SecretKey;
5452
import javax.security.auth.x500.X500Principal;
@@ -311,18 +309,11 @@ private static AlgorithmParameterSpec getSpecForKeyStoreKey(@NonNull final Conte
311309
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
312310
return getLegacySpecForKeyStoreKey(context, alias);
313311
} else {
314-
final String certInfo = String.format(Locale.ROOT, "CN=%s, OU=%s",
315-
alias,
316-
context.getPackageName());
317-
final int certValidYears = 100;
318-
int purposes = KeyProperties.PURPOSE_WRAP_KEY | KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT;
312+
int purposes = KeyProperties.PURPOSE_WRAP_KEY | KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT;
319313
return new KeyGenParameterSpec.Builder(alias, purposes)
320-
.setCertificateSubject(new X500Principal(certInfo))
321-
.setCertificateSerialNumber(BigInteger.ONE)
322-
.setCertificateNotBefore(new Date())
323-
.setCertificateNotAfter(new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(365 * certValidYears)))
324314
.setKeySize(2048)
325315
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
316+
.setBlockModes(KeyProperties.BLOCK_MODE_ECB) // Ensure compatibility with RSA
326317
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
327318
.build();
328319
}

0 commit comments

Comments
 (0)