Exemple #1
0
        public ActionResult Upload()
        {
            ClearOldFiles();

            if (Request.Form.Files.Any())
            {
                var file = Request.Form.Files[0];

                MemoryStream target = new MemoryStream();
                file.OpenReadStream().CopyTo(target);
                byte[] data = target.ToArray();

                SshKeyFile keyFile = new SshKeyFile()
                {
                    Filename    = file.FileName,
                    ContentType = file.ContentType,
                    CreatedOn   = DateTime.Now,
                    CreatedBy   = CurrentUser
                };

                if (ValidateSshKeyFile(data))
                {
                    db.SshKeyFiles.Add(keyFile);
                    db.SaveChanges();

                    string dataString = Convert.ToBase64String(data);
                    _passwordManager.SetSecret(SecretType.SshKeyFile.ToString() + "_" + keyFile.Id, dataString);
                }
                else
                {
                    return(Json(new { Status = "error", Message = "The file you uploaded was not a valid SSH key file, please upload a different file." }));
                }

                return(Json(new { Status = "ok", SshKeyFileID = keyFile.Id, Filename = keyFile.Filename }));
            }
            else
            {
                return(Json(new { Status = "error", Message = "Error uploading file, please try again" }));
            }
        }
Exemple #2
0
        public SshProxyCredentials(IPasswordManager passwordManager, string username, SshKeyFile sshKeyFile)
        {
            _passwordManager = passwordManager;

            this.Username  = username;
            this.UseSshKey = true;

            this.PrivateKeyFile = null;
            if (sshKeyFile != null)
            {
                var data = _passwordManager.GetSecret(SecretType.SshKeyFile.ToString() + "_" + sshKeyFile.Id);
                if (data != null)
                {
                    this.PrivateKeyFile = new PrivateKeyFile(new MemoryStream(Convert.FromBase64String(data)));
                }
            }
        }