public void Java2NetAddressedLTALevelTma()
        {
            RunJava("etee.crypto.test.Seal MANDATORY");

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

            using (file)
            {
                IDataUnsealer unsealer = DataUnsealerFactory.CreateFromTimemarkAuthority(Level.LTA_Level, new CurrentTimemarkProvider(), 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 #2
0
        private void Unseal(Stream output)
        {
            IDataUnsealer unsealer;

            if (!level.HasValue || level.Value == Level.B_Level || !useTmaInsteadOfTsa)
            {
                unsealer = DataUnsealerFactory.Create(level, alice, bob);
            }
            else
            {
                unsealer = DataUnsealerFactory.CreateFromTimemarkAuthority(level.Value, new CurrentTimemarkProvider(), 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.AreEqual(subject, result.AuthenticationCertificate.Subject);
            if (nonRepudiatable)
            {
                Assert.AreEqual(subject2, result.SigningCertificate.Subject);
            }
            else
            {
                Assert.AreEqual(subject, result.SigningCertificate.Subject);
            }
            Assert.AreEqual(bob["825373489"].Thumbprint, result.SecurityInformation.Encryption.Subject.Certificate.Thumbprint);
            Assert.AreEqual(clearMessage, Encoding.UTF8.GetString(stream.ToArray()));
            Assert.IsNotNull(result.SecurityInformation.ToString());
        }