Beispiel #1
0
        private void NonAddressed(IDataSealer sealer, IDataUnsealer unsealer)
        {
            String str = "This is a secret message from Alice";

            SecretKey key    = new SecretKey("btSefztkXjZmlZyHQIumLA==", "aaUnRynIwd3GFQmhXfW+VQ==");
            Stream    output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), key);

            UnsealResult result = unsealer.Unseal(output, key);

            Console.WriteLine(result.SecurityInformation.ToString());

            output.Close();

            MemoryStream stream = new MemoryStream();

            Utils.Copy(result.UnsealedData, stream);

            //Assert.IsInstanceOfType(result.UnsealedData, typeof(WindowsTempFileStream));
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.IsNull(result.SecurityInformation.Encryption.Subject);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
        public void Java2NetAddressedBLevel()
        {
            RunJava("etee.crypto.test.Seal NONE");

            UnsealResult result;
            FileStream   file = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.Open);

            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.Create(null, bob);
                result = unsealer.Unseal(file);
            }
            System.Console.WriteLine(result.SecurityInformation);

            Assert.AreEqual(Egelke.EHealth.Etee.Crypto.Status.TrustStatus.Full, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);

            Assert.AreEqual("SERIALNUMBER=79021802145, G=Bryan Eduard, SN=Brouckaert, CN=Bryan Brouckaert (Authentication), C=BE", result.AuthenticationCertificate.Subject);

            byte[] bytes = new byte[result.UnsealedData.Length];
            result.UnsealedData.Read(bytes, 0, bytes.Length);
            String msg = Encoding.UTF8.GetString(bytes);

            Assert.IsTrue(msg.StartsWith("This is a message to bob"));
        }
Beispiel #3
0
        private void Addressed(IDataSealer sealer, IDataUnsealer unsealer)
        {
            String str = "This is a secret message from Alice for Bob";

            //Get ETK
            EncryptionToken receiver = new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk")));

            Stream output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), receiver);

            UnsealResult result = unsealer.Unseal(output);

            Console.WriteLine(result.SecurityInformation.ToString());

            output.Close();

            MemoryStream stream = new MemoryStream();

            Utils.Copy(result.UnsealedData, stream);

            //Assert.IsInstanceOfType(result.UnsealedData, typeof(WindowsTempFileStream));
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
Beispiel #4
0
        private void Unseal(Stream output)
        {
            IDataUnsealer unsealer = DataUnsealerFactory.Create(level, alice, bob);

            UnsealResult result = unsealer.Unseal(output);

            Console.WriteLine(result.SecurityInformation.ToString());

            MemoryStream stream = new MemoryStream();

            Utils.Copy(result.UnsealedData, stream);
            result.UnsealedData.Close();

            Assert.IsTrue((DateTime.UtcNow - result.SealedOn) < new TimeSpan(0, 1, 0));
            Assert.IsNotNull(result.SignatureValue);
            Assert.AreEqual(validationStatus, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(trustStatus, result.SecurityInformation.TrustStatus);
            Assert.IsNull(result.SecurityInformation.OuterSignature.Signer);
            Assert.IsNotNull(result.SecurityInformation.OuterSignature.SignerId);
            Assert.IsNull(result.SecurityInformation.InnerSignature.Signer);
            Assert.IsNotNull(result.SecurityInformation.InnerSignature.SignerId);
            //todo:encrypt for WebKey
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(clearMessage, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
        public void MyClassInitialize(TestContext ctx)
        {
            var alice = new EHealthP12(GetAbsoluteTestFilePath("alice/old_alices_private_key_store.p12"), "test");
            var bob   = new EHealthP12(GetAbsoluteTestFilePath("bob/old_bobs_private_key_store.p12"), "test");


            aliceSealer  = EhDataSealerFactory.Create(Level.B_Level, alice);
            bobUnsealer  = DataUnsealerFactory.Create(null, bob);
            anonUnsealer = DataUnsealerFactory.Create(null);
        }
Beispiel #6
0
        public void Size31KFile()
        {
            Random rand = new Random();

            byte[]     buffer    = new byte[1024]; //1k blocks
            String     file      = Path.GetTempFileName();
            FileStream hudgeFile = new FileStream(file, FileMode.Open);

            try
            {
                //Write random stuff into it, exactly 32K
                for (int i = 0; i < 31; i++)
                {
                    rand.NextBytes(buffer);
                    hudgeFile.Write(buffer, 0, buffer.Length);
                }
                rand.NextBytes(buffer);
                hudgeFile.Write(buffer, 0, 512);
                //Rest
                hudgeFile.Position = 0;

                //Get ETK
                EncryptionToken receiver = new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk")));

                //Seal
                IDataSealer sealer = EhDataSealerFactory.Create(Level.B_Level, alice);
                Stream      output = sealer.Seal(hudgeFile, receiver);
                hudgeFile.Position = 0;

                UnsealResult result;
                using (output)
                {
                    //Unseal again
                    IDataUnsealer unsealer = DataUnsealerFactory.Create(null, alice, bob);
                    result = unsealer.Unseal(output);
                }
                Console.WriteLine(result.SecurityInformation.ToString());

                //check the lenth and the first bytes
                Assert.AreEqual(hudgeFile.Length, result.UnsealedData.Length);
                Assert.AreEqual(hudgeFile.ReadByte(), result.UnsealedData.ReadByte());
                Assert.AreEqual(hudgeFile.ReadByte(), result.UnsealedData.ReadByte());
                Assert.AreEqual(hudgeFile.ReadByte(), result.UnsealedData.ReadByte());
                Assert.AreEqual(hudgeFile.ReadByte(), result.UnsealedData.ReadByte());
                Assert.AreEqual(hudgeFile.ReadByte(), result.UnsealedData.ReadByte());

                result.UnsealedData.Dispose();
            }
            finally
            {
                hudgeFile.Close();
                File.Delete(file);
            }
        }
Beispiel #7
0
        public void ReuseOfSealerAndUnsealer()
        {
            IDataSealer   sealer        = EhDataSealerFactory.Create(Level.B_Level, alice);
            IDataUnsealer unsealer      = DataUnsealerFactory.Create(null, bob);
            IDataUnsealer unsealerAlice = DataUnsealerFactory.Create(null, alice);

            Addressed(sealer, unsealer);
            NonAddressed(sealer, unsealer);
            Mixed(sealer, unsealer);
            Mixed(sealer, unsealer);
            NonAddressed(sealer, unsealer);
            Addressed(sealer, unsealer);
        }
Beispiel #8
0
        public void Java2NetBasic()
        {
            RunJava("etee.crypto.test.Seal BASIC");

            //check adressed
            UnsealResult result;
            FileStream   file = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.Open);

            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.Create(null, bob);
                result = unsealer.Unseal(file);
            }
            System.Console.WriteLine(result.SecurityInformation);

            Assert.AreEqual(Egelke.EHealth.Etee.Crypto.Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            //Assert.AreEqual(mcn["authentication"].Subject, result.AuthenticationCertificate.Subject);

            byte[] bytes = new byte[result.UnsealedData.Length];
            result.UnsealedData.Read(bytes, 0, bytes.Length);
            String msg = Encoding.UTF8.GetString(bytes);

            Assert.AreEqual("Hello from Alice to Bob", msg);

            //check unaddressed
            SecretKey sk = new SecretKey("btSefztkXjZmlZyHQIumLA==", "QUFBQUFBQUFBQUFBQUFBQQ==");

            file = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.Open);
            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.Create(null);
                result = unsealer.Unseal(file, sk);
            }
            System.Console.WriteLine(result.SecurityInformation);

            Assert.AreEqual(Egelke.EHealth.Etee.Crypto.Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            //Assert.AreEqual(mcn["authentication"].Subject, result.AuthenticationCertificate.Subject);

            bytes = new byte[result.UnsealedData.Length];
            result.UnsealedData.Read(bytes, 0, bytes.Length);
            msg = Encoding.UTF8.GetString(bytes);
            Assert.AreEqual("Hello from Alice to Bob", msg);
        }
        public void Java2NetAddressedLTALevel()
        {
            RunJava("etee.crypto.test.Seal NONE");

            File.Copy(GetAbsoluteTestFilePath("message_to_bob.msg"), GetAbsoluteTestFilePath("message_to_store.msg"), true);

            String output = RunJava("etee.crypto.test.Verify OPTIONAL");

            SHA256 sha = SHA256.Create();

            byte[] hash = sha.ComputeHash(Convert.FromBase64String(output.Trim()));

            var tsa = new TimeStampAuthorityClient(new StsBinding(), new EndpointAddress("https://services-acpt.ehealth.fgov.be/TimestampAuthority/v2"));

            tsa.Endpoint.Behaviors.Remove <ClientCredentials>();
            tsa.Endpoint.Behaviors.Add(new OptClientCredentials());
            tsa.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindByThumbprint, "566fd3fe13e3ab185a7224bcec8ad9cffbf9e9c2");

            var tsProvider = new EHealthTimestampProvider(tsa);

            byte[] tst = tsProvider.GetTimestampFromDocumentHash(hash, "http://www.w3.org/2001/04/xmlenc#sha256");

            File.Copy(GetAbsoluteTestFilePath("message_to_bob.msg"), GetAbsoluteTestFilePath("message_to_store.msg"), true);

            RunJava("etee.crypto.test.Stamp " + Convert.ToBase64String(tst));

            UnsealResult result;
            FileStream   file = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.Open);

            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.Create(Level.LTA_Level, bob);
                result = unsealer.Unseal(file);
            }
            System.Console.WriteLine(result.SecurityInformation);

            Assert.AreEqual(Egelke.EHealth.Etee.Crypto.Status.TrustStatus.Full, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);

            Assert.AreEqual("SERIALNUMBER=79021802145, G=Bryan Eduard, SN=Brouckaert, CN=Bryan Brouckaert (Authentication), C=BE", result.AuthenticationCertificate.Subject);

            byte[] bytes = new byte[result.UnsealedData.Length];
            result.UnsealedData.Read(bytes, 0, bytes.Length);
            String msg = Encoding.UTF8.GetString(bytes);

            Assert.IsTrue(msg.StartsWith("This is a message to bob"));
        }
Beispiel #10
0
        public void Java2NetEid()
        {
            RunJava("etee.crypto.test.Seal EID");

            UnsealResult result;
            FileStream   file = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.Open);

            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.Create(null, bob);
                result = unsealer.Unseal(file);
            }
            System.Console.WriteLine(result.SecurityInformation);

            Assert.AreEqual(Egelke.EHealth.Etee.Crypto.Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.IsFalse(result.IsNonRepudiatable);
        }
Beispiel #11
0
        private void Mixed(IDataSealer sealer, IDataUnsealer unsealer)
        {
            String str = "This is a secret message from Alice to everybody";

            SecretKey key = new SecretKey("btSefztkXjZmlZyHQIumLA==", "aaUnRynIwd3GFQmhXfW+VQ==");

            EncryptionToken receiver1 = new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk")));

            Stream output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), key, receiver1);

            UnsealResult result = unsealer.Unseal(output, key);

            Console.WriteLine(result.SecurityInformation.ToString());

            MemoryStream stream = new MemoryStream();

            Utils.Copy(result.UnsealedData, stream);

            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.IsNull(result.SecurityInformation.Encryption.Subject);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());

            output.Position = 0;
            result          = unsealer.Unseal(output);
            Console.WriteLine(result.SecurityInformation.ToString());

            stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
Beispiel #12
0
        public void Java2NetAddressedLTALevelTmaCached()
        {
            UnsealResult result;
            FileStream   file = new FileStream(GetAbsoluteTestFilePath("msg/LTA_Tma.msg"), FileMode.Open);

            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.CreateFromTimemarkAuthority(Level.LTA_Level, new FixedTimemarkProvider(new DateTime(2014, 4, 8, 20, 36, 30, DateTimeKind.Local)), bob);
                result = unsealer.Unseal(file);
            }
            System.Console.WriteLine(result.SecurityInformation);

            Assert.AreEqual(Egelke.EHealth.Etee.Crypto.Status.TrustStatus.Full, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);

            Assert.AreEqual("SERIALNUMBER=79021802145, G=Bryan Eduard, SN=Brouckaert, CN=Bryan Brouckaert (Authentication), C=BE", result.AuthenticationCertificate.Subject);

            byte[] bytes = new byte[result.UnsealedData.Length];
            result.UnsealedData.Read(bytes, 0, bytes.Length);
            String msg = Encoding.UTF8.GetString(bytes);

            Assert.IsTrue(msg.StartsWith("This is a message to bob"));
        }
Beispiel #13
0
        private void Mixed(IDataSealer sealer, IDataUnsealer unsealer)
        {
            String str = "This is a secret message from Alice to everybody";

            SecretKey key = new SecretKey("btSefztkXjZmlZyHQIumLA==", "aaUnRynIwd3GFQmhXfW+VQ==");

            EncryptionToken receiver1 = new EncryptionToken(Utils.ReadFully("../../bob/bobs_public_key.etk"));

            Stream output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), key, receiver1);

            UnsealResult result = unsealer.Unseal(output, key);
            Console.WriteLine(result.SecurityInformation.ToString());

            MemoryStream stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.IsNull(result.SecurityInformation.Encryption.Subject);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());

            output.Position = 0;
            result = unsealer.Unseal(output);
            Console.WriteLine(result.SecurityInformation.ToString());

            stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
Beispiel #14
0
        private void NonAddressed(IDataSealer sealer, IDataUnsealer unsealer)
        {
            String str = "This is a secret message from Alice";

            SecretKey key = new SecretKey("btSefztkXjZmlZyHQIumLA==", "aaUnRynIwd3GFQmhXfW+VQ==");
            Stream output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), key);

            UnsealResult result = unsealer.Unseal(output, key);
            Console.WriteLine(result.SecurityInformation.ToString());

            output.Close();

            MemoryStream stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            //Assert.IsInstanceOfType(result.UnsealedData, typeof(WindowsTempFileStream));
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.IsNull(result.SecurityInformation.Encryption.Subject);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
Beispiel #15
0
        public void MultiAddressed()
        {
            String str = "This is a secret message from Alice for Bob and Herself";

            //Get ETK
            EncryptionToken receiver1 = new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk")));
            EncryptionToken receiver2 = new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("alice/alices_public_key.etk")));

            IDataSealer sealer = EhDataSealerFactory.Create(Level.B_Level, alice);
            Stream      output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), receiver1, receiver2);

            IDataUnsealer unsealer = DataUnsealerFactory.Create(null, alice, bob);
            UnsealResult  result   = unsealer.Unseal(output);

            Console.WriteLine(result.SecurityInformation.ToString());

            output.Position = 0;

            MemoryStream stream = new MemoryStream();

            Utils.Copy(result.UnsealedData, stream);

            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());


            unsealer = DataUnsealerFactory.Create(null, alice);
            result   = unsealer.Unseal(output);
            Console.WriteLine(result.SecurityInformation.ToString());

            output.Position = 0;


            stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            //Assert.IsInstanceOfType(result.UnsealedData, typeof(WindowsTempFileStream));
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(alice["1204544406096826217265"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());

            unsealer = DataUnsealerFactory.Create(null, bob);
            result   = unsealer.Unseal(output);
            Console.WriteLine(result.SecurityInformation.ToString());

            output.Position = 0;

            output.Close();

            stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            //Assert.IsInstanceOfType(result.UnsealedData, typeof(WindowsTempFileStream));
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.IsTrue(result.IsNonRepudiatable);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }
        public void MyClassInitialize()
        {
            var alice = new EHealthP12("../../alice/old_alices_private_key_store.p12", "test");
            var bob = new EHealthP12("../../bob/old_bobs_private_key_store.p12", "test");

            aliceSealer = EhDataSealerFactory.Create(Level.B_Level, alice);
            bobUnsealer = DataUnsealerFactory.Create(null, bob);
            anonUnsealer = DataUnsealerFactory.Create(null);
        }
Beispiel #17
0
        private void Addressed(IDataSealer sealer, IDataUnsealer unsealer)
        {
            String str = "This is a secret message from Alice for Bob";

            //Get ETK
            EncryptionToken receiver = new EncryptionToken(Utils.ReadFully("../../bob/bobs_public_key.etk"));
            //receiver.Verify();

            Stream output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(str)), receiver);

            UnsealResult result = unsealer.Unseal(output);
            Console.WriteLine(result.SecurityInformation.ToString());

            output.Close();

            MemoryStream stream = new MemoryStream();
            Utils.Copy(result.UnsealedData, stream);

            //Assert.IsInstanceOfType(result.UnsealedData, typeof(WindowsTempFileStream));
            Assert.AreEqual(ValidationStatus.Valid, result.SecurityInformation.ValidationStatus);
            Assert.AreEqual(ETEE::Status.TrustStatus.Unsure, result.SecurityInformation.TrustStatus);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.AuthenticationCertificate.Thumbprint);
            Assert.AreEqual(alice["Authentication"].Thumbprint, result.SigningCertificate.Thumbprint);
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(str, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }