package j1;

import androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure;
import e1.AbstractC0453a;
import i1.g;
import java.io.IOException;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.Arrays;
import k1.C0599q;
import l1.AbstractC0621d;
import l1.C0620c;
import l1.C0623f;
import l1.C0624g;

/* JADX INFO: renamed from: j1.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0558d extends AbstractC0555a {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private static final int f4536k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private static final String f4537l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private static final String f4538m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private static final String f4539n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private static final String f4540o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private static final int f4541p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private static final SecureRandom f4542q = new SecureRandom();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private byte[] f4543d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private byte[] f4544e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private String f4545f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private String f4546g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private String f4547h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private byte[] f4548i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private byte[] f4549j = null;

    static {
        f4536k = (AbstractC0453a.a("jcifs.smb.client.useUnicode", true) ? 1 : 2) | 512;
        String strO = null;
        f4537l = AbstractC0453a.h("jcifs.smb.client.domain", null);
        f4538m = AbstractC0453a.h("jcifs.smb.client.username", null);
        f4539n = AbstractC0453a.h("jcifs.smb.client.password", null);
        try {
            strO = g.q().o();
        } catch (UnknownHostException unused) {
        }
        f4540o = strO;
        f4541p = AbstractC0453a.d("jcifs.smb.lmCompatibility", 3);
    }

    public C0558d(C0557c c0557c, String str, String str2, String str3, String str4, int i2) {
        this.f4548i = null;
        f(i2 | j(c0557c));
        B(str4 == null ? k() : str4);
        w(str2);
        A(str3);
        int i3 = f4541p;
        if (i3 == 0 || i3 == 1) {
            if ((a() & 524288) == 0) {
                x(n(c0557c, str));
                y(s(c0557c, str));
                return;
            }
            byte[] bArr = new byte[24];
            SecureRandom secureRandom = f4542q;
            secureRandom.nextBytes(bArr);
            Arrays.fill(bArr, 8, 24, (byte) 0);
            byte[] bArrP = C0599q.p(str);
            byte[] bArrF = C0599q.f(bArrP, c0557c.j(), bArr);
            x(bArr);
            y(bArrF);
            if ((a() & 16) == 16) {
                byte[] bArr2 = new byte[16];
                System.arraycopy(c0557c.j(), 0, bArr2, 0, 8);
                System.arraycopy(bArr, 0, bArr2, 8, 8);
                C0623f c0623f = new C0623f();
                c0623f.update(bArrP);
                C0620c c0620c = new C0620c(c0623f.digest());
                c0620c.update(bArr2);
                byte[] bArrDigest = c0620c.digest();
                if ((a() & BasicMeasure.EXACTLY) == 0) {
                    this.f4548i = bArrDigest;
                    return;
                }
                byte[] bArr3 = new byte[16];
                this.f4548i = bArr3;
                secureRandom.nextBytes(bArr3);
                byte[] bArr4 = new byte[16];
                new C0624g(bArrDigest).b(this.f4548i, 0, 16, bArr4, 0);
                z(bArr4);
                return;
            }
            return;
        }
        if (i3 == 2) {
            byte[] bArrS = s(c0557c, str);
            x(bArrS);
            y(bArrS);
            return;
        }
        if (i3 != 3 && i3 != 4 && i3 != 5) {
            x(n(c0557c, str));
            y(s(c0557c, str));
            return;
        }
        byte[] bArrQ = C0599q.q(str2, str3, str);
        byte[] bArr5 = new byte[8];
        SecureRandom secureRandom2 = f4542q;
        secureRandom2.nextBytes(bArr5);
        x(o(c0557c, str2, str3, str, bArr5));
        byte[] bArr6 = new byte[8];
        secureRandom2.nextBytes(bArr6);
        y(q(c0557c, bArrQ, bArr6));
        if ((a() & 16) == 16) {
            C0620c c0620c2 = new C0620c(bArrQ);
            c0620c2.update(this.f4544e, 0, 16);
            byte[] bArrDigest2 = c0620c2.digest();
            if ((a() & BasicMeasure.EXACTLY) == 0) {
                this.f4548i = bArrDigest2;
                return;
            }
            byte[] bArr7 = new byte[16];
            this.f4548i = bArr7;
            secureRandom2.nextBytes(bArr7);
            byte[] bArr8 = new byte[16];
            new C0624g(bArrDigest2).b(this.f4548i, 0, 16, bArr8, 0);
            z(bArr8);
        }
    }

    public static int j(C0557c c0557c) {
        if (c0557c == null) {
            return f4536k;
        }
        return ((c0557c.a() & 1) == 0 ? 2 : 1) | 512;
    }

    public static String k() {
        return f4540o;
    }

    public static byte[] n(C0557c c0557c, String str) {
        if (c0557c == null || str == null) {
            return null;
        }
        return C0599q.j(str, c0557c.j());
    }

    public static byte[] o(C0557c c0557c, String str, String str2, String str3, byte[] bArr) {
        if (c0557c == null || str == null || str2 == null || str3 == null || bArr == null) {
            return null;
        }
        return C0599q.e(str, str2, str3, c0557c.j(), bArr);
    }

    public static byte[] q(C0557c c0557c, byte[] bArr, byte[] bArr2) {
        if (c0557c == null || bArr == null || bArr2 == null) {
            return null;
        }
        return C0599q.h(bArr, c0557c.j(), bArr2, (System.currentTimeMillis() + 11644473600000L) * 10000, c0557c.m());
    }

    public static byte[] s(C0557c c0557c, String str) {
        if (c0557c == null || str == null) {
            return null;
        }
        return C0599q.g(str, c0557c.j());
    }

    public void A(String str) {
        this.f4546g = str;
    }

    public void B(String str) {
        this.f4547h = str;
    }

    public byte[] C() {
        try {
            int iA = a();
            boolean z2 = (iA & 1) != 0;
            byte[] bytes = null;
            String strB = z2 ? null : AbstractC0555a.b();
            String strL = l();
            byte[] bytes2 = (strL == null || strL.length() == 0) ? null : z2 ? strL.getBytes("UTF-16LE") : strL.getBytes(strB);
            int length = bytes2 != null ? bytes2.length : 0;
            String strU = u();
            byte[] bytes3 = (strU == null || strU.length() == 0) ? null : z2 ? strU.getBytes("UTF-16LE") : strU.toUpperCase().getBytes(strB);
            int length2 = bytes3 != null ? bytes3.length : 0;
            String strV = v();
            if (strV != null && strV.length() != 0) {
                bytes = z2 ? strV.getBytes("UTF-16LE") : strV.toUpperCase().getBytes(strB);
            }
            int length3 = bytes != null ? bytes.length : 0;
            byte[] bArrM = m();
            int length4 = bArrM != null ? bArrM.length : 0;
            byte[] bArrR = r();
            int length5 = bArrR != null ? bArrR.length : 0;
            byte[] bArrT = t();
            byte[] bArr = new byte[length + 64 + length2 + length3 + length4 + length5 + (bArrT != null ? bArrT.length : 0)];
            System.arraycopy(AbstractC0555a.f4521b, 0, bArr, 0, 8);
            AbstractC0555a.h(bArr, 8, 3);
            AbstractC0555a.g(bArr, 12, 64, bArrM);
            int i2 = length4 + 64;
            AbstractC0555a.g(bArr, 20, i2, bArrR);
            int i3 = i2 + length5;
            AbstractC0555a.g(bArr, 28, i3, bytes2);
            int i4 = i3 + length;
            AbstractC0555a.g(bArr, 36, i4, bytes3);
            int i5 = i4 + length2;
            AbstractC0555a.g(bArr, 44, i5, bytes);
            AbstractC0555a.g(bArr, 52, i5 + length3, bArrT);
            AbstractC0555a.h(bArr, 60, iA);
            return bArr;
        } catch (IOException e2) {
            throw new IllegalStateException(e2.getMessage());
        }
    }

    public String l() {
        return this.f4545f;
    }

    public byte[] m() {
        return this.f4543d;
    }

    public byte[] p() {
        return this.f4548i;
    }

    public byte[] r() {
        return this.f4544e;
    }

    public byte[] t() {
        return this.f4549j;
    }

    public String toString() {
        String str;
        String str2;
        String strU = u();
        String strL = l();
        String strV = v();
        byte[] bArrM = m();
        byte[] bArrR = r();
        byte[] bArrT = t();
        StringBuilder sb = new StringBuilder();
        sb.append("Type3Message[domain=");
        sb.append(strL);
        sb.append(",user=");
        sb.append(strU);
        sb.append(",workstation=");
        sb.append(strV);
        sb.append(",lmResponse=");
        String str3 = "null";
        if (bArrM == null) {
            str = "null";
        } else {
            str = "<" + bArrM.length + " bytes>";
        }
        sb.append(str);
        sb.append(",ntResponse=");
        if (bArrR == null) {
            str2 = "null";
        } else {
            str2 = "<" + bArrR.length + " bytes>";
        }
        sb.append(str2);
        sb.append(",sessionKey=");
        if (bArrT != null) {
            str3 = "<" + bArrT.length + " bytes>";
        }
        sb.append(str3);
        sb.append(",flags=0x");
        sb.append(AbstractC0621d.c(a(), 8));
        sb.append("]");
        return sb.toString();
    }

    public String u() {
        return this.f4546g;
    }

    public String v() {
        return this.f4547h;
    }

    public void w(String str) {
        this.f4545f = str;
    }

    public void x(byte[] bArr) {
        this.f4543d = bArr;
    }

    public void y(byte[] bArr) {
        this.f4544e = bArr;
    }

    public void z(byte[] bArr) {
        this.f4549j = bArr;
    }
}
