Exemple #1
0
        /// <summary>This method handles IPPackets that come from Brunet, i.e.,
        /// abroad.  </summary>
        /// <param name="packet"> The packet from Brunet.</param>
        /// <param name="ret">An ISender to send data to the Brunet node that sent
        /// the packet.</param>
        public virtual void HandleIPIn(MemBlock packet, ISender ret)
        {
            Address addr = _conn_handler.GetAddress(ret);

            if (_translator != null)
            {
                try {
                    packet = _translator.Translate(packet, addr);
                }
                catch (Exception e) {
                    if (ProtocolLog.Exceptions.Enabled)
                    {
                        ProtocolLog.Write(ProtocolLog.Exceptions, e.ToString());
                    }
                    return;
                }
            }

            IPPacket ipp = new IPPacket(packet);

            if (!_address_resolver.Check(ipp.SourceIP, addr))
            {
                Address other = _address_resolver.Resolve(ipp.SourceIP);
                if (other == null)
                {
                    MissedMapping(ipp.SSourceIP, addr);
                    return;
                }
                else if (other != addr)
                {
                    ProtocolLog.WriteIf(IpopLog.ResolverLog, String.Format(
                                            "IP:P2P Mismatch IP: {0}, Claimed P2P: {1}, Local P2P: {2}",
                                            ipp.SourceIP, addr, other));
                    return;
                }
            }

            if (IpopLog.PacketLog.Enabled)
            {
                ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                                      "Incoming packet:: IP src: {0}, IP dst: {1}, p2p " +
                                      "from: {2}, size: {3}", ipp.SSourceIP, ipp.SDestinationIP,
                                      ret, packet.Length));
            }

            WriteIP(packet);
        }
 public AddressModel Resolve(CarWorkshopDto source, CarWorkshopModel destination, AddressModel destMember, ResolutionContext context)
 {
     return(_addressResolver.Resolve(source));
 }
        public async Task InitializeAsync()
        {
            //if (await manager.FindByClientIdAsync("react") == null)
            //{
            //    var descriptor = new OpenIddictApplicationDescriptor
            //    {
            //        ClientId = "react",
            //        ClientSecret = "react_secret",
            //        DisplayName = "SPA client application",
            //        PostLogoutRedirectUris = { new Uri("http://localhost:3000/signout-callback-oidc") },
            //        RedirectUris = { new Uri("http://localhost:3000/signin-oidc") },
            //        Permissions =
            //        {
            //            OpenIddictConstants.Permissions.Endpoints.Authorization,
            //            OpenIddictConstants.Permissions.Endpoints.Logout,
            //            OpenIddictConstants.Permissions.GrantTypes.Implicit
            //        }
            //    };

            //    await manager.CreateAsync(descriptor);
            //}

            var resourceServer = await manager.FindByClientIdAsync("resource_server");

            if (resourceServer == null)
            {
                var descriptor = new OpenIddictApplicationDescriptor
                {
                    ClientId     = "resource_server",
                    ClientSecret = "resource_server_secret",
                    Permissions  =
                    {
                        OpenIddictConstants.Permissions.Endpoints.Token,
                        OpenIddictConstants.Permissions.GrantTypes.ClientCredentials
                    }
                };

                await manager.CreateAsync(descriptor);
            }

            var mvcClient = await manager.FindByClientIdAsync("mvc_client");

            if (mvcClient == null)
            {
                var descriptor = new OpenIddictApplicationDescriptor
                {
                    ClientId               = "mvc_client",
                    ClientSecret           = "mvc_client_secret",
                    DisplayName            = "MVC Client application",
                    PostLogoutRedirectUris = { new Uri($"{configuration["Client:BaseUrl"]}external/logout") },
                    RedirectUris           = { new Uri($"{configuration["Client:BaseUrl"]}external/login") },
                    Permissions            =
                    {
                        OpenIddictConstants.Permissions.Endpoints.Authorization,
                        OpenIddictConstants.Permissions.Endpoints.Logout,
                        OpenIddictConstants.Permissions.Endpoints.Token,
                        OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode,
                        OpenIddictConstants.Permissions.GrantTypes.RefreshToken
                    }
                };

                foreach (var scope in scopes.GetScopes())
                {
                    descriptor.Permissions.Add($"scp:{scope}");
                }

                await manager.CreateAsync(descriptor);
            }
            else
            {
                var permissions = new JArray(
                    OpenIddictConstants.Permissions.Endpoints.Authorization,
                    OpenIddictConstants.Permissions.Endpoints.Logout,
                    OpenIddictConstants.Permissions.Endpoints.Token,
                    OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode,
                    OpenIddictConstants.Permissions.GrantTypes.RefreshToken);

                foreach (var scope in scopes.GetScopes())
                {
                    permissions.Add($"scp:{scope}");
                }

                mvcClient.Permissions = JsonConvert.SerializeObject(permissions);
                await manager.UpdateAsync(mvcClient);
            }

            var swagger = await manager.FindByClientIdAsync("swagger");

            if (swagger == null)
            {
                var descriptor = new OpenIddictApplicationDescriptor
                {
                    ClientId     = "swagger",
                    DisplayName  = "Swagger",
                    RedirectUris = { new Uri(Combine(addressResolver.Resolve(), "/swagger/oauth2-redirect.html")) },
                    Permissions  =
                    {
                        OpenIddictConstants.Permissions.Endpoints.Authorization,
                        OpenIddictConstants.Permissions.GrantTypes.Implicit
                    }
                };

                foreach (var scope in scopes.GetScopes())
                {
                    descriptor.Permissions.Add($"scp:{scope}");
                }

                await manager.CreateAsync(descriptor);
            }
            else
            {
                var permissions = new JArray(OpenIddictConstants.Permissions.Endpoints.Authorization, OpenIddictConstants.Permissions.GrantTypes.Implicit);
                foreach (var scope in scopes.GetScopes())
                {
                    permissions.Add($"scp:{scope}");
                }

                swagger.Permissions = JsonConvert.SerializeObject(permissions);
                await manager.UpdateAsync(swagger);
            }
        }
Exemple #4
0
        /// <summary>This method handles IPPackets that come from the TAP Device, i.e.,
        /// local system.</summary>
        /// <remarks>Currently this supports HandleMulticast (ip[0] >= 244 &&
        /// ip[0]<=239), HandleDns (dport = 53 and ip[3] == 1), dhcp (sport 68 and
        /// dport 67.</remarks>
        /// <param name="packet">The packet from the TAP device</param>
        /// <param name="from"> This should always be the tap device</param>
        protected virtual void HandleIPOut(EthernetPacket packet, ISender ret)
        {
            IPPacket ipp = new IPPacket(packet.Payload);

            if (IpopLog.PacketLog.Enabled)
            {
                ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                                      "Outgoing {0} packet::IP src: {1}, IP dst: {2}",
                                      ipp.Protocol, ipp.SSourceIP, ipp.SDestinationIP));
            }

            if (!IsLocalIP(ipp.SourceIP))
            {
                HandleNewStaticIP(packet.SourceAddress, ipp.SourceIP);
                return;
            }

            UdpPacket udpp = null;

            switch (ipp.Protocol)
            {
            case IPPacket.Protocols.Udp:
                udpp = new UdpPacket(ipp.Payload);
                if (udpp.SourcePort == _dhcp_client_port && udpp.DestinationPort == _dhcp_server_port)
                {
                    if (HandleDhcp(ipp))
                    {
                        return;
                    }
                }
                else if (udpp.DestinationPort == 53 && ipp.DestinationIP.Equals(_dhcp_server.ServerIP))
                {
                    if (HandleDns(ipp))
                    {
                        return;
                    }
                }
                break;
            }

            if (ipp.DestinationIP[0] >= 224 && ipp.DestinationIP[0] <= 239)
            {
                // We don't want to send Brunet multicast packets over IPOP!
                if (udpp != null && udpp.DestinationPort == IPHandler.mc_port)
                {
                    return;
                }
                else if (HandleMulticast(ipp))
                {
                    return;
                }
            }

            if (ipp.DestinationIP.Equals(IPPacket.BroadcastAddress))
            {
                if (HandleBroadcast(ipp))
                {
                    return;
                }
            }

            if (HandleOther(ipp))
            {
                return;
            }

            if (_dhcp_server == null || ipp.DestinationIP.Equals(_dhcp_server.ServerIP))
            {
                return;
            }

            Address target = null;

            try {
                target = _address_resolver.Resolve(ipp.DestinationIP) as AHAddress;
            } catch (AddressResolutionException ex) {
                if (ex.Issue != AddressResolutionException.Issues.DoesNotExist)
                {
                    throw;
                }
                // Otherwise nothing to do, mapping doesn't exist...
            }

            if (target != null)
            {
                if (IpopLog.PacketLog.Enabled)
                {
                    ProtocolLog.Write(IpopLog.PacketLog, String.Format(
                                          "Brunet destination ID: {0}", target));
                }
                SendIP(target, packet.Payload);
                _ondemand.Set(target);
            }
        }
 public AddressModel Resolve(UserDto source, UserModel destination, AddressModel destMember, ResolutionContext context)
 {
     return(_addressResolver.Resolve(source));
 }