[btls] Remove btls-cert-sync and integrate it into cert-sync
[mono.git] / mcs / tools / security / cert-sync.cs
index 56797562e50592fbcf07f610d2bc5b2eed162755..b7b77f8f7660c78044a0fce67e6a2255a356946e 100644 (file)
@@ -1,5 +1,5 @@
 //
-// cert-sync.cs: Import the root certificates from Linux SSL store into Mono
+// cert-sync.cs: Import the root certificates from a certificate store into Mono
 //
 // Authors:
 //     Sebastien Pouliot <sebastien@ximian.com>
@@ -38,8 +38,8 @@ using System.Text;
 
 using Mono.Security.X509;
 
-[assembly: AssemblyTitle ("Linux Cert Store Sync")]
-[assembly: AssemblyDescription ("Synchronize local certs with certs from local Linux trust store.")]
+[assembly: AssemblyTitle ("Mono Certificate Store Sync")]
+[assembly: AssemblyDescription ("Populate Mono certificate store from a concatenated list of certificates.")]
 
 namespace Mono.Tools
 {
@@ -50,7 +50,6 @@ namespace Mono.Tools
                static string inputFile;
                static bool quiet;
                static bool userStore;
-               static bool btlsStore = false;
 
                static X509Certificate DecodeCertificate (string s)
                {
@@ -116,13 +115,26 @@ namespace Mono.Tools
                                WriteLine ("No certificates were found.");
                                return 0;
                        }
-                               
-                       X509Stores stores;
-                       if (userStore)
-                               stores = btlsStore ? X509StoreManager.NewCurrentUser : X509StoreManager.CurrentUser;
-                       else
-                               stores = btlsStore ? X509StoreManager.NewLocalMachine : X509StoreManager.LocalMachine;
-                       X509Store store = stores.TrustedRoot;
+
+                       if (userStore) {
+                               WriteLine ("Importing into legacy user store:");
+                               ImportToStore (roots, X509StoreManager.CurrentUser.TrustedRoot);
+                               WriteLine ("");
+                               WriteLine ("Importing into BTLS user store:");
+                               ImportToStore (roots, X509StoreManager.NewCurrentUser.TrustedRoot);
+                       } else {
+                               WriteLine ("Importing into legacy system store:");
+                               ImportToStore (roots, X509StoreManager.LocalMachine.TrustedRoot);
+                               WriteLine ("");
+                               WriteLine ("Importing into BTLS system store:");
+                               ImportToStore (roots, X509StoreManager.NewLocalMachine.TrustedRoot);
+                       }
+
+                       return 0;
+               }
+
+               static void ImportToStore (X509CertificateCollection roots, X509Store store)
+               {
                        X509CertificateCollection trusted = store.Certificates;
                        int additions = 0;
                        WriteLine ("I already trust {0}, your new list has {1}", trusted.Count, roots.Count);
@@ -156,7 +168,6 @@ namespace Mono.Tools
                                }
                        }
                        WriteLine ("Import process completed.");
-                       return 0;
                }
 
                static string Thumbprint (string algorithm, X509Certificate certificate)
@@ -179,8 +190,7 @@ namespace Mono.Tools
                                case "--user":
                                        userStore = true;
                                        break;
-                               case "--btls":
-                                       btlsStore = true;
+                               case "--btls": // we always import to the btls store too now, keep for compat
                                        break;
                                default:
                                        WriteLine ("Unknown option '{0}'.", args[i]);