コード例 #1
0
 internal LoadLinker(IReferenceLoader referenceLoader, List <List <Type> > referenceTypesToBeLoadedForEachLoadingLevel, LoadLinkProtocol loadLinkProtocol)
 {
     _referenceLoader = referenceLoader;
     _referenceTypesToBeLoadedForEachLoadingLevel = referenceTypesToBeLoadedForEachLoadingLevel;
     _loadLinkProtocol = loadLinkProtocol;
     _linker           = new Linker(_loadLinkProtocol, _dataStore);
 }
コード例 #2
0
        public CollectibleAssemblyLoadContext Get(string moduleName, IServiceCollection services, ApplicationPartManager apm, IServiceScope scope, InBizModuleEnum inBizModuleEnum = InBizModuleEnum.Boot)
        {
            string folderName = inBizModuleEnum == InBizModuleEnum.Boot ? "boot" : "hot";
            CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);
            IReferenceLoader  loader              = scope.ServiceProvider.GetService <IReferenceLoader>();
            InBizModuleLoader inBizModuleLoader   = scope.ServiceProvider.GetService <InBizModuleLoader>();
            string            filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", folderName, moduleName, $"{moduleName}.dll");
            string            viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", folderName, moduleName, $"{moduleName}.Views.dll");
            string            referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", folderName, moduleName);

            if (File.Exists(filePath))
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {
                    Assembly assembly = context.LoadFromStream(fs);
                    context.SetEntryPoint(assembly);
                    loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);
                    AssemblyPart controllerAssemblyPart = new AssemblyPart(assembly);
                    apm.ApplicationParts.Add(controllerAssemblyPart);
                    //services.AddAssembly(assembly);
                    foreach (var type in assembly.GetTypes())
                    {
                        if (AbpModule.IsAbpModule(type))
                        {
                            inBizModuleLoader.LoadModules(services, type, new PlugInSourceList());
                            inBizModuleLoader.ConfigureServices(services);
                            inBizModuleLoader.InitializeModules(new Volo.Abp.ApplicationInitializationContext(scope.ServiceProvider));
                        }
                    }
                    var resources = assembly.GetManifestResourceNames();
                    if (resources.Any())
                    {
                        foreach (var item in resources)
                        {
                            var stream = new MemoryStream();
                            var source = assembly.GetManifestResourceStream(item);
                            source.CopyTo(stream);
                            context.RegisterResource(item, stream.ToArray());
                        }
                    }
                }
            }
            else
            {
                return(null);
            }
            if (File.Exists(viewFilePath))
            {
                using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
                {
                    Assembly vwAssembly = context.LoadFromStream(fsView);
                    loader.LoadStreamsIntoContext(context, referenceFolderPath, vwAssembly);

                    InBizRazorAssemblyPart moduleView = new InBizRazorAssemblyPart(vwAssembly, moduleName);
                    apm.ApplicationParts.Add(moduleView);
                }
            }
            context.Enable();
            return(context);
        }
コード例 #3
0
ファイル: Reference.cs プロジェクト: kurtrips/tc
 /// <summary>
 /// This constructor should be used when signing SOAP messages.
 /// Create a new Reference instance with the input parameters initilaized to member variables.
 /// </summary>
 /// <param name="referenceURI">uri for the reference</param>
 /// <param name="transformerInstanceDefinitions">
 /// a ordered list of keys that identify transformers to use</param>
 /// <param name="digesterInstanceDefinition">
 /// a single digester instance definition used to fetch/create a corresponding digester</param>
 /// <param name="soapRefLoader">The SOAPMessageReferenceLoader to use for loading the data of soapMessage
 /// </param>
 public Reference(string referenceURI, IList <InstantiationVO> transformerInstanceDefinitions,
                  InstantiationVO digesterInstanceDefinition, IReferenceLoader soapRefLoader) : this(referenceURI,
                                                                                                     transformerInstanceDefinitions, digesterInstanceDefinition, "soap")
 {
     ExceptionHelper.ValidateNotNull(soapRefLoader, "soapRefLoader");
     this.soapRefLoader = soapRefLoader;
 }
コード例 #4
0
 public MvcModuleSetup(ApplicationPartManager partManager, ServiceConfigurationContext serviceContext, IReferenceLoader referenceLoader, IHttpContextAccessor httpContextAccessor)
 {
     _partManager     = partManager;
     _referenceLoader = referenceLoader;
     _context         = httpContextAccessor;
     _serviceContext  = serviceContext;
 }
コード例 #5
0
ファイル: ProcessRegistry.cs プロジェクト: kurtrips/tc
        /// <summary>
        /// <p>Creates and returns a new IReferenceLoader instance based on the input key. The input key is treated
        /// almso like a type which is usually gotten from the protocol that is used to load up the reference.</p>
        /// </summary>
        /// <exception cref="ProcessRegistryException">if the requested instance cannot be cast to IReferenceLoader
        /// or the parameters cannot be set due to reflection issues
        /// </exception>
        /// <exception cref="ArgumentNullException">If key or parameters is null</exception>
        /// <exception cref="ArgumentException">If key is empty string</exception>
        /// <param name="key">reference loader key (protocol type)</param>
        /// <param name="parameters">parameters</param>
        /// <returns>instance of IreferenceLoader as identified by the key or null if key does not exist in map</returns>
        public IReferenceLoader GetReferenceLoaderInstance(string key, IDictionary <string, object> parameters)
        {
            //Validate key and parameters
            ExceptionHelper.ValidateStringNotNullNotEmpty(key, "key");
            ExceptionHelper.ValidateNotNull(parameters, "parameters");

            //If key does not exist, return null
            if (!registeredDefinitionsMap.ContainsKey(key))
            {
                return(null);
            }

            try
            {
                //Get type of class to load, from RegisteredDefinitionsMap
                Type typeOfClass = GetTypeOfClass(key);

                //Create instance of class by reflection
                IReferenceLoader ret = (IReferenceLoader)Activator.CreateInstance(typeOfClass);

                //Set properties of the instance created
                SetPropertiesOfInstance(ret, parameters, typeOfClass);

                return(ret);
            }
            catch (Exception ex)
            {
                throw new ProcessRegistryException("Reference Loader" + UNABLE_CRT_INST_MSG, ex);
            }
        }
コード例 #6
0
ファイル: NameTagger.cs プロジェクト: rferg/HmmParser
 internal NameTagger(IReferenceLoader referenceLoader)
 {
     Prefixes        = referenceLoader.GetPrefixes();
     GivenNames      = referenceLoader.GetGivenNames();
     Surnames        = referenceLoader.GetSurnames();
     Suffixes        = referenceLoader.GetSuffixes();
     SurnamePrefixes = referenceLoader.GetSurnamePrefixes();
 }
コード例 #7
0
ファイル: LoadLinker.cs プロジェクト: fynnen/LinkIt
 internal LoadLinker(Func <IReferenceLoader> getReferenceLoader, IReadOnlyList <IReadOnlyList <Type> > referenceTypesToBeLoadedForEachLoadingLevel, LoadLinkProtocol loadLinkProtocol, LoadLinkDetails <TRootLinkedSource, TRootLinkedSourceModel> loadLinkDetails)
 {
     _referenceLoader = getReferenceLoader();
     _referenceTypesToBeLoadedForEachLoadingLevel = referenceTypesToBeLoadedForEachLoadingLevel;
     _loadLinkProtocol = loadLinkProtocol;
     _loadLinkDetails  = loadLinkDetails;
     _linker           = new Linker(_loadLinkProtocol, _dataStore);
 }
コード例 #8
0
        public void TestGetReferenceLoaderInstance()
        {
            IReferenceLoader refLoader = pr.GetReferenceLoaderInstance("http", emptyDic);

            Assert.IsNotNull(refLoader, "ReferenceLoader instance is null");
            Assert.IsTrue(refLoader is ReferenceLoaders.WebBasedReferenceLoader,
                          "ReferenceLoader has incorect type");
        }
コード例 #9
0
ファイル: AddressTagger.cs プロジェクト: rferg/HmmParser
 internal AddressTagger(IReferenceLoader referenceLoader)
 {
     StreetTypes       = referenceLoader.GetStreetTypes();
     UnitTypes         = referenceLoader.GetUnitTypes();
     Boxes             = referenceLoader.GetBoxes();
     States            = referenceLoader.GetUSStates();
     CityIndicators    = referenceLoader.GetCityIndicators();
     Directions        = referenceLoader.GetDirections();
     CommonStreetNames = referenceLoader.GetCommonStreetNames();
 }
コード例 #10
0
ファイル: CoolCatStartup.cs プロジェクト: nov14/CoolCat
        public static void CoolCatSetup(this IServiceCollection services, IConfiguration configuration)
        {
            _serviceCollection = services;

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IDbHelper, DbHelper>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <ISystemManager, SystemManager>();
            services.AddScoped <IUnitOfWork, Repository.MySql.UnitOfWork>();
            services.AddSingleton <INotificationRegister, NotificationRegister>();
            services.AddSingleton <IActionDescriptorChangeProvider>(CoolCatActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();

            var documentation = new CoolCatModuleDocumentation();

            services.AddSingleton <IQueryDocumentation>(documentation);
            services.AddSingleton(CoolCatActionDescriptorChangeProvider.Instance);

            IMvcBuilder mvcBuilder = services.AddMvc();

            ServiceProvider provider = services.BuildServiceProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                IUnitOfWork unitOfWork = scope.ServiceProvider.GetService <IUnitOfWork>();
                var         dataStore  = new DefaultDataStore(scope.ServiceProvider.GetService <ILogger <DefaultDataStore> >());
                services.AddSingleton <IDataStore>(dataStore);
                var contextProvider = new CollectibleAssemblyLoadContextProvider();

                if (unitOfWork.CheckDatabase())
                {
                    List <ViewModels.PluginListItemViewModel> allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                    IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

                    foreach (ViewModels.PluginListItemViewModel plugin in allEnabledPlugins)
                    {
                        var context = contextProvider.Get(plugin.Name, mvcBuilder, scope, dataStore, documentation);
                        PluginsLoadContexts.Add(plugin.Name, context);
                    }
                }
            }

            AssemblyLoadContextResoving();

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            services.Replace <IViewCompilerProvider, CoolCatViewCompilerProvider>();
        }
コード例 #11
0
 public SuggestionsService(
     IActivityService activityService,
     IUserRepository userRepository,
     ITimeReportRepository timeReportRepository,
     IReferenceLoader referenceLoader
     )
 {
     this.activityService      = activityService;
     this.userRepository       = userRepository;
     this.timeReportRepository = timeReportRepository;
     this.referenceLoader      = referenceLoader;
 }
コード例 #12
0
        public CollectibleAssemblyLoadContext Get(string moduleName, IMvcBuilder mvcBuilder, IServiceScope scope, IDataStore dataStore, IQueryDocumentation documentation)
        {
            CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);
            IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

            string filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.dll");
            string viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.Views.dll");
            string referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName);

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                Assembly assembly = context.LoadFromStream(fs);

                context.SetEntryPoint(assembly);

                loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                AssemblyPart controllerAssemblyPart = new AssemblyPart(assembly);
                mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);


                var resources = assembly.GetManifestResourceNames();

                if (resources.Any())
                {
                    foreach (var item in resources)
                    {
                        var stream = new MemoryStream();
                        var source = assembly.GetManifestResourceStream(item);
                        source.CopyTo(stream);

                        context.RegisterResource(item, stream.ToArray());
                    }
                }

                BuildNotificationProvider(assembly, scope);
                RegisterModuleQueries(dataStore, moduleName, assembly, scope, documentation);
            }

            using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
            {
                Assembly viewAssembly = context.LoadFromStream(fsView);
                loader.LoadStreamsIntoContext(context, referenceFolderPath, viewAssembly);

                CoolCatRazorAssemblyPart moduleView = new CoolCatRazorAssemblyPart(viewAssembly, moduleName);
                mvcBuilder.PartManager.ApplicationParts.Add(moduleView);
            }

            context.Enable();

            return(context);
        }
コード例 #13
0
ファイル: SignatureManager.cs プロジェクト: kurtrips/tc
        /// <summary>
        /// <p>Process the Signature node and verify the digital signatire of the contents.</p>
        /// </summary>
        /// <exception cref="VerificationException">if something went wrong during verification</exception>
        /// <exception cref="VerificationFailedException">if the signature is invalid</exception>
        /// <exception cref="ArgumentNullException">If any input parameter is null</exception>
        /// <param name="node">xml node with digital signature to be verified</param>
        /// <param name="keyInfoProvider">The key information for verifying the signature</param>
        /// <param name="soapRefLoader">SoapMessageRefernceLoader instance if the Signature was used on a
        /// SoapMessage. Should not be null incase of verification of soapMessage.
        /// Can be null if verification is of a web reference.
        /// </param>
        ///
        /// <example>
        /// <para>If Signature node to be verified contains all non soap references
        /// <code>
        /// SignatureManager sm = new SignatureManager();
        /// sm.VerifySignature(node, keyInfoProvider, null);
        /// </code>
        /// </para>
        /// <para>If Signature node to be verified contains soap references
        /// <code>
        /// SignatureManager sm = new SignatureManager();
        /// SoapMessageReferenceLoader smrl = new SoapMessageRefernceLoader(theSoapMessage);
        /// sm.VerifySignature(node, keyInfoProvider, smrl);
        /// </code>
        /// Here theSoapMessage is the soap message that was signed.
        /// </para>
        /// For more information see the demo in CS and in test cases.
        /// </example>
        public void VerifySignature(XmlNode node, InstantiationVO keyInfoProvider, IReferenceLoader soapRefLoader)
        {
            //Validate not null
            ExceptionHelper.ValidateNotNull(node, "node");
            ExceptionHelper.ValidateNotNull(keyInfoProvider, "keyInfoProvider");

            try
            {
                // we use namespace manager since <Signature> has default namespace
                XmlNamespaceManager nsMgr = new XmlNamespaceManager(node.OwnerDocument.NameTable);
                nsMgr.AddNamespace("ds", DEF_XMLDSIG_NS);

                //Get SignedInfo node
                XmlNode signedInfoNode = node.SelectSingleNode("ds:SignedInfo", nsMgr);

                //Get CanonicalizationNode
                XmlNode canonNode   = signedInfoNode.SelectSingleNode("ds:CanonicalizationMethod", nsMgr);
                string  canonMethod = canonNode.Attributes.GetNamedItem("Algorithm").Value;
                //Get Canonicalization instance
                ICanonicalizer canonInst     = registry.GetCanonicalizerInstance(canonMethod, emptyDic);
                string         canonicalized = canonInst.BringToCanonicalForm(signedInfoNode.OuterXml);

                //Get Signing Algo
                XmlNode signAlgoNode = node.SelectSingleNode("ds:SignedInfo/ds:SignatureMethod", nsMgr);
                string  signingAlgo  = signAlgoNode.Attributes.GetNamedItem("Algorithm").Value;

                //Get Signer instance using the Signature mEthos Algorithm attribute value
                ISigner signer = registry.GetSignerInstance(signingAlgo, emptyDic);

                //Get keyInfoProvider instance
                IKeyInfoProvider keyInfoProviderInst = registry.GetKeyInfoProviderInstance(keyInfoProvider.Key,
                                                                                           keyInfoProvider.Params);

                //Verify the sign
                signer.Verify(canonicalized, keyInfoProviderInst, node);

                //Now proceed to check all references
                XmlNodeList list = node.SelectNodes("ds:SignedInfo/ds:Reference", nsMgr);
                VerifyReferences(list, soapRefLoader);
            }
            catch (VerificationFailedException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new VerificationException(VERIF_EXCP_MSG, ex);
            }
        }
コード例 #14
0
 public MvcModuleSetup(ApplicationPartManager partManager, IReferenceLoader referenceLoader,
                       IPluginsAssemblyLoadContexts pluginsLoadContexts, DynamicChangeTokenProvider dynamicChangeTokenProvider,
                       INotificationRegister notificationRegister, IOptions <PluginOptions> options, IWebHostEnvironment webHostEnvironment, IRazorViewEngine razorViewEngine, IViewCompilerProvider viewCompiler)
 {
     _partManager                = partManager;
     _referenceLoader            = referenceLoader;
     _pluginsLoadContexts        = pluginsLoadContexts;
     _dynamicChangeTokenProvider = dynamicChangeTokenProvider;
     _notificationRegister       = notificationRegister;
     _pluginOptions              = options.Value;
     _env = webHostEnvironment;
     //_baseDirectory = AppContext.BaseDirectory;
     _baseDirectory   = _env.ContentRootPath;
     _razorViewEngine = razorViewEngine;
     _viewCompiler    = viewCompiler;
 }
コード例 #15
0
 public TimeReportService(
     IUnitOfWork unitOfWork,
     ITimeReportRepository timeReportRepository,
     IActivityRepository activityRepository,
     IUserRepository userRepository,
     IActivityTypeRepository activityTypeRepository,
     IReferenceLoader referenceLoader)
 {
     this.unitOfWork             = unitOfWork;
     this.timeReportRepository   = timeReportRepository;
     this.activityRepository     = activityRepository;
     this.userRepository         = userRepository;
     this.activityTypeRepository = activityTypeRepository;
     this.referenceLoader        = referenceLoader;
     userId = UserIdIsUnknownValue;
 }
コード例 #16
0
        public CollectibleAssemblyLoadContext Get(string moduleName, ApplicationPartManager apm, IServiceScope scope, IDataStore dataStore, IQueryDocumentation documentation)
        {
            CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);
            IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

            string filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.dll");
            string viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.Views.dll");
            string referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName);

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                Assembly assembly = context.LoadFromStream(fs);

                context.SetEntryPoint(assembly);

                loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                AssemblyPart controllerAssemblyPart = new AssemblyPart(assembly);
                apm.ApplicationParts.Add(controllerAssemblyPart);

                BuildNotificationProvider(assembly, scope);
                RegisterModuleQueries(dataStore, moduleName, assembly, scope, documentation);
            }

            using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
            {
                Assembly viewAssembly = context.LoadFromStream(fsView);
                loader.LoadStreamsIntoContext(context, referenceFolderPath, viewAssembly);

                CoolCatRazorAssemblyPart moduleView = new CoolCatRazorAssemblyPart(viewAssembly, moduleName);
                apm.ApplicationParts.Add(moduleView);
            }

            context.Enable();

            return(context);
        }
コード例 #17
0
ファイル: SignatureManager.cs プロジェクト: kurtrips/tc
        /// <summary>
        /// Verifies the references in all the Reference nodes passed in the list
        /// </summary>
        /// <param name="list">The list of XmlNodes containing the Reference nodes</param>
        /// <param name="soapRefLoader">The SoapReferenceLoader incase we are verifying SOAP messages</param>
        private void VerifyReferences(XmlNodeList list, IReferenceLoader soapRefLoader)
        {
            try
            {
                foreach (XmlNode referenceNode in list)
                {
                    //Get URI
                    string uri = referenceNode.Attributes.GetNamedItem("URI").Value;

                    //Get protocol and load reference loader
                    string protocol = ExtractProtocol(uri);

                    // we use namespace manager since <Signature> has default namespace
                    XmlNamespaceManager nsMgr = new XmlNamespaceManager(
                        referenceNode.OwnerDocument.NameTable);
                    nsMgr.AddNamespace("ds", DEF_XMLDSIG_NS);

                    //Make array for holding the refernce data after loading
                    byte[] refData = null;
                    switch (protocol)
                    {
                    case "http":
                    {
                        IReferenceLoader httpRefLoader =
                            registry.GetReferenceLoaderInstance(protocol, emptyDic);

                        //Load reference
                        refData = httpRefLoader.LoadReferenceData(uri);
                        break;
                    }

                    case "soap":
                    {
                        ExceptionHelper.ValidateNotNull(soapRefLoader, "soapRefLoader");

                        //Load reference
                        refData = soapRefLoader.LoadReferenceData(uri);

                        // get transformers
                        XmlNodeList nodeList = referenceNode.SelectNodes("ds:Transforms", nsMgr);
                        if (nodeList != null)
                        {
                            IDictionary <string, object> dict = new Dictionary <string, object>();
                            foreach (XmlNode node in nodeList)
                            {
                                XmlNode transformNode = node.SelectSingleNode("ds:Transform", nsMgr);
                                string  transformKey  = (transformNode as XmlElement).GetAttribute("Algorithm");

                                //Get Transformer instance
                                ITransformer transfInst =
                                    registry.GetTransformerInstance(transformKey, dict);

                                //Do the transform
                                refData = transfInst.Transform(refData);
                            }
                        }
                        break;
                    }

                    default:
                        break;
                    }

                    //Get Digest method and load digester
                    XmlNode   digestMethodNode = referenceNode.SelectSingleNode("ds:DigestMethod", nsMgr);
                    string    digestAlgo       = digestMethodNode.Attributes.GetNamedItem("Algorithm").Value;
                    IDigester digester         = registry.GetDigesterInstance(digestAlgo, emptyDic);

                    //Digest reference data
                    byte[] calculatedDigest = digester.Digest(refData);

                    //Get digest value in xml
                    XmlNode digestInXmlNode = referenceNode.SelectSingleNode("ds:DigestValue", nsMgr);
                    byte[]  digestInXml     = Convert.FromBase64String(digestInXmlNode.InnerXml);

                    //If calculated digest and digest in xml are not same,
                    //either the reference itself has changed or we have a tampered reference node.
                    if (CompareByteArrays(calculatedDigest, digestInXml) == false)
                    {
                        throw new VerificationFailedException(REF_VERIF_FAILED);
                    }
                }
            }
            catch (VerificationFailedException vfEx)
            {
                throw vfEx;
            }
            catch (Exception ex)
            {
                throw new VerificationException(VERIF_EXCP_MSG, ex);
            }
        }
コード例 #18
0
ファイル: SignatureManager.cs プロジェクト: kurtrips/tc
        /// <summary>
        /// Creates SignedInfo node according to Xml spec at http://www.w3.org/TR/xmldsig-core/#sec-SignedInfo
        /// </summary>
        /// <param name="doc">XmlDocument used to create new attribute and nodes</param>
        /// <param name="canonicalizer">InstantiationVO containing the instance and
        /// property values of the canonicalizer to load</param>
        /// <param name="signer">InstantiationVO containing the instance and property
        /// values of the signer to load</param>
        /// <param name="references">List of references to sign</param>
        /// <returns>SignedInfo node according to Xml spec at http://www.w3.org/TR/xmldsig-core/#sec-SignedInfo
        /// </returns>
        private XmlNode CreateSignedInfoNode(XmlDocument doc, InstantiationVO canonicalizer, InstantiationVO signer,
                                             IList <IReference> references)
        {
            //Create SignedInfo node
            XmlNode signedInfoNode = doc.CreateNode(XmlNodeType.Element, "SignedInfo", null);

            //Create CanonicalizationMethod node and add it to SignedInfo node
            XmlNode canonMethodNode = CreateCanonicalizationMethodNode(doc, canonicalizer.Key);

            signedInfoNode.InnerXml += canonMethodNode.OuterXml;

            //Create SignatureMethod node and add it to SignedInfo node
            XmlNode signMethodNode = CreateSignatureMethod(doc, signer.Key);

            signedInfoNode.InnerXml += signMethodNode.OuterXml;

            //Process all the references
            foreach (IReference reference in references)
            {
                //Get instance of reference loader.
                IReferenceLoader referenceLoader = null;

                switch (reference.Protocol)
                {
                case "http":
                    referenceLoader = registry.GetReferenceLoaderInstance("http", emptyDic);
                    break;

                case "soap":
                    referenceLoader = reference.SoapRefLoader;
                    break;
                }

                //Load reference data using the reference loader.
                byte[] uriData = referenceLoader.LoadReferenceData(reference.ReferenceURI);

                XmlNode dummyNode = doc.CreateElement("dummy");
                //Apply Transforms if necessary
                if (reference.TransformerInstanceDefinitions.Count > 0)
                {
                    //Create Transforms node
                    XmlNode transformsNode = doc.CreateNode(XmlNodeType.Element, "Transforms", null);
                    foreach (InstantiationVO transfInstVO in reference.TransformerInstanceDefinitions)
                    {
                        //Get Transformer instance
                        ITransformer transfInst =
                            registry.GetTransformerInstance(transfInstVO.Key, transfInstVO.Params);

                        //Create Transform node and add Algorithm attribute
                        XmlNode      transformNode = doc.CreateNode(XmlNodeType.Element, "Transform", null);
                        XmlAttribute attr          = doc.CreateAttribute("Algorithm");
                        attr.Value = transfInstVO.Key;
                        transformNode.Attributes.Append(attr);

                        //Add Transform node to Transforms node
                        transformsNode.InnerXml += transformNode.OuterXml;

                        //Do the transform
                        uriData = transfInst.Transform(uriData);
                    }
                    //Add Transforms node to the dummy node
                    dummyNode.InnerXml += transformsNode.OuterXml;
                }

                //Get instance of digester
                IDigester digester = registry.GetDigesterInstance(reference.DigesterInstanceDefinition.Key,
                                                                  reference.DigesterInstanceDefinition.Params);

                //Produce a digest for the reference data bytes
                byte[] digestedData = digester.Digest(uriData);

                //Create Reference node with appropriate data set
                XmlNode refNode = CreateReferenceNode(doc, Convert.ToBase64String(digestedData),
                                                      reference.ReferenceURI, reference.DigesterInstanceDefinition.Key);

                //Add Transforms node to the dummy node
                refNode.InnerXml = dummyNode.InnerXml + refNode.InnerXml;

                //Add reference node to SignedInfo node
                signedInfoNode.InnerXml += refNode.OuterXml;
            }

            return(signedInfoNode);
        }
コード例 #19
0
 private LoadLinker <TRootLinkedSource, TRootLinkedSourceModel> CreateLoadLinker(IReferenceLoader referenceLoader)
 {
     return(new LoadLinker <TRootLinkedSource, TRootLinkedSourceModel>(referenceLoader, _referenceTypeToBeLoadedForEachLoadingLevel, _loadLinkProtocol));
 }
コード例 #20
0
        public static IApplicationBuilder UsePlugin(this IApplicationBuilder applicationBuilder)
        {
            var           serviceProvider = applicationBuilder.ApplicationServices;
            PluginOptions _pluginOptions  = serviceProvider.GetService <IOptions <PluginOptions> >().Value;

            if (!_pluginOptions.Enable)
            {
                return(applicationBuilder);
            }
            MvcRazorRuntimeCompilationOptions option = serviceProvider.GetService <IOptions <MvcRazorRuntimeCompilationOptions> >()?.Value;

            var pluginsLoadContexts = serviceProvider.GetService <IPluginsAssemblyLoadContexts>();
            //AssemblyLoadContextResoving(pluginsLoadContexts);
            IReferenceLoader loader                 = serviceProvider.GetService <IReferenceLoader>();
            var moduleSetup                         = serviceProvider.GetService <IMvcModuleSetup>();
            IPluginManagerService pluginManager     = serviceProvider.GetService <IPluginManagerService>();
            List <PluginInfoDto>  allEnabledPlugins = pluginManager.GetAllPlugins().ConfigureAwait(false).GetAwaiter().GetResult();

            ModuleChangeDelegate moduleStarted = (moduleEvent, context) =>
            {
                if (context?.PluginContext == null || context?.PluginContext.PluginEntityAssemblies.Count() == 0)
                {
                    return;
                }

                //var pluginContexts = pluginsLoadContexts.All().Select(c => c.PluginContext).SkipWhile(c => c == null);
                switch (moduleEvent)
                {
                case ModuleEvent.Installed:
                    HandleModuleInstallEvent(serviceProvider, context);
                    break;

                case ModuleEvent.Loaded:
                    HandleModuleLoadEvent(serviceProvider, context);
                    break;

                case ModuleEvent.Started:
                    break;

                case ModuleEvent.Stoped:
                    break;

                case ModuleEvent.UnInstalled:
                    HandleModuleUnintallEvent(serviceProvider, context);
                    break;

                default:
                    break;
                }
            };

            moduleSetup.ModuleChangeEventHandler += moduleStarted;
            var env = serviceProvider.GetService <IHostEnvironment>();

            foreach (var plugin in allEnabledPlugins)
            {
                string filePath = Path.Combine(env.ContentRootPath, _pluginOptions.InstallBasePath, plugin.Name, $"{ plugin.Name}.dll");
                //option.FileProviders.Add(new PhysicalFileProvider(Path.Combine(AppContext.BaseDirectory, _pluginOptions.InstallBasePath, plugin.Name)));
                option.AdditionalReferencePaths.Add(filePath);
                if (plugin.IsEnable)
                {
                    moduleSetup.EnableModule(plugin.Name);
                }
                else
                {
                    moduleSetup.LoadModule(plugin.Name, false);
                }
            }

            AdditionalReferencePathHolder.AdditionalReferencePaths = option?.AdditionalReferencePaths;
            var razorViewEngineOptions = serviceProvider.GetService <IOptions <RazorViewEngineOptions> >()?.Value;

            razorViewEngineOptions?.AreaViewLocationFormats.Add("/Plugins/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
            razorViewEngineOptions?.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");


            return(applicationBuilder);
        }
コード例 #21
0
 /// <summary>
 /// 初始化一个<see cref="PackageLoader"/>类型的实例
 /// </summary>
 /// <param name="tableLoader">数据表加载器</param>
 /// <param name="referenceLoader">引用加载器</param>
 public PackageLoader(ITableLoader tableLoader, IReferenceLoader referenceLoader)
 {
     _tableLoader     = tableLoader;
     _referenceLoader = referenceLoader;
 }
コード例 #22
0
ファイル: IndividualChecker.cs プロジェクト: rferg/HmmParser
 internal IndividualChecker(IReferenceLoader referenceLoader)
 {
     OrgIndicators = referenceLoader.GetOrgIndicators();
 }
コード例 #23
0
ファイル: MystiqueStartup.cs プロジェクト: pentest30/Mystique
        public static void MystiqueSetup(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddOptions();
            services.Configure <ConnectionStringSetting>(configuration.GetSection("ConnectionStringSetting"));

            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddSingleton <INotificationRegister, NotificationRegister>();
            services.AddSingleton <IActionDescriptorChangeProvider>(MystiqueActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();
            services.AddSingleton(MystiqueActionDescriptorChangeProvider.Instance);

            IMvcBuilder mvcBuilder = services.AddMvc();

            ServiceProvider provider = services.BuildServiceProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                MvcRazorRuntimeCompilationOptions option = scope.ServiceProvider.GetService <MvcRazorRuntimeCompilationOptions>();

                IUnitOfWork unitOfWork = scope.ServiceProvider.GetService <IUnitOfWork>();
                List <ViewModels.PluginListItemViewModel> allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

                foreach (ViewModels.PluginListItemViewModel plugin in allEnabledPlugins)
                {
                    CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(plugin.Name);
                    string moduleName          = plugin.Name;
                    string filePath            = $"{AppDomain.CurrentDomain.BaseDirectory}Modules/{moduleName}/{moduleName}.dll";
                    string referenceFolderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Modules/{moduleName}";

                    _presets.Add(filePath);
                    using (FileStream fs = new FileStream(filePath, FileMode.Open))
                    {
                        System.Reflection.Assembly assembly = context.LoadFromStream(fs);
                        context.SetEntryPoint(assembly);
                        loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                        MystiqueAssemblyPart controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
                        mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);
                        PluginsLoadContexts.Add(plugin.Name, context);

                        var providers = assembly.GetExportedTypes().Where(p => p.GetInterfaces().Any(x => x.Name == "INotificationProvider"));

                        if (providers.Any())
                        {
                            var register = scope.ServiceProvider.GetService <INotificationRegister>();

                            foreach (var p in providers)
                            {
                                var obj    = (INotificationProvider)assembly.CreateInstance(p.FullName);
                                var result = obj.GetNotifications();

                                foreach (var item in result)
                                {
                                    foreach (var i in item.Value)
                                    {
                                        register.Subscribe(item.Key, i);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            mvcBuilder.AddRazorRuntimeCompilation(o =>
            {
                foreach (string item in _presets)
                {
                    o.AdditionalReferencePaths.Add(item);
                }

                AdditionalReferencePathHolder.AdditionalReferencePaths = o.AdditionalReferencePaths;
            });

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });
        }
コード例 #24
0
ファイル: MystiqueStartup.cs プロジェクト: neoayi/Mystique
        public static void MystiqueSetup(this IServiceCollection services, IConfiguration configuration)
        {
            _serviceCollection = services;

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddSingleton <IMvcModuleSetup, MvcModuleSetup>();
            services.AddScoped <IPluginManager, PluginManager>();
            services.AddScoped <ISystemManager, SystemManager>();
            services.AddScoped <IUnitOfWork, Repository.MySql.UnitOfWork>();
            services.AddSingleton <INotificationRegister, NotificationRegister>();
            services.AddSingleton <IActionDescriptorChangeProvider>(MystiqueActionDescriptorChangeProvider.Instance);
            services.AddSingleton <IReferenceContainer, DefaultReferenceContainer>();
            services.AddSingleton <IReferenceLoader, DefaultReferenceLoader>();
            services.AddSingleton(MystiqueActionDescriptorChangeProvider.Instance);

            IMvcBuilder mvcBuilder = services.AddMvc();

            ServiceProvider provider = services.BuildServiceProvider();

            using (IServiceScope scope = provider.CreateScope())
            {
                IUnitOfWork unitOfWork = scope.ServiceProvider.GetService <IUnitOfWork>();

                if (unitOfWork.CheckDatabase())
                {
                    List <ViewModels.PluginListItemViewModel> allEnabledPlugins = unitOfWork.PluginRepository.GetAllEnabledPlugins();
                    IReferenceLoader loader = scope.ServiceProvider.GetService <IReferenceLoader>();

                    foreach (ViewModels.PluginListItemViewModel plugin in allEnabledPlugins)
                    {
                        CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(plugin.Name);
                        string moduleName = plugin.Name;

                        string filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.dll");
                        string viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName, $"{moduleName}.Views.dll");
                        string referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", moduleName);

                        _presets.Add(filePath);
                        using (FileStream fs = new FileStream(filePath, FileMode.Open))
                        {
                            Assembly assembly = context.LoadFromStream(fs);
                            context.SetEntryPoint(assembly);

                            loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                            MystiqueAssemblyPart controllerAssemblyPart = new MystiqueAssemblyPart(assembly);
                            mvcBuilder.PartManager.ApplicationParts.Add(controllerAssemblyPart);
                            PluginsLoadContexts.Add(plugin.Name, context);

                            BuildNotificationProvider(assembly, scope);
                        }

                        using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
                        {
                            Assembly viewAssembly = context.LoadFromStream(fsView);
                            loader.LoadStreamsIntoContext(context, referenceFolderPath, viewAssembly);

                            MystiqueRazorAssemblyPart moduleView = new MystiqueRazorAssemblyPart(viewAssembly, moduleName);
                            mvcBuilder.PartManager.ApplicationParts.Add(moduleView);
                        }

                        context.Enable();
                    }
                }
            }

            AssemblyLoadContextResoving();

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.AreaViewLocationFormats.Add("/Modules/{2}/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.AreaViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
            });

            services.Replace <IViewCompilerProvider, MystiqueViewCompilerProvider>();
        }
コード例 #25
0
ファイル: MvcModuleSetup.cs プロジェクト: pentest30/Mystique
 public MvcModuleSetup(ApplicationPartManager partManager, IReferenceLoader referenceLoader)
 {
     _partManager     = partManager;
     _referenceLoader = referenceLoader;
 }
コード例 #26
0
ファイル: SignatureManager.cs プロジェクト: kurtrips/tc
        /// <summary>
        /// Verifies the references in all the Reference nodes passed in the list
        /// </summary>
        /// <param name="list">The list of XmlNodes containing the Reference nodes</param>
        /// <param name="soapRefLoader">The SoapReferenceLoader incase we are verifying SOAP messages</param>
        private void VerifyReferences(XmlNodeList list, IReferenceLoader soapRefLoader)
        {
            try
            {
                foreach (XmlNode referenceNode in list)
                {
                    //Get URI
                    string uri = referenceNode.Attributes.GetNamedItem("URI").Value;

                    //Get protocol and load reference loader
                    string protocol = ExtractProtocol(uri);

                    //Make array for holding the refernce data after loading
                    byte[] refData = null;
                    switch (protocol)
                    {
                    case "http":
                    {
                        IReferenceLoader httpRefLoader =
                            registry.GetReferenceLoaderInstance(protocol, emptyDic);

                        //Load reference
                        refData = httpRefLoader.LoadReferenceData(uri);
                        break;
                    }

                    case "soap":
                    {
                        ExceptionHelper.ValidateNotNull(soapRefLoader, "soapRefLoader");

                        //Load reference
                        refData = soapRefLoader.LoadReferenceData(uri);
                        break;
                    }

                    default:
                        break;
                    }

                    //Get Digest method and load digester
                    XmlNode   digestMethodNode = referenceNode.SelectSingleNode("DigestMethod");
                    string    digestAlgo       = digestMethodNode.Attributes.GetNamedItem("Algorithm").Value;
                    IDigester digester         = registry.GetDigesterInstance(digestAlgo, emptyDic);

                    //Digest reference data
                    byte[] calculatedDigest = digester.Digest(refData);

                    //Get digest value in xml
                    XmlNode digestInXmlNode = referenceNode.SelectSingleNode("DigestValue");
                    byte[]  digestInXml     = Convert.FromBase64String(digestInXmlNode.InnerXml);

                    //If calculated digest and digest in xml are not same,
                    //either the reference itself has changed or we have a tampered reference node.
                    if (CompareByteArrays(calculatedDigest, digestInXml) == false)
                    {
                        throw new VerificationFailedException(REF_VERIF_FAILED);
                    }
                }
            }
            catch (VerificationFailedException vfEx)
            {
                throw vfEx;
            }
            catch (Exception ex)
            {
                throw new VerificationException(VERIF_EXCP_MSG, ex);
            }
        }
コード例 #27
0
 public MutationRunner(IList <IMutator> mutators, ITestRunner testRunner, IReferenceLoader referenceLoader)
 {
     Mutators        = mutators;
     TestRunner      = testRunner;
     ReferenceLoader = referenceLoader;
 }
コード例 #28
0
ファイル: MvcModuleSetup.cs プロジェクト: Eric-xgc/Mystique
 public MvcModuleSetup(ApplicationPartManager partManager, IReferenceLoader referenceLoader, IHttpContextAccessor httpContextAccessor)
 {
     _partManager     = partManager;
     _referenceLoader = referenceLoader;
     _context         = httpContextAccessor;
 }