Esempio n. 1
0
        }         // proc OnEndReadConfiguration

        public override bool Request(IDEContext r)
        {
            // create the full file name
            var fileName = Path.GetFullPath(Path.Combine(directoryBase, ProcsDE.GetLocalPath(r.RelativeSubPath)));

            // Check for a directory escape
            if (!fileName.StartsWith(directoryBase, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            // is the filename a directory, add index.html
            if (Directory.Exists(fileName))
            {
                fileName = Path.Combine(fileName, "Index.html");
            }

            if (File.Exists(fileName))
            {
                // security
                DemandFile(r, fileName);
                // Send the file
                r.WriteFile(fileName, GetFileContentType(fileName));
                return(true);
            }
            else
            {
                return(false);
            }
        }         // func Request
Esempio n. 2
0
 public void CertificateSelect01()
 {
     foreach (var c in ProcsDE.FindCertificate("store://currentuser/my/CN=OFTP2Test"))
     {
         Console.WriteLine(c.Subject);
     }
 }
Esempio n. 3
0
        }         // proc RefreshSecurityTokens

        private bool TestPassword(string testPassword)
        {
            var password = ConfigNode.GetAttribute <SecureString>("password");

            if (password != null)
            {
                return(password.Compare(testPassword));
            }
            else
            {
                var passwordHash = Config.GetAttribute("passwordHash", null);
                if (passwordHash == "*")
                {
                    return(true);                    // allow all passwords
                }
                try
                {
                    var tmp = ProcsDE.PasswordCompare(testPassword, passwordHash);
                    if (!tmp)
                    {
                        Log.LogMsg(LogMsgType.Warning, String.Format("Autentification failed ({0}).", "Password"));
                    }
                    return(tmp);
                }
                catch (Exception e)
                {
                    Log.LogMsg(LogMsgType.Error, "Autentification failed ({0}).", e.Message);
                    return(false);
                }
            }
        }         // func TestPassword
Esempio n. 4
0
File: User.cs Progetto: s72785/des
        }         // proc RefreshSecurityTokens

        private bool TestPassword(string testPassword)
        {
            var password = Config.GetAttribute("password", null);

            if (password != null)
            {
                return(password == testPassword);
            }
            else
            {
                try
                {
                    var l = ProcsDE.PasswordCompare(testPassword, Config.GetAttribute("passwordHash", null));
                    if (!l)
                    {
                        Log.LogMsg(LogMsgType.Warning, String.Format("Autentification failed ({0}).", "Password"));
                    }
                    return(l);
                }
                catch (Exception e)
                {
                    Log.LogMsg(LogMsgType.Error, "Autentification failed ({0}).", e.Message);
                    return(false);
                }
            }
        }         // func TestPassword
Esempio n. 5
0
        IOdetteFileService IOdetteFileServiceFactory.CreateFileService(string destinationId, string password)
        {
            if (destinationId == this.destinationId)             // case sensitive
            {
                // check the password
                var passwordHash = Config.GetAttribute("passwordHash", null);
                if (passwordHash == null)
                {
                    if (!String.IsNullOrEmpty(password))
                    {
                        Log.Warn("Password is empty, but a password is transmitted.");
                    }
                }
                else if (!ProcsDE.PasswordCompare(password, passwordHash))
                {
                    Log.Warn("Wrong password for asked destination.");
                    return(null);
                }

                return(new FileServiceSession(this, GetSessionId()));
            }
            else
            {
                return(null);
            }
        }         // func CreateFileService
Esempio n. 6
0
        private bool ChangeConfigurationValue(ParseContext context, XObject x, string currentValue, out string newValue)
        {
            var valueModified = ChangeConfigurationStringValue(context, currentValue, out newValue);

            // first check for type converter
            var attributeDefinition = GetAttribute(x);

            if (attributeDefinition != null)
            {
                if (attributeDefinition.TypeName == "PathType")
                {
                    newValue = ProcsDE.GetFileName(x, newValue);

                    valueModified |= true;
                }
                else if (attributeDefinition.TypeName == "PathArray")
                {
                    newValue = Procs.JoinPaths(Procs.SplitPaths(newValue).Select(c => ProcsDE.GetFileName(x, c)));

                    valueModified |= true;
                }
                else if (attributeDefinition.TypeName == "CertificateType")
                {
                    if (String.IsNullOrEmpty(newValue) || !newValue.StartsWith("store://"))
                    {
                        newValue       = ProcsDE.GetFileName(x, newValue);
                        valueModified |= true;
                    }
                }
            }

            return(valueModified);
        }         // func ChangeConfigurationValue
Esempio n. 7
0
        public void ReplaceEnv()
        {
            var expected = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"..\test.txt");
            var actual   = ProcsDE.GetEnvironmentPath(@"%executedirectory%\..\test.txt");

            Assert.AreEqual(expected, actual);
        }
Esempio n. 8
0
        public void CertFind03()
        {
            var certs = ProcsDE.FindCertificate("store://cu/root/thumbprint:75e0abb6138512271c04f85fddde38e4b7242efe").ToArray();

            //X509KeyUsageExtension a;
            //a.KeyUsages = X509KeyUsageFlags.
            Assert.IsTrue(certs.Count() == 1);
        }
Esempio n. 9
0
File: Stuff.cs Progetto: s72785/des
 public void XmlRemoveInvalidChars()
 {
     Assert.AreEqual(ProcsDE.RemoveInvalidXmlChars(null), null);
     Assert.AreEqual(ProcsDE.RemoveInvalidXmlChars(String.Empty), String.Empty);
     Assert.AreEqual(ProcsDE.RemoveInvalidXmlChars("String.Empty"), "String.Empty");
     Assert.AreEqual(XmlConvert.VerifyXmlChars(ProcsDE.RemoveInvalidXmlChars("String\x1A.Empty")), "String.Empty");
     Assert.AreEqual(XmlConvert.VerifyXmlChars(ProcsDE.RemoveInvalidXmlChars("\x001AEmp\x001Aty\x001A")), "Empty");
     Assert.AreEqual(XmlConvert.VerifyXmlChars(ProcsDE.RemoveInvalidXmlChars("String\x001AEmp\x10000ty")), "StringEmp\x10000ty");
 }
Esempio n. 10
0
        }         // proc WriteElementProperty

        public void WriteAttributeProperty(string propertyName, object _value)
        {
            var value = _value.ChangeType <string>();

            if (value != null)
            {
                xml.WriteAttributeString(propertyName, ProcsDE.RemoveInvalidXmlChars(value, '?'));
            }
        } // proc WriteAttributeProperty
Esempio n. 11
0
        }         // proc OnEndReadConfiguration

        private bool TestFilter(XElement x, string subPath)
        {
            var value = x.GetAttribute <string>("filter", null);

            if (value == null || value.Length == 0 || value == "*")
            {
                return(true);
            }
            else
            {
                return(ProcsDE.IsFilterEqual(subPath, value));
            }
        }         // func TestFilter
Esempio n. 12
0
            }             // proc PopFrame

            #endregion

            #region -- LoadFile -------------------------------------------------------------

            /// <summary></summary>
            /// <param name="source"></param>
            /// <param name="fileName"></param>
            /// <returns></returns>
            public XDocument LoadFile(XObject source, string fileName)
            {
                try
                {
                    // resolve macros
                    ChangeConfigurationStringValue(this, fileName, out fileName);
                    // load the file name
                    return(LoadFile(ProcsDE.GetFileName(source, fileName)));
                }
                catch (Exception e)
                {
                    throw CreateConfigException(source, String.Format("Could not load reference '{0}'.", fileName), e);
                }
            }             // func LoadFile
Esempio n. 13
0
        }         // proc Dispose

        #endregion

        #region -- TryGetState --------------------------------------------------------

        private DateTime GetCurrentCertifcateNotAfter(string commonName)
        {
            var cert = ProcsDE.FindCertificate("store://lm/my/CN=" + commonName)
                       .OrderByDescending(c => c.NotAfter)
                       .FirstOrDefault();

            if (cert == null)
            {
                return(DateTime.MinValue);
            }

            certificateThumbprint.Value = cert.Thumbprint;
            certificateNotAfter.Value   = cert.NotAfter;

            return(cert.NotAfter);
        }         // func GetCurrentCertifcateNotAfter
Esempio n. 14
0
        }         // proc ICronJobExecute.RunJob

        bool ICronJobExecute.CanRunParallelTo(ICronJobExecute other)
        {
            if (other == this)             // do not run parallel the same job
            {
                return(false);
            }

            if (runAfterJob == null)
            {
                return(true);
            }
            else
            {
                var o = other as ICronJobItem;
                return(o == null || runAfterJob.FirstOrDefault(c => ProcsDE.IsFilterEqual(o.UniqueName, c)) == null || CanRunParallelTo(o));
            }
        }         // func ICronJobExecute.CanRunParallelTo
Esempio n. 15
0
        }         // proc WriteStartProperty

        public void WriteValue(object _value)
        {
            var value = _value.ChangeType <string>();

            if (value == null)
            {
                return;
            }

            if (value.IndexOfAny(isCDateEmitChar) >= 0)             // check for specials
            {
                xml.WriteCData(ProcsDE.RemoveInvalidXmlChars(value, '?'));
            }
            else
            {
                xml.WriteValue(ProcsDE.RemoveInvalidXmlChars(value, '?'));
            }
        }         // proc WriteValue
Esempio n. 16
0
            }             // proc Dispose

            public override bool Equals(IIdentity other)
            {
                if (other is HttpListenerBasicIdentity basicIdentity)
                {
                    if (String.Compare(userName, other.Name, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        return(false);
                    }
                    return(ProcsDE.PasswordCompare(basicIdentity.Password, passwordHash));
                }
                else if (other is PpsBasicIdentity checkSql)
                {
                    if (String.Compare(userName, checkSql.Name, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        return(false);
                    }
                    return(Procs.CompareBytes(passwordHash, checkSql.passwordHash));
                }
                else
                {
                    return(false);
                }
            }             // func Equals
Esempio n. 17
0
        }         // proc Dispose

        protected override void OnBeginReadConfiguration(IDEConfigLoading config)
        {
            base.OnBeginReadConfiguration(config);

            // is there the tcp listener
            serverTcp = this.GetService <IServerTcp>(true);

            var useSsl = config.ConfigNew.GetAttribute("ssl", String.Empty);

            if (String.IsNullOrEmpty(useSsl))
            {
                serverCertificate = null;
            }
            else
            {
                Log.Info("Try to locate certificate: {0}", useSsl);
                serverCertificate = (from crt in ProcsDE.FindCertificate(useSsl) orderby crt.NotAfter descending select crt).FirstOrDefault();
                if (serverCertificate == null)
                {
                    throw new ArgumentException("Server certificate not found.");
                }
                Log.Info("Locate certificate: {0} {1}", serverCertificate.Thumbprint, serverCertificate.Subject);
            }
        }         // proc OnBeginReadConfiguration
Esempio n. 18
0
        }         // class PpsReportSession

        #endregion

        private void BeginReadConfigurationReport(IDEConfigLoading config)
        {
            var currentNode = XConfigNode.Create(Server.Configuration, config.ConfigNew).Element(PpsStuff.xnReports);

            var systemPath = currentNode.GetAttribute <string>("system") ?? throw new DEConfigurationException(currentNode.Data, "@system is empty.");
            var basePath   = currentNode.GetAttribute <string>("base") ?? throw new DEConfigurationException(currentNode.Data, "@base is empty.");
            var logPath    = currentNode.GetAttribute <string>("logs");
            var workPath   = currentNode.GetAttribute <string>("work");

            // check for recreate the reporting engine
            if (reporting == null ||
                !ProcsDE.IsPathEqual(reporting.EnginePath, systemPath) ||
                !ProcsDE.IsPathEqual(reporting.BasePath, basePath) ||
                (logPath != null && !ProcsDE.IsPathEqual(reporting.LogPath, logPath)) ||
                (workPath != null && !ProcsDE.IsPathEqual(reporting.WorkingPath, workPath)))
            {
                reporting = new PpsReportEngine(systemPath, basePath, reportProvider, CreateReportSession, reportWorkingPath: workPath, reportLogPath: logPath);
            }

            // update values
            reporting.CleanBaseDirectoryAfter = currentNode.GetAttribute <int>("cleanBaseDirectory");
            reporting.ZipLogFiles             = currentNode.GetAttribute <bool>("zipLogFiles");
            reporting.StoreSuccessLogs        = currentNode.GetAttribute <bool>("storeSuccessLogs");
        }         // proc BeginReadConfigurationReport
Esempio n. 19
0
        }         // proc OnBeginReadConfiguration

        public override bool Request(IDEContext r)
        {
            if (assembly == null || namespaceRoot == null)
            {
                return(false);
            }

            // create the resource name
            var resourceName = namespaceRoot + r.RelativeSubPath.Replace('/', '.');

            var src = (Stream)null;

            try
            {
                DateTime stamp;
                // try to open the resource stream
                var forceAlternativeCheck = nonePresentAlternativeExtensions != null && nonePresentAlternativeExtensions.FirstOrDefault(c => resourceName.EndsWith(c, StringComparison.OrdinalIgnoreCase)) != null;
                src = assembly.GetManifestResourceStream(resourceName);
                if (src == null && !forceAlternativeCheck)                 // nothing...
                {
                    return(false);
                }

                // check if there is a newer file
                if (alternativeRoots != null)
                {
                    var relativeFileName = ProcsDE.GetLocalPath(r.RelativeSubPath);
                    var alternativeFile  = (from c in alternativeRoots
                                            let fi = new FileInfo(Path.Combine(c, relativeFileName))
                                                     where fi.Exists && (forceAlternativeCheck || fi.LastWriteTimeUtc > assemblyStamp)
                                                     orderby fi.LastWriteTimeUtc descending
                                                     select fi).FirstOrDefault();

                    if (alternativeFile != null)
                    {
                        src?.Close();
                        src   = alternativeFile.OpenRead();
                        stamp = alternativeFile.LastWriteTimeUtc;
                    }
                    else
                    {
                        stamp = assemblyStamp;
                        if (forceAlternativeCheck && src == null)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    stamp = assemblyStamp;
                    if (forceAlternativeCheck && src == null)
                    {
                        return(false);
                    }
                }

                // security
                DemandFile(r, resourceName);
                // send the file
                r.SetLastModified(stamp)
                .WriteStream(src, GetFileContentType(resourceName) ?? r.Server.GetContentType(Path.GetExtension(resourceName)));
                return(true);
            }
            finally
            {
                Procs.FreeAndNil(ref src);
            }
        }         // func Request
Esempio n. 20
0
        public IEnumerable <FileInfo> ListFiles(string relativePath = null)
        {
            var directory = new DirectoryInfo(Path.GetFullPath(Path.Combine(directoryBase.FullName, ProcsDE.GetLocalPath(relativePath))));

            if (directory.Exists)
            {
                return(directory.EnumerateFiles(filterPattern, SearchOption.TopDirectoryOnly));
            }
            else
            {
                return(Array.Empty <FileInfo>());
            }
        }         // func ListFiles
Esempio n. 21
0
        public void CertFind02()
        {
            var certs = ProcsDE.FindCertificate("store://cu/root/subject:CN=GlobalSign").ToArray();

            Assert.IsTrue(certs.Count() != 0);
        }
Esempio n. 22
0
        /// <summary></summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public override async Task <bool> RequestAsync(IDEWebRequestScope r)
        {
            if (String.IsNullOrEmpty(filterPattern))
            {
                return(false);
            }

            // create the full file name
            var useIndex            = false;
            var fullDirectoryName   = this.directoryBase.FullName;
            var fileName            = Path.GetFullPath(Path.Combine(fullDirectoryName, ProcsDE.GetLocalPath(r.RelativeSubPath)));
            var directoryBaseOffset = fullDirectoryName[fullDirectoryName.Length - 1] == Path.DirectorySeparatorChar ? fullDirectoryName.Length - 1 : fullDirectoryName.Length;

            // Check for a directory escape
            if (!fileName.StartsWith(directoryBase.FullName, StringComparison.OrdinalIgnoreCase) ||
                (fileName.Length > directoryBaseOffset && fileName[directoryBaseOffset] != Path.DirectorySeparatorChar))
            {
                return(false);
            }

            // is the filename a directory, add index.html
            if (Directory.Exists(fileName))
            {
                if (!String.IsNullOrEmpty(r.AbsolutePath) && r.AbsolutePath[r.AbsolutePath.Length - 1] != '/')
                {
                    r.Redirect(r.AbsolutePath + '/');
                    return(true);
                }
                else
                {
                    fileName = Path.Combine(fileName, ConfigNode.GetAttribute <string>("indexPage"));
                    useIndex = true;
                }
            }
            else if (filterPattern != "*")             // check for filter pattern
            {
                if (!Procs.IsFilterEqual(Path.GetFileName(fileName), filterPattern))
                {
                    return(false);                    // pattern does not fit
                }
            }

            if (File.Exists(fileName))
            {
                // security
                DemandFile(r, fileName);
                // Send the file
                await Task.Run(() => r.WriteFile(fileName, GetFileContentType(fileName), defaultReadEncoding));

                return(true);
            }
            else if (useIndex && allowListing)             // write index table
            {
                await Task.Run(() => r.WriteResource(typeof(HttpWorker), "Resources.Listing.html", "text/html"));

                return(true);
            }
            else
            {
                return(false);
            }
        }         // func Request