I want to construct a WPF system that can incorporate addin developed by an external developer community. Since I can t vouch for those developers, I want their code to run in a safe environment. It seems that MAF is a good solution, so I decided to investigate the security of MAF. One can define a precise permission set for each addon, which is very nice.
然而,我希望Addons能够退回世界森林论坛的控制。 为此,他们需要能够管理人民论坛的议会。 此外,我并不希望添加物能够操作不受管理的代码,以便它们能够在装上添加物时推翻我所设定的安全许可。
因此,这里的问题是——如果我未经许可就装上添加物,以操作不受管理的代码,那么该添加物就能够建立世界森林论坛的控制。 我如何解决这一问题?
为了测试这一问题,我撰写了一份小型的WPF app,并试图装上它,从第二个手表操作。 下面是装上和操作《世界森林框架》的代码。 如果像现在一样,如果我删除了最后的“增加排放”声明(即有“UnmanageCode”旗帜的声明),那么它就停止了工作,说它可能制造“世界森林论坛”申请的窗口。
PermissionSet set = new PermissionSet(PermissionState.None);
set.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, PATH));
set.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
set.AddPermission(new UIPermission(PermissionState.Unrestricted));
set.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
Evidence ev = new Evidence();
AppDomain domain = AppDomain.CreateDomain("Test", ev, new AppDomainSetup() { ApplicationBase = PATH }, set);
domain.ExecuteAssembly(PATH);