152 lines
5.5 KiB
Java
152 lines
5.5 KiB
Java
|
package o;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.security.keystore.KeyGenParameterSpec;
|
||
|
import android.util.Log;
|
||
|
import com.google.android.gms.stats.CodePackage;
|
||
|
import com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException;
|
||
|
import java.io.FileNotFoundException;
|
||
|
import java.io.IOException;
|
||
|
import java.security.GeneralSecurityException;
|
||
|
import java.security.KeyStore;
|
||
|
import java.security.KeyStoreException;
|
||
|
import java.security.ProviderException;
|
||
|
import javax.crypto.KeyGenerator;
|
||
|
|
||
|
/* renamed from: o.sxu, reason: case insensitive filesystem */
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class C16996sxu {
|
||
|
static final String c = "AndroidKeysetManager";
|
||
|
private final InterfaceC4280bVg a;
|
||
|
private final kKN b;
|
||
|
private JsG e;
|
||
|
|
||
|
/* synthetic */ C16996sxu(RVV rvv, byte b) throws GeneralSecurityException, IOException {
|
||
|
this(rvv);
|
||
|
}
|
||
|
|
||
|
private C16996sxu(RVV rvv) throws GeneralSecurityException, IOException {
|
||
|
this.b = rvv.a;
|
||
|
this.a = rvv.b;
|
||
|
this.e = rvv.d;
|
||
|
}
|
||
|
|
||
|
/* renamed from: o.sxu$RVV */
|
||
|
/* loaded from: classes2.dex */
|
||
|
public static final class RVV {
|
||
|
JsG d;
|
||
|
private gEg h = null;
|
||
|
kKN a = null;
|
||
|
private String j = null;
|
||
|
InterfaceC4280bVg b = null;
|
||
|
private boolean g = true;
|
||
|
public RyZ e = null;
|
||
|
private KeyStore c = null;
|
||
|
|
||
|
public final RVV a(Context context, String str, String str2) throws IOException {
|
||
|
if (context == null) {
|
||
|
throw new IllegalArgumentException("need an Android context");
|
||
|
}
|
||
|
this.h = new Tll(context, str, str2);
|
||
|
this.a = new qzc(context, str, str2);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final RVV d(String str) {
|
||
|
if (!str.startsWith("android-keystore://")) {
|
||
|
throw new IllegalArgumentException("key URI must start with android-keystore://");
|
||
|
}
|
||
|
if (!this.g) {
|
||
|
throw new IllegalArgumentException("cannot call withMasterKeyUri() after calling doNotUseKeystore()");
|
||
|
}
|
||
|
this.j = str;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final C16996sxu d() throws GeneralSecurityException, IOException {
|
||
|
C16996sxu c16996sxu;
|
||
|
synchronized (this) {
|
||
|
if (this.j != null) {
|
||
|
this.b = a();
|
||
|
}
|
||
|
this.d = e();
|
||
|
c16996sxu = new C16996sxu(this, (byte) 0);
|
||
|
}
|
||
|
return c16996sxu;
|
||
|
}
|
||
|
|
||
|
private InterfaceC4280bVg a() throws GeneralSecurityException {
|
||
|
NNk nNk = new NNk();
|
||
|
boolean e = nNk.e(this.j);
|
||
|
if (!e) {
|
||
|
try {
|
||
|
String str = this.j;
|
||
|
if (new NNk().e(str)) {
|
||
|
throw new IllegalArgumentException(String.format("cannot generate a new key %s because it already exists; please delete it with deleteKey() and try again", str));
|
||
|
}
|
||
|
String c = ifG.c("android-keystore://", str);
|
||
|
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES", "AndroidKeyStore");
|
||
|
keyGenerator.init(new KeyGenParameterSpec.Builder(c, 3).setKeySize(256).setBlockModes(CodePackage.GCM).setEncryptionPaddings("NoPadding").build());
|
||
|
keyGenerator.generateKey();
|
||
|
} catch (GeneralSecurityException | ProviderException unused) {
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
return nNk.d(this.j);
|
||
|
} catch (GeneralSecurityException | ProviderException e2) {
|
||
|
if (e) {
|
||
|
throw new KeyStoreException(String.format("the master key %s exists but is unusable", this.j), e2);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private JsG e() throws GeneralSecurityException, IOException {
|
||
|
try {
|
||
|
return b();
|
||
|
} catch (FileNotFoundException e) {
|
||
|
if (Log.isLoggable(C16996sxu.c, 4)) {
|
||
|
new Object[]{e.getMessage()};
|
||
|
}
|
||
|
if (this.e != null) {
|
||
|
JsG e2 = new JsG(Yzk.d()).e(this.e);
|
||
|
JsG e3 = e2.e(RDp.c(e2.e().b).keyInfo_.get(0).keyId_);
|
||
|
if (this.b != null) {
|
||
|
VJf e4 = e3.e();
|
||
|
this.a.a(VJf.e(e4.b, this.b, new byte[0]));
|
||
|
} else {
|
||
|
this.a.e(e3.e().b);
|
||
|
}
|
||
|
return e3;
|
||
|
}
|
||
|
throw new GeneralSecurityException("cannot read or generate keyset");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private JsG b() throws GeneralSecurityException, IOException {
|
||
|
InterfaceC4280bVg interfaceC4280bVg = this.b;
|
||
|
if (interfaceC4280bVg != null) {
|
||
|
try {
|
||
|
byte[] bArr = new byte[0];
|
||
|
C0587KSr e = this.h.e();
|
||
|
if (e == null || e.encryptedKeyset_.d() == 0) {
|
||
|
throw new GeneralSecurityException("empty keyset");
|
||
|
}
|
||
|
return new JsG(new VJf(VJf.e(e, interfaceC4280bVg, bArr)).b.p());
|
||
|
} catch (InvalidProtocolBufferException | GeneralSecurityException unused) {
|
||
|
}
|
||
|
}
|
||
|
return new JsG(VJf.c(this.h.c()).b.p());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final VJf e() throws GeneralSecurityException {
|
||
|
VJf e;
|
||
|
synchronized (this) {
|
||
|
e = this.e.e();
|
||
|
}
|
||
|
return e;
|
||
|
}
|
||
|
}
|