static int Process()
{
X509CertificateCollection roots = DecodeCollection ();
if (roots == null) {
return 1;
} else if (roots.Count == 0) {
WriteLine ("No certificates were found.");
return 0;
}
X509Stores stores = userStore ? X509StoreManager.CurrentUser : X509StoreManager.LocalMachine;
X509CertificateCollection trusted = stores.TrustedRoot.Certificates;
int additions = 0;
WriteLine ("I already trust {0}, your new list has {1}", trusted.Count, roots.Count);
foreach (X509Certificate root in roots) {
if (!trusted.Contains (root)) {
try {
stores.TrustedRoot.Import (root);
WriteLine ("Certificate added: {0}", root.SubjectName);
additions++;
} catch (Exception e) {
WriteLine ("Warning: Could not import {0}", root.SubjectName);
WriteLine (e.ToString ());
}
}
}
if (additions > 0)
WriteLine ("{0} new root certificates were added to your trust store.", additions);
X509CertificateCollection removed = new X509CertificateCollection ();
foreach (X509Certificate trust in trusted) {
if (!roots.Contains (trust)) {
removed.Add (trust);
}
}
if (removed.Count > 0) {
WriteLine ("{0} previously trusted certificates were removed.", removed.Count);
foreach (X509Certificate old in removed) {
stores.TrustedRoot.Remove (old);
WriteLine ("Certificate removed: {0}", old.SubjectName);
}
}
WriteLine ("Import process completed.");
return 0;
}