Ejemplo n.º 1
0
        public void TestSigning()
        {
            Bundle b = new Bundle();

            b.Title       = "Updates to resource 233";
            b.Id          = new Uri("urn:uuid:0d0dcca9-23b9-4149-8619-65002224c3");
            b.LastUpdated = new DateTimeOffset(2012, 11, 2, 14, 17, 21, TimeSpan.Zero);
            b.AuthorName  = "Ewout Kramer";

            ResourceEntry <Patient> p = new ResourceEntry <Patient>();

            p.Id            = new ResourceIdentity("http://test.com/fhir/Patient/233");
            p.Resource      = new Patient();
            p.Resource.Name = new List <HumanName> {
                HumanName.ForFamily("Kramer").WithGiven("Ewout")
            };
            b.Entries.Add(p);

            var certificate = getCertificate();

            var bundleData   = FhirSerializer.SerializeBundleToXmlBytes(b);
            var bundleXml    = Encoding.UTF8.GetString(bundleData);
            var bundleSigned = XmlSignatureHelper.Sign(bundleXml, certificate);

            _signedXml = bundleSigned;

            using (var response = postBundle(bundleSigned))
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    TestResult.Fail("Server refused POSTing signed document at /");
                }
            }
        }
Ejemplo n.º 2
0
        public void Sign(X509Certificate2 certificate)
        {
            string xml = GetDefinitionsXml();
            var    signatureElement = XmlSignatureHelper.Sign(xml, certificate);

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SignatureType));

            using (StringReader stringReader = new StringReader(signatureElement.OuterXml))
            {
                Signature = ((SignatureType)(xmlSerializer.Deserialize(System.Xml.XmlReader.Create(stringReader))));
            }
        }
Ejemplo n.º 3
0
        public void TestSigning()
        {
            Bundle b = new Bundle();

            b.Title       = "Updates to resource 233";
            b.Id          = new Uri("urn:uuid:0d0dcca9-23b9-4149-8619-65002224c3");
            b.LastUpdated = new DateTimeOffset(2012, 11, 2, 14, 17, 21, TimeSpan.Zero);
            b.AuthorName  = "Ewout Kramer";

            ResourceEntry <Patient> p = new ResourceEntry <Patient>();

            p.Id            = new ResourceIdentity("http://test.com/fhir/Patient/233");
            p.Resource      = new Patient();
            p.Resource.Name = new List <HumanName> {
                HumanName.ForFamily("Kramer").WithGiven("Ewout")
            };
            b.Entries.Add(p);

            var myAssembly = typeof(TestXmlSignature).Assembly;
            var stream     = myAssembly.GetManifestResourceStream("Spark.Tests.spark.pfx");

            var data = new byte[stream.Length];

            stream.Read(data, 0, (int)stream.Length);
            var certificate = new X509Certificate2(data);

            var bundleData = FhirSerializer.SerializeBundleToXmlBytes(b);
            var bundleXml  = Encoding.UTF8.GetString(bundleData);

            var bundleSigned = XmlSignatureHelper.Sign(bundleXml, certificate);

            Assert.IsTrue(XmlSignatureHelper.IsSigned(bundleSigned));
            Assert.IsTrue(XmlSignatureHelper.VerifySignature(bundleSigned));

            var changedBundle = bundleSigned.Replace("<name>Ewout", "<name>Ewald");

            Assert.AreEqual(bundleSigned.Length, changedBundle.Length);

            Assert.IsFalse(XmlSignatureHelper.VerifySignature(changedBundle));
        }