/// <summary> /// Gets locally registered enrollment policy server endpoints. /// </summary> /// <param name="userContext">Specifies whether to retrieve enrollment policy server endpoints for user or machine context.</param> /// <exception cref="NotSupportedException">The operating system do not support certificate enrollment policy servers.</exception> /// <returns>An array of registered enrollment policy server endpoints.</returns> public static PolicyServerClient[] GetPolicyServers(Boolean userContext) { if (!CryptographyUtils.TestCepCompat()) { throw new NotSupportedException(); } List <PolicyServerClient> policies = new List <PolicyServerClient>(); X509CertificateEnrollmentContext context = userContext ? X509CertificateEnrollmentContext.ContextUser : X509CertificateEnrollmentContext.ContextMachine; foreach (PolicyServerUrlFlags flag in new [] { PolicyServerUrlFlags.PsfLocationGroupPolicy, PolicyServerUrlFlags.PsfLocationRegistry }) { CX509PolicyServerListManager serverManager = new CX509PolicyServerListManager(); try { serverManager.Initialize(context, flag); IEnumerator enumerator = serverManager.GetEnumerator(); do { if (enumerator.Current != null) { policies.Add(new PolicyServerClient((IX509PolicyServerUrl)enumerator.Current, userContext)); } } while (enumerator.MoveNext()); } finally { CryptographyUtils.ReleaseCom(serverManager); } } return(policies.ToArray()); }
void set_property(String propName, Object propValue) { if (FromPolicy) { return; } if (propValue == null) { return; } CX509PolicyServerListManager serverManager = new CX509PolicyServerListManager(); X509CertificateEnrollmentContext context = UserContext ? X509CertificateEnrollmentContext.ContextUser : X509CertificateEnrollmentContext.ContextMachine; try { serverManager.Initialize(context, PolicyServerUrlFlags.PsfLocationRegistry); IEnumerator enumerator = serverManager.GetEnumerator(); do { if (enumerator.Current != null) { if (((IX509PolicyServerUrl)enumerator.Current).GetStringProperty(PolicyServerUrlPropertyID.PsPolicyID) == PolicyId) { switch (propName) { case "Name": ((IX509PolicyServerUrl)enumerator.Current).SetStringProperty(PolicyServerUrlPropertyID.PsFriendlyName, (String)propValue); break; case "Priority": ((IX509PolicyServerUrl)enumerator.Current).Cost = (UInt32)propValue; break; case "Authentication": ((IX509PolicyServerUrl)enumerator.Current).AuthFlags = (X509EnrollmentAuthFlags)propValue; break; case "Flags": ((IX509PolicyServerUrl)enumerator.Current).Flags = (PolicyServerUrlFlags)propValue; break; } ((IX509PolicyServerUrl)enumerator.Current).UpdateRegistry(context); CryptographyUtils.ReleaseCom(serverManager); return; } } } while (enumerator.MoveNext()); } finally { CryptographyUtils.ReleaseCom(serverManager); } }