c93e68a367a1ab57d81322748f5ad8c1427ee431
[mono.git] / mcs / class / referencesource / mscorlib / system / security / policy / applicationtrust.cs
1 // ==++==
2 //
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 //
5 // ==--==
6 // <OWNER>Microsoft</OWNER>
7 // 
8
9 //
10 // ApplicationTrust.cs
11 //
12 // This class encapsulates security decisions about an application.
13 //
14
15 namespace System.Security.Policy {
16     using System.Collections;
17     using System.Collections.Generic;
18 #if FEATURE_CLICKONCE        
19     using System.Deployment.Internal.Isolation;
20     using System.Deployment.Internal.Isolation.Manifest;
21 #endif    
22     using System.Globalization;
23     using System.IO;
24     using System.Runtime.InteropServices;
25 #if FEATURE_SERIALIZATION
26     using System.Runtime.Serialization;
27     using System.Runtime.Serialization.Formatters.Binary;
28 #endif // FEATURE_SERIALIZATION
29     using System.Runtime.Versioning;
30     using System.Security.Permissions;
31     using System.Security.Util;
32     using System.Text;
33     using System.Threading;
34     using System.Diagnostics.Contracts;
35
36     [System.Runtime.InteropServices.ComVisible(true)]
37     public enum ApplicationVersionMatch {
38         MatchExactVersion,
39         MatchAllVersions
40     }
41
42     [System.Runtime.InteropServices.ComVisible(true)]
43     [Serializable]
44     public sealed class ApplicationTrust : EvidenceBase, ISecurityEncodable
45     {
46 #if FEATURE_CLICKONCE
47         private ApplicationIdentity m_appId;
48         private bool m_appTrustedToRun;
49         private bool m_persist;
50         
51         private object m_extraInfo;
52         private SecurityElement m_elExtraInfo;
53 #endif
54         private PolicyStatement m_psDefaultGrant;
55         private IList<StrongName> m_fullTrustAssemblies;
56
57         // Permission special flags for the default grant set in this ApplicationTrust.  This should be
58         // updated in sync with any updates to the default grant set.
59         // 
60         // In the general case, these values cannot be trusted - we only store a reference to the
61         // DefaultGrantSet, and return the reference directly, which means that code can update the
62         // permission set without our knowledge.  That would lead to the flags getting out of sync with the
63         // grant set.
64         // 
65         // However, we only care about these flags when we're creating a homogenous AppDomain, and in that
66         // case we control the ApplicationTrust object end-to-end, and know that the permission set will not
67         // change after the flags are calculated.
68         [NonSerialized]
69         private int m_grantSetSpecialFlags;
70
71 #if FEATURE_CLICKONCE        
72         public ApplicationTrust (ApplicationIdentity applicationIdentity) : this () {
73             ApplicationIdentity = applicationIdentity;
74         }
75 #endif 
76         public ApplicationTrust () : this (new PermissionSet(PermissionState.None))
77         {
78         }
79
80         internal ApplicationTrust (PermissionSet defaultGrantSet)
81         {
82             InitDefaultGrantSet(defaultGrantSet);
83
84             m_fullTrustAssemblies = new List<StrongName>().AsReadOnly();
85         }
86
87         public ApplicationTrust(PermissionSet defaultGrantSet, IEnumerable<StrongName> fullTrustAssemblies) {
88             if (fullTrustAssemblies == null) {
89                 throw new ArgumentNullException("fullTrustAssemblies");
90             }
91
92             InitDefaultGrantSet(defaultGrantSet);
93
94             List<StrongName> fullTrustList = new List<StrongName>();
95             foreach (StrongName strongName in fullTrustAssemblies) {
96                 if (strongName == null) {
97                     throw new ArgumentException(Environment.GetResourceString("Argument_NullFullTrustAssembly"));
98                 }
99
100                 fullTrustList.Add(new StrongName(strongName.PublicKey, strongName.Name, strongName.Version));
101             }
102
103             m_fullTrustAssemblies = fullTrustList.AsReadOnly();
104         }
105
106         // Sets up the default grant set for all constructors. Extracted to avoid the cost of
107         // IEnumerable virtual dispatches on startup when there are no fullTrustAssemblies (CoreCLR)
108         private void InitDefaultGrantSet(PermissionSet defaultGrantSet) {
109             if (defaultGrantSet == null) {
110                 throw new ArgumentNullException("defaultGrantSet");
111             }
112
113             // Creating a PolicyStatement copies the incoming permission set, so we don't have to worry
114             // about the PermissionSet parameter changing underneath us after we've calculated the
115             // permisison flags in the DefaultGrantSet setter.
116             DefaultGrantSet = new PolicyStatement(defaultGrantSet);
117         }
118
119 #if FEATURE_CLICKONCE        
120         public ApplicationIdentity ApplicationIdentity {
121             get {
122                 return m_appId;
123             }
124             set {
125                 if (value == null)
126                     throw new ArgumentNullException(Environment.GetResourceString("Argument_InvalidAppId"));
127                 Contract.EndContractBlock();
128                 m_appId = value;
129             }
130         }
131 #endif
132         public PolicyStatement DefaultGrantSet {
133             get {
134                 if (m_psDefaultGrant == null)
135                     return new PolicyStatement(new PermissionSet(PermissionState.None));
136                 return m_psDefaultGrant;
137             }
138             set {
139                 if (value == null) {
140                     m_psDefaultGrant = null;
141                     m_grantSetSpecialFlags = 0;
142                 }
143                 else {
144                     m_psDefaultGrant = value;
145                     m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(m_psDefaultGrant.PermissionSet, null);
146                 }
147             }
148         }
149
150         public IList<StrongName> FullTrustAssemblies {
151             get {
152                 return m_fullTrustAssemblies;
153             }
154         }
155 #if FEATURE_CLICKONCE        
156         public bool IsApplicationTrustedToRun {
157             get {
158                 return m_appTrustedToRun;
159             }
160             set {
161                 m_appTrustedToRun = value;
162             }
163         }
164
165         public bool Persist {
166             get {
167                 return m_persist;
168             }
169             set {
170                 m_persist = value;
171             }
172         }
173
174          public object ExtraInfo {
175             get {
176                 if (m_elExtraInfo != null) {
177                     m_extraInfo = ObjectFromXml(m_elExtraInfo);
178                     m_elExtraInfo = null;
179                 }
180                 return m_extraInfo;
181             }
182             set {
183                 m_elExtraInfo = null;
184                 m_extraInfo = value;
185             }
186         }
187 #endif //FEATURE_CLICKONCE
188
189 #if FEATURE_CAS_POLICY
190         public SecurityElement ToXml () {
191             SecurityElement elRoot = new SecurityElement("ApplicationTrust");
192             elRoot.AddAttribute("version", "1");
193
194 #if FEATURE_CLICKONCE
195             if (m_appId != null) {
196                 elRoot.AddAttribute("FullName", SecurityElement.Escape(m_appId.FullName));
197             }
198             if (m_appTrustedToRun) {
199                 elRoot.AddAttribute("TrustedToRun", "true");
200             }
201             if (m_persist) {
202                 elRoot.AddAttribute("Persist", "true");
203             }
204 #endif // FEATURE_CLICKONCE
205  
206             if (m_psDefaultGrant != null) {
207                 SecurityElement elDefaultGrant = new SecurityElement("DefaultGrant");
208                 elDefaultGrant.AddChild(m_psDefaultGrant.ToXml());
209                 elRoot.AddChild(elDefaultGrant);
210             }
211             if (m_fullTrustAssemblies.Count > 0) {
212                 SecurityElement elFullTrustAssemblies = new SecurityElement("FullTrustAssemblies");
213                 foreach (StrongName fullTrustAssembly in m_fullTrustAssemblies) {
214                     elFullTrustAssemblies.AddChild(fullTrustAssembly.ToXml());
215                 }
216                 elRoot.AddChild(elFullTrustAssemblies);
217             }
218
219 #if FEATURE_CLICKONCE
220             if (ExtraInfo != null) {
221                 elRoot.AddChild(ObjectToXml("ExtraInfo", ExtraInfo));
222             }
223 #endif // FEATURE_CLICKONCE
224             return elRoot;
225         }
226
227         public void FromXml (SecurityElement element) {
228             if (element == null)
229                 throw new ArgumentNullException("element");
230             if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
231                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
232
233 #if FEATURE_CLICKONCE
234             m_appTrustedToRun = false;
235             string isAppTrustedToRun = element.Attribute("TrustedToRun");
236             if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) {
237                 m_appTrustedToRun = true;
238             }
239
240             m_persist = false;
241             string persist = element.Attribute("Persist");
242             if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) {
243                 m_persist = true;
244             }
245
246             m_appId = null;
247             string fullName = element.Attribute("FullName");
248             if (fullName != null && fullName.Length > 0) {
249                 m_appId = new ApplicationIdentity(fullName);
250             }
251 #endif // FEATURE_CLICKONCE
252
253             m_psDefaultGrant = null;
254             m_grantSetSpecialFlags = 0;
255             SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
256             if (elDefaultGrant != null) {
257                 SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
258                 if (elDefaultGrantPS != null) {
259                     PolicyStatement ps = new PolicyStatement(null);
260                     ps.FromXml(elDefaultGrantPS);
261                     m_psDefaultGrant = ps;
262                     m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
263                 }
264             }
265
266             List<StrongName> fullTrustAssemblies = new List<StrongName>();
267             SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
268             if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) {
269                 IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
270                 while (enumerator.MoveNext()) {
271                     StrongName fullTrustAssembly = new StrongName();
272                     fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
273                     fullTrustAssemblies.Add(fullTrustAssembly);
274                 }
275             }
276
277             m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly();
278
279 #if FEATURE_CLICKONCE
280             m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
281 #endif // FEATURE_CLICKONCE
282         }
283
284 #if FEATURE_CLICKONCE
285         private static SecurityElement ObjectToXml (string tag, Object obj) {
286             BCLDebug.Assert(obj != null, "You need to pass in an object");
287
288             ISecurityEncodable encodableObj = obj as ISecurityEncodable;
289
290             SecurityElement elObject;
291             if (encodableObj != null) {
292                 elObject = encodableObj.ToXml();
293                 if (!elObject.Tag.Equals(tag))
294                     throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
295             }
296
297             MemoryStream stream = new MemoryStream();
298             BinaryFormatter formatter = new BinaryFormatter();
299             formatter.Serialize(stream, obj);
300             byte[] array = stream.ToArray();
301
302             elObject = new SecurityElement(tag);
303             elObject.AddAttribute("Data", Hex.EncodeHexString(array));
304             return elObject;
305         }
306
307         private static Object ObjectFromXml (SecurityElement elObject) {
308             BCLDebug.Assert(elObject != null, "You need to pass in a security element");
309
310             if (elObject.Attribute("class") != null) {
311                 ISecurityEncodable encodableObj = XMLUtil.CreateCodeGroup(elObject) as ISecurityEncodable;
312                 if (encodableObj != null) {
313                     encodableObj.FromXml(elObject);
314                     return encodableObj;
315                 }
316             }
317
318             string objectData = elObject.Attribute("Data");
319             MemoryStream stream = new MemoryStream(Hex.DecodeHexString(objectData));
320             BinaryFormatter formatter = new BinaryFormatter();
321             return formatter.Deserialize(stream);
322         }
323 #endif // FEATURE_CLICKONCE
324 #endif // FEATURE_CAS_POLICY
325
326 #pragma warning disable 618
327         [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
328 #pragma warning restore 618
329         [SecuritySafeCritical]
330         public override EvidenceBase Clone()
331         {
332             return base.Clone();
333         }
334     }
335
336 #if FEATURE_CLICKONCE
337     [System.Security.SecurityCritical]  // auto-generated_required
338     [System.Runtime.InteropServices.ComVisible(true)]
339     public sealed class ApplicationTrustCollection : ICollection {
340         private const string ApplicationTrustProperty = "ApplicationTrust";
341         private const string InstallerIdentifier = "{60051b8f-4f12-400a-8e50-dd05ebd438d1}";
342         private static Guid ClrPropertySet = new Guid("c989bb7a-8385-4715-98cf-a741a8edb823");
343
344         // The CLR specific constant install reference.
345         private static object s_installReference = null;
346         private static StoreApplicationReference InstallReference {
347             get {
348                 if (s_installReference == null) {
349                     Interlocked.CompareExchange(ref s_installReference,
350                                                 new StoreApplicationReference(
351                                                     IsolationInterop.GUID_SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING,
352                                                     InstallerIdentifier,
353                                                     null),
354                                                 null);
355                 }
356                 return (StoreApplicationReference) s_installReference;
357             }
358         }
359
360         private object m_appTrusts = null;
361         private ArrayList AppTrusts {
362             [System.Security.SecurityCritical]  // auto-generated
363             get {
364                 if (m_appTrusts == null) {
365                     ArrayList appTrusts = new ArrayList();
366                     if (m_storeBounded) {
367                         RefreshStorePointer();
368                         // enumerate the user store and populate the collection
369                         StoreDeploymentMetadataEnumeration deplEnum = m_pStore.EnumInstallerDeployments(IsolationInterop.GUID_SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING, InstallerIdentifier, ApplicationTrustProperty, null);
370                         foreach (IDefinitionAppId defAppId in deplEnum) {
371                             StoreDeploymentMetadataPropertyEnumeration metadataEnum = m_pStore.EnumInstallerDeploymentProperties(IsolationInterop.GUID_SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING, InstallerIdentifier, ApplicationTrustProperty, defAppId);
372                             foreach (StoreOperationMetadataProperty appTrustProperty in metadataEnum) {
373                                 string appTrustXml = appTrustProperty.Value;
374                                 if (appTrustXml != null && appTrustXml.Length > 0) {
375                                     SecurityElement seTrust = SecurityElement.FromString(appTrustXml);
376                                     ApplicationTrust appTrust = new ApplicationTrust();
377                                     appTrust.FromXml(seTrust);
378                                     appTrusts.Add(appTrust);
379                                 }
380                             }
381                         }
382                     }
383                     Interlocked.CompareExchange(ref m_appTrusts, appTrusts, null);
384                 }
385                 return m_appTrusts as ArrayList;
386             }
387         }
388
389         private bool m_storeBounded = false;
390         private Store m_pStore = null; // Component store interface pointer.
391
392         // Only internal constructors are exposed.
393         [System.Security.SecurityCritical]  // auto-generated
394         internal ApplicationTrustCollection () : this(false) {}
395         internal ApplicationTrustCollection (bool storeBounded) {
396             m_storeBounded = storeBounded;
397         }
398
399         [System.Security.SecurityCritical]  // auto-generated
400         private void RefreshStorePointer () {
401             // Refresh store pointer.
402             if (m_pStore != null)
403                 Marshal.ReleaseComObject(m_pStore.InternalStore);
404             m_pStore = IsolationInterop.GetUserStore();
405         }
406
407         public int Count
408         {
409             [System.Security.SecuritySafeCritical] // overrides public transparent member
410             get {
411                 return AppTrusts.Count;
412             }
413         }
414
415         public ApplicationTrust this[int index] {
416             [System.Security.SecurityCritical]  // auto-generated
417             get {
418                 return AppTrusts[index] as ApplicationTrust;
419             }
420         }
421
422         public ApplicationTrust this[string appFullName] {
423             [System.Security.SecurityCritical]  // auto-generated
424             get {
425                 ApplicationIdentity identity = new ApplicationIdentity(appFullName);
426                 ApplicationTrustCollection appTrusts = Find(identity, ApplicationVersionMatch.MatchExactVersion);
427                 if (appTrusts.Count > 0)
428                     return appTrusts[0];
429                 return null;
430             }
431         }
432
433         [System.Security.SecurityCritical]  // auto-generated
434         [ResourceExposure(ResourceScope.None)]
435         [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
436         private void CommitApplicationTrust(ApplicationIdentity applicationIdentity, string trustXml) {
437             StoreOperationMetadataProperty[] properties = new StoreOperationMetadataProperty[] {
438                     new StoreOperationMetadataProperty(ClrPropertySet, ApplicationTrustProperty, trustXml)
439                 };
440
441             IEnumDefinitionIdentity idenum = applicationIdentity.Identity.EnumAppPath();
442             IDefinitionIdentity[] asbId = new IDefinitionIdentity[1];
443             IDefinitionIdentity deplId = null;
444             if (idenum.Next(1, asbId) == 1)
445                 deplId = asbId[0];
446
447             IDefinitionAppId defAppId = IsolationInterop.AppIdAuthority.CreateDefinition();
448             defAppId.SetAppPath(1, new IDefinitionIdentity[] {deplId});
449             defAppId.put_Codebase(applicationIdentity.CodeBase);
450
451             using (StoreTransaction storeTxn = new StoreTransaction()) {
452                 storeTxn.Add(new StoreOperationSetDeploymentMetadata(defAppId, InstallReference, properties));
453                 RefreshStorePointer();
454                 m_pStore.Transact(storeTxn.Operations);
455             }
456
457             m_appTrusts = null; // reset the app trusts in the collection.
458         }
459
460         [System.Security.SecurityCritical]  // auto-generated
461         public int Add (ApplicationTrust trust) {
462             if (trust == null)
463                 throw new ArgumentNullException("trust");
464             if (trust.ApplicationIdentity == null)
465                 throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
466             Contract.EndContractBlock();
467
468             // Add the trust decision of the application to the fusion store.
469             if (m_storeBounded) {
470                 CommitApplicationTrust(trust.ApplicationIdentity, trust.ToXml().ToString());
471                 return -1;
472             } else {
473                 return AppTrusts.Add(trust);
474             }
475         }
476
477         [System.Security.SecurityCritical]  // auto-generated
478         public void AddRange (ApplicationTrust[] trusts) {
479             if (trusts == null)
480                 throw new ArgumentNullException("trusts");
481             Contract.EndContractBlock();
482
483             int i=0;
484             try {
485                 for (; i<trusts.Length; i++) {
486                     Add(trusts[i]);
487                 }
488             } catch {
489                 for (int j=0; j<i; j++) {
490                     Remove(trusts[j]);
491                 }
492                 throw;
493             }
494         }
495
496         [System.Security.SecurityCritical]  // auto-generated
497         public void AddRange (ApplicationTrustCollection trusts) {
498             if (trusts == null)
499                 throw new ArgumentNullException("trusts");
500             Contract.EndContractBlock();
501
502             int i = 0;
503             try {
504                 foreach (ApplicationTrust trust in trusts) {
505                     Add(trust);
506                     i++;
507                 }
508             } catch {
509                 for (int j=0; j<i; j++) {
510                     Remove(trusts[j]);
511                 }
512                 throw;
513             }
514         }
515
516         [System.Security.SecurityCritical]  // auto-generated
517         public ApplicationTrustCollection Find (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch) {
518             ApplicationTrustCollection collection = new ApplicationTrustCollection(false);
519             foreach (ApplicationTrust trust in this) {
520                 if (CmsUtils.CompareIdentities(trust.ApplicationIdentity, applicationIdentity, versionMatch))
521                     collection.Add(trust);
522             }
523             return collection;
524         }
525
526         [System.Security.SecurityCritical]  // auto-generated
527         public void Remove (ApplicationIdentity applicationIdentity, ApplicationVersionMatch versionMatch) {
528             ApplicationTrustCollection collection = Find(applicationIdentity, versionMatch);
529             RemoveRange(collection);
530         }
531
532         [System.Security.SecurityCritical]  // auto-generated
533         public void Remove (ApplicationTrust trust) {
534             if (trust == null)
535                 throw new ArgumentNullException("trust");
536             if (trust.ApplicationIdentity == null)
537                 throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
538             Contract.EndContractBlock();
539
540             // Remove the trust decision of the application from the fusion store.
541             if (m_storeBounded) {
542                 CommitApplicationTrust(trust.ApplicationIdentity, null);
543             } else {
544                 AppTrusts.Remove(trust);
545             }
546         }
547
548         [System.Security.SecurityCritical]  // auto-generated
549         public void RemoveRange (ApplicationTrust[] trusts) {
550             if (trusts == null)
551                 throw new ArgumentNullException("trusts");
552             Contract.EndContractBlock();
553
554             int i=0;
555             try {
556                 for (; i<trusts.Length; i++) {
557                     Remove(trusts[i]);
558                 }
559             } catch {
560                 for (int j=0; j<i; j++) {
561                     Add(trusts[j]);
562                 }
563                 throw;
564             }
565         }
566
567         [System.Security.SecurityCritical]  // auto-generated
568         public void RemoveRange (ApplicationTrustCollection trusts) {
569             if (trusts == null)
570                 throw new ArgumentNullException("trusts");
571             Contract.EndContractBlock();
572
573             int i = 0;
574             try {
575                 foreach (ApplicationTrust trust in trusts) {
576                     Remove(trust);
577                     i++;
578                 }
579             } catch {
580                 for (int j=0; j<i; j++) {
581                     Add(trusts[j]);
582                 }
583                 throw;
584             }
585         }
586
587         [System.Security.SecurityCritical]  // auto-generated
588         public void Clear() {
589             // remove all trust decisions in the collection.
590             ArrayList trusts = this.AppTrusts;
591             if (m_storeBounded) {
592                 foreach (ApplicationTrust trust in trusts) {
593                     if (trust.ApplicationIdentity == null)
594                         throw new ArgumentException(Environment.GetResourceString("Argument_ApplicationTrustShouldHaveIdentity"));
595
596                     // Remove the trust decision of the application from the fusion store.
597                     CommitApplicationTrust(trust.ApplicationIdentity, null);
598                 }
599             }
600             trusts.Clear();
601         }
602
603         public ApplicationTrustEnumerator GetEnumerator() {
604             return new ApplicationTrustEnumerator(this);
605         }
606
607         /// <internalonly/>
608         [System.Security.SecuritySafeCritical] // overrides public transparent member
609         IEnumerator IEnumerable.GetEnumerator()
610         {
611             return new ApplicationTrustEnumerator(this);
612         }
613
614         /// <internalonly/>
615         [System.Security.SecuritySafeCritical] // overrides public transparent member
616         void ICollection.CopyTo(Array array, int index) {
617             if (array == null)
618                 throw new ArgumentNullException("array");
619             if (array.Rank != 1)
620                 throw new ArgumentException(Environment.GetResourceString("Arg_RankMultiDimNotSupported"));
621             if (index < 0 || index >= array.Length)
622                 throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));
623             if (array.Length - index < this.Count)
624                 throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
625             Contract.EndContractBlock();
626
627             for (int i=0; i < this.Count; i++) {
628                 array.SetValue(this[i], index++);
629             }
630         }
631
632         public void CopyTo (ApplicationTrust[] array, int index) {
633             ((ICollection)this).CopyTo(array, index);
634         }
635
636         public bool IsSynchronized {
637             [System.Security.SecuritySafeCritical] // overrides public transparent member
638             get
639             {
640                 return false;
641             }
642         }
643
644         public object SyncRoot {
645             [System.Security.SecuritySafeCritical] // overrides public transparent member
646             get
647             {
648                 return this;
649             }
650         }
651     }
652
653     [System.Runtime.InteropServices.ComVisible(true)]
654     public sealed class ApplicationTrustEnumerator : IEnumerator {
655         [System.Security.SecurityCritical] // auto-generated
656         private ApplicationTrustCollection m_trusts;
657         private int m_current;
658
659         private ApplicationTrustEnumerator() {}
660         [System.Security.SecurityCritical]  // auto-generated
661         internal ApplicationTrustEnumerator(ApplicationTrustCollection trusts) {
662             m_trusts = trusts;
663             m_current = -1;
664         }
665
666         public ApplicationTrust Current {
667             [System.Security.SecuritySafeCritical]  // auto-generated
668             get {
669                 return m_trusts[m_current];
670             }
671         }
672
673         /// <internalonly/>
674         object IEnumerator.Current {
675             [System.Security.SecuritySafeCritical]  // auto-generated
676             get {
677                 return (object) m_trusts[m_current];
678             }
679         }
680
681         [System.Security.SecuritySafeCritical]  // auto-generated
682         public bool MoveNext() {
683             if (m_current == ((int) m_trusts.Count - 1))
684                 return false;
685             m_current++;
686             return true;
687         }
688
689         public void Reset() {
690             m_current = -1;
691         }
692     }
693 #endif // FEATURE_CLICKONCE    
694 }