Ejemplo n.º 1
0
        public void OrganizationsNetworkTest()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;

            var xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""https://disco.eduvpn.org/v2/organization_list.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey>RWRtBSX1alxyGX+Xn3LuZnWUT0w//B6EmTJvgaAxBMYzlQeI+jdrO6KF</PublicKey>
							<PublicKey>RWQKqtqvd0R7rUDp0rWzbtYPA3towPWcLDCl7eY9pBMMI/ohCmrS0WiM</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));

            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            var source = new ResourceRef();

            source.ReadXml(xmlReader);

            // Load list of organizations.
            var organizationListJson = Response.Get(source);
            var dict = new OrganizationDictionary();

            dict.LoadJSON(organizationListJson.Value);

            // Re-load list of organizations.
            Response.Get(
                res: source,
                previous: organizationListJson);
        }
Ejemplo n.º 2
0
        public void ResponseTest()
        {
            var xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""http://besana.amebis.si/""></ResourceRef>")));

            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            var source = new ResourceRef();

            source.ReadXml(xmlReader);
            Response.Get(
                res: source,
                responseType: "*/*");

            xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""http://govorec.amebis.si/""></ResourceRef>")));
            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            source = new ResourceRef();
            source.ReadXml(xmlReader);
            Assert.ThrowsException <HttpRedirectToUnsafeUriException>(() =>
                                                                      Response.Get(
                                                                          res: source,
                                                                          responseType: "*/*"));
        }
Ejemplo n.º 3
0
        public void OrganizationsNetworkTest()
        {
            // .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 | (SecurityProtocolType)0x3000;

            var xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""https://disco.eduvpn.org/v2/organization_list.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey>RWRtBSX1alxyGX+Xn3LuZnWUT0w//B6EmTJvgaAxBMYzlQeI+jdrO6KF</PublicKey>
							<PublicKey>RWQ68Y5/b8DED0TJ41B1LE7yAvkmavZWjDwCBUuC+Z2pP9HaSawzpEDA</PublicKey>
							<PublicKey>RWQKqtqvd0R7rUDp0rWzbtYPA3towPWcLDCl7eY9pBMMI/ohCmrS0WiM</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));

            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            var source = new ResourceRef();

            source.ReadXml(xmlReader);

            // Load list of organizations.
            var organizationListJson = Xml.Response.Get(source);
            var dict = new OrganizationDictionary();

            dict.LoadJSON(organizationListJson.Value);

            // Re-load list of organizations.
            Xml.Response.Get(
                res: source,
                previous: organizationListJson);
        }
Ejemplo n.º 4
0
        public void ServersNetworkTest()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;

            var xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""https://disco.eduvpn.org/v2/server_list.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey>RWRtBSX1alxyGX+Xn3LuZnWUT0w//B6EmTJvgaAxBMYzlQeI+jdrO6KF</PublicKey>
							<PublicKey>RWQKqtqvd0R7rUDp0rWzbtYPA3towPWcLDCl7eY9pBMMI/ohCmrS0WiM</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));

            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            var source = new ResourceRef();

            source.ReadXml(xmlReader);

            // Load list of servers.
            var server_list_list_json = Response.Get(source);
            var server_list_list_ia   = new ServerDictionary();

            server_list_list_ia.LoadJSON(server_list_list_json.Value);

            // Load all servers APIs.
            Parallel.ForEach(server_list_list_ia.Values, srv =>
            {
                var uriBuilder   = new UriBuilder(srv.Base);
                uriBuilder.Path += "info.json";
                try
                {
                    new ServerEndpoints().LoadJSON(Response.Get(uriBuilder.Uri).Value);
                }
                catch (UnsupportedServerAPIException)
                {
                    // Ignore non-APIv3 servers.
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerException is WebException ex_web &&
                        (ex_web.Status == WebExceptionStatus.NameResolutionFailure || // DNS resolving failure
                         ex_web.Status == WebExceptionStatus.ConnectFailure ||        // connection refused
                         ex_web.Status == WebExceptionStatus.TrustFailure ||          // expired or invalid server certificate
                         ex_web.Status == WebExceptionStatus.SecureChannelFailure ||  // TLS failure
                         ex_web.Status == WebExceptionStatus.Timeout))                // server down
                    {
                        // Ignore connection failure WebException(s), as some servers are not publicly available or have other issues.
                    }
Ejemplo n.º 5
0
        public void ServersNetworkTest()
        {
            // .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 | (SecurityProtocolType)0x3000;

            var xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""https://disco.eduvpn.org/v2/server_list.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey>RWRtBSX1alxyGX+Xn3LuZnWUT0w//B6EmTJvgaAxBMYzlQeI+jdrO6KF</PublicKey>
							<PublicKey>RWQ68Y5/b8DED0TJ41B1LE7yAvkmavZWjDwCBUuC+Z2pP9HaSawzpEDA</PublicKey>
							<PublicKey>RWQKqtqvd0R7rUDp0rWzbtYPA3towPWcLDCl7eY9pBMMI/ohCmrS0WiM</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));

            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            var source = new ResourceRef();

            source.ReadXml(xmlReader);

            // Load list of servers.
            var server_list_list_json = Xml.Response.Get(source);
            var server_list_list_ia   = new ServerDictionary();

            server_list_list_ia.LoadJSON(server_list_list_json.Value);

            // Load all servers APIs.
            Parallel.ForEach(server_list_list_ia.Values, srv =>
            {
                var uriBuilder   = new UriBuilder(srv.Base);
                uriBuilder.Path += "info.json";
                try
                {
                    new Models.ServerEndpoints().LoadJSON(Xml.Response.Get(uriBuilder.Uri).Value);
                }
                catch (AggregateException ex)
                {
                    if (ex.InnerException is WebException ex_web &&
                        (ex_web.Status == WebExceptionStatus.ConnectFailure ||       // connection refused
                         ex_web.Status == WebExceptionStatus.TrustFailure ||         // expired or invalid server certificate
                         ex_web.Status == WebExceptionStatus.SecureChannelFailure || // TLS failure
                         ex_web.Status == WebExceptionStatus.Timeout))               // server down
                    {
                        // Ignore connection failure WebException(s), as some servers are not publicly available or have other issues.
                    }
Ejemplo n.º 6
0
        public void MinisignVerifyTest()
        {
            var xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""../../Setup/eduVPN.windows.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey SupportedAlgorithms=""2"">RWRPrtnepBgoU86pKtSnHJXBtmtJjv6T5wN2Q+P7vPgHPdr3v8kGme13</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));

            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            var source = new ResourceRef();

            source.ReadXml(xmlReader);
            Response.Get(source);

            xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""../../Setup/eduVPN.windows.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey SupportedAlgorithms=""1"">RWRPrtnepBgoU86pKtSnHJXBtmtJjv6T5wN2Q+P7vPgHPdr3v8kGme13</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));
            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            source = new ResourceRef();
            source.ReadXml(xmlReader);
            Assert.ThrowsException <ArgumentException>(() => Response.Get(source));

            xmlReader = XmlReader.Create(new MemoryStream(Encoding.UTF8.GetBytes(@"<ResourceRef Uri=""../../Setup/eduVPN.windows.json"">
						<MinisignPublicKeyDictionary Key=""PublicKeys"">
							<PublicKey>RWRtBSX1alxyGX+Xn3LuZnWUT0w//B6EmTJvgaAxBMYzlQeI+jdrO6KF</PublicKey>
						</MinisignPublicKeyDictionary>
					</ResourceRef>"                    )));
            while (xmlReader.ReadState == ReadState.Initial)
            {
                xmlReader.Read();
            }
            source = new ResourceRef();
            source.ReadXml(xmlReader);
            Assert.ThrowsException <SecurityException>(() => Response.Get(source));
        }