Inheritance: MonoBehaviour
Exemple #1
0
        static public byte[] makeSign(keyInfo key, byte[] data)
        {
            int len   = key.bits >> 3;
            Ber signB = new Ber(BigInteger.Parse("3011300D060960864801650304020105000400", NumberStyles.AllowHexSpecifier).ToByteArray().Reverse().ToArray());

            signB.childs[1].payload = SHA256.Create().ComputeHash(data);
            byte[] messB = signB.makeDer().Reverse().Concat(new byte[] { 0 }).ToArray();
            messB = messB.Concat(Enumerable.Repeat((byte)0xff, len - (messB.Length % len) - 2)).Concat(new byte[] { 1, 0 }).ToArray();
            IEnumerable <byte> ans = new byte[] { 0 };

            byte[] block = new byte[len + 1];

            BigInteger n = new BigInteger(key.key.childs[1].payload.Reverse().ToArray());
            BigInteger d = new BigInteger(key.key.childs[3].payload.Reverse().ToArray());

            for (int i = 0; i < messB.Length; i += len)
            {
                Array.Copy(messB, i, block, 0, len);
                byte[] crBlock = BigInteger.ModPow(new BigInteger(block), d, n).ToByteArray();
                if (crBlock.Length < len)
                {
                    ans = ans.Concat(crBlock.Concat(Enumerable.Repeat((byte)0x0, len - crBlock.Length)).Reverse());
                }
                else if (crBlock.Length > len)
                {
                    ans = ans.Concat(crBlock.Take(len).Reverse());
                }
                else
                {
                    ans = ans.Concat(crBlock.Reverse());
                }
            }
            return(ans.ToArray());
        }
Exemple #2
0
        static public byte[] makeRootCertFromPriv(string KeyName)
        {
            keyInfo key  = State.session.keys[KeyName];
            Ber     cert = new Ber(new byte[] {
                0x30, 0x80,
                0x30, 0x80,
                0xA0, 0x03, 0x02, 0x01, 0x02,
                0x02, 0x00,
                0x30, 0x80,
                0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
                0x05, 0x00,
                0x00, 0x00,
                0x30, 0x80,
                0x31, 0x80,
                0x30, 0x80,
                0x06, 0x03, 0x55, 0x04, 0x03,
                0x0C, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x30, 0x80,
                0x17, 0x00,
                0x17, 0x00,
                0x00, 0x00,
                0x30, 0x80,
                0x31, 0x80,
                0x30, 0x80,
                0x06, 0x03, 0x55, 0x04, 0x03,
                0x0C, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0xA3, 0x80,
                0x30, 0x80,
                0x30, 0x0F,
                0x06, 0x03, 0x55, 0x1D, 0x13,
                0x01, 0x01, 0xFF,
                0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF,
                0x00, 0x00,
                0x00, 0x00,
                0x00, 0x00,
                0x30, 0x80,
                0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B,
                0x05, 0x00,
                0x00, 0x00,
                0x03, 0x01, 0,
                0x00, 0x00
            });

            cert.childs[0].childs[4].childs[0].payload = Encoding.UTF8.GetBytes(DateTime.UtcNow.ToString(@"yyMMddhhmmssZ"));
            cert.childs[0].childs[4].childs[1].payload = Encoding.UTF8.GetBytes(DateTime.UtcNow.AddDays(365).ToString(@"yyMMddhhmmssZ"));
            cert.childs[0].childs[3].childs[0].childs[0].childs[1].payload = Encoding.UTF8.GetBytes(KeyName);
            cert.childs[0].childs[5].childs[0].childs[0].childs[1].payload = cert.childs[0].childs[3].childs[0].childs[0].childs[1].payload;
            cert.childs[0].childs[1].payload = cert.childs[0].childs[5].childs[0].childs[0].childs[1].payload;//BitConverter.GetBytes(DateTime.UtcNow.ToUniversalTime().Subtract(new DateTime(1970, 1, 1)).TotalSeconds);
            cert.childs[0].childs.Insert(6, key.pub);
            cert.childs[2].payload = makeSign(key, cert.childs[0].makeDer());
            return(cert.makeDer());
        }
Exemple #3
0
        public certInfo(Ber data)
        {
            cert = data;
            int len = cert.childs[0].childs[6].childs[1].childs[0].childs[0].payloadLength;

            bits = len * 8 - 8 - cert.childs[0].childs[6].childs[1].childs[0].childs[0].payload[0];
            Ber payload = new Ber(0, BerTags.SEQUENCE, true);

            payload.addChild(cert.childs[0].childs[6].childs[1].childs[0].childs[0]);
            payload.addChild(cert.childs[0].childs[6].childs[1].childs[0].childs[1]);
            pub = new Ber(0, BerTags.SEQUENCE, true);
            pub.addChild(new Ber(0, BerTags.SEQUENCE, true));
            pub.addChild(new Ber(0, BerTags.BIT_STRING, false)).addChild(payload);
            pub.childs.First().addChild(new Ber(0, BerTags.OBJECT_IDENTIFIER, false, new byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 }));
            pub.childs.First().addChild(new Ber(0, BerTags.NULL, false));

            pinSHA256   = Convert.ToBase64String(SHA256.Create().ComputeHash(pub.makeDer()));
            fingerPrint = utils.getHex(SHA1.Create().ComputeHash(cert.makeDer()));
            payload     = cert.childs[0].childs[3];
            iCN         = null;
            for (int i = 0; i < payload.childs.Count; i++)
            {
                if (!Enumerable.SequenceEqual(payload.childs[i].childs[0].childs[0].payload, utils.CName))
                {
                    continue;
                }
                iCN = Encoding.UTF8.GetString(payload.childs[i].childs[0].childs[1].payload);
                break;
            }
            payload = cert.childs[0].childs[5];
            CN      = null;
            for (int i = 0; i < payload.childs.Count; i++)
            {
                if (!Enumerable.SequenceEqual(payload.childs[i].childs[0].childs[0].payload, utils.CName))
                {
                    continue;
                }
                CN = Encoding.UTF8.GetString(payload.childs[i].childs[0].childs[1].payload);
                break;
            }
            //if (CN == iCN) {
            //BigInteger n = new BigInteger(cert.childs[0].childs[6].childs[1].childs[0].childs[0].payload.Reverse().ToArray());
            //BigInteger e = new BigInteger(cert.childs[0].childs[6].childs[1].childs[0].childs[1].payload.Reverse().ToArray());
            //BigInteger sign = new BigInteger(cert.childs[2].payload.Reverse().ToArray());

            //BigInteger ans = BigInteger.ModPow(sign, e, n);
            //string ss = utils.getHex(ans.ToByteArray().Reverse());
            //string ss2 = utils.getHex(SHA256.Create().ComputeHash(cert.childs[0].makeDer()));
            //}
        }
Exemple #4
0
        public keyInfo(Ber data)
        {
            key = data;
            int len = key.childs[1].payloadLength;

            bits = len * 8 - ((key.childs[1].payload[0] == 0) ? 8 : 0);
            Ber payload = new Ber(0, BerTags.SEQUENCE, true);

            payload.addChild(key.childs[1]);
            payload.addChild(key.childs[2]);
            pub = new Ber(0, BerTags.SEQUENCE, true);
            pub.addChild(new Ber(0, BerTags.SEQUENCE, true));
            pub.addChild(new Ber(0, BerTags.BIT_STRING, false)).addChild(payload);
            pub.childs.First().addChild(new Ber(0, BerTags.OBJECT_IDENTIFIER, false, new byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 }));
            pub.childs.First().addChild(new Ber(0, BerTags.NULL, false));
            pinSHA256 = Convert.ToBase64String(SHA256.Create().ComputeHash(pub.makeDer()));
        }
Exemple #5
0
        static public bool saveStorage(storageInfo sess)
        {
            Ber data = new Ber(3, 0xB183651C18E500, true);

            data.UNKLength = true;
            using (data)
            {
                data.addChild(new Ber(BerClass.UNIVERSAL, BerTags.UTF8String, false, Encoding.UTF8.GetBytes("shStorage")));
                data.addChild(new Ber(BerClass.UNIVERSAL, BerTags.INTEGER, false, new byte[] { 1 }));
                data.addChild(storageParse.saveVER1(sess));
                data.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, SHA256.Create().ComputeHash(data.childs.Last().makeDer())));
                byte[] raw = data.makeDer();
                sess.file.Seek(0, SeekOrigin.Begin);
                sess.file.Write(raw, 0, raw.Length);
                sess.file.SetLength(raw.Length);
                sess.file.Flush();
            }
            return(true);
        }
Exemple #6
0
        static public byte[] makeCSR(keyInfo key, string def, DomainInfo dom, System.ComponentModel.BackgroundWorker worker, bool star)
        {
            worker.ReportProgress(101, new object[] { -3, "Pattern parse.." });
            Ber csr = new Ber(BigInteger.Parse(
                                  "3042302e020100300b3109300706035504030c00a01c301a06092a864886f70d01090e310d300b30090603551d1104023000300d06092a864886f70d01010b0500030100",
                                  NumberStyles.AllowHexSpecifier).ToByteArray().Reverse().ToArray());

            worker.ReportProgress(101, new object[] { -3, "OK\r\nEdit CN.." });
            if (star)
            {
                csr.childs[0].childs[1].childs[0].childs[0].childs[1].payload = Encoding.UTF8.GetBytes((def == "@") ? dom.dns : String.Format("{0}.{1}", def, dom.dns));
            }
            else
            {
                csr.childs[0].childs[1].childs[0].childs[0].childs[1].payload = Encoding.UTF8.GetBytes((def == "@") ? dom.dns : String.Format("{0}.{1}", def, dom.dns).Replace("*.", ""));
            }
            Ber subs = csr.childs[0].childs[2].childs[0].childs[1].childs[0].childs[0].childs[1].childs[0];

            csr.childs[0].childs.Insert(2, key.pub.cloneAsParrent());
            worker.ReportProgress(101, new object[] { -3, "OK\r\nEdit subs.." });
            foreach (string sub in dom.subs2)
            {
                if (Regex.IsMatch(sub, "\\*"))
                {
                    subs.addChild(new Ber(BerClass.CONTEXT, BerTags.INTEGER, false, Encoding.UTF8.GetBytes(String.Format("{0}.{1}", sub, dom.dns))));
                    subs.addChild(new Ber(BerClass.CONTEXT, BerTags.INTEGER, false, Encoding.UTF8.GetBytes((sub == "*") ? dom.dns : String.Format("{0}.{1}", sub, dom.dns))));
                }
                else
                {
                    subs.addChild(new Ber(BerClass.CONTEXT, BerTags.INTEGER, false, Encoding.UTF8.GetBytes((sub == "@") ? dom.dns : String.Format("{0}.{1}", sub, dom.dns))));
                }
            }
            ;
            worker.ReportProgress(101, new object[] { -3, "OK\r\nMake sign.." });
            csr.childs[2].payload = makeSign(key, csr.childs[0].makeDer());
            worker.ReportProgress(101, new object[] { -3, "OK\r\nGet DER.." });
            return(csr.makeDer());
        }
Exemple #7
0
        static public storageInfo openStorage(Stream file)
        {
            Ber data = null;

            byte[]      buf  = null;
            storageInfo sess = new storageInfo();

            sess.file = file;
            try
            {
                if (file.Length < 18)
                {
                    pu(98);
                }
                if (file.Length > 99 * (1 << 20))
                {
                    pu(99);
                }
                try
                {
                    buf = new byte[file.Length];
                    file.Read(buf, 0, (int)file.Length);
                    data = new Ber(buf);
                } catch (Exception ex) { pu(100); }

                if (data.tClass != 0x3)
                {
                    pu(97);
                }
                if (data.tag != 0xB183651C18E500)
                {
                    pu(97);
                }
                if (data.childs.Count < 3)
                {
                    pu(97);
                }
                if (data.childs[0].tag != (UInt64)BerTags.UTF8String)
                {
                    pu(97);
                }
                if (Encoding.UTF8.GetString(data.childs[0].payload) != "shStorage")
                {
                    pu(97);
                }
                if (data.childs[1].tag != (UInt64)BerTags.INTEGER)
                {
                    pu(97);
                }
                if (data.childs[0].tClass != 0 || data.childs[1].tClass != 0)
                {
                    pu(97);
                }
                if (data.childs[1].payloadLength == 1)
                {
                    switch (data.childs[1].payload[0])
                    {
                    case 1:
                        if (data.childs.Count != 4)
                        {
                            pu(96);
                        }
                        if (data.childs[3].container || data.childs[3].tag != (UInt64)BerTags.OCTET_STRING || data.childs[3].tClass != (byte)BerClass.PRIVATE || data.childs[3].payloadLength != 32)
                        {
                            utils.pu(96);
                        }
                        if (!SHA256.Create().ComputeHash(data.childs[2].makeDer()).SequenceEqual(data.childs[3].payload))
                        {
                            pu(96);
                        }
                        storageParse.parseVER1(sess, data.childs[2]);
                        break;

                    default: pu(100); break;
                    }
                }
                else
                {
                    pu(97);
                }

                if (data != null)
                {
                    data.Dispose();
                }
                return(sess);
            }
            catch (Exception ex) {
                if (data != null)
                {
                    data.Dispose();
                }
                sess.Dispose();
                if (ex.Data.Contains("sh"))
                {
                    switch ((int)ex.Data["sh"])
                    {
                    case 96:
                        throw new Exception("Файл поврежден.");

                    case 97:
                        throw new Exception("Файл не является хранилищем");

                    case 98:
                        throw new Exception("Размер файла слишком мал, чтобы быть файлом программы.");

                    case 99:
                        throw new Exception("Размер файла слишком велик, чтобы быть файлом программы. Попробуте обновить программу и попробовать снова.");

                    case 100:
                        throw new Exception("Файл не поддерживается программой. Попробуте обновить программу и попробовать снова.");

                    default: throw ex;
                    }
                }
                else
                {
                    throw ex;
                }
            }
        }
Exemple #8
0
        static public certInfo parsePubKey(Stream myStream)
        {
            if (myStream.Length > 128 * 1024)
            {
                throw new Exception("Файл слишком большой..");
            }
            myStream.Seek(0, SeekOrigin.Begin);
            byte[] buff    = new byte[myStream.Length];
            int    buffMax = myStream.Read(buff, 0, (int)myStream.Length);

            if (buff[0] == '-')
            {
                int i = 0;
                for (i = 0; i < utils.certOpen.Length; i++)
                {
                    if (buff[i] != utils.certOpen[i])
                    {
                        throw new Exception("Файл не является CERTIFICATE");
                    }
                }

                while (i < myStream.Length)
                {
                    if (buff[i] == '\r' || buff[i] == '\n')
                    {
                        i++;
                        continue;
                    }
                    if (buff[i] != 'M')
                    {
                        throw new Exception("Файл не является CERTIFICATE_");
                    }
                    break;
                }
                int startBase64 = i;
                while ((i < myStream.Length) && (buff[i] != '-'))
                {
                    i++;
                }

                for (int j = 0; j < utils.certClose.Length; j++)
                {
                    if (buff[i + j] != utils.certClose[j])
                    {
                        throw new Exception("Файл не завершен как CERTIFICATE");
                    }
                }
                buff = Convert.FromBase64CharArray(Encoding.UTF8.GetString(buff).ToCharArray(), startBase64, i - startBase64);
            }
            buffMax = buff.Length;
            if (buff[0] != 0x30)
            {
                throw new Exception("Ошибка в ASN1 данных");
            }
            Ber data = new Ber(buff, 0, (uint)buff.Length);

            if (data.childs.Count != 3)
            {
                throw new Exception("Не удалось обнаружить сертификат");
            }
            return(new certInfo(data));
        }
Exemple #9
0
        static public keyInfo parsePrivKey(Stream myStream)
        {
            if (myStream.Length > 16 * 1024)
            {
                throw new Exception("Файл слишком большой..");
            }
            myStream.Seek(0, SeekOrigin.Begin);
            byte[] buff    = new byte[myStream.Length];
            int    buffMax = myStream.Read(buff, 0, (int)myStream.Length);

            if (buff[0] == '-')
            {
                int  i   = 0;
                bool rsa = true;
                for (i = 0; i < utils.keyOpen.Length; i++)
                {
                    if (buff[i] != utils.keyOpen[i])
                    {
                        rsa = false;
                        for (i = 0; i < utils.keyOpen2.Length; i++)
                        {
                            if (buff[i] != utils.keyOpen2[i])
                            {
                                throw new Exception("Файл не является (RSA)? PRIVATE KEY");
                            }
                        }
                        break;
                    }
                }

                while (i < myStream.Length)
                {
                    if (buff[i] == '\r' || buff[i] == '\n')
                    {
                        i++;
                        continue;
                    }
                    if (buff[i] != 'M')
                    {
                        throw new Exception("Ключ возможно зашифрован. Выберете незашифрованный приватный ключ");
                    }
                    break;
                }
                int startBase64 = i;
                while ((i < myStream.Length) && (buff[i] != '-'))
                {
                    i++;
                }
                if (rsa)
                {
                    for (int j = 0; j < utils.keyClose.Length; j++)
                    {
                        if (buff[i + j] != utils.keyClose[j])
                        {
                            throw new Exception("Файл не завершен как RSA PRIVATE KEY");
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < utils.keyClose2.Length; j++)
                    {
                        if (buff[i + j] != utils.keyClose2[j])
                        {
                            throw new Exception("Файл не завершен как PRIVATE KEY");
                        }
                    }
                }
                buff = Convert.FromBase64CharArray(Encoding.UTF8.GetString(buff).ToCharArray(), startBase64, i - startBase64);
            }
            buffMax = buff.Length;
            if (buff[0] != 0x30)
            {
                throw new Exception("Ошибка в ASN1 данных");
            }
            Ber data = new Ber(buff, 0, (uint)buff.Length);

            if (data.childs.Count != 9)
            {
                try
                {
                    data = data.childs[2].childs[0];
                    if (data.childs.Count != 9)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception Eex)
                {
                    throw new Exception("Не удалось обнаружить приватный ключ");
                }
            }
            try
            {
                if (data.childs[0].payloadLength != 1 || data.childs[0].tag != (ulong)BerTags.INTEGER || data.childs[0].payload[0] != 0)
                {
                    throw new Exception();
                }
            }
            catch (Exception Eex)
            {
                throw new Exception("Не удалось обнаружить приватный ключ");
            }
            data.deleteParrent();
            return(new keyInfo(data));
        }
Exemple #10
0
        static public Ber saveVER1(storageInfo sess)
        {
            int j       = 77;
            Ber storage = new Ber(BerClass.UNIVERSAL, BerTags.SEQUENCE, true);
            Ber box     = null;

            string[] ar = null;
            //save domains
            if (sess.domains.Count > 0)
            {
                box = storage.addChild(new Ber(3, 'D', true));
                ar  = new String[sess.domains.Keys.Count];
                sess.domains.Keys.CopyTo(ar, 0);
                Array.Sort(ar, StringComparer.InvariantCulture);

                foreach (string domainName in ar)
                {
                    Ber temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(domainName)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 70)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j   += 43;
                    temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(sess.domains[domainName].dns)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 73)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j   -= 9;
                    temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(sess.domains[domainName].subs)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 79)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j = j * 3 - 1;
                }
                box = null;
            }
            //certs
            if (sess.certs.Count > 0)
            {
                box = storage.addChild(new Ber(3, 'C', true));
                ar  = new String[sess.certs.Keys.Count];
                sess.certs.Keys.CopyTo(ar, 0);
                Array.Sort(ar, StringComparer.InvariantCulture);

                foreach (string certName in ar)
                {
                    Ber temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(certName)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 149)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j   += 35;
                    temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, sess.certs[certName].cert.makeDer()));
                    for (int i = 0; i < temp.payload.Length; i++, j += 137)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j -= 15;
                }
                box = null;
            }
            //save keys
            if (sess.keys.Count > 0)
            {
                box = storage.addChild(new Ber(3, 'K', true));
                ar  = new String[sess.keys.Keys.Count];
                sess.keys.Keys.CopyTo(ar, 0);
                Array.Sort(ar, StringComparer.InvariantCulture);

                foreach (string keyName in ar)
                {
                    Ber temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(keyName)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 171)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j   += 31;
                    temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, sess.keys[keyName].key.makeDer()));
                    for (int i = 0; i < temp.payload.Length; i++, j += 73)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j -= 18;
                }
                box = null;
            }
            //save servers
            if (sess.servers.Count > 0)
            {
                box = storage.addChild(new Ber(3, 'S', true));
                ar  = new String[sess.servers.Keys.Count];
                sess.servers.Keys.CopyTo(ar, 0);
                Array.Sort(ar, StringComparer.InvariantCulture);

                foreach (string keyName in ar)
                {
                    Ber temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(keyName)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 97)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j   += 89;
                    temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(sess.servers[keyName].link)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 29)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j   -= 21;
                    temp = box.addChild(new Ber(BerClass.PRIVATE, BerTags.OCTET_STRING, false, Encoding.UTF8.GetBytes(sess.servers[keyName].pass)));
                    for (int i = 0; i < temp.payload.Length; i++, j += 31)
                    {
                        temp.payload[i] ^= (byte)j;
                    }
                    j = j * 2 + 1;
                }
                box = null;
            }


            return(storage);
        }
Exemple #11
0
        static public void parseVER1(storageInfo sess, Ber box)
        {
            int j = 77;

            if (box.tag != (UInt64)BerTags.SEQUENCE || box.tClass != (byte)BerClass.UNIVERSAL || !box.container)
            {
                utils.pu(100);
            }

            for (int stType = 0; stType < box.childs.Count; stType++)
            {
                Ber box1 = box.childs[stType];
                if (box1.tClass != (byte)BerClass.PRIVATE || !box1.container)
                {
                    utils.pu(96);
                }
                switch (box1.tag)
                {
                case 67:
                    if (box1.childs.Count == 0)
                    {
                        break;
                    }
                    if ((box1.childs.Count & 1) != 0)
                    {
                        utils.pu(96);
                    }
                    for (int certIndex = 0; certIndex < box1.childs.Count; certIndex += 2)
                    {
                        byte[] kk = null;
                        if (box1.childs[certIndex].container || box1.childs[certIndex].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[certIndex].tClass != (byte)BerClass.PRIVATE || box1.childs[certIndex].payloadLength < 1)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[certIndex].payload;
                        for (int i = 0; i < kk.Length; i++, j += 149)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j += 35;
                        string certName = Encoding.UTF8.GetString(kk);
                        if (box1.childs[certIndex + 1].container || box1.childs[certIndex + 1].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[certIndex + 1].tClass != (byte)BerClass.PRIVATE || box1.childs[certIndex + 1].payloadLength < 16)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[certIndex + 1].payload;
                        for (int i = 0; i < kk.Length; i++, j += 137)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j -= 15;
                        Ber cert = new Ber(kk, 0, (uint)kk.Length);
                        if (cert.childs.Count != 3)
                        {
                            utils.pu(96);
                        }
                        sess.certs.Add(certName, new certInfo(cert));
                    }
                    break;

                case 68:
                    if (box1.childs.Count == 0)
                    {
                        break;
                    }
                    if ((box1.childs.Count % 3) != 0)
                    {
                        utils.pu(96);
                    }
                    for (int domainIndex = 0; domainIndex < box1.childs.Count; domainIndex += 3)
                    {
                        byte[] kk = null;
                        if (box1.childs[domainIndex].container || box1.childs[domainIndex].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[domainIndex].tClass != (byte)BerClass.PRIVATE || box1.childs[domainIndex].payloadLength < 1)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[domainIndex].payload;
                        for (int i = 0; i < kk.Length; i++, j += 70)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j += 43;
                        string domainName = Encoding.UTF8.GetString(kk);
                        if (box1.childs[domainIndex + 1].container || box1.childs[domainIndex + 1].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[domainIndex + 1].tClass != (byte)BerClass.PRIVATE || box1.childs[domainIndex + 2].payloadLength < 1)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[domainIndex + 1].payload;
                        for (int i = 0; i < kk.Length; i++, j += 73)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j -= 9;
                        string dns = Encoding.UTF8.GetString(kk);
                        if (box1.childs[domainIndex + 2].container || box1.childs[domainIndex + 2].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[domainIndex + 2].tClass != (byte)BerClass.PRIVATE || box1.childs[domainIndex + 2].payloadLength < 1)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[domainIndex + 2].payload;
                        for (int i = 0; i < kk.Length; i++, j += 79)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j = j * 3 - 1;
                        string subs = Encoding.UTF8.GetString(kk);

                        sess.domains.Add(domainName, new DomainInfo(dns, subs));
                    }
                    break;

                case 75:
                    if (box1.childs.Count == 0)
                    {
                        break;
                    }
                    if ((box1.childs.Count & 1) != 0)
                    {
                        utils.pu(96);
                    }
                    for (int keyIndex = 0; keyIndex < box1.childs.Count; keyIndex += 2)
                    {
                        byte[] kk = null;
                        if (box1.childs[keyIndex].container || box1.childs[keyIndex].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[keyIndex].tClass != (byte)BerClass.PRIVATE || box1.childs[keyIndex].payloadLength < 1)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[keyIndex].payload;
                        for (int i = 0; i < kk.Length; i++, j += 171)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j += 31;
                        string keyName = Encoding.UTF8.GetString(kk);
                        if (box1.childs[keyIndex + 1].container || box1.childs[keyIndex + 1].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[keyIndex + 1].tClass != (byte)BerClass.PRIVATE || box1.childs[keyIndex + 1].payloadLength < 16)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[keyIndex + 1].payload;
                        for (int i = 0; i < kk.Length; i++, j += 73)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j -= 18;
                        Ber key = new Ber(kk, 0, (uint)kk.Length);
                        if (key.childs.Count != 9)
                        {
                            utils.pu(96);
                        }
                        sess.keys.Add(keyName, new keyInfo(key));
                    }
                    break;

                case 83:
                    if (box1.childs.Count == 0)
                    {
                        break;
                    }
                    if ((box1.childs.Count % 3) != 0)
                    {
                        utils.pu(96);
                    }
                    for (int keyIndex = 0; keyIndex < box1.childs.Count; keyIndex += 3)
                    {
                        byte[] kk = null;
                        if (box1.childs[keyIndex].container || box1.childs[keyIndex].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[keyIndex].tClass != (byte)BerClass.PRIVATE || box1.childs[keyIndex].payloadLength < 1)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[keyIndex].payload;
                        for (int i = 0; i < kk.Length; i++, j += 97)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j += 89;
                        string serverName = Encoding.UTF8.GetString(kk);
                        if (box1.childs[keyIndex + 1].container || box1.childs[keyIndex + 1].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[keyIndex + 1].tClass != (byte)BerClass.PRIVATE || box1.childs[keyIndex + 1].payloadLength < 16)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[keyIndex + 1].payload;
                        for (int i = 0; i < kk.Length; i++, j += 29)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j -= 21;
                        string link = Encoding.UTF8.GetString(kk);
                        if (box1.childs[keyIndex + 2].container || box1.childs[keyIndex + 2].tag != (UInt64)BerTags.OCTET_STRING || box1.childs[keyIndex + 2].tClass != (byte)BerClass.PRIVATE || box1.childs[keyIndex + 2].payloadLength < 16)
                        {
                            utils.pu(96);
                        }
                        kk = box1.childs[keyIndex + 2].payload;
                        for (int i = 0; i < kk.Length; i++, j += 31)
                        {
                            kk[i] ^= (byte)j;
                        }
                        j = j * 2 + 1;
                        string pass = Encoding.UTF8.GetString(kk);

                        sess.servers.Add(serverName, new ServerInfo(link, pass));
                    }
                    break;

                default: utils.pu(96); break;
                }
            }
        }