From 7915db67c55748e7e7ad3051b9749f9a992a1f17 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Tue, 21 Jun 2016 15:38:29 +0300 Subject: Check hashes when downloading assets --- tools/editor/asset_library_editor_plugin.cpp | 21 +++++++++++++-------- tools/editor/asset_library_editor_plugin.h | 7 +++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index c571310ded..de13265e89 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -227,11 +227,12 @@ void EditorAssetLibraryItemDescription::_preview_click(int p_id) { } } -void EditorAssetLibraryItemDescription::configure(const String& p_title,int p_asset_id,const String& p_category,int p_category_id,const String& p_author,int p_author_id,int p_rating,const String& p_cost,int p_version,const String& p_version_string,const String& p_description,const String& p_download_url,const String& p_browse_url) { +void EditorAssetLibraryItemDescription::configure(const String& p_title,int p_asset_id,const String& p_category,int p_category_id,const String& p_author,int p_author_id,int p_rating,const String& p_cost,int p_version,const String& p_version_string,const String& p_description,const String& p_download_url,const String& p_browse_url,const String& p_sha256_hash) { asset_id=p_asset_id; title=p_title; download_url=p_download_url; + sha256=p_sha256_hash; item->configure(p_title,p_asset_id,p_category,p_category_id,p_author,p_author_id,p_rating,p_cost); description->clear(); description->add_text("Version: "+p_version_string+"\n"); @@ -358,9 +359,12 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int if (p_code!=200) { error_text=("Request failed, return code: "+itos(p_code)); status->set_text("Failed: "+itos(p_code)); - } else { - - //all good + } else if(sha256 != "") { + String download_sha256 = FileAccess::get_sha256(download->get_download_file()); + if(sha256 != download_sha256) { + error_text="Bad download hash, assuming file has been tampered with.\nExpected: " + sha256 + "\nGot: " + download_sha256; + status->set_text("Failed sha256 hash check"); + } } } break; @@ -384,15 +388,15 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int } -void EditorAssetLibraryItemDownload::configure(const String& p_title,int p_asset_id,const Ref& p_preview, const String& p_download_url) { +void EditorAssetLibraryItemDownload::configure(const String& p_title,int p_asset_id,const Ref& p_preview, const String& p_download_url, const String& p_sha256_hash) { title->set_text(p_title); icon->set_texture(p_preview); asset_id=p_asset_id; if (!p_preview.is_valid()) icon->set_texture(get_icon("GodotAssetDefault","EditorIcons")); - host=p_download_url; + sha256=p_sha256_hash; asset_installer->connect("confirmed",this,"_close"); dismiss->set_normal_texture( get_icon("Close","EditorIcons")); _make_request(); @@ -604,7 +608,7 @@ void EditorAssetLibrary::_install_asset() { EditorAssetLibraryItemDownload * download = memnew( EditorAssetLibraryItemDownload ); downloads_hb->add_child(download); - download->configure(description->get_title(),description->get_asset_id(),description->get_preview_icon(),description->get_download_url()); + download->configure(description->get_title(),description->get_asset_id(),description->get_preview_icon(),description->get_download_url(),description->get_sha256()); } @@ -1134,6 +1138,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const ERR_FAIL_COND(!r.has("cost")); ERR_FAIL_COND(!r.has("description")); ERR_FAIL_COND(!r.has("download_url")); + ERR_FAIL_COND(!r.has("download_hash")); ERR_FAIL_COND(!r.has("browse_url")); if (description) { @@ -1145,7 +1150,7 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const description->popup_centered_minsize(); description->connect("confirmed",this,"_install_asset"); - description->configure(r["title"],r["asset_id"],category_map[r["category_id"]],r["category_id"],r["author"],r["author_id"],r["rating"],r["cost"],r["version"],r["version_string"],r["description"],r["download_url"],r["browse_url"]); + description->configure(r["title"],r["asset_id"],category_map[r["category_id"]],r["category_id"],r["author"],r["author_id"],r["rating"],r["cost"],r["version"],r["version_string"],r["description"],r["download_url"],r["browse_url"], r["download_hash"]); /*item->connect("asset_selected",this,"_select_asset"); item->connect("author_selected",this,"_select_author"); item->connect("category_selected",this,"_category_selected");*/ diff --git a/tools/editor/asset_library_editor_plugin.h b/tools/editor/asset_library_editor_plugin.h index 6a6e29338f..0f150fb0e6 100644 --- a/tools/editor/asset_library_editor_plugin.h +++ b/tools/editor/asset_library_editor_plugin.h @@ -111,6 +111,7 @@ class EditorAssetLibraryItemDescription : public ConfirmationDialog { int asset_id; String download_url; String title; + String sha256; Ref icon; void _link_click(const String& p_url); @@ -120,13 +121,14 @@ protected: static void _bind_methods(); public: - void configure(const String& p_title,int p_asset_id,const String& p_category,int p_category_id,const String& p_author,int p_author_id,int p_rating,const String& p_cost,int p_version,const String& p_version_string,const String& p_description,const String& p_download_url,const String& p_browse_url); + void configure(const String& p_title,int p_asset_id,const String& p_category,int p_category_id,const String& p_author,int p_author_id,int p_rating,const String& p_cost,int p_version,const String& p_version_string,const String& p_description,const String& p_download_url,const String& p_browse_url,const String& p_sha256_hash); void add_preview(int p_id, bool p_video,const String& p_url); String get_title() { return title; } Ref get_preview_icon() { return icon; } String get_download_url() { return download_url; } int get_asset_id() { return asset_id; } + String get_sha256() { return sha256; } EditorAssetLibraryItemDescription(); }; @@ -146,6 +148,7 @@ class EditorAssetLibraryItemDownload : public PanelContainer { AcceptDialog *download_error; HTTPRequest *download; String host; + String sha256; Label *status; int prev_status; @@ -166,7 +169,7 @@ protected: public: int get_asset_id() { return asset_id; } - void configure(const String& p_title,int p_asset_id,const Ref& p_preview, const String& p_download_url); + void configure(const String& p_title,int p_asset_id,const Ref& p_preview, const String& p_download_url, const String& p_sha256_hash); EditorAssetLibraryItemDownload(); }; -- cgit v1.2.3 From a2e39c8da00e0c8a1015a6dea8d0989a551ee016 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Tue, 21 Jun 2016 16:29:49 +0300 Subject: Add support levels to search --- tools/editor/asset_library_editor_plugin.cpp | 23 +++++++++++++++++++++++ tools/editor/asset_library_editor_plugin.h | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index de13265e89..e6667b1a81 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -628,6 +628,12 @@ const char* EditorAssetLibrary::sort_text[SORT_MAX]={ "Updated" }; +const char* EditorAssetLibrary::support_key[SUPPORT_MAX]={ + "official", + "community", + "testing" +}; + void EditorAssetLibrary::_select_author(int p_id) { @@ -839,11 +845,26 @@ void EditorAssetLibrary::_repository_changed(int p_repository_id) { _api_request("configure", REQUESTING_CONFIG); } +void EditorAssetLibrary::_support_toggled(int p_support) { + print_line(support_key[p_support]); + support->get_popup()->set_item_checked(p_support, !support->get_popup()->is_item_checked(p_support)); +} + void EditorAssetLibrary::_search(int p_page) { String args; args=String()+"?sort="+sort_key[sort->get_selected()]; + + String support_list; + for(int i = 0; i < SUPPORT_MAX; i++) { + if(support->get_popup()->is_item_checked(i)) { + support_list += String(support_key[i]) + "+"; + } + } + if(support_list != String()) { + args += "&support=" + support_list.substr(0, support_list.length() - 1); + } if (categories->get_selected()>0) { @@ -1236,6 +1257,7 @@ void EditorAssetLibrary::_bind_methods() { ObjectTypeDB::bind_method("_asset_open",&EditorAssetLibrary::_asset_open); ObjectTypeDB::bind_method("_asset_file_selected",&EditorAssetLibrary::_asset_file_selected); ObjectTypeDB::bind_method("_repository_changed",&EditorAssetLibrary::_repository_changed); + ObjectTypeDB::bind_method("_support_toggled",&EditorAssetLibrary::_support_toggled); } @@ -1345,6 +1367,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { support->get_popup()->add_check_item(TTR("Testing"),SUPPORT_TESTING); support->get_popup()->set_item_checked(SUPPORT_OFFICIAL,true); support->get_popup()->set_item_checked(SUPPORT_COMMUNITY,true); + support->get_popup()->connect("item_pressed",this,"_support_toggled"); ///////// diff --git a/tools/editor/asset_library_editor_plugin.h b/tools/editor/asset_library_editor_plugin.h index 0f150fb0e6..7f9514019e 100644 --- a/tools/editor/asset_library_editor_plugin.h +++ b/tools/editor/asset_library_editor_plugin.h @@ -213,7 +213,8 @@ class EditorAssetLibrary : public PanelContainer { enum Support { SUPPORT_OFFICIAL, SUPPORT_COMMUNITY, - SUPPORT_TESTING + SUPPORT_TESTING, + SUPPORT_MAX }; enum SortOrder { @@ -228,6 +229,7 @@ class EditorAssetLibrary : public PanelContainer { static const char* sort_key[SORT_MAX]; static const char* sort_text[SORT_MAX]; + static const char* support_key[SUPPORT_MAX]; ///MainListing @@ -296,6 +298,7 @@ class EditorAssetLibrary : public PanelContainer { void _http_download_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data); void _repository_changed(int p_repository_id); + void _support_toggled(int p_support); friend class EditorAssetLibraryItemDescription; friend class EditorAssetLibraryItem; -- cgit v1.2.3 From 1e08387ce032f1af5d60a0af6c05f83c2c7fc1f4 Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Tue, 21 Jun 2016 17:10:02 +0300 Subject: Fix project manager category list, small enchancements as well --- tools/editor/asset_library_editor_plugin.cpp | 24 +++++++++++++++++++++--- tools/editor/asset_library_editor_plugin.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index e6667b1a81..a2448921d7 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -842,19 +842,33 @@ void EditorAssetLibrary::_request_image(ObjectID p_for,String p_image_url,ImageT void EditorAssetLibrary::_repository_changed(int p_repository_id) { host=repository->get_item_metadata(p_repository_id); print_line(".." + host); - _api_request("configure", REQUESTING_CONFIG); + if(templates_only) { + _api_request("configure", REQUESTING_CONFIG, "?type=project"); + } else { + _api_request("configure", REQUESTING_CONFIG); + } } void EditorAssetLibrary::_support_toggled(int p_support) { - print_line(support_key[p_support]); support->get_popup()->set_item_checked(p_support, !support->get_popup()->is_item_checked(p_support)); + _search(); +} + +void EditorAssetLibrary::_rerun_search(int p_ignore) { + _search(); } void EditorAssetLibrary::_search(int p_page) { String args; - args=String()+"?sort="+sort_key[sort->get_selected()]; + if(templates_only) { + args += "?type=project&"; + } else { + args += "?"; + } + args+=String()+"sort="+sort_key[sort->get_selected()]; + String support_list; for(int i = 0; i < SUPPORT_MAX; i++) { @@ -1258,6 +1272,7 @@ void EditorAssetLibrary::_bind_methods() { ObjectTypeDB::bind_method("_asset_file_selected",&EditorAssetLibrary::_asset_file_selected); ObjectTypeDB::bind_method("_repository_changed",&EditorAssetLibrary::_repository_changed); ObjectTypeDB::bind_method("_support_toggled",&EditorAssetLibrary::_support_toggled); + ObjectTypeDB::bind_method("_rerun_search",&EditorAssetLibrary::_rerun_search); } @@ -1325,9 +1340,11 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { search_hb2->add_child(sort); sort->set_h_size_flags(SIZE_EXPAND_FILL); + sort->connect("item_selected", this, "_rerun_search"); reverse = memnew( ToolButton ); reverse->set_toggle_mode(true); + reverse->connect("toggled", this, "_rerun_search"); //reverse->set_text(TTR("Reverse")); search_hb2->add_child(reverse); @@ -1341,6 +1358,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { search_hb2->add_child(categories); categories->set_h_size_flags(SIZE_EXPAND_FILL); //search_hb2->add_spacer(); + categories->connect("item_selected", this, "_rerun_search"); search_hb2->add_child(memnew(VSeparator)); diff --git a/tools/editor/asset_library_editor_plugin.h b/tools/editor/asset_library_editor_plugin.h index 7f9514019e..89663aa00b 100644 --- a/tools/editor/asset_library_editor_plugin.h +++ b/tools/editor/asset_library_editor_plugin.h @@ -293,6 +293,7 @@ class EditorAssetLibrary : public PanelContainer { void _manage_plugins(); void _search(int p_page=0); + void _rerun_search(int p_ignore); void _api_request(const String& p_request, RequestType p_request_type, const String &p_arguments=""); void _http_request_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data); void _http_download_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data); -- cgit v1.2.3