public void IsValidSigningCertificateV2_AttributeCountChangeVerifyFailure()
        {
            var child  = TestCertificate.Generate().PublicCert;
            var parent = TestCertificate.Generate().PublicCert;
            var extra  = TestCertificate.Generate().PublicCert;

            var localChain = new List <X509Certificate2>()
            {
                child, parent
            };
            var attributeChain = new List <KeyValuePair <Common.HashAlgorithmName, byte[]> >()
            {
                new KeyValuePair <Common.HashAlgorithmName, byte[]>(Common.HashAlgorithmName.SHA512, Common.HashAlgorithmName.SHA512.GetHashProvider().ComputeHash(child.RawData)),
                new KeyValuePair <Common.HashAlgorithmName, byte[]>(Common.HashAlgorithmName.SHA512, Common.HashAlgorithmName.SHA512.GetHashProvider().ComputeHash(parent.RawData)),
                new KeyValuePair <Common.HashAlgorithmName, byte[]>(Common.HashAlgorithmName.SHA512, Common.HashAlgorithmName.SHA512.GetHashProvider().ComputeHash(extra.RawData))
            };

            AttributeUtility.IsValidSigningCertificateV2(child, localChain, attributeChain, SigningSpecifications.V1)
            .Should()
            .BeFalse();
        }
        public void GetESSCertIDv2Entries_ReturnsDecodedHashes(Common.HashAlgorithmName hashAlgorithm)
        {
            // Arrange
            var cert      = TestCertificate.Generate().PublicCert;
            var cert2     = TestCertificate.Generate().PublicCert;
            var attribute = AttributeUtility.GetSigningCertificateV2(
                new[] { cert, cert2 },
                hashAlgorithm);
            var certHash  = CryptoHashUtility.ComputeHash(hashAlgorithm, cert.RawData);
            var cert2Hash = CryptoHashUtility.ComputeHash(hashAlgorithm, cert2.RawData);

            // Act
            var actual = AttributeUtility.GetESSCertIDv2Entries(attribute);

            // Assert
            actual.ShouldBeEquivalentTo(new[]
            {
                new KeyValuePair <Common.HashAlgorithmName, byte[]>(hashAlgorithm, certHash),
                new KeyValuePair <Common.HashAlgorithmName, byte[]>(hashAlgorithm, cert2Hash),
            });
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddTransient <IdPSelectionCookieRepository>();

            services.Configure <Settings>(Configuration.GetSection("Settings"));

            services.Configure <Saml2Configuration>(Configuration.GetSection("Saml2"));
            services.Configure <Saml2Configuration>(saml2Configuration =>
            {
                //saml2Configuration.SignAuthnRequest = true;
                saml2Configuration.SigningCertificate = TestCertificate.GetSelfSignedCertificate(AppEnvironment.ContentRootPath, "test-sign-cert");

                saml2Configuration.AllowedAudienceUris.Add(saml2Configuration.Issuer);

                var entityDescriptor = new EntityDescriptor();
                entityDescriptor.ReadIdPSsoDescriptorFromUrl(new Uri(Configuration["Saml2:IdPMetadata"]));
                if (entityDescriptor.IdPSsoDescriptor != null)
                {
                    saml2Configuration.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
                    saml2Configuration.SingleLogoutDestination = entityDescriptor.IdPSsoDescriptor.SingleLogoutServices.First().Location;
                    saml2Configuration.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
                }
                else
                {
                    throw new Exception("IdPSsoDescriptor not loaded from metadata.");
                }
            });

            services.AddSaml2("/Saml/Login");

            services.AddControllersWithViews();
            services.AddHttpContextAccessor();
        }
示例#4
0
        public byte[] AddCertificate(string identity, TimeSpan?lifetime, IEnumerable <string> purposes)
        {
            var testIdentity = GetIdentity(identity);

            if (testIdentity == null)
            {
                throw new Exception("Unknwn identity " + identity);
            }

            var id = Guid.NewGuid().ToString("N");
            var certificateText = identity + ":" + id;
            var certificate     = new TestCertificate
            {
                Identity    = identity,
                Id          = id,
                Certificate = Encoding.UTF8.GetBytes(certificateText),
                Expiry      = lifetime.HasValue ? DateTime.UtcNow + lifetime : null,
                Purposes    = purposes == null ? new List <string>() : purposes.Where(p => !string.IsNullOrEmpty(p)).ToList()
            };

            testIdentity.Certificates.Add(certificate);
            return(certificate.Certificate);
        }
示例#5
0
 private void buttonTestDelete_Click(object sender, EventArgs e)
 {
     if (dataViewTC.SelectedRows.Count > 0)
     {
         int          testID       = Convert.ToInt32(dataViewTC.SelectedRows[0].Cells[0].Value);
         DialogResult dialogResult = MessageBox.Show("Xác nhận xóa phiếu xét nghiệm", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (dialogResult == DialogResult.Yes)
         {
             try
             {
                 if (TestDetail.DeleteTestDetail(testID) > 0 && TestCertificate.DeleteTC(testID) > 0)
                 {
                     MessageBox.Show("Xóa phiếu xét nghiệm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             catch
             {
                 MessageBox.Show("Không thể xóa phiếu xét nghiệm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         refreshDataViewTest();
         refreshDataViewTestDetail();
     }
 }
示例#6
0
        private void SetTDForUpdate(TestCertificate tDetail)
        {
            textBoxTCID.Text            = tDetail.TCID.ToString();
            textBoxPatientID.Text       = tDetail.PatientID.ToString();
            textBoxStaffID.Text         = tDetail.StafID.ToString();
            dateCreate.Value            = tDetail.Date;
            comboBoxState.SelectedIndex = tDetail.State;

            DataTable dtTestType = TestType.GetListTestType();

            for (int i = 0; i < dtTestType.Rows.Count; i++)
            {
                TestType newTestType = new TestType();
                newTestType.TestTypeID = Convert.ToInt16(dtTestType.Rows[i][0]);
                newTestType.TestName   = dtTestType.Rows[i][1].ToString();
                listTestType.Add(newTestType);
                comboBoxTestType.Items.Add(newTestType.TestName);
            }
            comboBoxTestType.SelectedIndex = 0;

            DataTable dtTestDetail = TestDetail.GetListTestDetail(tDetail.TCID);

            for (int i = 0; i < dtTestDetail.Rows.Count; i++)
            {
                TestDetail newTD = new TestDetail();
                newTD.TCID       = Convert.ToInt32(dtTestDetail.Rows[i][0]);
                newTD.TestTypeID = Convert.ToInt16(dtTestDetail.Rows[i][1]);
                newTD.Result     = dtTestDetail.Rows[i][2].ToString();
                listTD.Add(newTD);
                listSelectedTestType.Items.Add(dtTestDetail.Rows[i][3].ToString());
            }
            if (listSelectedTestType.Items.Count > 0)
            {
                listSelectedTestType.SelectedIndex = 0;
            }
        }
示例#7
0
 public SignatureTests(SigningTestFixture fixture)
 {
     _testFixture              = fixture ?? throw new ArgumentNullException(nameof(fixture));
     _trustedTestCert          = _testFixture.TrustedTestCertificate;
     _untrustedTestCertificate = _testFixture.UntrustedTestCertificate;
 }
        public TestCertificate CreateUntrustedTestCertificateThatWillExpireSoon()
        {
            Action <TestCertificateGenerator> actionGenerator = SigningTestUtility.CertificateModificationGeneratorForCertificateThatWillExpireSoon(SoonDuration);

            return(TestCertificate.Generate(actionGenerator));
        }
示例#9
0
 private void buttonOk_Click(object sender, EventArgs e)
 {
     if (!superValidator1.Validate())
     {
         return;
     }
     try
     {
         if (listSelectedTestType.Items.Count > 0)
         {
             TestCertificate newTC = new TestCertificate();
             newTC.PatientID = Convert.ToInt32(textBoxPatientID.Text);
             newTC.StafID    = Convert.ToInt32(textBoxStaffID.Text);
             newTC.Date      = dateCreate.Value;
             newTC.State     = comboBoxState.SelectedIndex;
             if (this.UserAction == "edit")
             {
                 newTC.TCID = Convert.ToInt32(textBoxTCID.Text);
                 DialogResult dialogResult = MessageBox.Show("Xác nhận cập nhập thông tin phiếu xét nghiệm", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                 if (dialogResult == DialogResult.OK)
                 {
                     if (TestCertificate.UpdateTC(newTC) > 0)
                     {
                         TestDetail.DeleteTestDetail(newTC.TCID);
                         for (int i = 0; i < listTD.Count; i++)
                         {
                             listTD[i].TCID = newTC.TCID;
                             TestDetail.InsertTestDetail(listTD[i]);
                         }
                         listTD.Clear();
                         MessageBox.Show("Cập nhập thông tin phiếu xét nghiệm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                 }
             }
             else
             {
                 newTC.TCID = 0;
                 if (TestCertificate.InsertTC(newTC) > 0)
                 {
                     int tcID = TestCertificate.GetCurrentIdentity();
                     for (int i = 0; i < listTD.Count; i++)
                     {
                         listTD[i].TCID = tcID;
                         TestDetail.InsertTestDetail(listTD[i]);
                     }
                     MessageBox.Show("Thêm phiếu xét nghiệm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     listTD.Clear();
                 }
             }
             this.Close();
         }
         else
         {
             MessageBox.Show("Yêu cầu nhập loại xét nghiệm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
     catch
     {
         MessageBox.Show("Lỗi dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#10
0
        public async Task TestAzureServiceBusQueueReceive()
        {
            X509Certificate2 testCertificate = TestCertificate.Find();

            using ISimulation simulation = Simulation.Create();
            const string queueName    = "sb-queue-x";
            Exception    busException = null;

            IDelivery[] deliveries = null;

            IServiceBusSimulator bus = simulation.AddServiceBus()
                                       .SetCertificate(testCertificate)
                                       .AddQueue(queueName)
                                       .Build();

            await bus.StartAsync();

            IQueue busQueue = bus.Queues[queueName];

            var receiver = new MessageReceiver(bus.ConnectionString, queueName);

            try
            {
                receiver.ServiceBusConnection.OperationTimeout = TimeSpan.FromHours(1);
                receiver.RegisterMessageHandler(async(message, cancellationToken) =>
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if (message.MessageId == "2481")
                    {
                        await receiver.DeadLetterAsync(message.SystemProperties.LockToken);
                    }
                    else if (message.MessageId == "51847")
                    {
                        await receiver.AbandonAsync(message.SystemProperties.LockToken);
                    }
                    else
                    {
                        await receiver.CompleteAsync(message.SystemProperties.LockToken);
                    }
                }, new MessageHandlerOptions(e =>
                {
                    if (!(e.Exception is OperationCanceledException))
                    {
                        busException = e.Exception;
                    }
                    return(Task.CompletedTask);
                })
                {
                    AutoComplete = false
                });

                busQueue.Post(new Amqp.Message
                {
                    Properties = new Amqp.Framing.Properties {
                        MessageId = "2481"
                    }
                });
                busQueue.Post(new Amqp.Message
                {
                    Properties = new Amqp.Framing.Properties {
                        MessageId = "51847"
                    },
                });
                busQueue.Post(new Amqp.Message
                {
                    Properties = new Amqp.Framing.Properties {
                        MessageId = "33782"
                    },
                });
                busQueue.Post(new Amqp.Message());
                deliveries = busQueue.Deliveries.ToArray();

                IEnumerable <Task <bool> > deliveryTasks = deliveries.Select(d => d.WaitAsync(TimeSpan.FromSeconds(5)));
                await Task.WhenAll(deliveryTasks);
            }
            finally
            {
                await receiver.CloseAsync();

                await bus.StopAsync();
            }

            bus.ShouldSatisfyAllConditions(
                () => deliveries.Length.ShouldBe(4),
                () => deliveries[0].Result.ShouldBe(DeliveryResult.DeadLettered),
                () => deliveries[1].Result.ShouldBe(DeliveryResult.Abandoned),
                () => deliveries[2].Result.ShouldBe(DeliveryResult.Completed),
                () => deliveries[3].Result.ShouldBe(DeliveryResult.Completed)
                );
        }