Example #1
0
        public static WpcPacket ParsePacket(string recvStr)
        {
            List <WpcEntry> o = WpcEntry.ParseDataEntry(recvStr);

            WpcEntry e;

            try
            {
                e = WpcEntry.FindEntry(o, "PACK");
                if (e != null)
                {
                    byte[] hash = Secure.HashSHA1(e.Data);
                    Pack   pack = null;

                    pack = Pack.CreateFromBuf(new Buf(e.Data));

                    e = WpcEntry.FindEntry(o, "HASH");

                    if (e != null)
                    {
                        byte[] hash2 = e.Data;

                        if (Util.CompareByte(hash, hash2))
                        {
                            e = WpcEntry.FindEntry(o, "CERT");
                            if (e != null)
                            {
                                Cert cert;

                                try
                                {
                                    cert = new Cert(e.Data);
                                }
                                catch
                                {
                                    return(null);
                                }

                                e = WpcEntry.FindEntry(o, "SIGN");
                                if (e != null)
                                {
                                    byte[] sign = e.Data;

                                    if (cert.RsaPublicKey.VerifyData(hash2, sign))
                                    {
                                        return(new WpcPacket(pack, hash2, cert, sign));
                                    }
                                }
                            }
                            else
                            {
                                return(new WpcPacket(pack, hash2));
                            }
                        }
                    }
                }
            }
            catch (OverflowException)
            {
                return(null);
            }

            return(null);
        }
Example #2
0
 private WpcPacket(Pack pack, byte[] hash)
     : this(pack, hash, null, null)
 {
 }
Example #3
0
 public static string GeneratePacket(Pack pack)
 {
     return(GeneratePacket(pack, null, null));
 }
Example #4
0
 public void SetResponse(Pack pack, Cert cert, Rsa key)
 {
     responsePack = pack;
     responseCert = cert;
     responseKey  = key;
 }