private List <Item> ExportLogins() { List <Item> items = new List <Item>(); // initialize AES var crypto = new AesCrypto(Convert.FromBase64String(MasterKeyText.Text)); // open the Cookie db string cs = string.Format("Data Source={0};", this.inputFile); string stm = "SELECT * FROM logins ORDER BY origin_url;"; var con = new SQLiteConnection(cs); con.Open(); var cmd = new SQLiteCommand(stm, con); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { byte[] encrypted_value = (byte[])reader["password_value"]; byte[] decrypted_value = null; if (encrypted_value[0] == 'v' && encrypted_value[1] == '1' && encrypted_value[2] == '0') { try { decrypted_value = crypto.Decrypt(encrypted_value); } catch (Exception e) { MessageBox.Show(e.Message); continue; } } else { // TODO: we could extract DPAPI keys too maybe continue; } Login login = new Login { origin_url = reader.GetString(0), action_url = reader.GetString(1), username_element = reader.GetString(2), username_value = reader.GetString(3), password_element = reader.GetString(4), password_value = encrypted_value, submit_element = reader.GetString(6), signon_realm = reader.GetString(7), date_created = reader.GetInt32(8), blacklisted_by_user = reader.GetInt32(9), scheme = reader.GetInt32(10), password_type = reader.GetInt32(11), times_used = reader.GetInt32(12), form_data = (byte[])reader["form_data"], date_synced = reader.GetInt32(14), display_name = reader.GetString(15), icon_url = reader.GetString(16), federation_url = reader.GetString(17), skip_zero_click = reader.GetInt32(18), generation_upload_status = reader.GetInt32(19), possible_username_pairs = (byte[])reader["possible_username_pairs"], id = reader.GetInt32(21), date_last_used = reader.GetInt32(22), moving_blocked_for = (byte[])reader["moving_blocked_for"], decrypted_password_value = decrypted_value }; items.Add(login); } } else { Console.WriteLine("No rows found."); } reader.Close(); return(items); }
private List <Item> ExportCookies() { List <Item> items = new List <Item>(); // initialize AES var crypto = new AesCrypto(Convert.FromBase64String(MasterKeyText.Text)); // open the Cookie db string cs = string.Format("Data Source={0};", this.inputFile); string stm = "SELECT creation_utc, host_key, name, value, " + "path, expires_utc, is_secure, is_httponly, last_access_utc, " + "has_expires, is_persistent, priority, encrypted_value, " + "samesite, source_scheme FROM cookies ORDER BY host_key;"; var con = new SQLiteConnection(cs); con.Open(); var cmd = new SQLiteCommand(stm, con); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { byte[] encrypted_value = (byte[])reader["encrypted_value"]; byte[] decrypted_value = null; if (encrypted_value[0] == 'v' && encrypted_value[1] == '1' && encrypted_value[2] == '0') { try { decrypted_value = crypto.Decrypt(encrypted_value); } catch (Exception e) { MessageBox.Show(e.Message); continue; } } else { // TODO: we could extract DPAPI keys too maybe continue; } var cookie = new Cookie { creation_utc = reader.GetInt64(0), host_key = reader.GetString(1), name = reader.GetString(2), value = reader.GetString(3), path = reader.GetString(4), expires_utc = reader.GetInt64(5), is_secure = reader.GetBoolean(6), is_httponly = reader.GetBoolean(7), last_access_utc = reader.GetInt64(8), has_expires = reader.GetBoolean(9), is_persistent = reader.GetBoolean(10), priority = reader.GetInt16(11), encrypted_value = encrypted_value, samesite = reader.GetBoolean(13), source_scheme = reader.GetInt16(14), decrypted_value = decrypted_value }; items.Add(cookie); } } else { Console.WriteLine("No rows found."); } reader.Close(); return(items); }