Ejemplo n.º 1
0
        public void Net2JavaAddressedBLevel()
        {
            String text = "This is a secret message from Alice for Bob written at " + DateTime.Now.ToString();

            IDataSealer sealer = EidDataSealerFactory.Create(Level.B_Level);
            Stream      msg    = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(text)), new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk"))));

            FileStream msgFile = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.OpenOrCreate);

            using (msgFile)
            {
                msg.CopyTo(msgFile);
            }

            String output = RunJava("etee.crypto.test.Unseal NONE"); //should be OK

            Assert.IsTrue(output.Contains(text));

            try
            {
                output = RunJava("etee.crypto.test.Unseal MANDATORY"); //should fail, with exception
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 2
0
        public void Net2JavaAddressedLTLevelInSteps()
        {
            String text = "This is a secret message from Alice for Bob written at " + DateTime.Now.ToString();

            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");

            IDataSealer sealer = EidDataSealerFactory.Create(Level.B_Level);
            Stream      msg    = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(text)), new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk"))));

            IDataCompleter completer = DataCompleterFactory.Create(Level.LT_Level, new EHealthTimestampProvider(tsa));
            Stream         msg2      = completer.Complete(msg);

            FileStream msgFile = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.OpenOrCreate);

            using (msgFile)
            {
                msg2.CopyTo(msgFile);
            }

            String output = RunJava("etee.crypto.test.Unseal MANDATORY");

            Assert.IsTrue(output.Contains(text));
        }
Ejemplo n.º 3
0
        private Stream Seal()
        {
            IDataSealer sealer;

            if (!level.HasValue || level.Value == Level.B_Level)
            {
                if (ehCert != null)
                {
                    sealer = new EhDataSealerFactory().Create(level == null ? Level.B_Level : level.Value, ehCert);
                }
                else
                {
                    sealer = new EidDataSealerFactory().Create(level == null ? Level.B_Level : level.Value, nonRepudiatable);
                }
            }
            else
            {
                if (ehCert != null)
                {
                    if (useTmaInsteadOfTsa)
                    {
                        sealer = new EhDataSealerFactory().CreateForTimemarkAuthority(level.Value, ehCert);
                    }
                    else
                    {
                        sealer = new EhDataSealerFactory().Create(level.Value, tsa, ehCert);
                    }
                }
                else
                {
                    if (useTmaInsteadOfTsa)
                    {
                        sealer = new EidDataSealerFactory().CreateForTimemarkAuthority(level.Value, nonRepudiatable);
                    }
                    else
                    {
                        sealer = new EidDataSealerFactory().Create(level.Value, tsa, nonRepudiatable);
                    }
                }
            }

            Stream output = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(clearMessage)), bobEtk);

            return(output);
        }
Ejemplo n.º 4
0
        public void Net2JavaEid()
        {
            String text = "This is a secret message from Alice for Bob written at " + DateTime.Now.ToString();

            IDataSealer sealer = EidDataSealerFactory.Create(Level.B_Level, false);
            Stream      msg    = sealer.Seal(new MemoryStream(Encoding.UTF8.GetBytes(text)), new EncryptionToken(Utils.ReadFully(GetAbsoluteTestFilePath("bob/bobs_public_key.etk"))));

            FileStream msgFile = new FileStream(GetAbsoluteTestFilePath("message_to_bob.msg"), FileMode.OpenOrCreate);

            using (msgFile)
            {
                msg.CopyTo(msgFile);
            }

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

            Assert.IsTrue(output.Contains(text));
        }