Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package com.amazonaws.internal;
import java.io.IOException;
/* loaded from: classes.dex */
public class CRC32MismatchException extends IOException {
private static final long serialVersionUID = 1;
public CRC32MismatchException(String str) {
super(str);
}
}

View File

@@ -0,0 +1,34 @@
package com.amazonaws.internal;
import android.support.v4.media.session.PlaybackStateCompat;
import java.io.InputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
/* loaded from: classes.dex */
public class SdkDigestInputStream extends DigestInputStream {
public SdkDigestInputStream(InputStream inputStream, MessageDigest messageDigest) {
super(inputStream, messageDigest);
}
@Override // java.io.FilterInputStream, java.io.InputStream
public final long skip(long j) {
if (j <= 0) {
return j;
}
int min = (int) Math.min(PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH, j);
byte[] bArr = new byte[min];
long j2 = j;
while (j2 > 0) {
int read = read(bArr, 0, (int) Math.min(j2, min));
if (read == -1) {
if (j2 == j) {
return -1L;
}
return j - j2;
}
j2 -= read;
}
return j;
}
}

View File

@@ -0,0 +1,58 @@
package com.amazonaws.internal;
import com.amazonaws.AbortedException;
import java.io.FilterInputStream;
import java.io.InputStream;
/* loaded from: classes.dex */
public abstract class SdkFilterInputStream extends FilterInputStream {
public void abort() {
}
public SdkFilterInputStream(InputStream inputStream) {
super(inputStream);
}
public final void abortIfNeeded() {
if (Thread.interrupted()) {
abort();
throw new AbortedException();
}
}
@Override // java.io.FilterInputStream, java.io.InputStream
public long skip(long j) {
abortIfNeeded();
return ((FilterInputStream) this).in.skip(j);
}
@Override // java.io.FilterInputStream, java.io.InputStream
public int available() {
abortIfNeeded();
return ((FilterInputStream) this).in.available();
}
@Override // java.io.FilterInputStream, java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
public void close() {
((FilterInputStream) this).in.close();
abortIfNeeded();
}
@Override // java.io.FilterInputStream, java.io.InputStream
public synchronized void mark(int i) {
abortIfNeeded();
((FilterInputStream) this).in.mark(i);
}
@Override // java.io.FilterInputStream, java.io.InputStream
public synchronized void reset() {
abortIfNeeded();
((FilterInputStream) this).in.reset();
}
@Override // java.io.FilterInputStream, java.io.InputStream
public boolean markSupported() {
abortIfNeeded();
return ((FilterInputStream) this).in.markSupported();
}
}

View File

@@ -0,0 +1,18 @@
package com.amazonaws.internal;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
/* loaded from: classes.dex */
public class StaticCredentialsProvider implements AWSCredentialsProvider {
public final AWSCredentials credentials;
@Override // com.amazonaws.auth.AWSCredentialsProvider
public AWSCredentials getCredentials() {
return this.credentials;
}
public StaticCredentialsProvider(AWSCredentials aWSCredentials) {
this.credentials = aWSCredentials;
}
}

View File

@@ -0,0 +1,34 @@
package com.amazonaws.internal.config;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
/* loaded from: classes.dex */
public class HostRegexToRegionMapping {
public final String hostNameRegex;
public final String regionName;
public String getHostNameRegex() {
return this.hostNameRegex;
}
public String getRegionName() {
return this.regionName;
}
public HostRegexToRegionMapping(String str, String str2) {
if (str == null || str.isEmpty()) {
throw new IllegalArgumentException("Invalid HostRegexToRegionMapping configuration: hostNameRegex must be non-empty");
}
try {
Pattern.compile(str);
if (str2 == null || str2.isEmpty()) {
throw new IllegalArgumentException("Invalid HostRegexToRegionMapping configuration: regionName must be non-empty");
}
this.hostNameRegex = str;
this.regionName = str2;
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Invalid HostRegexToRegionMapping configuration: hostNameRegex is not a valid regex", e);
}
}
}

View File

@@ -0,0 +1,18 @@
package com.amazonaws.internal.config;
/* loaded from: classes.dex */
public class HttpClientConfig {
public final String serviceName;
public String getServiceName() {
return this.serviceName;
}
public HttpClientConfig(String str) {
this.serviceName = str;
}
public String toString() {
return "serviceName: " + this.serviceName;
}
}

View File

@@ -0,0 +1,136 @@
package com.amazonaws.internal.config;
import com.amazonaws.logging.Log;
import com.amazonaws.logging.LogFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/* loaded from: classes.dex */
public class InternalConfig {
public static final Log log = LogFactory.getLog(InternalConfig.class);
public final SignerConfig defaultSignerConfig = getDefaultSigner();
public final Map regionSigners = getDefaultRegionSigners();
public final Map serviceSigners = getDefaultServiceSigners();
public final Map serviceRegionSigners = getDefaultServiceRegionSigners();
public final Map httpClients = getDefaultHttpClients();
public final List hostRegexToRegionMappings = getDefaultHostRegexToRegionMappings();
public HttpClientConfig getHttpClientConfig(String str) {
return (HttpClientConfig) this.httpClients.get(str);
}
public SignerConfig getSignerConfig(String str, String str2) {
if (str == null) {
throw new IllegalArgumentException();
}
if (str2 != null) {
SignerConfig signerConfig = (SignerConfig) this.serviceRegionSigners.get(str + "/" + str2);
if (signerConfig != null) {
return signerConfig;
}
SignerConfig signerConfig2 = (SignerConfig) this.regionSigners.get(str2);
if (signerConfig2 != null) {
return signerConfig2;
}
}
SignerConfig signerConfig3 = (SignerConfig) this.serviceSigners.get(str);
return signerConfig3 == null ? this.defaultSignerConfig : signerConfig3;
}
public List getHostRegexToRegionMappings() {
return Collections.unmodifiableList(this.hostRegexToRegionMappings);
}
public static Map getDefaultHttpClients() {
HashMap hashMap = new HashMap();
hashMap.put("AmazonCloudWatchClient", new HttpClientConfig("monitoring"));
hashMap.put("AmazonCloudWatchLogsClient", new HttpClientConfig("logs"));
hashMap.put("AmazonCognitoIdentityClient", new HttpClientConfig("cognito-identity"));
hashMap.put("AmazonCognitoIdentityProviderClient", new HttpClientConfig("cognito-idp"));
hashMap.put("AmazonCognitoSyncClient", new HttpClientConfig("cognito-sync"));
hashMap.put("AmazonComprehendClient", new HttpClientConfig("comprehend"));
hashMap.put("AmazonConnectClient", new HttpClientConfig("connect"));
hashMap.put("AmazonKinesisFirehoseClient", new HttpClientConfig("firehose"));
hashMap.put("AWSKinesisVideoArchivedMediaClient", new HttpClientConfig("kinesisvideo"));
hashMap.put("AWSKinesisVideoSignalingClient", new HttpClientConfig("kinesisvideo"));
hashMap.put("AWSIotClient", new HttpClientConfig("execute-api"));
hashMap.put("AmazonLexRuntimeClient", new HttpClientConfig("lex"));
hashMap.put("AmazonPinpointClient", new HttpClientConfig("mobiletargeting"));
hashMap.put("AmazonPinpointAnalyticsClient", new HttpClientConfig("mobileanalytics"));
hashMap.put("AmazonSageMakerRuntimeClient", new HttpClientConfig("sagemaker"));
hashMap.put("AmazonSimpleDBClient", new HttpClientConfig("sdb"));
hashMap.put("AmazonSimpleEmailServiceClient", new HttpClientConfig("email"));
hashMap.put("AWSSecurityTokenServiceClient", new HttpClientConfig("sts"));
hashMap.put("AmazonTextractClient", new HttpClientConfig("textract"));
hashMap.put("AmazonTranscribeClient", new HttpClientConfig("transcribe"));
hashMap.put("AmazonTranslateClient", new HttpClientConfig("translate"));
return hashMap;
}
public static Map getDefaultRegionSigners() {
HashMap hashMap = new HashMap();
hashMap.put("eu-central-1", new SignerConfig("AWS4SignerType"));
hashMap.put("cn-north-1", new SignerConfig("AWS4SignerType"));
return hashMap;
}
public static Map getDefaultServiceRegionSigners() {
HashMap hashMap = new HashMap();
hashMap.put("s3/eu-central-1", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("s3/cn-north-1", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("s3/us-east-2", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("s3/ca-central-1", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("s3/ap-south-1", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("s3/ap-northeast-2", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("s3/eu-west-2", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("lex/eu-central-1", new SignerConfig("AmazonLexV4Signer"));
hashMap.put("lex/cn-north-1", new SignerConfig("AmazonLexV4Signer"));
hashMap.put("polly/eu-central-1", new SignerConfig("AmazonPollyCustomPresigner"));
hashMap.put("polly/cn-north-1", new SignerConfig("AmazonPollyCustomPresigner"));
return hashMap;
}
public static Map getDefaultServiceSigners() {
HashMap hashMap = new HashMap();
hashMap.put("ec2", new SignerConfig("QueryStringSignerType"));
hashMap.put("email", new SignerConfig("AWS4SignerType"));
hashMap.put("s3", new SignerConfig("AWSS3V4SignerType"));
hashMap.put("sdb", new SignerConfig("QueryStringSignerType"));
hashMap.put("lex", new SignerConfig("AmazonLexV4Signer"));
hashMap.put("polly", new SignerConfig("AmazonPollyCustomPresigner"));
return hashMap;
}
public static SignerConfig getDefaultSigner() {
return new SignerConfig("AWS4SignerType");
}
public static List getDefaultHostRegexToRegionMappings() {
ArrayList arrayList = new ArrayList();
arrayList.add(new HostRegexToRegionMapping("(.+\\.)?s3\\.amazonaws\\.com", "us-east-1"));
arrayList.add(new HostRegexToRegionMapping("(.+\\.)?s3-external-1\\.amazonaws\\.com", "us-east-1"));
arrayList.add(new HostRegexToRegionMapping("(.+\\.)?s3-fips-us-gov-west-1\\.amazonaws\\.com", "us-gov-west-1"));
return arrayList;
}
public static class Factory {
public static final InternalConfig SINGELTON;
public static InternalConfig getInternalConfig() {
return SINGELTON;
}
static {
try {
SINGELTON = new InternalConfig();
} catch (RuntimeException e) {
throw e;
} catch (Exception e2) {
throw new IllegalStateException("Fatal: Failed to load the internal config for AWS Android SDK", e2);
}
}
}
}

View File

@@ -0,0 +1,18 @@
package com.amazonaws.internal.config;
/* loaded from: classes.dex */
public class SignerConfig {
public final String signerType;
public String getSignerType() {
return this.signerType;
}
public String toString() {
return this.signerType;
}
public SignerConfig(String str) {
this.signerType = str;
}
}

View File

@@ -0,0 +1,290 @@
package com.amazonaws.internal.keyvaluestore;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import com.amazonaws.logging.Log;
import com.amazonaws.logging.LogFactory;
import com.amazonaws.util.Base64;
import java.security.Key;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
/* loaded from: classes.dex */
public class AWSKeyValueStore {
public Map cache;
public Context context;
public boolean isPersistenceEnabled;
public KeyProvider keyProvider;
public SecureRandom secureRandom = new SecureRandom();
public SharedPreferences sharedPreferencesForData;
public SharedPreferences sharedPreferencesForEncryptionMaterials;
public final String sharedPreferencesName;
public static final Log logger = LogFactory.getLog(AWSKeyValueStore.class);
public static Map cacheFactory = new HashMap();
public static Map getCacheForKey(String str) {
if (cacheFactory.containsKey(str)) {
return (Map) cacheFactory.get(str);
}
HashMap hashMap = new HashMap();
cacheFactory.put(str, hashMap);
return hashMap;
}
public AWSKeyValueStore(Context context, String str, boolean z) {
this.cache = getCacheForKey(str);
this.sharedPreferencesName = str;
this.context = context;
setPersistenceEnabled(z);
}
public synchronized void setPersistenceEnabled(boolean z) {
try {
try {
boolean z2 = this.isPersistenceEnabled;
this.isPersistenceEnabled = z;
if (z && !z2) {
this.sharedPreferencesForData = this.context.getSharedPreferences(this.sharedPreferencesName, 0);
this.sharedPreferencesForEncryptionMaterials = this.context.getSharedPreferences(this.sharedPreferencesName + ".encryptionkey", 0);
initKeyProviderBasedOnAPILevel();
Log log = logger;
log.info("Detected Android API Level = " + Build.VERSION.SDK_INT);
log.info("Creating the AWSKeyValueStore with key for sharedPreferencesForData = " + this.sharedPreferencesName);
onMigrateFromNoEncryption();
} else if (!z) {
logger.info("Persistence is disabled. Data will be accessed from memory.");
}
if (!z && z2) {
this.sharedPreferencesForData.edit().clear().apply();
}
} catch (Exception e) {
logger.error("Error in enabling persistence for " + this.sharedPreferencesName, e);
}
} catch (Throwable th) {
throw th;
}
}
public synchronized boolean contains(String str) {
if (this.isPersistenceEnabled) {
if (this.cache.containsKey(str)) {
return true;
}
return this.sharedPreferencesForData.contains(getDataKeyUsedInPersistentStore(str));
}
return this.cache.containsKey(str);
}
public synchronized String get(String str) {
if (str == null) {
return null;
}
if (!this.cache.containsKey(str) && this.isPersistenceEnabled) {
String dataKeyUsedInPersistentStore = getDataKeyUsedInPersistentStore(str);
Key retrieveEncryptionKey = retrieveEncryptionKey(getEncryptionKeyAlias());
if (retrieveEncryptionKey == null) {
logger.warn("Error in retrieving the decryption key used to decrypt the data from the persistent store. Returning null for the requested dataKey = " + str);
return null;
}
if (!this.sharedPreferencesForData.contains(dataKeyUsedInPersistentStore)) {
return null;
}
try {
if (Integer.parseInt(this.sharedPreferencesForData.getString(dataKeyUsedInPersistentStore + ".keyvaluestoreversion", null)) != 1) {
logger.error("The version of the data read from SharedPreferences for " + str + " does not match the version of the store.");
return null;
}
String decrypt = decrypt(retrieveEncryptionKey, getInitializationVector(dataKeyUsedInPersistentStore), this.sharedPreferencesForData.getString(dataKeyUsedInPersistentStore, null));
this.cache.put(str, decrypt);
return decrypt;
} catch (Exception e) {
logger.warn("Error in retrieving value for dataKey = " + str, e);
remove(str);
return null;
}
}
return (String) this.cache.get(str);
}
public synchronized void put(String str, String str2) {
byte[] generateInitializationVector;
if (str == null) {
logger.error("dataKey is null.");
return;
}
this.cache.put(str, str2);
if (this.isPersistenceEnabled) {
if (str2 == null) {
logger.debug("Value is null. Removing the data, IV and version from SharedPreferences");
this.cache.remove(str);
remove(str);
return;
}
String dataKeyUsedInPersistentStore = getDataKeyUsedInPersistentStore(str);
String encryptionKeyAlias = getEncryptionKeyAlias();
Key retrieveEncryptionKey = retrieveEncryptionKey(encryptionKeyAlias);
if (retrieveEncryptionKey == null) {
Log log = logger;
log.warn("No encryption key found for encryptionKeyAlias: " + encryptionKeyAlias);
Key generateEncryptionKey = generateEncryptionKey(encryptionKeyAlias);
if (generateEncryptionKey == null) {
log.warn("Error in generating the encryption key for encryptionKeyAlias: " + encryptionKeyAlias + " used to encrypt the data before storing. Skipping persisting the data in the persistent store.");
return;
}
retrieveEncryptionKey = generateEncryptionKey;
}
try {
generateInitializationVector = generateInitializationVector();
} catch (Exception e) {
logger.error("Error in storing value for dataKey = " + str + ". This data has not been stored in the persistent store.", e);
}
if (generateInitializationVector == null) {
throw new Exception("The generated IV for dataKey = " + str + " is null.");
}
String encrypt = encrypt(retrieveEncryptionKey, getAlgorithmParameterSpecForIV(generateInitializationVector), str2);
String encodeAsString = Base64.encodeAsString(generateInitializationVector);
if (encodeAsString == null) {
throw new Exception("Error in Base64 encoding the IV for dataKey = " + str);
}
this.sharedPreferencesForData.edit().putString(dataKeyUsedInPersistentStore, encrypt).putString(dataKeyUsedInPersistentStore + ".iv", encodeAsString).putString(dataKeyUsedInPersistentStore + ".keyvaluestoreversion", String.valueOf(1)).apply();
}
}
public synchronized void remove(String str) {
this.cache.remove(str);
if (this.isPersistenceEnabled) {
String dataKeyUsedInPersistentStore = getDataKeyUsedInPersistentStore(str);
this.sharedPreferencesForData.edit().remove(dataKeyUsedInPersistentStore).remove(dataKeyUsedInPersistentStore + ".iv").remove(dataKeyUsedInPersistentStore + ".keyvaluestoreversion").apply();
}
}
public synchronized void clear() {
this.cache.clear();
if (this.isPersistenceEnabled) {
this.sharedPreferencesForData.edit().clear().apply();
}
}
public final String encrypt(Key key, AlgorithmParameterSpec algorithmParameterSpec, String str) {
try {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(1, key, algorithmParameterSpec);
return Base64.encodeAsString(cipher.doFinal(str.getBytes("UTF-8")));
} catch (Exception e) {
logger.error("Error in encrypting data. ", e);
return null;
}
}
public final String decrypt(Key key, AlgorithmParameterSpec algorithmParameterSpec, String str) {
try {
byte[] decode = Base64.decode(str);
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(2, key, algorithmParameterSpec);
return new String(cipher.doFinal(decode), "UTF-8");
} catch (Exception e) {
logger.error("Error in decrypting data. ", e);
return null;
}
}
public final AlgorithmParameterSpec getInitializationVector(String str) {
String str2 = str + ".iv";
if (!this.sharedPreferencesForData.contains(str2)) {
throw new Exception("Initialization vector for " + str + " is missing from the SharedPreferences.");
}
String string = this.sharedPreferencesForData.getString(str2, null);
if (string == null) {
throw new Exception("Cannot read the initialization vector for " + str + " from SharedPreferences.");
}
byte[] decode = Base64.decode(string);
if (decode == null || decode.length == 0) {
throw new Exception("Cannot base64 decode the initialization vector for " + str + " read from SharedPreferences.");
}
return getAlgorithmParameterSpecForIV(decode);
}
public final byte[] generateInitializationVector() {
byte[] bArr = new byte[12];
this.secureRandom.nextBytes(bArr);
return bArr;
}
public final AlgorithmParameterSpec getAlgorithmParameterSpecForIV(byte[] bArr) {
return new GCMParameterSpec(128, bArr);
}
public final synchronized Key retrieveEncryptionKey(String str) {
try {
} catch (KeyNotFoundException e) {
Log log = logger;
log.warn(e);
log.info("Deleting the encryption key identified by the keyAlias: " + str);
this.keyProvider.deleteKey(str);
return null;
}
return this.keyProvider.retrieveKey(str);
}
public synchronized Key generateEncryptionKey(String str) {
try {
} catch (KeyNotGeneratedException e) {
logger.error("Encryption Key cannot be generated successfully.", e);
return null;
}
return this.keyProvider.generateKey(str);
}
public final String getDataKeyUsedInPersistentStore(String str) {
if (str == null) {
return null;
}
return str + ".encrypted";
}
public final String getEncryptionKeyAlias() {
return this.sharedPreferencesName + ".aesKeyStoreAlias";
}
public final void initKeyProviderBasedOnAPILevel() {
this.keyProvider = new KeyProvider23();
}
public final void onMigrateFromNoEncryption() {
Map<String, ?> all = this.sharedPreferencesForData.getAll();
for (String str : all.keySet()) {
if (!str.endsWith(".encrypted") && !str.endsWith(".iv") && !str.endsWith(".keyvaluestoreversion")) {
if (all.get(str) instanceof Long) {
put(str, String.valueOf(Long.valueOf(this.sharedPreferencesForData.getLong(str, 0L))));
} else if (all.get(str) instanceof String) {
put(str, this.sharedPreferencesForData.getString(str, null));
} else if (all.get(str) instanceof Float) {
put(str, String.valueOf(Float.valueOf(this.sharedPreferencesForData.getFloat(str, 0.0f))));
} else if (all.get(str) instanceof Boolean) {
put(str, String.valueOf(Boolean.valueOf(this.sharedPreferencesForData.getBoolean(str, false))));
} else if (all.get(str) instanceof Integer) {
put(str, String.valueOf(Integer.valueOf(this.sharedPreferencesForData.getInt(str, 0))));
} else if (all.get(str) instanceof Set) {
Set set = (Set) all.get(str);
StringBuilder sb = new StringBuilder();
Iterator it = set.iterator();
while (it.hasNext()) {
sb.append((String) it.next());
if (it.hasNext()) {
sb.append(",");
}
}
put(str, sb.toString());
}
this.sharedPreferencesForData.edit().remove(str).apply();
}
}
}
}

View File

@@ -0,0 +1,14 @@
package com.amazonaws.internal.keyvaluestore;
/* loaded from: classes.dex */
public class KeyNotFoundException extends Exception {
private static final long serialVersionUID = 1;
public KeyNotFoundException(String str, Throwable th) {
super(str, th);
}
public KeyNotFoundException(String str) {
super(str);
}
}

View File

@@ -0,0 +1,12 @@
package com.amazonaws.internal.keyvaluestore;
/* loaded from: classes.dex */
public class KeyNotGeneratedException extends Exception {
public KeyNotGeneratedException(String str) {
super(str);
}
public KeyNotGeneratedException(String str, Throwable th) {
super(str, th);
}
}

View File

@@ -0,0 +1,12 @@
package com.amazonaws.internal.keyvaluestore;
import java.security.Key;
/* loaded from: classes.dex */
interface KeyProvider {
void deleteKey(String str);
Key generateKey(String str);
Key retrieveKey(String str);
}

View File

@@ -0,0 +1,75 @@
package com.amazonaws.internal.keyvaluestore;
import android.security.keystore.KeyGenParameterSpec;
import androidx.annotation.RequiresApi;
import com.amazonaws.logging.Log;
import com.amazonaws.logging.LogFactory;
import com.google.android.gms.stats.CodePackage;
import java.security.Key;
import java.security.KeyStore;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
@RequiresApi(api = 23)
/* loaded from: classes.dex */
class KeyProvider23 implements KeyProvider {
public static final Log logger = LogFactory.getLog(KeyProvider23.class);
@Override // com.amazonaws.internal.keyvaluestore.KeyProvider
public synchronized Key retrieveKey(String str) {
Key key;
try {
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
if (keyStore.containsAlias(str)) {
Log log = logger;
log.debug("AndroidKeyStore contains keyAlias " + str);
log.debug("Loading the encryption key from Android KeyStore.");
key = keyStore.getKey(str, null);
if (key == null) {
throw new KeyNotFoundException("Key is null even though the keyAlias: " + str + " is present in AndroidKeyStore");
}
} else {
throw new KeyNotFoundException("AndroidKeyStore does not contain the keyAlias: " + str);
}
} catch (Exception e) {
throw new KeyNotFoundException("Error occurred while accessing AndroidKeyStore to retrieve the key for keyAlias: " + str, e);
}
} catch (Throwable th) {
throw th;
}
return key;
}
@Override // com.amazonaws.internal.keyvaluestore.KeyProvider
public synchronized Key generateKey(String str) {
SecretKey generateKey;
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
if (!keyStore.containsAlias(str)) {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "AndroidKeyStore");
keyGenerator.init(new KeyGenParameterSpec.Builder(str, 3).setBlockModes(CodePackage.GCM).setEncryptionPaddings("NoPadding").setKeySize(256).setRandomizedEncryptionRequired(false).build());
generateKey = keyGenerator.generateKey();
logger.info("Generated the encryption key identified by the keyAlias: " + str + " using AndroidKeyStore");
} else {
throw new KeyNotGeneratedException("Key already exists for the keyAlias: " + str + " in AndroidKeyStore");
}
} catch (Exception e) {
throw new KeyNotGeneratedException("Cannot generate a key for alias: " + str + " in AndroidKeyStore", e);
}
return generateKey;
}
@Override // com.amazonaws.internal.keyvaluestore.KeyProvider
public synchronized void deleteKey(String str) {
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
keyStore.deleteEntry(str);
} catch (Exception e) {
logger.error("Error in deleting the key for keyAlias: " + str + " from Android KeyStore.", e);
}
}
}