summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Security/Policy/ApplicationTrust.cs
blob: 57b216e462072503ba519654c8c849dc2352c702 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// 

//
//
// This class encapsulates security decisions about an application.
//

namespace System.Security.Policy {
    using System.Collections;
    using System.Collections.Generic;
#if FEATURE_CLICKONCE        
    using System.Deployment.Internal.Isolation;
    using System.Deployment.Internal.Isolation.Manifest;
#endif    
    using System.Globalization;
    using System.IO;
    using System.Runtime.InteropServices;
#if FEATURE_SERIALIZATION
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
#endif // FEATURE_SERIALIZATION
    using System.Runtime.Versioning;
    using System.Security.Permissions;
    using System.Security.Util;
    using System.Text;
    using System.Threading;
    using System.Diagnostics.Contracts;

    [System.Runtime.InteropServices.ComVisible(true)]
    public enum ApplicationVersionMatch {
        MatchExactVersion,
        MatchAllVersions
    }

    [System.Runtime.InteropServices.ComVisible(true)]
    [Serializable]
    public sealed class ApplicationTrust : EvidenceBase, ISecurityEncodable
    {
#if FEATURE_CLICKONCE
        private ApplicationIdentity m_appId;
        private bool m_appTrustedToRun;
        private bool m_persist;
        
        private object m_extraInfo;
        private SecurityElement m_elExtraInfo;
#endif
        private PolicyStatement m_psDefaultGrant;
        private IList<StrongName> m_fullTrustAssemblies;

        // Permission special flags for the default grant set in this ApplicationTrust.  This should be
        // updated in sync with any updates to the default grant set.
        // 
        // In the general case, these values cannot be trusted - we only store a reference to the
        // DefaultGrantSet, and return the reference directly, which means that code can update the
        // permission set without our knowledge.  That would lead to the flags getting out of sync with the
        // grant set.
        // 
        // However, we only care about these flags when we're creating a homogenous AppDomain, and in that
        // case we control the ApplicationTrust object end-to-end, and know that the permission set will not
        // change after the flags are calculated.
        [NonSerialized]
        private int m_grantSetSpecialFlags;

#if FEATURE_CLICKONCE        
        public ApplicationTrust (ApplicationIdentity applicationIdentity) : this () {
            ApplicationIdentity = applicationIdentity;
        }
#endif 
        public ApplicationTrust () : this (new PermissionSet(PermissionState.None))
        {
        }

        internal ApplicationTrust (PermissionSet defaultGrantSet)
        {
            InitDefaultGrantSet(defaultGrantSet);

            m_fullTrustAssemblies = new List<StrongName>().AsReadOnly();
        }

        public ApplicationTrust(PermissionSet defaultGrantSet, IEnumerable<StrongName> fullTrustAssemblies) {
            if (fullTrustAssemblies == null) {
                throw new ArgumentNullException("fullTrustAssemblies");
            }

            InitDefaultGrantSet(defaultGrantSet);

            List<StrongName> fullTrustList = new List<StrongName>();
            foreach (StrongName strongName in fullTrustAssemblies) {
                if (strongName == null) {
                    throw new ArgumentException(Environment.GetResourceString("Argument_NullFullTrustAssembly"), "fullTrustAssemblies");
                }

                fullTrustList.Add(new StrongName(strongName.PublicKey, strongName.Name, strongName.Version));
            }

            m_fullTrustAssemblies = fullTrustList.AsReadOnly();
        }

        // Sets up the default grant set for all constructors. Extracted to avoid the cost of
        // IEnumerable virtual dispatches on startup when there are no fullTrustAssemblies (CoreCLR)
        private void InitDefaultGrantSet(PermissionSet defaultGrantSet) {
            if (defaultGrantSet == null) {
                throw new ArgumentNullException("defaultGrantSet");
            }

            // Creating a PolicyStatement copies the incoming permission set, so we don't have to worry
            // about the PermissionSet parameter changing underneath us after we've calculated the
            // permisison flags in the DefaultGrantSet setter.
            DefaultGrantSet = new PolicyStatement(defaultGrantSet);
        }

#if FEATURE_CLICKONCE        
        public ApplicationIdentity ApplicationIdentity {
            get {
                return m_appId;
            }
            set {
                if (value == null)
                    throw new ArgumentNullException("value", Environment.GetResourceString("Argument_InvalidAppId"));
                Contract.EndContractBlock();
                m_appId = value;
            }
        }
#endif
        public PolicyStatement DefaultGrantSet {
            get {
                if (m_psDefaultGrant == null)
                    return new PolicyStatement(new PermissionSet(PermissionState.None));
                return m_psDefaultGrant;
            }
            set {
                if (value == null) {
                    m_psDefaultGrant = null;
                    m_grantSetSpecialFlags = 0;
                }
                else {
                    m_psDefaultGrant = value;
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(m_psDefaultGrant.PermissionSet, null);
                }
            }
        }

        public IList<StrongName> FullTrustAssemblies {
            get {
                return m_fullTrustAssemblies;
            }
        }
#if FEATURE_CLICKONCE        
        public bool IsApplicationTrustedToRun {
            get {
                return m_appTrustedToRun;
            }
            set {
                m_appTrustedToRun = value;
            }
        }

        public bool Persist {
            get {
                return m_persist;
            }
            set {
                m_persist = value;
            }
        }

         public object ExtraInfo {
            get {
                if (m_elExtraInfo != null) {
                    m_extraInfo = ObjectFromXml(m_elExtraInfo);
                    m_elExtraInfo = null;
                }
                return m_extraInfo;
            }
            set {
                m_elExtraInfo = null;
                m_extraInfo = value;
            }
        }
#endif //FEATURE_CLICKONCE

#if FEATURE_CAS_POLICY
        public SecurityElement ToXml () {
            SecurityElement elRoot = new SecurityElement("ApplicationTrust");
            elRoot.AddAttribute("version", "1");

#if FEATURE_CLICKONCE
            if (m_appId != null) {
                elRoot.AddAttribute("FullName", SecurityElement.Escape(m_appId.FullName));
            }
            if (m_appTrustedToRun) {
                elRoot.AddAttribute("TrustedToRun", "true");
            }
            if (m_persist) {
                elRoot.AddAttribute("Persist", "true");
            }
#endif // FEATURE_CLICKONCE
 
            if (m_psDefaultGrant != null) {
                SecurityElement elDefaultGrant = new SecurityElement("DefaultGrant");
                elDefaultGrant.AddChild(m_psDefaultGrant.ToXml());
                elRoot.AddChild(elDefaultGrant);
            }
            if (m_fullTrustAssemblies.Count > 0) {
                SecurityElement elFullTrustAssemblies = new SecurityElement("FullTrustAssemblies");
                foreach (StrongName fullTrustAssembly in m_fullTrustAssemblies) {
                    elFullTrustAssemblies.AddChild(fullTrustAssembly.ToXml());
                }
                elRoot.AddChild(elFullTrustAssemblies);
            }

#if FEATURE_CLICKONCE
            if (ExtraInfo != null) {
                elRoot.AddChild(ObjectToXml("ExtraInfo", ExtraInfo));
            }
#endif // FEATURE_CLICKONCE
            return elRoot;
        }

        public void FromXml (SecurityElement element) {
            if (element == null)
                throw new ArgumentNullException("element");
            if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));

#if FEATURE_CLICKONCE
            m_appTrustedToRun = false;
            string isAppTrustedToRun = element.Attribute("TrustedToRun");
            if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) {
                m_appTrustedToRun = true;
            }

            m_persist = false;
            string persist = element.Attribute("Persist");
            if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) {
                m_persist = true;
            }

            m_appId = null;
            string fullName = element.Attribute("FullName");
            if (fullName != null && fullName.Length > 0) {
                m_appId = new ApplicationIdentity(fullName);
            }
#endif // FEATURE_CLICKONCE

            m_psDefaultGrant = null;
            m_grantSetSpecialFlags = 0;
            SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
            if (elDefaultGrant != null) {
                SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
                if (elDefaultGrantPS != null) {
                    PolicyStatement ps = new PolicyStatement(null);
                    ps.FromXml(elDefaultGrantPS);
                    m_psDefaultGrant = ps;
                    m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
                }
            }

            List<StrongName> fullTrustAssemblies = new List<StrongName>();
            SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
            if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) {
                IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
                while (enumerator.MoveNext()) {
                    StrongName fullTrustAssembly = new StrongName();
                    fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
                    fullTrustAssemblies.Add(fullTrustAssembly);
                }
            }

            m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly();

#if FEATURE_CLICKONCE
            m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
        }

#if FEATURE_CLICKONCE
        private static SecurityElement ObjectToXml (string tag, Object obj) {
            BCLDebug.Assert(obj != null, "You need to pass in an object");

            ISecurityEncodable encodableObj = obj as ISecurityEncodable;

            SecurityElement elObject;
            if (encodableObj != null) {
                elObject = encodableObj.ToXml();
                if (!elObject.Tag.Equals(tag))
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
            }

            MemoryStream stream = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, obj);
            byte[] array = stream.ToArray();

            elObject = new SecurityElement(tag);
            elObject.AddAttribute("Data", Hex.EncodeHexString(array));
            return elObject;
        }

        private static Object ObjectFromXml (SecurityElement elObject) {
            BCLDebug.Assert(elObject != null, "You need to pass in a security element");

            if (elObject.Attribute("class") != null) {
                ISecurityEncodable encodableObj = XMLUtil.CreateCodeGroup(elObject) as ISecurityEncodable;
                if (encodableObj != null) {
                    encodableObj.FromXml(elObject);
                    return encodableObj;
                }
            }

            string objectData = elObject.Attribute("Data");
            MemoryStream stream = new MemoryStream(Hex.DecodeHexString(objectData));
            BinaryFormatter formatter = new BinaryFormatter();
            return formatter.Deserialize(stream);
        }
#endif // FEATURE_CLICKONCE
#endif // FEATURE_CAS_POLICY

#pragma warning disable 618
        [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
#pragma warning restore 618
        [SecuritySafeCritical]
        public override EvidenceBase Clone()
        {
            return base.Clone();
        }
    }

#if FEATURE_CLICKONCE
    [System.Security.SecurityCritical]  // auto-generated_required
    [System.Runtime.InteropServices.ComVisible(true)]
    public sealed class ApplicationTrustCollection : ICollection {
        private const string ApplicationTrustProperty = "ApplicationTrust";
        private const string InstallerIdentifier = "{60051b8f-4f12-400a-8e50-dd05ebd438d1}";
        private static Guid ClrPropertySet = new Guid("c989bb7a-8385-4715-98cf-a741a8edb823");

        // The CLR specific constant install reference.
        private static object s_installReference = null;
        private static StoreApplicationReference InstallReference {
            get {
                if (s_installReference == null) {
                    Interlocked.CompareExchange(ref s_installReference,
                                                new StoreApplicationReference(
                                                    IsolationInterop.GUID_SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING,
                                                    InstallerIdentifier,
                                                    null),
                                                null);
                }
                return (StoreApplicationReference) s_installReference;
            }
        }

        private object m_appTrusts = null;
        private ArrayList AppTrusts {
            [System.Security.SecurityCritical]  // auto-generated
            get {
                if (m_appTrusts == null) {
                    ArrayList appTrusts = new ArrayList();
                    if (m_storeBounded) {
                        RefreshStorePointer();
                        // enumerate the user store and populate the collection
                        StoreDeploymentMetadataEnumeration deplEnum = m_pStore.EnumInstallerDeployments(IsolationInterop.GUID_SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING, InstallerIdentifier, ApplicationTrustProperty, null);
                        foreach (IDefinitionAppId defAppId in deplEnum) {
                            StoreDeploymentMetadataPropertyEnumeration metadataEnum = m_pStore.EnumInstallerDeploymentProperties(IsolationInterop.GUID_SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING, InstallerIdentifier, ApplicationTrustProperty, defAppId);
                            foreach (StoreOperationMetadataProperty appTrustProperty in metadataEnum) {
                                string appTrustXml = appTrustProperty.Value;
                                if (appTrustXml != null && appTrustXml.Length > 0) {
                                    SecurityElement seTrust = SecurityElement.FromString(appTrustXml);
                                    ApplicationTrust appTrust = new ApplicationTrust();
                                    appTrust.FromXml(seTrust);
                                    appTrusts.Add(appTrust);
                                }
                            }
                        }
                    }
                    Interlocked.CompareExchange(ref m_appTrusts, appTrusts, null);
                }
                return m_appTrusts as ArrayList;
            }
        }

        private bool m_storeBounded = false;
        private Store m_pStore = null; // Component store interface pointer.

        // Only internal constructors are exposed.
        [System.Security.SecurityCritical]  // auto-generated
        internal ApplicationTrustCollection () : this(false) {}
        internal ApplicationTrustCollection (bool storeBounded) {
            m_storeBounded = storeBounded;
        }

        [System.Security.SecurityCritical]  // auto-generated
        private void RefreshStorePointer () {
            // Refresh store pointer.
            if (m_pStore != null)
                Marshal.ReleaseComObject(m_pStore.InternalStore);
            m_pStore = IsolationInterop.GetUserStore();
        }

        public int Count
        {
            [System.Security.SecuritySafeCritical] // overrides public transparent member
            get {
                return AppTrusts.Count;
            }
        }

        public ApplicationTrust this[int index] {
            [System.Security.SecurityCritical]  // auto-generated
            get {
                return AppTrusts[index] as ApplicationTrust;
            }
        }

        public ApplicationTrust this[string appFullName] {
            [System.Security.SecurityCritical]  // auto-generated
            get {
                ApplicationIdentity identity = new ApplicationIdentity(appFullName);
                ApplicationTrustCollection appTrusts = Find(identity, ApplicationVersionMatch.MatchExactVersion);
                if (appTrusts.Count > 0)
                    return appTrusts[0];
                return null;
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        private void CommitApplicationTrust(ApplicationIdentity applicationIdentity, string trustXml) {
            StoreOperationMetadataProperty[] properties = new StoreOperationMetadataProperty[] {
                    new StoreOperationMetadataProperty(ClrPropertySet, ApplicationTrustProperty, trustXml)
                };

            IEnumDefinitionIdentity idenum = applicationIdentity.Identity.EnumAppPath();
            IDefinitionIdentity[] asbId = new IDefinitionIdentity[1];
            IDefinitionIdentity deplId = null;
            if (idenum.Next(1, asbId) == 1)
                deplId = asbId[0];

            IDefinitionAppId defAppId = IsolationInterop.AppIdAuthority.CreateDefinition();
            defAppId.SetAppPath(1, new IDefinitionIdentity[] {deplId});
            defAppId.put_Codebase(applicationIdentity.CodeBase);

            using (StoreTransaction storeTxn = new StoreTransaction()) {
                storeTxn.Add(new StoreOperationSetDeploymentMetadata(defAppId, InstallReference, properties));
                RefreshStorePointer();
                m_pStore.Transact(storeTxn.Operations);
            }

            m_appTrusts = null; // reset the app trusts in the collection.
        }

        [System.Security.SecurityCritical]  // auto-generated
        public int Add (ApplicationTrust trust) {
            if (trust == null)
                throw new ArgumentNullException("trust");
            if (trust.ApplicationIdentity == null)
                throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
            Contract.EndContractBlock();

            // Add the trust decision of the application to the fusion store.
            if (m_storeBounded) {
                CommitApplicationTrust(trust.ApplicationIdentity, trust.ToXml().ToString());
                return -1;
            } else {
                return AppTrusts.Add(trust);
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void AddRange (ApplicationTrust[] trusts) {
            if (trusts == null)
                throw new ArgumentNullException("trusts");
            Contract.EndContractBlock();

            int i=0;
            try {
                for (; i<trusts.Length; i++) {
                    Add(trusts[i]);
                }
            } catch {
                for (int j=0; j<i; j++) {
                    Remove(trusts[j]);
                }
                throw;
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void AddRange (ApplicationTrustCollection trusts) {
            if (trusts == null)
                throw new ArgumentNullException("trusts");
            Contract.EndContractBlock();

            int i = 0;
            try {
                foreach (ApplicationTrust trust in trusts) {
                    Add(trust);
                    i++;
                }
            } catch {
                for (int j=0; j<i; j++) {
                    Remove(trusts[j]);
                }
                throw;
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        public ApplicationTrustCollection Find (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch) {
            ApplicationTrustCollection collection = new ApplicationTrustCollection(false);
            foreach (ApplicationTrust trust in this) {
                if (CmsUtils.CompareIdentities(trust.ApplicationIdentity, applicationIdentity, versionMatch))
                    collection.Add(trust);
            }
            return collection;
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void Remove (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch) {
            ApplicationTrustCollection collection = Find(applicationIdentity, versionMatch);
            RemoveRange(collection);
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void Remove (ApplicationTrust trust) {
            if (trust == null)
                throw new ArgumentNullException("trust");
            if (trust.ApplicationIdentity == null)
                throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
            Contract.EndContractBlock();

            // Remove the trust decision of the application from the fusion store.
            if (m_storeBounded) {
                CommitApplicationTrust(trust.ApplicationIdentity, null);
            } else {
                AppTrusts.Remove(trust);
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void RemoveRange (ApplicationTrust[] trusts) {
            if (trusts == null)
                throw new ArgumentNullException("trusts");
            Contract.EndContractBlock();

            int i=0;
            try {
                for (; i<trusts.Length; i++) {
                    Remove(trusts[i]);
                }
            } catch {
                for (int j=0; j<i; j++) {
                    Add(trusts[j]);
                }
                throw;
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void RemoveRange (ApplicationTrustCollection trusts) {
            if (trusts == null)
                throw new ArgumentNullException("trusts");
            Contract.EndContractBlock();

            int i = 0;
            try {
                foreach (ApplicationTrust trust in trusts) {
                    Remove(trust);
                    i++;
                }
            } catch {
                for (int j=0; j<i; j++) {
                    Add(trusts[j]);
                }
                throw;
            }
        }

        [System.Security.SecurityCritical]  // auto-generated
        public void Clear() {
            // remove all trust decisions in the collection.
            ArrayList trusts = this.AppTrusts;
            if (m_storeBounded) {
                foreach (ApplicationTrust trust in trusts) {
                    if (trust.ApplicationIdentity == null)
                        throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));

                    // Remove the trust decision of the application from the fusion store.
                    CommitApplicationTrust(trust.ApplicationIdentity, null);
                }
            }
            trusts.Clear();
        }

        public ApplicationTrustEnumerator GetEnumerator() {
            return new ApplicationTrustEnumerator(this);
        }

        /// <internalonly/>
        [System.Security.SecuritySafeCritical] // overrides public transparent member
        IEnumerator IEnumerable.GetEnumerator()
        {
            return new ApplicationTrustEnumerator(this);
        }

        /// <internalonly/>
        [System.Security.SecuritySafeCritical] // overrides public transparent member
        void ICollection.CopyTo(Array array, int index) {
            if (array == null)
                throw new ArgumentNullException("array");
            if (array.Rank != 1)
                throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
            if (index < 0 || index >= array.Length)
                throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
            if (array.Length - index < this.Count)
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
            Contract.EndContractBlock();

            for (int i=0; i < this.Count; i++) {
                array.SetValue(this[i], index++);
            }
        }

        public void CopyTo (ApplicationTrust[] array, int index) {
            ((ICollection)this).CopyTo(array, index);
        }

        public bool IsSynchronized {
            [System.Security.SecuritySafeCritical] // overrides public transparent member
            get
            {
                return false;
            }
        }

        public object SyncRoot {
            [System.Security.SecuritySafeCritical] // overrides public transparent member
            get
            {
                return this;
            }
        }
    }

    [System.Runtime.InteropServices.ComVisible(true)]
    public sealed class ApplicationTrustEnumerator : IEnumerator {
        [System.Security.SecurityCritical] // auto-generated
        private ApplicationTrustCollection m_trusts;
        private int m_current;

        private ApplicationTrustEnumerator() {}
        [System.Security.SecurityCritical]  // auto-generated
        internal ApplicationTrustEnumerator(ApplicationTrustCollection trusts) {
            m_trusts = trusts;
            m_current = -1;
        }

        public ApplicationTrust Current {
            [System.Security.SecuritySafeCritical]  // auto-generated
            get {
                return m_trusts[m_current];
            }
        }

        /// <internalonly/>
        object IEnumerator.Current {
            [System.Security.SecuritySafeCritical]  // auto-generated
            get {
                return (object) m_trusts[m_current];
            }
        }

        [System.Security.SecuritySafeCritical]  // auto-generated
        public bool MoveNext() {
            if (m_current == ((int) m_trusts.Count - 1))
                return false;
            m_current++;
            return true;
        }

        public void Reset() {
            m_current = -1;
        }
    }
#endif // FEATURE_CLICKONCE    
}