public void TestDownloadCerts()
        {
            AnchorBundleDownloader downloader = new AnchorBundleDownloader();

            downloader.MaxRetries = 1;

            X509Certificate2Collection bundle = null;

            Assert.DoesNotThrow(() => bundle = downloader.DownloadCertificates(new Uri(PatientTestBundleUrl)));
            Assert.True(!bundle.IsNullOrEmpty());
        }
Example #2
0
        public void BundlesDownloadCerts(string[] args)
        {
            string owner      = args.GetRequiredValue <string>(0);
            string folderpath = args.GetRequiredValue <string>(1);

            if (!Directory.Exists(folderpath))
            {
                WriteLine("Folder not found");
                return;
            }

            AnchorBundleDownloader bundleDownloader = new AnchorBundleDownloader();

            bundleDownloader.TimeoutMS  = 30 * 1000;
            bundleDownloader.MaxRetries = 1;
            bundleDownloader.VerifySSL  = false;

            Bundle[] bundles = Client.GetBundlesForOwner(owner);
            foreach (Bundle bundle in bundles)
            {
                try
                {
                    WriteLine("Downloading ID={0}, {1}", bundle.ID, bundle.Url);
                    string bundleFolderPath = Path.Combine(folderpath, string.Format("Bundle_{0}", bundle.ID));
                    if (Directory.Exists(bundleFolderPath))
                    {
                        Directory.Delete(bundleFolderPath);
                    }
                    Directory.CreateDirectory(bundleFolderPath);

                    X509Certificate2Collection certs = bundleDownloader.DownloadCertificates(bundle.Uri);
                    foreach (X509Certificate2 cert in certs)
                    {
                        string certName = cert.ExtractEmailNameOrName();
                        WriteLine(certName);
                        string fileName = certName.ToFileName() + ".cer";
                        File.WriteAllBytes(Path.Combine(bundleFolderPath, fileName), cert.RawData);
                    }
                    WriteLine("ok");
                }
                catch (Exception ex)
                {
                    WriteLine("Error downloading bundle {0} from {1}", bundle.ID, bundle.Url);
                    WriteLine(ex.Message);
                }
            }
        }