Exemple #1
0
        public Functional()
        {
            var appEnv = CallContextServiceLocator.Locator.ServiceProvider.GetService(typeof(IApplicationEnvironment)) as IApplicationEnvironment;
            Debug.Assert(appEnv != null, "appEnv != null");
            var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath);
            builder.AddJsonFile("config.json");
            builder.AddJsonFile("config.private.json", true);
            var configuration = builder.Build();

            var uri = new Uri(configuration["ServerCredentialUri"]);
            var username = configuration["ServerCredentialUsername"];
            var password = configuration["ServerCredentialPassword"];

            _serverCredential = new ServerCredential(uri, username, password);

            _freeMusicTorrentFile =
                new HttpClient().GetByteArrayAsync(
                    new Uri("http://bt.etree.org/download.php/582271/hottuna2015-09-11.flac16.torrent")).Result;
            _freeMusicTorrentHash = "9ecc7229ff971d27552dd399509e188847dbbbf1";

            // Make sure there is no torrents before executing the tests
            var api = new Api(_serverCredential);
            var torrents = api.GetTorrents().Result;
            if (torrents.Any())
            {
                var result = api.Perform(Action.Removedata, torrents.Select(t => t.InfoHash)).Result;
                Assert.True(result);
            }
        }
Exemple #2
0
        /// <summary>
        /// Performs basic initialization of a new instance of the ServerContext class. The ServerContext
        /// is not ready for message manipulation until a security context has been established with a client.
        /// </summary>
        /// <param name="cred"></param>
        /// <param name="requestedAttribs"></param>
        public ServerContext(ServerCredential cred, ContextAttrib requestedAttribs) : base(cred)
        {
            this.requestedAttribs = requestedAttribs;
            this.finalAttribs     = ContextAttrib.Zero;

            this.impersonating = false;

            this.SupportsImpersonate = this.Credential.PackageInfo.Capabilities.HasFlag(SecPkgCapability.Impersonation);
        }
Exemple #3
0
        public IHttpActionResult GetCredential(int id)
        {
            ServerCredential credential = _serverManager.GetServerCredential(id);

            if (credential == null)
            {
                return(NotFound());
            }
            return(Ok(credential));
        }
Exemple #4
0
        public IHttpActionResult UpdateServerCredentials(ServerCredential serverCredential)
        {
            bool status = _serverManager.UpdateServerCredential(serverCredential);

            if (status == false)
            {
                return(NotFound());
            }
            return(Ok(status));
        }
Exemple #5
0
        public bool InsertServerCredential(ServerCredential serverCredential)
        {
            bool status = false;

            db.ServerCredentials.Add(serverCredential);
            if (db.SaveChanges() > 0)
            {
                status = true;
            }
            return(status);
        }
Exemple #6
0
        public bool DeleteServerCredential(int id)
        {
            bool             status           = false;
            ServerCredential serverCredential = db.ServerCredentials.Find(id);

            db.ServerCredentials.Remove(serverCredential);
            if (db.SaveChanges() > 0)
            {
                status = true;
            }
            return(status);
        }
Exemple #7
0
 public static ServerContext GetServerContext(ServerCredential serverCredential)
 {
     return(new ServerContext(
                serverCredential,
                ContextAttrib.AcceptIntegrity |
                ContextAttrib.ReplayDetect |
                ContextAttrib.SequenceDetect |
                ContextAttrib.MutualAuth |
                ContextAttrib.Delegate |
                ContextAttrib.Confidentiality
                ));
 }
Exemple #8
0
        public Functional()
        {
            var builder = new ConfigurationBuilder();
            builder.AddJsonFile("config.json");
            builder.AddJsonFile("config.private.json", true);
            var configuration = builder.Build();

            var uri = new Uri(configuration["ServerCredentialUri"]);
            var username = configuration["ServerCredentialUsername"];
            var password = configuration["ServerCredentialPassword"];

            _serverCredential = new ServerCredential(uri, username, password);
        }
Exemple #9
0
        public bool UpdateServerCredential(ServerCredential serverCredential)
        {
            bool             status            = false;
            ServerCredential serverCredential1 = db.ServerCredentials.Where(x => x.ServerCredentialsId == serverCredential.ServerCredentialsId).AsNoTracking().FirstOrDefault();

            serverCredential.ServerId        = serverCredential1.ServerId;
            db.Entry(serverCredential).State = EntityState.Modified;
            if (db.SaveChanges() > 0)
            {
                status = true;
            }
            return(status);
        }
Exemple #10
0
        public Functional()
        {
            var builder = new ConfigurationBuilder();

            builder.AddJsonFile("config.json");
            builder.AddJsonFile("config.private.json", true);
            var configuration = builder.Build();

            var uri      = new Uri(configuration["ServerCredentialUri"]);
            var username = configuration["ServerCredentialUsername"];
            var password = configuration["ServerCredentialPassword"];

            _serverCredential = new ServerCredential(uri, username, password);
        }
Exemple #11
0
        public async Task <ActionResult> EditCredential(int id)
        {
            ServerCredential    credential = new ServerCredential();
            string              token      = Session["UserToken"].ToString();
            string              address    = "api/Servers/GetCredential?id=" + id.ToString();
            HttpResponseMessage Res        = await Helpers.Get(address, token);

            if (Res.IsSuccessStatusCode)
            {
                var MainMEnuResponse = Res.Content.ReadAsStringAsync().Result;
                credential = JsonConvert.DeserializeObject <ServerCredential>(MainMEnuResponse);
            }
            return(PartialView(credential));
        }
Exemple #12
0
        public ServerForm()
        {
            InitializeComponent();

            this.serverCred = new ServerCredential(PackageNames.Negotiate);

            this.serverContext = new ServerContext(
                serverCred,
                ContextAttrib.AcceptIntegrity |
                ContextAttrib.ReplayDetect |
                ContextAttrib.SequenceDetect |
                ContextAttrib.MutualAuth |
                ContextAttrib.Delegate |
                ContextAttrib.Confidentiality
                );

            this.server               = new CustomServer();
            this.server.Received     += server_Received;
            this.server.Disconnected += server_Disconnected;

            this.FormClosing += Form1_FormClosing;

            this.startButton.Click += startButton_Click;
            this.stopButton.Click  += stopButton_Click;

            this.encryptButton.Click     += encryptButton_Click;
            this.signButton.Click        += signButton_Click;
            this.impersonateButton.Click += impersonateButton_Click;

            this.running      = false;
            this.initializing = false;
            this.connected    = false;

            UpdateButtons();

            this.serverUsernameTextbox.Text = this.serverCred.PrincipleName;
        }
Exemple #13
0
        public async Task <ActionResult> ShareServer(int id)
        {
            string              token            = Session["UserToken"].ToString();
            List <User>         users            = new List <User>();
            ServerConfig        serverConfig     = new ServerConfig();
            ServerCredential    serverCredential = new ServerCredential();
            string              address1         = "api/Servers/GetServerConfig?id=" + id.ToString();
            HttpResponseMessage Res = await Helpers.Get(address1, token);

            if (Res.IsSuccessStatusCode)
            {
                var MainMEnuResponse = Res.Content.ReadAsStringAsync().Result;
                serverConfig = JsonConvert.DeserializeObject <ServerConfig>(MainMEnuResponse);
            }
            if (serverConfig != null)
            {
                var    oid               = serverConfig.OrganisationId;
                string address           = "api/Users/GetAllUsersOfOrganization?id=" + oid.ToString();
                HttpResponseMessage Res1 = await Helpers.Get(address, token);

                if (Res1.IsSuccessStatusCode)
                {
                    var UserResponse = Res1.Content.ReadAsStringAsync().Result;
                    users = JsonConvert.DeserializeObject <List <User> >(UserResponse);
                    var userTemp = users.Select(x => new SelectListItem {
                        Text = x.Email, Value = x.UserId.ToString()
                    }).ToList();
                    if (Session["Role"].ToString() != "ReleaseManager")
                    {
                        userTemp = userTemp.Where(x => x.Value == Session["Organization"].ToString()).ToList();
                    }
                    ViewBag.To = userTemp;
                }
            }
            return(PartialView());
        }
Exemple #14
0
        public bool InsertServerCredential(ServerCredential serverCredential)
        {
            bool status = _serverCredentialDataRepository.InsertServerCredential(serverCredential);

            return(status);
        }
Exemple #15
0
        public bool UpdateServerCredential(ServerCredential serverCredential)
        {
            bool status = _serverCredentialDataRepository.UpdateServerCredential(serverCredential);

            return(status);
        }
Exemple #16
0
        private static void CredTest(string packageName)
        {
            ClientCredential clientCred = null;
            ClientContext    client     = null;

            ServerCredential serverCred = null;
            ServerContext    server     = null;

            byte[] clientToken;
            byte[] serverToken;

            SecurityStatus clientStatus;
            SecurityStatus serverStatus;

            try
            {
                clientCred = new ClientCredential(packageName);
                serverCred = new ServerCredential(packageName);

                Console.Out.WriteLine(clientCred.PrincipleName);

                client = new ClientContext(
                    clientCred,
                    serverCred.PrincipleName,
                    ContextAttrib.MutualAuth |
                    ContextAttrib.InitIdentify |
                    ContextAttrib.Confidentiality |
                    ContextAttrib.ReplayDetect |
                    ContextAttrib.SequenceDetect |
                    ContextAttrib.Connection |
                    ContextAttrib.Delegate
                    );


                server = new ServerContext(
                    serverCred,
                    ContextAttrib.MutualAuth |
                    ContextAttrib.AcceptIdentify |
                    ContextAttrib.Confidentiality |
                    ContextAttrib.ReplayDetect |
                    ContextAttrib.SequenceDetect |
                    ContextAttrib.Connection |
                    ContextAttrib.Delegate
                    );

                clientToken = null;
                serverToken = null;

                clientStatus = client.Init(serverToken, out clientToken);

                while (true)
                {
                    serverStatus = server.AcceptToken(clientToken, out serverToken);

                    if (serverStatus != SecurityStatus.ContinueNeeded && clientStatus != SecurityStatus.ContinueNeeded)
                    {
                        break;
                    }

                    clientStatus = client.Init(serverToken, out clientToken);

                    if (serverStatus != SecurityStatus.ContinueNeeded && clientStatus != SecurityStatus.ContinueNeeded)
                    {
                        break;
                    }
                }


                Console.Out.WriteLine("Server authority: " + server.AuthorityName);
                Console.Out.WriteLine("Server context user: "******"Client authority: " + client.AuthorityName);
                Console.Out.WriteLine("Client context user: "******"Hello, world. This is a long message that will be encrypted";
                string rtMessage;

                byte[] plainText = new byte[Encoding.UTF8.GetByteCount(message)];
                byte[] cipherText;
                byte[] roundTripPlaintext;

                Encoding.UTF8.GetBytes(message, 0, message.Length, plainText, 0);

                cipherText = client.Encrypt(plainText);

                roundTripPlaintext = server.Decrypt(cipherText);

                if (roundTripPlaintext.Length != plainText.Length)
                {
                    throw new Exception();
                }

                for (int i = 0; i < plainText.Length; i++)
                {
                    if (plainText[i] != roundTripPlaintext[i])
                    {
                        throw new Exception();
                    }
                }

                rtMessage = Encoding.UTF8.GetString(roundTripPlaintext, 0, roundTripPlaintext.Length);

                if (rtMessage.Equals(message) == false)
                {
                    throw new Exception();
                }


                using (server.ImpersonateClient())
                {
                }

                cipherText = client.MakeSignature(plainText);

                bool goodSig = server.VerifySignature(cipherText, out roundTripPlaintext);

                if (goodSig == false ||
                    roundTripPlaintext.Length != plainText.Length)
                {
                    throw new Exception();
                }

                for (int i = 0; i < plainText.Length; i++)
                {
                    if (plainText[i] != roundTripPlaintext[i])
                    {
                        throw new Exception();
                    }
                }

                Console.Out.Flush();
            }
            finally
            {
                if (server != null)
                {
                    server.Dispose();
                }

                if (client != null)
                {
                    client.Dispose();
                }

                if (clientCred != null)
                {
                    clientCred.Dispose();
                }

                if (serverCred != null)
                {
                    serverCred.Dispose();
                }
            }
        }
Exemple #17
0
        public ServerCredential GetServerCredential(int id)
        {
            ServerCredential serverCredential = _serverCredentialDataRepository.GetServerCredential(id);

            return(serverCredential);
        }