Ejemplo n.º 1
0
        public bool IsBlackListValid()
        {
            Console.WriteLine("------------------ PROVERA CRNE LISTE ------------------");
            Console.WriteLine("Korisnik {0} je zatrazio proveru konfiguracije crne liste", Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name));
            string hexValidChecksum = readChecksum();
            string newChecksum      = checkMD5("Blacklist.xml");

            byte[] newC           = Encoding.Default.GetBytes(newChecksum);
            string hexNewChecksum = BitConverter.ToString(newC);

            if (hexNewChecksum == hexValidChecksum)
            {
                Console.WriteLine("Nije bilo izmena crne liste!");
                Console.WriteLine("------------------------------------------------------");
                return(true);
            }
            else
            {
                string pov = WCFServiceAudit.ReturnFactory().ConnectS("Blacklist");
                Console.WriteLine("Doslo je do ilegalnih izmena!!! ");
                Console.WriteLine("------------------------------------------------------");
                Program.host.Close();
                return(false);
            }
        }
Ejemplo n.º 2
0
        public PovratnaVrijednost CloseApp(byte[] encrypted)
        {
            OpenAppData decryted = (OpenAppData)AesAlg.Decrypt(encrypted, sessionKeys[Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name)]);

            IIdentity       identity    = Thread.CurrentPrincipal.Identity;
            WindowsIdentity winIdentity = identity as WindowsIdentity;

            string        user   = Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name);
            List <string> groups = GetUsergroups(winIdentity.Groups);


            blackList = Restriction.ReadBlackList();

            if (Restriction.IsRestricted(blackList, decryted, user, groups))
            {
                string pov = WCFServiceAudit.ReturnFactory().ConnectS(string.Format("{0}|{1}|{2}", user, decryted.Protokol, decryted.Port));
                if (pov == "DOS")
                {
                    return(PovratnaVrijednost.DOS);
                }
                return(PovratnaVrijednost.NEMADOZ);;
            }

            string key = string.Format("{0}", decryted.Port);

            if (servisi.ContainsKey(key))
            {
                servisi[key].Close();
                servisi.Remove(key);
                return(PovratnaVrijednost.USPJEH);
            }


            return(PovratnaVrijednost.NIJEOTV);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            /// Define the expected service certificate. It is required to establish cmmunication using certificates.
            string srvCertCN = "wcfservice";

            secretKey = SecretKey.GenerateKey();

            NetTcpBinding bindingAudit = new NetTcpBinding();

            bindingAudit.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate;

            /// Use CertManager class to obtain the certificate based on the "srvCertCN" representing the expected service identity.
            X509Certificate2 srvCert         = AuditCertManager.GetCertificateFromStorage(StoreName.TrustedPeople, StoreLocation.LocalMachine, srvCertCN);
            EndpointAddress  addressForAudit = new EndpointAddress(new Uri("net.tcp://localhost:8888/RecieverAudit"),
                                                                   new X509CertificateEndpointIdentity(srvCert));

            using (WCFServiceAudit proxy = new WCFServiceAudit(bindingAudit, addressForAudit))
            {
                /// 1. Communication test
                Console.WriteLine("proxy " + proxy.ConnectS("TryConnect"));
                Console.WriteLine("Connection() established. Press <enter> to continue ...");
            }

            //Windows autentifikacija
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            binding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
            string address = "net.tcp://localhost:9999/Receiver";

            host = new ServiceHost(typeof(WCFService));
            host.AddServiceEndpoint(typeof(IWCFContract), binding, address);

            host.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
            host.Description.Behaviors.Add(new ServiceDebugBehavior()
            {
                IncludeExceptionDetailInFaults = true
            });

            //autorizacija
            host.Authorization.ServiceAuthorizationManager = new CustomAuthorizationManager();
            host.Authorization.PrincipalPermissionMode     = PrincipalPermissionMode.Custom;
            List <IAuthorizationPolicy> policies = new List <IAuthorizationPolicy>();

            policies.Add(new CustomAuthorizationPolicy());
            host.Authorization.ExternalAuthorizationPolicies = policies.AsReadOnly();

            try
            {
                host.Open();
                Console.WriteLine("WCFService is started.\nPress <enter> to stop ...");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("[ERROR] {0}", e.Message);
                Console.WriteLine("[StackTrace] {0}", e.StackTrace);
            }
            finally
            {
                host.Close();
            }
        }
Ejemplo n.º 4
0
        public PovratnaVrijednost OpenApp(byte[] encrypted)
        {
            OpenAppData decryted = (OpenAppData)AesAlg.Decrypt(encrypted, sessionKeys[Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name)]);

            Console.WriteLine("------------------ OTVARANJE SERVISA ------------------");
            Console.WriteLine("Korisnik {0} je zatrazio otvaranje novog servisa na portu {1} sa protokolom {2}", Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name)
                              , decryted.Port, decryted.Protokol);
            IIdentity       identity    = Thread.CurrentPrincipal.Identity;
            WindowsIdentity winIdentity = identity as WindowsIdentity;

            string        user   = Formatter.ParseName(Thread.CurrentPrincipal.Identity.Name);
            List <string> groups = GetUsergroups(winIdentity.Groups);


            blackList = Restriction.ReadBlackList();

            if (Restriction.IsRestricted(blackList, decryted, user, groups))
            {
                Console.WriteLine("Korisnik nema dozvolu za otvaranje servisa na datom portu ili sa datim protokolom.");
                string pov = WCFServiceAudit.ReturnFactory().ConnectS(string.Format("{0}|{1}|{2}", user, decryted.Protokol, decryted.Port));
                Console.WriteLine("------------------ OTVARANJE NEUSPESNO ------------------");
                if (pov == "DoS")
                {
                    return(PovratnaVrijednost.DOS);
                }
                return(PovratnaVrijednost.NEMADOZ);;
            }


            if (servisi.ContainsKey(string.Format("{0}", decryted.Port)))
            {
                Console.WriteLine("Servis je vec otvoren na datom portu");
                Console.WriteLine("------------------ OTVARANJE NEUSPESNO ------------------");
                return(PovratnaVrijednost.VECOTV);
            }

            ServiceHost host = new ServiceHost(typeof(WCFService));

            if (decryted.Protokol == "UDP")
            {
                Console.WriteLine("Otvaranje UDP konekcije");
                UdpBinding binding = new UdpBinding();
                string     addr    = String.Format("soap.udp://localhost:{0}/{1}", decryted.Port, decryted.ImeMasine);
                host.AddServiceEndpoint(typeof(IWCFContract), binding, addr);
            }
            else if (decryted.Protokol == "HTTP")
            {
                Console.WriteLine("Otvaranje HTTP konekcije");
                NetHttpBinding binding = new NetHttpBinding();
                string         addr    = String.Format("http://localhost:{0}/{1}", decryted.Port, decryted.ImeMasine);
                host.AddServiceEndpoint(typeof(IWCFContract), binding, addr);
            }
            else
            {
                Console.WriteLine("Otvaranje TCP konekcije");
                NetTcpBinding binding = new NetTcpBinding();
                string        addr    = String.Format("net.tcp://localhost:{0}/{1}", decryted.Port, decryted.ImeMasine);
                host.AddServiceEndpoint(typeof(IWCFContract), binding, addr);
            }

            string key = String.Format("{0}", decryted.Port);

            servisi.Add(key, host);
            servisi[key].Open();
            Console.WriteLine("------------------ OTVARANJE USPESNO ------------------");
            return(PovratnaVrijednost.USPJEH);
        }