示例#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);
            }
        }
示例#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);
        }
示例#3
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);
        }