package o; import com.isprint.e2eea.client.util.E2EEAException; import java.io.PrintStream; import java.security.GeneralSecurityException; import java.security.InvalidKeyException; import java.security.Key; import java.util.HashMap; import java.util.HashSet; import java.util.Properties; import net.sf.scuba.smartcards.ISO7816; import o.Luy; /* loaded from: classes3.dex */ public final class bFB { private static final Luy.Sts c; private static final Luy.Sts d; static { Luy e = Luy.c().e("NONE-SHORT"); d = ((Luy) Luy.b(new Object[]{e, "DES-CBC"}, -322528280, 322528280, System.identityHashCode(e))).c(10).a(); Luy e2 = Luy.c().e("NONE-SHORT"); c = ((Luy) Luy.b(new Object[]{e2, "DES-CBC"}, -322528280, 322528280, System.identityHashCode(e2))).c(11).a(); } public final C10776eOe e(String str, String str2) { Luy.Sts sts = d; try { e(sts, str, str2); Key d2 = d(str); byte[] b = b(((Byte) sts.c.get("MASTER_KEY_VERSION")).byteValue(), ((Byte) sts.c.get("MASTER_KEY_USAGE")).byteValue(), ((Integer) sts.c.get("MASTER_KEY_KEYLENGTH")).intValue()); new HashMap(); Ymn.d(VBO.d(8)); String b2 = b(sts, d2, b, str2, null); C10776eOe c10776eOe = new C10776eOe(); c10776eOe.c = b2; return c10776eOe; } catch (E2EEAException e) { return c(e); } } private static String b(Luy.Sts sts, Key key, byte[] bArr, String str, String str2) throws E2EEAException { try { byte[][] d2 = d(bArr, 16, 8, 16); byte[] bArr2 = d2[0]; byte[] bArr3 = d2[1]; byte[] bArr4 = d2[2]; byte[] c2 = c(key, bArr); byte[] bArr5 = new byte[0]; if (str != null) { bArr5 = Ymn.d(c(bArr2, bArr3, Ymn.d(str))); } byte[] bArr6 = new byte[0]; if (str2 != null) { bArr6 = Ymn.d(c(bArr2, bArr3, Ymn.d(str2))); } byte[][] bArr7 = new byte[7]; bArr7[0] = (byte[]) sts.c.get("MESSAGE_VERSION"); byte[] bArr8 = null; bArr7[1] = !sts.c.containsKey("CIPHER_PARAM_MESSAGE_TYPE") ? null : (byte[]) sts.c.get("CIPHER_PARAM_MESSAGE_TYPE_BYTES"); bArr7[2] = c2; bArr7[3] = !sts.c.containsKey("CIPHER_PARAM_HASH_MODE") ? null : (byte[]) sts.c.get("CIPHER_PARAM_HASH_MODE_BYTES"); if (sts.c.containsKey("CIPHER_PARAM_ENCRYPTION_MODE")) { bArr8 = (byte[]) sts.c.get("CIPHER_PARAM_ENCRYPTION_MODE_BYTES"); } bArr7[4] = bArr8; bArr7[5] = bArr5; bArr7[6] = bArr6; byte[] a = C17821zzv.a(bArr7); return Ymn.a(C17821zzv.a(a, b(bArr4, a))); } catch (GeneralSecurityException e) { StringBuilder sb = new StringBuilder("Invalid PIN Message - "); sb.append(e.getMessage()); throw new E2EEAException.InvalidPINMessage(sb.toString()); } } private static byte[] c(Key key, byte[] bArr) throws GeneralSecurityException { try { return Ymn.d(VBO.b(key, bArr, "RSA", null)); } catch (InvalidKeyException unused) { throw new E2EEAException.InvalidRSAKey(); } } private static byte[][] d(byte[] bArr, int... iArr) throws E2EEAException { try { if (bArr == null) { throw new E2EEAException.InvalidMasterKey(); } if (bArr.length == 0) { throw new E2EEAException.InvalidMasterKeyLength(); } int length = iArr.length; int i = 0; for (int i2 = 0; i2 < 3; i2++) { i += iArr[i2]; } if (40 != i) { throw new E2EEAException.InvalidMasterKey("Invalid Key Derivation Length"); } byte[] bArr2 = new byte[40]; byte b = 65; int i3 = 0; while (i3 < 40) { int i4 = b + ISO7816.INS_GET_RESPONSE; byte[] bArr3 = new byte[bArr.length + i4]; for (int i5 = 0; i5 < i4; i5++) { bArr3[i5] = b; } System.arraycopy(bArr, 0, bArr3, i4, bArr.length); byte[] b2 = VBO.b(bArr3); System.arraycopy(b2, 0, bArr2, i3, b2.length); b = (byte) (b + 1); i3 += b2.length; } byte[][] bArr4 = new byte[iArr.length]; int i6 = 0; for (int i7 = 0; i7 < 3; i7++) { int i8 = iArr[i7]; byte[] bArr5 = new byte[i8]; System.arraycopy(bArr2, i6, bArr5, 0, i8); bArr4[i7] = bArr5; i6 += iArr[i7]; } int length2 = iArr.length; return bArr4; } catch (Throwable th) { StringBuilder sb = new StringBuilder("Invalid Key Derivation - "); sb.append(th.getMessage()); throw new E2EEAException.OtherError(sb.toString()); } } private static byte[] c(byte[] bArr, byte[] bArr2, byte[] bArr3) throws GeneralSecurityException { try { byte[] bArr4 = new byte[16]; System.arraycopy(bArr3, 0, bArr4, 0, bArr3.length); for (int length = bArr3.length; length < 16; length++) { bArr4[length] = 32; } return VBO.b(VBO.e(bArr), bArr4, "DESede/CBC/NoPadding", bArr2); } catch (GeneralSecurityException e) { StringBuilder sb = new StringBuilder("Invalid HEANPB - "); sb.append(e.getMessage()); throw new E2EEAException.InvalidPINMessage(sb.toString()); } catch (Throwable th) { StringBuilder sb2 = new StringBuilder("Invalid PIN String - "); sb2.append(th.getMessage()); throw new E2EEAException.InvalidPINBlock(sb2.toString()); } } private static byte[] b(byte b, byte b2, int i) { try { return C17821zzv.a(new byte[]{b, b2}, VBO.d(i)); } catch (Throwable th) { StringBuilder sb = new StringBuilder("Invalid Master Key - "); sb.append(th.getMessage()); throw new E2EEAException.InvalidMasterKey(sb.toString()); } } private static Key d(String str) { try { return VBO.e(str); } catch (ArrayIndexOutOfBoundsException e) { throw new E2EEAException.InvalidRSAKey(e.getMessage()); } catch (GeneralSecurityException e2) { throw new E2EEAException.InvalidRSAKey(e2.getMessage()); } } private static byte[] b(byte[] bArr, byte[] bArr2) throws E2EEAException { try { if (bArr == null) { throw new E2EEAException.InvalidMACKey(); } int length = bArr.length; if (length != 16 && length != 24) { throw new E2EEAException.InvalidMACKeyLength(); } byte[] bArr3 = new byte[8]; System.arraycopy(Ymn.d(VBO.b(bArr, bArr2)), 0, bArr3, 0, 8); return bArr3; } catch (GeneralSecurityException e) { StringBuilder sb = new StringBuilder("Invalid MAC - "); sb.append(e.getMessage()); throw new E2EEAException.InvalidPINMessage(sb.toString()); } } private static void e(Luy.Sts sts, String str, String str2) { if (str == null || "".equals(str)) { throw new E2EEAException.PublicKeyNotFound("Public key is not found"); } String[] split = str.split(",", 2); if (str.length() == 0 || split.length < 2) { throw new E2EEAException.InvalidRSAKeyLength(); } b(str2); if (sts == null) { throw new E2EEAException.InvalidSymmetricParameters(); } if ((!sts.c.containsKey("CIPHER_PARAM_HASH_MODE") ? null : (byte[]) sts.c.get("CIPHER_PARAM_HASH_MODE_BYTES")) == null) { throw new E2EEAException.InvalidSymmetricParameters("Hash mode not found"); } if ((!sts.c.containsKey("CIPHER_PARAM_ENCRYPTION_MODE") ? null : (byte[]) sts.c.get("CIPHER_PARAM_ENCRYPTION_MODE_BYTES")) == null) { throw new E2EEAException.InvalidSymmetricParameters("Encryption mode not found"); } if ((!sts.c.containsKey("CIPHER_PARAM_MESSAGE_TYPE") ? null : (byte[]) sts.c.get("CIPHER_PARAM_MESSAGE_TYPE_BYTES")) == null) { throw new E2EEAException.InvalidPINMessage(); } if ((sts.c.containsKey("CIPHER_PARAM_HASH_MODE") ? (byte[]) sts.c.get("CIPHER_PARAM_HASH_MODE_BYTES") : null)[0] == 48 && str2.length() > 16) { throw new E2EEAException.InvalidPINLength("PIN length exceeded for Hash Mode 0"); } int length = split[0].length() / 2; int length2 = split[1].length() / 2; if (length != length2) { StringBuilder sb = new StringBuilder("Invalid RSA key length mod="); sb.append(length); sb.append("<>"); sb.append(length); sb.append(" exp="); sb.append(length2); sb.append("<>"); sb.append(length); throw new E2EEAException.InvalidRSAKeyLength(sb.toString()); } if (((Integer) sts.c.get("MASTER_KEY_KEYLENGTH")).intValue() + 2 > length) { throw new E2EEAException.InvalidEncodedMessageLength("input data too large for RSA encryption"); } } private static void b(String str) { if (str == null || str.length() == 0) { throw new E2EEAException.InvalidPIN("Invalid PIN String"); } int length = str.length(); if (length > 30 || length <= 0) { throw new E2EEAException.InvalidPINLength("Invalid PIN length"); } for (int i = 0; i < str.length(); i++) { char charAt = str.charAt(i); if ((charAt < '0' || charAt > '9') && ((charAt < 'A' || charAt > 'Z') && (charAt < 'a' || charAt > 'z'))) { throw new E2EEAException.InvalidPIN("Invalid PIN String"); } } } private C10776eOe c(E2EEAException e2EEAException) { String message = e2EEAException.getMessage() != null ? e2EEAException.getMessage() : ""; PrintStream printStream = System.out; StringBuilder sb = new StringBuilder("Error no : "); sb.append(e2EEAException.e()); sb.append(" - "); sb.append(message); printStream.println(sb.toString()); StringBuilder sb2 = new StringBuilder(); sb2.append(getClass().getSimpleName()); sb2.append("Debug"); "true".equals(System.getProperty(sb2.toString())); C10776eOe c10776eOe = new C10776eOe(); c10776eOe.d = e2EEAException.e(); c10776eOe.a = e2EEAException.getMessage(); return c10776eOe; } public final C10776eOe d(String str, String str2, String str3, Properties properties) { int charAt; int charAt2; Luy.Sts sts = c; try { b(str3); String property = properties.getProperty("param_other_passwordQualityPolicy"); if (property != null && !"".equals(property)) { C0946SPr c0946SPr = new C0946SPr(property); String property2 = properties.getProperty("param_other_userId"); if (str3.length() < c0946SPr.k || str3.length() > c0946SPr.f) { throw new E2EEAException.DeniedByPasswordLengthPolicy(c0946SPr.k, c0946SPr.f); } if (c0946SPr.c == 0 && str3.equalsIgnoreCase(property2)) { throw new E2EEAException.DeniedByPasswordDisallowSameAsUserIdPolicy(); } if (c0946SPr.c == 1 && (str3.trim().indexOf(property2.trim()) >= 0 || str3.trim().indexOf(property2.trim()) >= 0)) { throw new E2EEAException.DeniedByPasswordDisallowSameAsUserIdPolicy(); } if (!c0946SPr.d) { HashSet hashSet = new HashSet(); int i = 0; while (i < str3.length()) { int i2 = i + 1; if (hashSet.contains(str3.substring(i, i2))) { throw new E2EEAException.DeniedByPasswordRepeatedCharPolicy(); } hashSet.add(str3.substring(i, i2)); i = i2; } } if (c0946SPr.d && c0946SPr.e.matcher(str3).matches()) { throw new E2EEAException.DeniedByPasswordConsecutiveCharPolicy(); } if (c0946SPr.j == 0 && !Character.isLetter(str3.charAt(0))) { throw new E2EEAException.DeniedByPasswordFirstCharCheckingPolicy(c0946SPr.j); } if (c0946SPr.j == 1 && !Character.isDigit(str3.charAt(0))) { throw new E2EEAException.DeniedByPasswordFirstCharCheckingPolicy(c0946SPr.j); } if (c0946SPr.j == 2 && Character.isLetterOrDigit(str3.charAt(0))) { throw new E2EEAException.DeniedByPasswordFirstCharCheckingPolicy(c0946SPr.j); } if (c0946SPr.g > 0) { int i3 = 0; for (int i4 = 0; i4 < str3.length(); i4++) { if (Character.isLetter(str3.charAt(i4))) { i3++; } } if (i3 < c0946SPr.g) { throw new E2EEAException.DeniedByPasswordMinAlphaPolicy(c0946SPr.g); } } if (!c0946SPr.a) { int i5 = 0; int i6 = 0; for (int i7 = 0; i7 < str3.length(); i7++) { if (i5 > i6) { i6 = i5; } if (i7 > 0) { int i8 = i7 - 1; if (Character.isLetter(str3.charAt(i8)) && Character.isLetter(str3.charAt(i7)) && ((charAt2 = str3.charAt(i8) - str3.charAt(i7)) == 1 || charAt2 == -1)) { i5++; } } i5 = 0; } if (i5 <= i6) { i5 = i6; } if (i5 + 1 > Math.max(c0946SPr.i, 1)) { throw new E2EEAException.DeniedByPasswordRepeatedAlphabetPolicy(); } } if (!c0946SPr.b) { int i9 = 0; int i10 = 0; for (int i11 = 0; i11 < str3.length(); i11++) { if (i9 > i10) { i10 = i9; } if (i11 > 0) { int i12 = i11 - 1; if (Character.isDigit(str3.charAt(i12)) && Character.isDigit(str3.charAt(i11)) && ((charAt = str3.charAt(i12) - str3.charAt(i11)) == 1 || charAt == -1)) { i9++; } } i9 = 0; } if (i9 <= i10) { i9 = i10; } if (i9 + 1 > Math.max(c0946SPr.i, 1)) { throw new E2EEAException.DeniedByPasswordRepeatedNumericPolicy(); } } int i13 = 0; int i14 = 0; int i15 = 0; for (int i16 = 0; i16 < str3.length(); i16++) { char charAt3 = str3.charAt(i16); if (charAt3 >= 'A' && charAt3 <= 'Z') { i14++; } else if (charAt3 >= 'a' && charAt3 <= 'z') { i15++; } else if (charAt3 >= '0' && charAt3 <= '9') { i13++; } } if (i13 < c0946SPr.f8361o) { throw new E2EEAException.DeniedByPasswordMinNumericCharsPolicy(c0946SPr.f8361o); } if (i14 < c0946SPr.n) { throw new E2EEAException.DeniedByPasswordMinUppercaseCharsPolicy(c0946SPr.n); } if (i15 < c0946SPr.h) { throw new E2EEAException.DeniedByPasswordMinLowercaseCharsPolicy(c0946SPr.h); } } if ((!sts.c.containsKey("CIPHER_PARAM_HASH_MODE") ? null : (byte[]) sts.c.get("CIPHER_PARAM_HASH_MODE_BYTES"))[0] == 48 && str3.length() > 16) { throw new E2EEAException.InvalidPINLength("PIN length exceeded for Hash Mode 0"); } e(sts, str, str2); Key d2 = d(str); byte[] b = b(((Byte) sts.c.get("MASTER_KEY_VERSION")).byteValue(), ((Byte) sts.c.get("MASTER_KEY_USAGE")).byteValue(), ((Integer) sts.c.get("MASTER_KEY_KEYLENGTH")).intValue()); new HashMap(); Ymn.d(VBO.d(8)); String b2 = b(sts, d2, b, str2, str3); C10776eOe c10776eOe = new C10776eOe(); c10776eOe.c = b2; return c10776eOe; } catch (E2EEAException e) { return c(e); } } }