예제 #1
0
        public void InstanceSourceInfoTest()
        {
            // .NET 3.5 allows Schannel to use SSL 3 and TLS 1.0 by default. Instead of hacking user computer's registry, extend it in runtime.
            // System.Net.SecurityProtocolType lacks appropriate constants prior to .NET 4.5.
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)0x0C00;

            var pub_key = Convert.FromBase64String("E5On0JTtyUVZmcWd+I/FXRm32nSq8R2ioyW7dcu/U88=");

            Parallel.ForEach(new List <ResourceRef>()
            {
                new ResourceRef()
                {
                    Uri       = new Uri("https://static.eduvpn.nl/disco/institute_access.json"),
                    PublicKey = pub_key,
                },
                new ResourceRef()
                {
                    Uri       = new Uri("https://static.eduvpn.nl/disco/secure_internet.json"),
                    PublicKey = pub_key,
                },
            }, source =>
            {
                // Load list of instances.
                var instance_source_json = Xml.Response.Get(source);
                var instance_source_ia   = new InstanceSource();
                instance_source_ia.LoadJSON(instance_source_json.Value);

                // Load all instances APIs.
                Parallel.ForEach(instance_source_ia.InstanceList, i =>
                {
                    var uri_builder   = new UriBuilder(i.Base);
                    uri_builder.Path += "info.json";
                    try
                    {
                        new Models.InstanceEndpoints().LoadJSON(Xml.Response.Get(uri_builder.Uri).Value);
                    }
                    catch (AggregateException ex)
                    {
                        if (ex.InnerException is WebException ex_web && (ex_web.Status == WebExceptionStatus.ConnectFailure || ex_web.Status == WebExceptionStatus.SecureChannelFailure))
                        {
                            // Ignore connection failure WebException(s), as some instances are not publicly available or have other issues.
                        }
                        else
                        {
                            throw;
                        }
                    }
예제 #2
0
        public void InstanceSourceInfoTest()
        {
            // .NET 3.5 allows Schannel to use SSL 3 and TLS 1.0 by default. Instead of hacking user computer's registry, extend it in runtime.
            // System.Net.SecurityProtocolType lacks appropriate constants prior to .NET 4.5.
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)0x0C00;

            var pub_key = Convert.FromBase64String("E5On0JTtyUVZmcWd+I/FXRm32nSq8R2ioyW7dcu/U88=");

            Parallel.ForEach(new List <KeyValuePair <Uri, byte[]> >()
            {
                new KeyValuePair <Uri, byte[]>(new Uri("https://static.eduvpn.nl/disco/institute_access.json"), pub_key),
                new KeyValuePair <Uri, byte[]>(new Uri("https://static.eduvpn.nl/disco/secure_internet.json"), pub_key),
            }, source =>
            {
                // Load list of instances.
                var instance_source_json = Xml.Response.Get(
                    uri: source.Key,
                    pub_key: source.Value);
                var instance_source_ia = new InstanceSource();
                instance_source_ia.LoadJSON(instance_source_json.Value);

                // Load all instances APIs.
                Parallel.ForEach(instance_source_ia.InstanceList, i =>
                {
                    var uri_builder   = new UriBuilder(i.Base);
                    uri_builder.Path += "info.json";
                    new Models.InstanceEndpoints().LoadJSON(Xml.Response.Get(uri_builder.Uri).Value);
                });

                // Re-load list of instances.
                instance_source_json = Xml.Response.Get(
                    uri: source.Key,
                    pub_key: source.Value,
                    previous: instance_source_json);
            });
        }