Beispiel #1
0
 public void Stub13()
 {
     // <SnippetMediaPermission4>
     // Provide full access to the resource protected by the permission.
     MediaPermission mediaPermission = new MediaPermission(PermissionState.Unrestricted);
     // </SnippetMediaPermission4>
 }
Beispiel #2
0
        // </SnippetMediaPermissionAttribute9>
        public void Stub09()
        {
            // <SnippetMediaPermission3>
            MediaPermission mediaPermission = new MediaPermission(MediaPermissionVideo.AllVideo);
            // </SnippetMediaPermission3>

            // <SnippetMediaPermission8>
            MediaPermissionVideo mediaPermissionVideo = mediaPermission.Video;
            // </SnippetMediaPermission8>
        }
Beispiel #3
0
        // </SnippetMediaPermissionAttribute6>
        public void Stub06()
        {
            // <SnippetMediaPermission2>
            MediaPermission mediaPermission = new MediaPermission(MediaPermissionImage.NoImage);
            // </SnippetMediaPermission2>

            // <SnippetMediaPermission7>
            MediaPermissionImage mediaPermissionImage = mediaPermission.Image;
            // </SnippetMediaPermission7>
        }
Beispiel #4
0
        // </SnippetMediaPermissionAttribute4>
        public void Stub04()
        {
            // <SnippetMediaPermission1>
            MediaPermission mediaPermission = new MediaPermission(MediaPermissionAudio.SiteOfOriginAudio);
            // </SnippetMediaPermission1>

            // <SnippetMediaPermission6>
            MediaPermissionAudio mediaPermissionAudio = mediaPermission.Audio;
            // </SnippetMediaPermission6>
        }
Beispiel #5
0
 public void Stub14()
 {
     // <SnippetMediaPermission5>
     // Provide full access to the resource protected by the permission.
     MediaPermission mediaPermission = new MediaPermission(
         MediaPermissionAudio.SiteOfOriginAudio,
         MediaPermissionVideo.SiteOfOriginVideo,
         MediaPermissionImage.SiteOfOriginImage);
     // </SnippetMediaPermission5>
 }
Beispiel #6
0
        public void Stub15()
        {
            MediaPermission mediaPermission = new MediaPermission(
                MediaPermissionAudio.AllAudio,
                MediaPermissionVideo.AllVideo,
                MediaPermissionImage.AllImage);

            // <SnippetMediaPermission16>
            bool isUnrestricted = mediaPermission.IsUnrestricted();
            // </SnippetMediaPermission16>
        }
        public SecuritySettings()
        {
            SocketPermission = new SocketPermission(PermissionState.None);

            WebPermission = new WebPermission(PermissionState.None);
            foreach (var uri in  Config.Instance.SelectedProfile.InstalledAssemblies.Select(u => u.Location))
            {
                WebPermission.AddPermission(NetworkAccess.Connect, uri);
            }

            FileIoPermission = new FileIOPermission(PermissionState.None);
            FileIoPermission.AddPathList(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write | FileIOPermissionAccess.Append, Directories.DataDirectory);

            MediaPermission = new MediaPermission(PermissionState.None);
        }
Beispiel #8
0
        public static void MediaPermissionCallMethods()
        {
            MediaPermission mp  = new MediaPermission();
            MediaPermission mp2 = new MediaPermission(MediaPermissionAudio.AllAudio);
            MediaPermission mp3 = new MediaPermission(MediaPermissionVideo.AllVideo);
            MediaPermission mp4 = new MediaPermission(MediaPermissionImage.AllImage);
            MediaPermission mp5 = new MediaPermission(MediaPermissionAudio.AllAudio,
                                                      MediaPermissionVideo.AllVideo,
                                                      MediaPermissionImage.AllImage);
            bool        testbool = mp.IsUnrestricted();
            IPermission ip       = mp.Copy();
            IPermission ip2      = mp.Intersect(ip);
            IPermission ip3      = mp.Union(ip);

            testbool = mp.IsSubsetOf(ip);
            SecurityElement se = new SecurityElement("");

            mp.FromXml(se);
            se = mp.ToXml();
        }
Beispiel #9
0
        internal static CodeAccessPermission CreateMediaAccessPermission(string uri)
        {
            CodeAccessPermission result = null;

            if (uri != null)
            {
                if (string.Compare("image", uri, true, TypeConverterHelper.InvariantEnglishUS) == 0)
                {
                    result = new MediaPermission(MediaPermissionAudio.NoAudio, MediaPermissionVideo.NoVideo, MediaPermissionImage.AllImage);
                }
                else if (string.Compare(BaseUriHelper.GetResolvedUri(BaseUriHelper.BaseUri, new Uri(uri, UriKind.RelativeOrAbsolute)).Scheme, PackUriHelper.UriSchemePack, true, TypeConverterHelper.InvariantEnglishUS) != 0 && !CallerHasWebPermission(new Uri(uri, UriKind.RelativeOrAbsolute)))
                {
                    result = new MediaPermission(MediaPermissionAudio.NoAudio, MediaPermissionVideo.NoVideo, MediaPermissionImage.AllImage);
                }
            }
            else
            {
                result = new MediaPermission(MediaPermissionAudio.NoAudio, MediaPermissionVideo.NoVideo, MediaPermissionImage.AllImage);
            }
            return(result);
        }
Beispiel #10
0
        CreateMediaAccessPermission(String uri)
        {
            CodeAccessPermission codeAccessPermission = null;

            if (uri != null)
            {
                // do a Case invariant dotnet culture specific string compare
                if (String.Compare(SafeSecurityHelper.IMAGE, uri, true /*Ignore case*/, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS) == 0)
                {
                    codeAccessPermission = new MediaPermission(MediaPermissionAudio.NoAudio,
                                                               MediaPermissionVideo.NoVideo,
                                                               MediaPermissionImage.AllImage);
                }
                else
                {
                    // we allow access to pack: bits so assuming scheme is not pack: we demand
                    if (String.Compare((System.Windows.Navigation.BaseUriHelper.GetResolvedUri(System.Windows.Navigation.BaseUriHelper.BaseUri, new Uri(uri, UriKind.RelativeOrAbsolute))).Scheme,
                                       PackUriHelper.UriSchemePack, true /* ignore case */,
                                       System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS) != 0)
                    {
                        // Creating a URI is fine it is going the other way that is risky
                        if (!SecurityHelper.CallerHasWebPermission(new Uri(uri, UriKind.RelativeOrAbsolute)))
                        {
                            codeAccessPermission = new MediaPermission(MediaPermissionAudio.NoAudio,
                                                                       MediaPermissionVideo.NoVideo,
                                                                       MediaPermissionImage.AllImage);
                        }
                    }
                }
            }
            else
            {
                codeAccessPermission = new MediaPermission(MediaPermissionAudio.NoAudio,
                                                           MediaPermissionVideo.NoVideo,
                                                           MediaPermissionImage.AllImage);
            }
            return(codeAccessPermission);
        }
        private bool GenericPrimMediaPermission(SceneObjectPart part, UUID agentID, MediaPermission perms)
        {
//            if (IsAdministrator(agentID))
//                return true;
            
            if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
                return true;

            if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
            {
                if (agentID == part.OwnerID)
                    return true;
            }
            
            if ((perms & MediaPermission.Group) == MediaPermission.Group)
            {
                if (IsGroupMember(part.GroupID, agentID, 0))
                    return true;
            }
            
            return false;
        }
Beispiel #12
0
        public void GetStandardPermissionSetLocalIntranetPermissionSetTest()
        {
            // Get a copy of LocalIntranet which is not extended with any same-site permission
            PermissionSet intranetBase = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, null);

            // It shouldn't be fully trusted, and should contain a set of well known permissions
            Assert.IsFalse(intranetBase.IsUnrestricted());
            Assert.IsTrue(intranetBase.Count == 8 || intranetBase.Count == 10);

            // We should have SecurityPermission/Execution,Assertion,BindingRedirects
            SecurityPermission baseSecurityPermission = intranetBase.GetPermission(typeof(SecurityPermission)) as SecurityPermission;

            Assert.IsNotNull(baseSecurityPermission);
            Assert.AreEqual(SecurityPermissionFlag.Execution | SecurityPermissionFlag.Assertion | SecurityPermissionFlag.BindingRedirects, baseSecurityPermission.Flags);

            // Unrestricted FileDialogPermission
            FileDialogPermission baseFileDialogPermission = intranetBase.GetPermission(typeof(FileDialogPermission)) as FileDialogPermission;

            Assert.IsNotNull(baseFileDialogPermission);
            Assert.IsTrue(baseFileDialogPermission.IsUnrestricted());

            // IsolatedStorageFilePermission/AssemblyIsolationByUser
            IsolatedStorageFilePermission baseIsostorePermission = intranetBase.GetPermission(typeof(IsolatedStorageFilePermission)) as IsolatedStorageFilePermission;

            Assert.IsNotNull(baseIsostorePermission);
            Assert.AreEqual(IsolatedStorageContainment.AssemblyIsolationByUser, baseIsostorePermission.UsageAllowed);

            // Unrestricted UIPermission
            UIPermission baseUIPermission = intranetBase.GetPermission(typeof(UIPermission)) as UIPermission;

            Assert.IsNotNull(baseUIPermission);
            Assert.IsTrue(baseUIPermission.IsUnrestricted());

            // PrintingPermission/DefaultPrinting
            PrintingPermission basePrintingPermission = intranetBase.GetPermission(typeof(PrintingPermission)) as PrintingPermission;

            Assert.IsNotNull(basePrintingPermission);
            Assert.AreEqual(PrintingPermissionLevel.DefaultPrinting, basePrintingPermission.Level);

            // EnvironmentPermission/Read USERNAME
            EnvironmentPermission baseEnvironmentPermission = intranetBase.GetPermission(typeof(EnvironmentPermission)) as EnvironmentPermission;

            Assert.IsNotNull(baseEnvironmentPermission);
            Assert.AreEqual("USERNAME", baseEnvironmentPermission.GetPathList(EnvironmentPermissionAccess.Read));

            // ReflectionPermission/ReflectionEmit
            ReflectionPermission baseReflectionPermission = intranetBase.GetPermission(typeof(ReflectionPermission)) as ReflectionPermission;

            Assert.IsNotNull(baseReflectionPermission);
            Assert.AreEqual(ReflectionPermissionFlag.ReflectionEmit, baseReflectionPermission.Flags);

            // Unrestricted DNS permission
            DnsPermission baseDnsPermission = intranetBase.GetPermission(typeof(DnsPermission)) as DnsPermission;

            Assert.IsNotNull(baseDnsPermission);
            Assert.IsTrue(baseDnsPermission.IsUnrestricted());

            // Also check for WPF extensions
            MediaPermission baseMediaPermission = intranetBase.GetPermission(typeof(MediaPermission)) as MediaPermission;

            if (baseMediaPermission != null)
            {
                Assert.AreEqual(MediaPermissionAudio.SafeAudio, baseMediaPermission.Audio);
                Assert.AreEqual(MediaPermissionImage.SafeImage, baseMediaPermission.Image);
                Assert.AreEqual(MediaPermissionVideo.SafeVideo, baseMediaPermission.Video);
            }

            WebBrowserPermission baseWebPermission = intranetBase.GetPermission(typeof(WebBrowserPermission)) as WebBrowserPermission;

            if (baseWebPermission != null)
            {
                Assert.AreEqual(WebBrowserPermissionLevel.Safe, baseWebPermission.Level);
            }

            // Now try to extend with a local URL - we should get FileIOPermission
            Url           localUrl = new Url(@"file://c:\windows");
            PermissionSet intranetLocalExtended = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, localUrl);

            Assert.IsTrue(intranetBase.IsSubsetOf(intranetLocalExtended));
            Assert.IsFalse(intranetLocalExtended.IsUnrestricted());
            Assert.AreEqual(intranetBase.Count + 1, intranetLocalExtended.Count);

            FileIOPermission filePermission = intranetLocalExtended.GetPermission(typeof(FileIOPermission)) as FileIOPermission;

            Assert.IsNotNull(filePermission);
            Assert.IsFalse(filePermission.IsUnrestricted());

            // Finally, try to extend with a Web URL, which should provide same site web access
            Url           webUrl = new Url("htt://www.microsoft.com/");
            PermissionSet intranetWebExtended = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, webUrl);

            Assert.IsTrue(intranetBase.IsSubsetOf(intranetWebExtended));
            Assert.IsFalse(intranetWebExtended.IsUnrestricted());
            Assert.AreEqual(intranetBase.Count + 1, intranetWebExtended.Count);

            WebPermission webPermission = intranetWebExtended.GetPermission(typeof(WebPermission)) as WebPermission;

            Assert.IsNotNull(webPermission);
            Assert.IsFalse(webPermission.IsUnrestricted());
        }
Beispiel #13
0
        public void GetStandardPermissionSetInternetPermissionSetTest()
        {
            // Get a copy of Internet which is not extended with any same-site permission
            PermissionSet internetBase = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.Internet, null);

            // It shouldn't be fully trusted, and should contain a set of well known permissions
            Assert.IsFalse(internetBase.IsUnrestricted());
            Assert.IsTrue(internetBase.Count == 5 || internetBase.Count == 7);

            // We should have SecurityPermission/Execution
            SecurityPermission baseSecurityPermission = internetBase.GetPermission(typeof(SecurityPermission)) as SecurityPermission;

            Assert.IsNotNull(baseSecurityPermission);
            Assert.AreEqual(SecurityPermissionFlag.Execution, baseSecurityPermission.Flags);

            // FileDialogPermission/Open
            FileDialogPermission baseFileDialogPermission = internetBase.GetPermission(typeof(FileDialogPermission)) as FileDialogPermission;

            Assert.IsNotNull(baseFileDialogPermission);
            Assert.AreEqual(FileDialogPermissionAccess.Open, baseFileDialogPermission.Access);

            // IsolatedStorageFilePermission/ApplicationIsolationByUser
            IsolatedStorageFilePermission baseIsostorePermission = internetBase.GetPermission(typeof(IsolatedStorageFilePermission)) as IsolatedStorageFilePermission;

            Assert.IsNotNull(baseIsostorePermission);
            Assert.AreEqual(IsolatedStorageContainment.ApplicationIsolationByUser, baseIsostorePermission.UsageAllowed);

            // UIPermission/SafeTopLevelWindows and UIPermission/OwnClipboard
            UIPermission baseUIPermission = internetBase.GetPermission(typeof(UIPermission)) as UIPermission;

            Assert.IsNotNull(baseUIPermission);
            Assert.AreEqual(UIPermissionWindow.SafeTopLevelWindows, baseUIPermission.Window);
            Assert.AreEqual(UIPermissionClipboard.OwnClipboard, baseUIPermission.Clipboard);

            // PrintingPermission/SafePrinting
            PrintingPermission basePrintingPermission = internetBase.GetPermission(typeof(PrintingPermission)) as PrintingPermission;

            Assert.IsNotNull(basePrintingPermission);
            Assert.AreEqual(PrintingPermissionLevel.SafePrinting, basePrintingPermission.Level);

            // Also check for WPF extensions
            MediaPermission baseMediaPermission = internetBase.GetPermission(typeof(MediaPermission)) as MediaPermission;

            if (baseMediaPermission != null)
            {
                Assert.AreEqual(MediaPermissionAudio.SafeAudio, baseMediaPermission.Audio);
                Assert.AreEqual(MediaPermissionImage.SafeImage, baseMediaPermission.Image);
                Assert.AreEqual(MediaPermissionVideo.SafeVideo, baseMediaPermission.Video);
            }

            WebBrowserPermission baseWebPermission = internetBase.GetPermission(typeof(WebBrowserPermission)) as WebBrowserPermission;

            if (baseWebPermission != null)
            {
                Assert.AreEqual(WebBrowserPermissionLevel.Safe, baseWebPermission.Level);
            }

            // Now try to extend with a local URL - we should get no extensions
            Url           localUrl = new Url(@"file://c:\windows");
            PermissionSet internetLocalExtended = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.Internet, localUrl);

            Assert.IsTrue(internetLocalExtended.IsSubsetOf(internetBase));
            Assert.IsTrue(internetBase.IsSubsetOf(internetLocalExtended));

            // Finally, try to extend with a Web URL, which should provide same site web access
            Url           webUrl = new Url("htt://www.microsoft.com/");
            PermissionSet internetWebExtended = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.Internet, webUrl);

            Assert.IsTrue(internetBase.IsSubsetOf(internetWebExtended));
            Assert.IsFalse(internetWebExtended.IsUnrestricted());
            Assert.AreEqual(internetBase.Count + 1, internetWebExtended.Count);

            WebPermission webPermission = internetWebExtended.GetPermission(typeof(WebPermission)) as WebPermission;

            Assert.IsNotNull(webPermission);
            Assert.IsFalse(webPermission.IsUnrestricted());
        }
        private bool GenericPrimMediaPermission(ISceneChildEntity part, UUID agentID, MediaPermission perms)
        {
            if ((perms & MediaPermission.Anyone) == MediaPermission.Anyone)
                return true;

            if ((perms & MediaPermission.Owner) == MediaPermission.Owner)
            {
                if (agentID == part.OwnerID)
                    return true;
            }

            if ((perms & MediaPermission.Group) == MediaPermission.Group)
            {
                if (IsGroupMember(part.GroupID, agentID, 0))
                    return true;
            }

            return false;
        }