Ejemplo n.º 1
0
        /// <summary>
        /// GetUserStoredCredentials method implementation
        /// </summary>
        public List <WebAuthNCredentialInformation> GetUserStoredCredentials(AuthenticationContext ctx)
        {
            List <WebAuthNCredentialInformation> wcreds = new List <WebAuthNCredentialInformation>();

            var user = RuntimeRepository.GetUser(Config, ctx.UPN);

            List <MFAUserCredential> creds = RuntimeRepository.GetCredentialsByUser(Config, user);

            if (creds.Count == 0)
            {
                return(wcreds);
            }
            foreach (MFAUserCredential st in creds)
            {
                WebAuthNCredentialInformation itm = new WebAuthNCredentialInformation()
                {
                    CredentialID     = HexaEncoding.GetHexStringFromByteArray(st.Descriptor.Id),
                    AaGuid           = st.AaGuid,
                    CredType         = st.CredType,
                    RegDate          = st.RegDate,
                    SignatureCounter = st.SignatureCounter
                };
                if (st.Descriptor.Type != null)
                {
                    itm.Type = EnumExtensions.ToEnumMemberValue(st.Descriptor.Type.Value);
                }
                wcreds.Add(itm);
            }
            return(wcreds.OrderByDescending(c => c.RegDate).ToList <WebAuthNCredentialInformation>());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// UpdateCounter method implementation
        /// </summary>
        public void UpdateCounter(MFAWebAuthNUser user, byte[] credentialId, uint counter)
        {
            string            credsid = HexaEncoding.GetHexStringFromByteArray(credentialId);
            MFAUserCredential cred    = GetCredentialByCredentialId(user, credsid);

            if (cred != null)
            {
                cred.SignatureCounter = counter;
                SetUserCredential(user, cred);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// GetUsersByCredentialId method implementation
        /// </summary>
        public List <MFAWebAuthNUser> GetUsersByCredentialId(MFAWebAuthNUser user, byte[] credentialId)
        {
            List <MFAWebAuthNUser> _users = new List <MFAWebAuthNUser>();
            string            credsid     = HexaEncoding.GetHexStringFromByteArray(credentialId);
            MFAUserCredential cred        = GetCredentialByCredentialId(user, credsid);

            if (cred != null)
            {
                _users.Add(user);
            }
            return(_users);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// RemoveUserCredential method implementation
 /// </summary>
 public bool RemoveUserCredential(MFAWebAuthNUser user, string credentialId)
 {
     try
     {
         List <MFAUserCredential> _lst = _mfacredusers.GetData();
         int res = _lst.RemoveAll(s => s.UserId.SequenceEqual(user.Id) && (HexaEncoding.GetHexStringFromByteArray(s.Descriptor.Id)).Equals(credentialId));
         _mfacredusers.SetData(_lst);
         return(res > 0);
     }
     catch (Exception ex)
     {
         DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
         throw new Exception(ex.Message);
     }
 }
        /// <summary>
        /// GetUserStoredCredentials method implementation
        /// </summary>
        public List <WebAuthNCredentialInformation> GetUserStoredCredentials(string upn)
        {
            List <WebAuthNCredentialInformation> wcreds = new List <WebAuthNCredentialInformation>();

            try
            {
                MFAWebAuthNUser user = RuntimeRepository.GetUser(Config, upn);
                if (user != null)
                {
                    List <MFAUserCredential> creds = RuntimeRepository.GetCredentialsByUser(Config, user);
                    if (creds.Count == 0)
                    {
                        return(null);
                    }
                    // return wcreds;
                    foreach (MFAUserCredential st in creds)
                    {
                        WebAuthNCredentialInformation itm = new WebAuthNCredentialInformation()
                        {
                            CredentialID     = HexaEncoding.GetHexStringFromByteArray(st.Descriptor.Id),
                            AaGuid           = st.AaGuid,
                            CredType         = st.CredType,
                            RegDate          = st.RegDate,
                            SignatureCounter = st.SignatureCounter,
                            NickName         = st.NickName
                        };
                        if (st.Descriptor.Type != null)
                        {
                            itm.Type = EnumExtensions.ToEnumMemberValue(st.Descriptor.Type.Value);
                        }
                        wcreds.Add(itm);
                    }
                    return(wcreds.OrderByDescending(c => c.RegDate).ToList());
                }
                else
                {
                    Log.WriteEntry(string.Format("{0}\r\n{1}", upn, "User does not exists !"), EventLogEntryType.Error, 5000);
                    throw new ArgumentNullException(string.Format("{0}\r\n{1}", upn, "User does not exists !"));;
                }
            }
            catch (Exception e)
            {
                Log.WriteEntry(string.Format("{0}\r\n{1}", upn, e.Message), EventLogEntryType.Error, 5000);
                throw e;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// GetCredentialById method implementation
        /// </summary>
        public MFAUserCredential GetCredentialById(MFAWebAuthNUser user, byte[] id)
        {
            string credsid = HexaEncoding.GetHexStringFromByteArray(id);

            return(GetCredentialByCredentialId(user, credsid));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// GetCredentialByCredentialId method implementation
 /// </summary>
 public MFAUserCredential GetCredentialByCredentialId(MFAWebAuthNUser user, string credentialId)
 {
     try
     {
         List <MFAUserCredential> _creds = _mfacredusers.GetData();
         return(_creds.FirstOrDefault(s => s.UserId.SequenceEqual(user.Id) && (HexaEncoding.GetHexStringFromByteArray(s.Descriptor.Id)).Equals(credentialId)));
     }
     catch (Exception ex)
     {
         DataLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error, 5000);
         throw new Exception(ex.Message);
     }
 }