Exemple #1
0
        /// <inheritdoc/>
        public async Task <bool> VerifyAsync(KeyHandle handle, byte[] hash,
                                             SignatureType algorithm, byte[] signature, CancellationToken ct)
        {
            var document = await _keys.GetAsync <KeyDocument>(KeyId.GetId(handle), ct);

            if (document.Value.IsDisabled)
            {
                throw new InvalidOperationException("Key is disabled");
            }
            var key = document.Value.KeyJson.ToKey();

            if (key == null)
            {
                throw new ResourceNotFoundException("Key not found");
            }
            switch (key.Type)
            {
            case KeyType.RSA:
                using (var rsa = key.ToRSA()) {
                    return(rsa.VerifyHash(hash, signature, algorithm.ToHashAlgorithmName(),
                                          algorithm.ToRSASignaturePadding()));
                }

            case KeyType.ECC:
                using (var ecc = key.ToECDsa()) {
                    return(ecc.VerifyHash(hash, signature));
                }

            default:
                throw new ArgumentException("Bad key type passed for signing");
            }
        }
Exemple #2
0
        private void cboThang_SelectedIndexChanged(object sender, EventArgs e)
        {
            RefreshView();
            int thang    = int.Parse(cboThang.Text);
            int nam      = LopBLL.GetNamHoc(thang, KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));
            int dieuKien = HocPhiBLL.CoTheCapNhatHocPhi(thang, nam, DateTime.Now);

            cboChiPhi.Enabled        = false;
            txtSoTien.Enabled        = false;
            btnThemChiPhi.Enabled    = false;
            btnCapNhatChiPhi.Enabled = false;
            btnXoa.Enabled           = false;
            btnApDungHocPhi.Enabled  = false;
            if (dieuKien == -1)
            {
                lbMessage.Text = "Đã quá hạn áp dụng học phí";
            }
            else if (dieuKien == 1)
            {
                lbMessage.Text = "Chưa tới thời gian áp dụng học phí";
            }
            else
            {
                lbMessage.Text           = "";
                cboChiPhi.Enabled        = true;
                txtSoTien.Enabled        = true;
                btnThemChiPhi.Enabled    = true;
                btnCapNhatChiPhi.Enabled = true;
                btnXoa.Enabled           = true;
                btnApDungHocPhi.Enabled  = true;
            }

            CapNhatTienNoThangTruoc();
        }
Exemple #3
0
        /// <inheritdoc/>
        public async Task DisableKeyAsync(KeyHandle handle, CancellationToken ct)
        {
            var keyId = KeyId.GetId(handle);

            while (true)
            {
                try {
                    var document = await _keys.FindAsync <KeyDocument>(keyId, ct);

                    if (document == null)
                    {
                        throw new ResourceNotFoundException($"{keyId} not found");
                    }
                    if (!document.Value.IsDisabled)
                    {
                        await _keys.ReplaceAsync(document, new KeyDocument {
                            Id         = document.Value.Id,
                            IsDisabled = true,
                            KeyJson    = document.Value.KeyJson
                        }, ct);
                    }
                    return;
                }
                catch (ResourceOutOfDateException) {
                    continue;
                }
            }
        }
 private void btnTaoPhieuMoi_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult confirm = new DialogResult();
         if (dgvPhieuBeNgoan.RowCount > 0)
         {
             confirm = MessageBox.Show("Tháng này đã có dữ liệu. Bạn có chắc muốn xóa để tạo mới hoàn toàn?",
                                       "Cân nhắc", MessageBoxButtons.YesNo);
         }
         if (confirm == DialogResult.Yes || dgvPhieuBeNgoan.RowCount <= 0)
         {
             XoaPhieuCu();
             dgvPhieuBeNgoan.Columns.Clear();
             if (!string.IsNullOrEmpty(cboLop.Text))
             {
                 dgvPhieuBeNgoan.DataSource = PhieuBeNgoanBLL.TaoPhieuBeNgoanMoi(
                     LopBLL.GetInfoLop(KeyHandle.GetKeyFromCombobox(cboLop.SelectedItem.ToString())),
                     dtThangLapPhieu.Text);
                 TaoPhieuTrong();
                 MessageBox.Show("Một phiếu mới hoàn toàn vừa được tạo", "Thông báo");
                 btnLuuPhieu.Enabled = true;
             }
         }
         else if (confirm == DialogResult.No)
         {
             return;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Lỗi");
     }
 }
Exemple #5
0
        private void cboTuThang_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            NamHoc namHoc = LopBLL.GetInfoNamHoc(KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));

            int thangBatDau  = int.Parse(cboTuThang.SelectedItem.ToString());
            int thangKetThuc = namHoc.NgayKetThuc.Month;

            List <int> listThang = new List <int>();

            while (thangBatDau != thangKetThuc)
            {
                thangBatDau++;
                if (thangBatDau > 12)
                {
                    thangBatDau = 1;
                }
                listThang.Add(thangBatDau);
            }

            cboDenThang.Items.Clear();
            foreach (int thang in listThang)
            {
                cboDenThang.Items.Add(thang.ToString());
            }
        }
 /// <summary>
 /// Create signature generator.
 /// </summary>
 /// <param name="signKey">The signing key</param>
 /// <param name="signer">Digest signer to use</param>
 /// <param name="signature"></param>
 public X509SignatureGeneratorAdapter(IDigestSigner signer, KeyHandle signKey,
                                      SignatureType signature)
 {
     _signKey   = signKey ?? throw new ArgumentNullException(nameof(signKey));
     _signer    = signer ?? throw new ArgumentNullException(nameof(signer));
     _signature = signature;
 }
        /// <inheritdoc/>
        public async Task DisableKeyAsync(KeyHandle handle, CancellationToken ct)
        {
            var bundle = KeyVaultKeyHandle.GetBundle(handle);

            try {
                if (!string.IsNullOrEmpty(bundle.KeyIdentifier))
                {
                    await _keyVaultClient.UpdateKeyAsync(bundle.KeyIdentifier, null,
                                                         new KeyAttributes {
                        Enabled = false,
                        Expires = DateTime.UtcNow
                    }, null, ct);
                }
                if (!string.IsNullOrEmpty(bundle.SecretIdentifier))
                {
                    // Delete private key secret also
                    await _keyVaultClient.UpdateSecretAsync(bundle.SecretIdentifier,
                                                            ContentEncodings.MimeTypeJson, new SecretAttributes {
                        Enabled = false,
                        Expires = DateTime.UtcNow
                    }, null, ct);
                }
            }
            catch (KeyVaultErrorException kex) {
                throw new ExternalDependencyException("Failed to create key", kex);
            }
        }
Exemple #8
0
        private void cboLop_SelectedIndexChanged(object sender, EventArgs e)
        {
            loadDataGridView();

            DateTime ngayBatDau  = NamHocBLL.GetNgayBatDau(KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));
            DateTime ngayKetThuc = NamHocBLL.GetNgayKetThuc(KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));

            if (LopBLL.GetSiSo(KeyHandle.GetKeyFromCombobox(cboLop.SelectedItem.ToString())) > 0 &&
                Checking.IsInOfDate(ngayBatDau, ngayKetThuc))
            {
                //btnLuuDiemDanh.Enabled = true;
                btnTaoBangMoi.Enabled = true;
            }
            else if (LopBLL.GetSiSo(KeyHandle.GetKeyFromCombobox(cboLop.SelectedItem.ToString())) <= 0)
            {
                lbThongBao.Text       += "\nLớp không có học sinh, không thể tạo phiếu mới";
                lbThongBao.Visible     = true;
                btnLuuDiemDanh.Enabled = false;
                btnTaoBangMoi.Enabled  = false;
            }
            else if (!Checking.IsInOfDate(ngayBatDau, ngayKetThuc))
            {
                lbThongBao.Text       += "\nNiên khóa đã qua, không thể tạo phiếu mới";
                lbThongBao.Visible     = true;
                btnLuuDiemDanh.Enabled = false;
                btnTaoBangMoi.Enabled  = false;
            }
        }
Exemple #9
0
        /// <inheritdoc/>
        public async Task <Key> GetPublicKeyAsync(KeyHandle handle, CancellationToken ct)
        {
            var document = await _keys.GetAsync <KeyDocument>(
                KeyId.GetId(handle), ct);

            return(document.Value.KeyJson.ToKey().GetPublicKey());
        }
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (txtCanNang.Text == "")
            {
                MessageBox.Show("Cân nặng không được để trống.");
                return;
            }
            if (txtChieuCao.Text == "")
            {
                MessageBox.Show("Chiều cao không được để trống.");
                return;
            }
            SucKhoe sucKhoe = new SucKhoe();

            sucKhoe.MaTre     = maTre;
            sucKhoe.Thang     = int.Parse(cboThang.Text);
            sucKhoe.Nam       = LopBLL.GetNamHoc(sucKhoe.Thang, KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));
            sucKhoe.CanNang   = txtCanNang.Text.Trim() == "" ? 0 : double.Parse(txtCanNang.Text);
            sucKhoe.ChieuCao  = txtChieuCao.Text.Trim() == "" ? 0 : double.Parse(txtChieuCao.Text);
            sucKhoe.BMI       = txtBMI.Text.Trim() == "" ? 0 : double.Parse(txtBMI.Text);
            sucKhoe.TinhTrang = txtTinhTrang.Text;
            sucKhoe.GhiChu    = txtGhiChu.Text;
            if (SucKhoeBLL.CapNhatSucKhoe(sucKhoe))
            {
                MessageBox.Show("Cập nhật thành công!");
                LoadDataGirdView();
            }
            else
            {
                MessageBox.Show("Đã xảy ra lỗi.");
            }
        }
        public void Validate()
        {
            if (UserPublicKey == null)
            {
                throw new InvalidOperationException("UserPublicKey is missing in " + typeof(FidoRegistrationData).Name);
            }

            if (KeyHandle == null)
            {
                throw new InvalidOperationException("KeyHandle is missing in " + typeof(FidoRegistrationData).Name);
            }

            if (Signature == null)
            {
                throw new InvalidOperationException("Signature is missing in " + typeof(FidoRegistrationData).Name);
            }

            if (AttestationCertificate == null)
            {
                throw new InvalidOperationException("AttestationCertificate is missing in " + typeof(FidoRegistrationData).Name);
            }

            UserPublicKey.Validate();
            KeyHandle.Validate();
            Signature.Validate();
            AttestationCertificate.Validate();
        }
        private void dgvSucKhoe_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && e.RowIndex != dgvSucKhoe.RowCount)
            {
                try
                {
                    maTre             = dgvSucKhoe.Rows[e.RowIndex].Cells["MaTre"].Value.ToString();
                    gioiTinh          = dgvSucKhoe.Rows[e.RowIndex].Cells["GioiTinh"].Value.ToString();
                    ngaySinh          = (DateTime)dgvSucKhoe.Rows[e.RowIndex].Cells["NgaySinh"].Value;
                    txtTenTre.Text    = dgvSucKhoe.Rows[e.RowIndex].Cells["HoTenTre"].Value.ToString();
                    txtCanNang.Text   = dgvSucKhoe.Rows[e.RowIndex].Cells["CanNang"].Value.ToString();
                    txtChieuCao.Text  = dgvSucKhoe.Rows[e.RowIndex].Cells["ChieuCao"].Value.ToString();
                    txtBMI.Text       = dgvSucKhoe.Rows[e.RowIndex].Cells["BMI"].Value.ToString();
                    txtTinhTrang.Text = dgvSucKhoe.Rows[e.RowIndex].Cells["TinhTrang"].Value.ToString();
                    txtGhiChu.Text    = dgvSucKhoe.Rows[e.RowIndex].Cells["GhiChu"].Value.ToString();

                    int dieuKien = SucKhoeBLL.CoTheCapNhatSucKhoe(
                        int.Parse(cboThang.Text),
                        KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));
                    string maTinhTrang = dgvSucKhoe.Rows[e.RowIndex].Cells["MaTinhTrang"].Value.ToString().Trim();
                    XetRangBuocCapNhatSucKhoe(maTinhTrang, dieuKien);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Đã xảy ra lỗi. " + ex.Message);
                }
            }
        }
Exemple #13
0
        private void LoadListThang()
        {
            NamHoc namHoc = LopBLL.GetInfoNamHoc(KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()));

            int thangBatDau  = namHoc.NgayBatDau.Month;
            int thangKetThuc = namHoc.NgayKetThuc.Month;

            List <int> listThang = new List <int>();

            listThang.Add(thangBatDau);

            while (thangBatDau != thangKetThuc)
            {
                thangBatDau++;
                if (thangBatDau > 12)
                {
                    thangBatDau = 1;
                }
                listThang.Add(thangBatDau);
            }

            cboTuThang.Items.Clear();
            cboDenThang.Items.Clear();

            foreach (int thang in listThang)
            {
                cboTuThang.Items.Add(thang.ToString());
                cboDenThang.Items.Add(thang.ToString());
            }

            cboTuThang.Text  = namHoc.NgayBatDau.Month.ToString();
            cboDenThang.Text = namHoc.NgayKetThuc.Month.ToString();
        }
        /// <inheritdoc/>
        public async Task <Key> GetPublicKeyAsync(KeyHandle handle, CancellationToken ct)
        {
            var bundle = await _keyVaultClient.GetKeyAsync(_vaultBaseUrl,
                                                           KeyVaultKeyHandle.GetBundle(handle).KeyIdentifier, ct);

            return(bundle.Key.ToKey());
        }
Exemple #15
0
        private void btnThoiHoc_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Bạn có chắc là thôi học những trẻ đã được chọn?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Hand);

            if (result == DialogResult.Yes)
            {
                // B1: thôi học những trẻ ở trong DGV danh sách (left) trước
                if (cboLoaiLop_LuaChon.SelectedItem != null)
                {
                    string maLopLuaChon = KeyHandle.GetKeyFromCombobox(cboLopHoc_LuaChon.SelectedItem.ToString());
                    RemoveAllListMaTre();
                    SaveListMaTre(dgvDanhSach);
                    ThoiHoc(listMaTre, maLopLuaChon);
                    LoadDGVDanhSach();
                    LopBLL.CapNhatSiSo(maLopLuaChon, GetSiSo(dgvDanhSach));
                    txtSiSo_LuaChon.Text = LopBLL.GetSiSo(maLopLuaChon).ToString();
                }

                // B2: thôi học những trẻ ở trong DGV kết quả (right) trước
                if (cboLop.SelectedItem != null)
                {
                    string maLop = KeyHandle.GetKeyFromCombobox(cboLop.SelectedItem.ToString());
                    RemoveAllListMaTre();
                    SaveListMaTre(dgvKetQua);
                    ThoiHoc(listMaTre, maLop);
                    LoadDGVKetQua();
                    LopBLL.CapNhatSiSo(maLop, GetSiSo(dgvKetQua));
                    txtSiSo.Text = LopBLL.GetSiSo(maLop).ToString();
                }
            }
            else
            {
                MessageBox.Show("Đã hủy thôi học!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #16
0
        private void btnTaoBangMoi_Click(object sender, EventArgs e)
        {
            DialogResult confirm = new DialogResult();

            if (dgvDiemDanh.RowCount > 0)
            {
                confirm = MessageBox.Show("Ngày này đã có dữ liệu điểm danh. Bạn có chắc muốn xóa để tạo mới hoàn toàn?",
                                          "Cân nhắc", MessageBoxButtons.YesNo);
            }
            if (confirm == DialogResult.Yes || dgvDiemDanh.RowCount <= 0)
            {
                XoaPhieuCu();
                dgvDiemDanh.Columns.Clear();
                if (!string.IsNullOrEmpty(cboLop.Text))
                {
                    dgvDiemDanh.DataSource = DiemDanhBLL.TaoBangDiemDanhMoi(
                        LopBLL.GetInfoLop(KeyHandle.GetKeyFromCombobox(cboLop.SelectedItem.ToString())),
                        dtNgayDiemDanh.Text);
                    TaoPhieuTrong();
                    MessageBox.Show("Một phiếu mới hoàn toàn vừa được tạo", "Thông báo");
                    btnLuuDiemDanh.Enabled = true;
                }
            }
            else if (confirm == DialogResult.No)
            {
                return;
            }
        }
Exemple #17
0
        private void LoadDataGridView()
        {
            if (cboLop.SelectedItem == null)
            {
                dgvTre.DataSource = TreBLL.GetListTreTheoMaLop("");
            }
            else
            {
                dgvTre.DataSource = TreBLL.GetListTreTheoMaLop(
                    KeyHandle.GetKeyFromCombobox(cboLop.SelectedItem.ToString()));
            }

            dgvTre.Columns["HoTenTre"].DisplayIndex    = 1;
            dgvTre.Columns["NgaySinh"].DisplayIndex    = 2;
            dgvTre.Columns["GioiTinhCol"].DisplayIndex = 3;

            dgvTre.Columns["HoTenTre"].HeaderText    = "Họ tên trẻ";
            dgvTre.Columns["NgaySinh"].HeaderText    = "Ngày sinh";
            dgvTre.Columns["GioiTinhCol"].HeaderText = "Giới tính";

            dgvTre.Columns["HoTenTre"].Width    = 200;
            dgvTre.Columns["NgaySinh"].Width    = 120;
            dgvTre.Columns["GioiTinhCol"].Width = 80;

            string[] listProp = { "STT", "HoTenTre", "GioiTinhCol", "NgaySinh" };
            ControlFormat.DataGridViewFormat(dgvTre, listProp);

            dgvTre.ClearSelection();
            maTre = "";
            UpdateChartData();
        }
 /// <summary>
 /// Get id from handle
 /// </summary>
 /// <param name="handle"></param>
 /// <returns></returns>
 public static KeyVaultKeyHandle GetBundle(KeyHandle handle)
 {
     if (handle is KeyVaultKeyHandle id)
     {
         return(id);
     }
     throw new ArgumentException("Bad handle type");
 }
Exemple #19
0
 /// <summary>
 /// Get id from handle
 /// </summary>
 /// <param name="handle"></param>
 /// <returns></returns>
 public static string GetId(KeyHandle handle)
 {
     if (handle is KeyId id)
     {
         return(id.Id);
     }
     throw new ArgumentException("Bad handle type");
 }
 /// <inheritdoc/>
 public JToken SerializeHandle(KeyHandle handle)
 {
     if (handle is KeyId id)
     {
         return(JToken.FromObject(id));
     }
     throw new ArgumentException("Bad handle type");
 }
        public override int GetHashCode()
        {
            int hash = PublicKey.Sum(b => b + 31);

            hash += AttestationCert.Sum(b => b + 31);
            hash += KeyHandle.Sum(b => b + 31);
            return(hash);
        }
Exemple #22
0
 /// <inheritdoc/>
 public byte[] SerializeHandle(KeyHandle handle)
 {
     if (handle is KeyId id)
     {
         return(_serializer.SerializeToBytes(id).ToArray());
     }
     throw new ArgumentException("Bad handle type");
 }
Exemple #23
0
 /// <summary>
 /// Parse buffer into cert
 /// </summary>
 /// <param name="buffer"></param>
 /// <param name="key"></param>
 /// <param name="policies"></param>
 /// <param name="revoked"></param>
 /// <returns></returns>
 public static Certificate Create(byte[] buffer,
                                  KeyHandle key          = null, IssuerPolicies policies = null,
                                  RevocationInfo revoked = null)
 {
     using (var cert = new X509Certificate2(buffer)) {
         return(ToCertificate(cert, policies, key, revoked));
     }
 }
Exemple #24
0
        public override int GetHashCode()
        {
            int hash = 23 + Version.Sum(c => c + 31);

            hash += Challenge.Sum(c => c + 31);
            hash += AppId.Sum(c => c + 31);
            hash += KeyHandle.Sum(c => c + 31);

            return(hash);
        }
Exemple #25
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (UserPublicKey != null ? UserPublicKey.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (KeyHandle != null ? KeyHandle.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AttestationCertificate != null ? AttestationCertificate.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Signature != null ? Signature.GetHashCode() : 0);
         return(hashCode);
     }
 }
        /// <summary>
        /// Create signed certificate from request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="signer"></param>
        /// <param name="issuer"></param>
        /// <param name="signingKey"></param>
        /// <param name="signatureType"></param>
        /// <param name="notBefore"></param>
        /// <param name="notAfter"></param>
        /// <param name="serialNumber"></param>
        /// <returns></returns>
        public static X509Certificate2 Create(this CertificateRequest request, IDigestSigner signer,
                                              X500DistinguishedName issuer, KeyHandle signingKey, SignatureType signatureType,
                                              DateTime notBefore, DateTime notAfter, byte[] serialNumber)
        {
            var signatureGenerator = signer.CreateX509SignatureGenerator(
                signingKey, signatureType);
            var signedCert = request.Create(issuer, signatureGenerator, notBefore,
                                            notAfter, serialNumber);

            return(signedCert);
        }
 private void loadListLop()
 {
     cboLop.Items.Clear();
     cboLop.DisplayMember = "Text";
     cboLop.ValueMember   = "Value";
     foreach (Lop lop in LopBLL.GetListLop(KeyHandle.GetKeyFromCombobox(cboNamHoc.SelectedItem.ToString()),
                                           KeyHandle.GetKeyFromCombobox(cboLoaiLop.SelectedItem.ToString())))
     {
         cboLop.Items.Add(new { Text = lop.TenLop.Trim(), Value = lop.MaLop.Trim() });
     }
 }
Exemple #28
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Version != null ? Version.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Challenge != null ? Challenge.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AppId != null ? AppId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (KeyHandle != null ? KeyHandle.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SessionId != null ? SessionId.GetHashCode() : 0);
         return(hashCode);
     }
 }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = EnrollmentTime.GetHashCode();
         hashCode = (hashCode * 397) ^ (Transports != null ? Transports.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (KeyHandle != null ? KeyHandle.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (PublicKey != null ? PublicKey.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AttestationCertificate != null ? AttestationCertificate.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Counter;
         return(hashCode);
     }
 }
        /// <inheritdoc/>
        public async Task <bool> VerifyAsync(KeyHandle handle, byte[] digest,
                                             SignatureType algorithm, byte[] signature, CancellationToken ct)
        {
            var signingKey = KeyVaultKeyHandle.GetBundle(handle).KeyIdentifier;

            try {
                return(await _keyVaultClient.VerifyAsync(signingKey,
                                                         algorithm.ToJsonWebKeySignatureAlgorithm(), digest, signature, ct));
            }
            catch (KeyVaultErrorException kex) {
                throw new ExternalDependencyException("Failed to Sign", kex);
            }
        }