Пример #1
0
        public static IEnumerator LoadReleases(string url, string authToken = null)
        {
            string proxiedUrl = UpliftPreferences.FromDefaultFile().GetProxiedUrl(url);

            WWW www = string.IsNullOrEmpty(authToken) ?
                      new WWW(proxiedUrl) :
                      new WWW(
                proxiedUrl,
                null,
                new Dictionary <string, string>
            {
                { "Authorization", "token " + authToken }
            });

            while (www.isDone == false)
            {
                yield return(null);
            }
            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);
                Debug.LogWarning(www.text);

                yield return(null);
            }
            else
            {
                yield return(ParseReleases(www.text));
            }
        }
Пример #2
0
        public static Stream GetAssetStream(GitHubAsset asset, string token)
        {
            string proxiedUrl = UpliftPreferences.FromDefaultFile().GetProxiedUrl(asset.apiURL);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(proxiedUrl);

            request.Method = "GET";
            if (!string.IsNullOrEmpty(token))
            {
                request.Headers["Authorization"] = "token " + token;
            }
            request.Accept            = "application/octet-stream";
            request.UserAgent         = "Uplift GithubRepository/1.0 - https://github.com/DragonBox/uplift";
            request.AllowAutoRedirect = false;

            ServicePointManager.ServerCertificateValidationCallback = GitHub.CertificateValidationCallback;
            Uri            address;
            HttpStatusCode responseStatus;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                responseStatus = response.StatusCode;
                if ((int)response.StatusCode < 300 || (int)response.StatusCode > 399)
                {
                    throw new ApplicationException("Request should be redirected");
                }
                address = new Uri(response.GetResponseHeader("Location"));
            }

            request           = (HttpWebRequest)WebRequest.Create(UpliftPreferences.FromDefaultFile().GetProxiedUrl(address.OriginalString));
            request.Method    = "GET";
            request.UserAgent = "Uplift GithubRepository/1.0 - https://github.com/DragonBox/uplift";
            HttpWebResponse finalResponse = (HttpWebResponse)request.GetResponse();

            responseStatus = finalResponse.StatusCode;
            if ((int)finalResponse.StatusCode >= 200 && (int)finalResponse.StatusCode <= 299)
            {
                return(finalResponse.GetResponseStream());
            }

            throw new ApplicationException("Could not get asset at " + asset.apiURL);
        }
Пример #3
0
        public static bool CertificateValidationCallback(
            System.Object sender,
            X509Certificate certificate,
            X509Chain chain,
            SslPolicyErrors sslPolicyErrors
            )
        {
            bool correct = true;

            if (sslPolicyErrors == SslPolicyErrors.None)
            {
                return(true);
            }

            X509Certificate[] githubCertificates = GetCertificates();

            if (!(githubCertificates.Any(cert => cert.GetCertHashString() == certificate.GetCertHashString()) || UpliftPreferences.FromDefaultFile().TrustUnknowCertificates))
            {
                Debug.LogErrorFormat("The received certificate ({0}) is not known by Uplift. We cannot download the update package. You could update Uplift manually, or go to Preferences and set 'Trust unknown certificates' to true.", certificate.GetCertHashString());
                Debug.Log("Known certificates are:");
                foreach (X509Certificate cert in githubCertificates)
                {
                    Debug.Log(" -- " + cert.GetCertHashString());
                }
                return(false);
            }

            for (int i = 0; i < chain.ChainStatus.Length; i++)
            {
                if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown)
                {
                    continue;
                }
                chain.ChainPolicy.RevocationFlag      = X509RevocationFlag.EntireChain;
                chain.ChainPolicy.RevocationMode      = X509RevocationMode.Online;
                chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 1, 0);
                chain.ChainPolicy.VerificationFlags   = X509VerificationFlags.AllFlags;
                bool chainIsValid = chain.Build((X509Certificate2)certificate);
                if (!chainIsValid)
                {
                    correct = false;
                    break;
                }
            }

            return(correct);
        }