Ejemplo n.º 1
0
        public async Task <IPAddress> GetMyIpAsync(IPVersion ver = IPVersion.IPv4, CancellationToken cancel = default)
        {
            string url;

            if (ver == IPVersion.IPv4)
            {
                url = Consts.Urls.GetMyIpUrl_IPv4;
            }
            else
            {
                url = Consts.Urls.GetMyIpUrl_IPv6;
            }

            Exception?error = null;

            IPAddress?ret = null;

            for (int i = 0; i < CoresConfig.GetMyIpClientSettings.NumRetry; i++)
            {
                try
                {
                    WebRet webRet = await Web.SimpleQueryAsync(WebMethods.GET, url, cancel);

                    string str = webRet.Data._GetString_Ascii()._OneLine("");

                    if (str.StartsWith("IP=", StringComparison.OrdinalIgnoreCase))
                    {
                        ret = IPAddress.Parse(str.Substring(3));
                        break;
                    }
                    else
                    {
                        throw new ApplicationException($"Invalid IP str: \"{str}\"");
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            }

            if (ret == null)
            {
                throw error !;
            }

            return(ret);
        }
Ejemplo n.º 2
0
        public async Task <byte[]> SignAsync(string password, ReadOnlyMemory <byte> srcData, string certName, string flags, string comment, int numRetry = 5, CancellationToken cancel = default)
        {
            QueryStringList qs = new QueryStringList();

            qs.Add("password", password);
            qs.Add("cert", certName);
            qs.Add("flags", flags);
            qs.Add("comment", comment);
            qs.Add("numretry", numRetry.ToString());

            WebRet ret = await this.Web.SimplePostDataAsync(this.Url + "?" + qs, srcData.ToArray(), cancel, Consts.MimeTypes.OctetStream);

            if (ret.Data.Length <= (srcData.Length * 9L / 10L))
            {
                throw new CoresException("ret.Data.Length <= (srcData.Length * 9L / 10L)");
            }

            if (ExeSignChecker.CheckFileDigitalSignature(ret.Data, flags._InStr("driver", true)) == false)
            {
                throw new CoresException("CheckFileDigitalSignature failed.");
            }

            return(ret.Data);
        }
Ejemplo n.º 3
0
 public WebUserRet(WebRet web, TUser user) : base(web, user)
 {
 }