Exemple #1
0
        /**
         * Constructor of EsptouchGenerator, it will cost some time(maybe a bit
         * much)
         *
         * @param apSsid      the Ap's ssid
         * @param apBssid     the Ap's bssid
         * @param apPassword  the Ap's password
         * @param inetAddress the phone's or pad's local ip address allocated by Ap
         */
        public EsptouchGenerator(byte[] apSsid, byte[] apBssid, byte[] apPassword, IPAddress inetAddress,
                                 ITouchEncryptor encryptor)
        {
            // generate guide code
            GuideCode gc = new GuideCode();

            char[] gcU81 = gc.getU8s();
            mGcBytes2 = new byte[gcU81.Length][];

            for (int i = 0; i < mGcBytes2.Length; i++)
            {
                mGcBytes2[i] = ByteUtil.genSpecBytes(gcU81[i]);
            }

            // generate data code
            DatumCode dc = new DatumCode(apSsid, apBssid, apPassword, inetAddress, encryptor);

            char[] dcU81 = dc.getU8s();

            string dcstr = new string(dcU81);

            string debug = Convert.ToBase64String(Encoding.UTF8.GetBytes(dcstr));

            System.Diagnostics.Debug.WriteLine($"DatumCode({dcU81.Length}): {debug}");

            mDcBytes2 = new byte[dcU81.Length][];

            for (int i = 0; i < mDcBytes2.Length; i++)
            {
                mDcBytes2[i] = ByteUtil.genSpecBytes(dcU81[i]);
            }
        }
Exemple #2
0
        private void init(TouchData apSsid, TouchData apBssid, TouchData apPassword, ITouchEncryptor encryptor, IEsptouchTaskParameter parameter)
        {
            Debug.WriteLine($"Welcome Esptouch {ESPTOUCH_VERSION}");

            mEncryptor  = encryptor;
            mApSsid     = apSsid.getData();
            mApPassword = apPassword.getData();
            mApBssid    = apBssid.getData();

            mIsCancelled = false;

            mSocketClient = new UdpSocketClient();
            mParameter    = parameter;

            mSocketServer = new UdpSocketServer(mParameter.PortListening,
                                                mParameter.WaitUdpTotalMillisecond);

            mEsptouchResultList   = new List <EsptouchResult>();
            mBssidTaskSucCountMap = new Dictionary <string, int>();
        }
Exemple #3
0
        /**
         * Constructor of DatumCode
         *
         * @param apSsid      the Ap's ssid
         * @param apBssid     the Ap's bssid
         * @param apPassword  the Ap's password
         * @param ipAddress   the ip address of the phone or pad
         * @param encryptor null use origin data, not null use encrypted data
         */
        public DatumCode(byte[] apSsid, byte[] apBssid, byte[] apPassword,
                         IPAddress ipAddress, ITouchEncryptor encryptor)
        {
            // Data = total len(1 byte) + apPwd len(1 byte) + SSID CRC(1 byte) +
            // BSSID CRC(1 byte) + TOTAL XOR(1 byte)+ ipAddress(4 byte) + apPwd + apSsid apPwdLen <=
            // 105 at the moment

            // total xor
            char totalXor = (char)0;

            char apPwdLen = (char)apPassword.Length;
            CRC8 crc      = new CRC8();

            crc.update(apSsid);
            char apSsidCrc = (char)crc.getValue();

            crc.reset();
            crc.update(apBssid);
            char apBssidCrc = (char)crc.getValue();

            char apSsidLen = (char)apSsid.Length;

            byte[] ipBytes = ipAddress.GetAddressBytes();
            int    ipLen   = ipBytes.Length;

            char totalLen = (char)(EXTRA_HEAD_LEN + ipLen + apPwdLen + apSsidLen);

            // build data codes
            mDataCodes = new List <DataCode>();
            mDataCodes.Add(new DataCode(totalLen, 0));
            totalXor ^= totalLen;
            mDataCodes.Add(new DataCode(apPwdLen, 1));
            totalXor ^= apPwdLen;
            mDataCodes.Add(new DataCode(apSsidCrc, 2));
            totalXor ^= apSsidCrc;
            mDataCodes.Add(new DataCode(apBssidCrc, 3));
            totalXor ^= apBssidCrc;
            // ESPDataCode 4 is null
            for (int i = 0; i < ipLen; ++i)
            {
                char c = ByteUtil.convertByte2Uint8(ipBytes[i]);
                totalXor ^= c;
                mDataCodes.Add(new DataCode(c, i + EXTRA_HEAD_LEN));
            }

            for (int i = 0; i < apPassword.Length; i++)
            {
                char c = ByteUtil.convertByte2Uint8(apPassword[i]);
                totalXor ^= c;
                mDataCodes.Add(new DataCode(c, i + EXTRA_HEAD_LEN + ipLen));
            }

            // totalXor will xor apSsidChars no matter whether the ssid is hidden
            for (int i = 0; i < apSsid.Length; i++)
            {
                char c = ByteUtil.convertByte2Uint8(apSsid[i]);
                totalXor ^= c;
                mDataCodes.Add(new DataCode(c, i + EXTRA_HEAD_LEN + ipLen + apPwdLen));
            }

            // add total xor last
            mDataCodes.Insert(4, new DataCode(totalXor, 4));

            // add bssid
            int bssidInsertIndex = EXTRA_HEAD_LEN;

            for (int i = 0; i < apBssid.Length; i++)
            {
                int      index = totalLen + i;
                char     c     = ByteUtil.convertByte2Uint8(apBssid[i]);
                DataCode dc    = new DataCode(c, index);
                if (bssidInsertIndex >= mDataCodes.Count)
                {
                    mDataCodes.Add(dc);
                }
                else
                {
                    mDataCodes.Insert(bssidInsertIndex, dc);
                }
                bssidInsertIndex += 4;
            }
        }
Exemple #4
0
 public EsptouchTask(TouchData apSsid, TouchData apBssid, TouchData apPassword,
                     ITouchEncryptor encryptor, IEsptouchTaskParameter parameter)
 {
     this.init(apSsid, apBssid, apPassword, encryptor, parameter);
 }