Esempio n. 1
0
        /// <summary>
        /// DoInsertUserKey method implementation
        /// </summary>
        private void DoInsertUserKey(string upn, string secretkey)
        {
            List <MFAUserKeys> _lst = _mfakeysusers.GetData();
            MFAUserKeys        _itm = new MFAUserKeys()
            {
                UserName = upn.ToLower(),
                UserKey  = secretkey
            };

            _lst.Add(_itm);
            _mfakeysusers.SetData(_lst);
        }
Esempio n. 2
0
        /// <summary>
        /// GetUserKey method implementation
        /// </summary>
        public override string GetUserKey(string upn)
        {
            string result = string.Empty;

            try
            {
                List <MFAUserKeys> _lst = _mfakeysusers.GetData();
                MFAUserKeys        _itm = _lst.FirstOrDefault(s => s.UserName.ToLower().Equals(upn.ToLower()) && (!string.IsNullOrEmpty(s.UserKey)));
                if (_itm != null)
                {
                    result = _itm.UserKey;
                }
            }
            catch (Exception ex)
            {
                DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
                throw new Exception(ex.Message);
            }
            return(result);
        }
        /// <summary>
        /// GetUserCertificate method implementation
        /// </summary>
        public override X509Certificate2 GetUserCertificate(string upn, string password)
        {
            X509Certificate2 result = null;

            try
            {
                List <MFAUserKeys> _lst = _mfakeysusers.GetData();
                MFAUserKeys        _itm = _lst.FirstOrDefault(s => s.UserName.ToLower().Equals(upn.ToLower()) && (!string.IsNullOrEmpty(s.UserCertificate)));
                if (_itm != null)
                {
                    X509Certificate2 cert = new X509Certificate2(Convert.FromBase64String(_itm.UserCertificate), password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.EphemeralKeySet);
                    result = cert;
                }
            }
            catch (Exception ex)
            {
                DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
                throw new Exception(ex.Message);
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// DoInsertUserCertificate method implementation
        /// </summary>
        private void DoInsertUserCertificate(string upn, X509Certificate2 cert)
        {
            List <MFAUserKeys> _lst = _mfakeysusers.GetData();

            try
            {
                MFAUserKeys _itm = new MFAUserKeys()
                {
                    UserName        = upn.ToLower(),
                    UserKey         = string.Empty,
                    UserCertificate = Convert.ToBase64String(cert.Export(X509ContentType.Pfx, CheckSumEncoding.CheckSumAsString(upn)))
                };
                cert.Reset();
                _lst.Add(_itm);
                _mfakeysusers.SetData(_lst);
            }
            catch (Exception ex)
            {
                DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
                throw new Exception(ex.Message);
            }
        }