Ejemplo n.º 1
0
 public static void Serialize(string filename, ClearCanvasManifest manifest)
 {
     using (FileStream fs = new FileStream(filename, FileMode.CreateNew))
     {
         Serialize(fs, manifest);
         fs.Close();
     }
 }
Ejemplo n.º 2
0
 public static void Serialize(string filename, ClearCanvasManifest manifest)
 {
     using (FileStream fs = new FileStream(filename, FileMode.CreateNew))
     {
         Serialize(fs, manifest);
         fs.Close();
     }
 }
Ejemplo n.º 3
0
        private void LoadReferencedProduct()
        {
            ClearCanvasManifest input = ClearCanvasManifest.Deserialize(_cmdLine.ProductManifest);

            _manifest.PackageManifest.Package.Product.Name      = input.ProductManifest.Product.Name;
            _manifest.PackageManifest.Package.Product.Suffix    = input.ProductManifest.Product.Suffix;
            _manifest.PackageManifest.Package.Product.Version   = input.ProductManifest.Product.Version;
            _manifest.PackageManifest.Package.Product.Component = input.ProductManifest.Product.Component;
            _manifest.PackageManifest.Package.Product.Edition   = input.ProductManifest.Product.Edition;
        }
Ejemplo n.º 4
0
        public static ClearCanvasManifest Deserialize(string filename)
        {
            XmlSerializer theSerializer = new XmlSerializer(typeof(ClearCanvasManifest));

            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                ClearCanvasManifest input = (ClearCanvasManifest)theSerializer.Deserialize(fs);

                return(input);
            }
        }
Ejemplo n.º 5
0
        public static XmlDocument Serialize(ClearCanvasManifest manifest)
        {
            using (MemoryStream fs = new MemoryStream())
            {
                Serialize(fs, manifest);

                fs.Seek(0, SeekOrigin.Begin);
                fs.Flush();

                XmlDocument doc = new XmlDocument();
                doc.Load(fs);
                return doc;
            }
        }
Ejemplo n.º 6
0
        public static XmlDocument Serialize(ClearCanvasManifest manifest)
        {
            using (MemoryStream fs = new MemoryStream())
            {
                Serialize(fs, manifest);

                fs.Seek(0, SeekOrigin.Begin);
                fs.Flush();

                XmlDocument doc = new XmlDocument();
                doc.Load(fs);
                return(doc);
            }
        }
Ejemplo n.º 7
0
        public static void Serialize(Stream stream, ClearCanvasManifest manifest)
        {
            XmlSerializer theSerializer = new XmlSerializer(typeof (ClearCanvasManifest));

            XmlWriterSettings settings = new XmlWriterSettings
                                             {
                                                 Indent = true,
                                                 IndentChars = "  ",
                                                 Encoding = Encoding.UTF8,
                                             };

            XmlWriter writer = XmlWriter.Create(stream, settings);
            if (writer != null)
                theSerializer.Serialize(writer, manifest);
            stream.Flush();
        }
Ejemplo n.º 8
0
        public static void Serialize(Stream stream, ClearCanvasManifest manifest)
        {
            XmlSerializer theSerializer = new XmlSerializer(typeof(ClearCanvasManifest));

            XmlWriterSettings settings = new XmlWriterSettings
            {
                Indent      = true,
                IndentChars = "  ",
                Encoding    = Encoding.UTF8,
            };

            XmlWriter writer = XmlWriter.Create(stream, settings);

            if (writer != null)
            {
                theSerializer.Serialize(writer, manifest);
            }
            stream.Flush();
        }
Ejemplo n.º 9
0
        private void LoadManifestFiles(out Exception delayedException)
        {
            List <string> files = new List <string>();

            FileProcessor.Process(Platform.ManifestDirectory, null,
                                  delegate(string filePath, out bool cancel)
            {
                files.Add(filePath);
                cancel = false;
            }, true);

            List <ClearCanvasManifest> manifests = new List <ClearCanvasManifest>();

            bool foundManifest = false;

            delayedException = null;
            foreach (string file in files)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();

                    // must open stream manually in case file is read-only
                    using (var fileStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        doc.Load(fileStream);
                    }

                    XmlElement modulusNode =
                        (XmlElement)CollectionUtils.FirstElement(doc.GetElementsByTagName("Modulus"));
                    XmlElement exponentNode =
                        (XmlElement)CollectionUtils.FirstElement(doc.GetElementsByTagName("Exponent"));

                    // delay these exceptions until after verifying contents of manifest, in order to make manifests easier to debug
                    if (!modulusNode.InnerText.Equals("gRuWfDdo9ZCQ9G4hIt6amEgr1DBPDltP0NoBQI/GpooT6hGh6UkFRpaYQMt4ijxbHI5UDGZvAU66Vjt+FUcRVJ4I8AAuhyI4mU2BIzsfpUsKjxJMNdh3fxjaAOjMc4s5pX0CUvCJuZEhY/+PY/aYnjX2a6wes3nGHTx/YJhh42M="))
                    {
                        delayedException = new ApplicationException("Invalid public key in digital signature.");
                    }
                    else if (!exponentNode.InnerText.Equals("AQAB"))
                    {
                        delayedException = new ApplicationException("Invalid public key in digital signature.");
                    }

                    if (!ManifestSignature.VerifyXmlSignature(doc))
                    {
                        throw new ApplicationException("Manifest digital signature failed verification.");
                    }

                    ClearCanvasManifest manifest = ClearCanvasManifest.Deserialize(file);

                    if (manifest.ProductManifest != null)
                    {
                        if (string.IsNullOrEmpty(manifest.ProductManifest.Product.Version))
                        {
                            // The ClearCanvas.Common.ProductInformation class uses the
                            // clearcanvas.common.dll version if a version is not contained in
                            // the ProductSettings.
                            foreach (ManifestFile manFile in manifest.ProductManifest.Files)
                            {
                                if (manFile.Filename.ToLower().Equals("common\\clearcanvas.common.dll"))
                                {
                                    manifest.ProductManifest.Product.Version = manFile.Version;
                                }
                            }
                        }
                        foundManifest = true;
                        if (!manifest.ProductManifest.Product.Manifest.Equals("Manifest.xml"))
                        {
                            throw new ApplicationException("Product manifest not named Manifest.xml");
                        }

                        _productManifest = manifest;

                        if (!manifest.ProductManifest.Product.Manifest.Equals(Path.GetFileName(file)))
                        {
                            throw new ApplicationException("Manifest name does not match manifest: " +
                                                           Path.GetFileName(file));
                        }
                    }
                    else if (manifest.PackageManifest != null)
                    {
                        if (!manifest.PackageManifest.Package.Manifest.Equals(Path.GetFileName(file)))
                        {
                            throw new ApplicationException("Package Manifest name does not match manifest: " +
                                                           Path.GetFileName(file));
                        }
                    }

                    manifests.Add(manifest);
                }
                catch (Exception e)
                {
                    throw new ApplicationException("Unexpected problem parsing manifest: " + e.Message + " (" + Path.GetFileName(file) + ")");
                }
            }

            if (!foundManifest)
            {
                throw new ApplicationException("Unable to find Manifest.xml");
            }

            _manifests = manifests.ToArray();
        }
Ejemplo n.º 10
0
        public void RunApplication(string[] args)
        {
            try
            {
                _cmdLine.Parse(args);

                List <ManifestInput> list = new List <ManifestInput>();
                foreach (string filename in _cmdLine.Positional)
                {
                    string[] files = filename.Split(new[] { ';' });
                    foreach (string f in files)
                    {
                        list.Add(ManifestInput.Deserialize(f));
                    }
                }

                if (_cmdLine.Package)
                {
                    if (string.IsNullOrEmpty(_cmdLine.ProductManifest))
                    {
                        throw new ApplicationException("ProductManifest not specified on the command line");
                    }

                    if (string.IsNullOrEmpty(_cmdLine.PackageName))
                    {
                        throw new ApplicationException("PackageName not specified on the command line");
                    }

                    _manifest.PackageManifest = new PackageManifest
                    {
                        Package = new Package()
                    };
                    _manifest.PackageManifest.Package.Manifest = _cmdLine.Manifest;
                    _manifest.PackageManifest.Package.Name     = _cmdLine.PackageName;
                    _manifest.PackageManifest.Package.Product  = new Product
                    {
                        Name = string.Empty
                    };
                    LoadReferencedProduct();
                }
                else
                {
                    _manifest.ProductManifest = new ProductManifest
                    {
                        Product = new Product()
                    };
                    _manifest.ProductManifest.Product.Manifest = _cmdLine.Manifest;
                }

                ProcessFiles(list);

                ProcessConfiguration(list);

                //TODO: get rid of "manifest" constant  Derive from Platform.ManifestDirectory
                string manifestPath = Path.Combine(_cmdLine.DistributionDirectory, "manifest");
                manifestPath = Path.Combine(manifestPath, _cmdLine.Manifest);

                if (File.Exists(manifestPath))
                {
                    File.Delete(manifestPath);
                }

                XmlDocument doc = ClearCanvasManifest.Serialize(_manifest);

                // Generate a signing key.
                RSACryptoServiceProvider rsaCsp;
                if (string.IsNullOrEmpty(_cmdLine.Certificate))
                {
                    rsaCsp = new RSACryptoServiceProvider(2048);
                }
                else
                {
                    X509Certificate2 certificate = new X509Certificate2(_cmdLine.Certificate, _cmdLine.Password ?? string.Empty);
                    rsaCsp = (RSACryptoServiceProvider)certificate.PrivateKey;
                }

                ManifestSignature.SignXmlFile(doc, manifestPath, rsaCsp);
                Environment.ExitCode = 0;
            }
            catch (CommandLineException e)
            {
                Platform.Log(LogLevel.Error, e, "Command line exception when generating manifest.");
                Console.WriteLine(e.Message);
                _cmdLine.PrintUsage(Console.Out);
                Environment.ExitCode = -1;
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when generating manifest.");
                string message    = String.Format("Unexpected exception when generating manifest: {0}", e.Message);
                string stackTrace = e.StackTrace;
                Console.WriteLine(message);
                Console.WriteLine(stackTrace);
                Environment.ExitCode = -1;
            }
        }
Ejemplo n.º 11
0
        private void LoadManifestFiles()
        {
            List<string> files = new List<string>();
            FileProcessor.Process(Platform.ManifestDirectory, null,
                                    delegate(string filePath, out bool cancel)
                                        {
                                            files.Add(filePath);
                                            cancel = false;
                                        }, true);

            List<ClearCanvasManifest> manifests = new List<ClearCanvasManifest>();

            bool foundManifest = false;

            foreach (string file in files)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();

                    // must open stream manually in case file is read-only
                    using (var fileStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        doc.Load(fileStream);
                    }

                    XmlElement modulusNode =
                        (XmlElement) CollectionUtils.FirstElement(doc.GetElementsByTagName("Modulus"));
                    XmlElement exponentNode =
                        (XmlElement) CollectionUtils.FirstElement(doc.GetElementsByTagName("Exponent"));

                    if (!modulusNode.InnerText.Equals("gRuWfDdo9ZCQ9G4hIt6amEgr1DBPDltP0NoBQI/GpooT6hGh6UkFRpaYQMt4ijxbHI5UDGZvAU66Vjt+FUcRVJ4I8AAuhyI4mU2BIzsfpUsKjxJMNdh3fxjaAOjMc4s5pX0CUvCJuZEhY/+PY/aYnjX2a6wes3nGHTx/YJhh42M="))
                        throw new ApplicationException("Invalid public key in digitial signature.");
                    if (!exponentNode.InnerText.Equals("AQAB"))
                        throw new ApplicationException("Invalid public key in digitial signature.");

                    if (!ManifestSignature.VerifyXmlSignature(doc))
                        throw new ApplicationException("Manifest digital signature failed verification.");

                    ClearCanvasManifest manifest = ClearCanvasManifest.Deserialize(file);

                    if (manifest.ProductManifest != null)
                    {
                        if (string.IsNullOrEmpty(manifest.ProductManifest.Product.Version))
                        {
                            // The ClearCanvas.Common.ProductInformation class uses the 
                            // clearcanvas.common.dll version if a version is not contained in
                            // the ProductSettings.
                            foreach (ManifestFile manFile in manifest.ProductManifest.Files)
                                if (manFile.Filename.ToLower().Equals("common\\clearcanvas.common.dll"))
                                    manifest.ProductManifest.Product.Version = manFile.Version;                            
                        }
                        foundManifest = true;
                        if (!manifest.ProductManifest.Product.Manifest.Equals("Manifest.xml"))
                            throw new ApplicationException("Product manifest not named Manifest.xml");

                        _productManifest = manifest;

                        if (!manifest.ProductManifest.Product.Manifest.Equals(Path.GetFileName(file)))
                            throw new ApplicationException("Manifest name does not match manifest: " +
                                                           Path.GetFileName(file));
                    }
                    else if (manifest.PackageManifest != null)
                    {
                        if (!manifest.PackageManifest.Package.Manifest.Equals(Path.GetFileName(file)))
                            throw new ApplicationException("Package Manifest name does not match manifest: " +
                                                           Path.GetFileName(file));
                    }
        
                    manifests.Add(manifest);
                }
                catch (Exception e)
                {
                    throw new ApplicationException("Unexpected problem parsing manifest: " + e.Message + " (" + Path.GetFileName(file) + ")");
                }
            }

            if (!foundManifest)
                throw new ApplicationException("Unable to find Manifest.xml");

            _manifests = manifests.ToArray();
        }