Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Member builds: GitHub's longer tokens (up to 4096 chars) sign in; Windows keeps a long sign-in across Credential Manager entries
islandmed36db9872e360
diff --git a/changes/fix-token-length.md b/changes/fix-token-length.mdnew file mode 100644index 00000000..17e0414b--- /dev/null+++ b/changes/fix-token-length.md@@ -0,0 +1,11 @@+---+fixed: **Member builds sign-in** accepts GitHub's longer tokens (its new ~520-character format, and up to 4096+ characters): before, a long token was refused and the sign-in failed without a word. On Windows, where one Credential+ Manager entry holds at most 2560 bytes, a longer sign-in is kept across several entries (studio sign-ins too);+ sign-ins stored by earlier versions still load.+testers:+ - Windows: in the update panel's Member builds section, Sign in with GitHub; restart; still signed in. Sign out; Credential Manager shows no+ SculptForge member-builds entries left.+---+Device codes get the same 4096 cap. HTTP headers were already unbounded std::string (curl_slist / WinHTTP); no+workflow assumes a token length (grep of .github/workflows).diff --git a/src/core/Keychain.cpp b/src/core/Keychain.cppindex b91b4b3a..987d453f 100644--- a/src/core/Keychain.cpp+++ b/src/core/Keychain.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#include "core/Keychain.h"+#include <algorithm>#include <atomic>#include <cstdlib>#include <cstring>@@ -25,6 +26,7 @@ namespace sf::keychain {namespace {std::atomic<bool> gMemory{false};+std::atomic<size_t> gMemoryMaxEntry{0};std::mutex gMemoryMutex;std::map<std::string, std::string>& memoryStore() {static std::map<std::string, std::string> m;@@ -46,8 +48,9 @@ const char* labelFor(const std::string& account) {} // namespace-void useMemoryForTests(bool on) {+void useMemoryForTests(bool on, size_t maxEntry) {gMemory = on;+ gMemoryMaxEntry = maxEntry;std::lock_guard lock(gMemoryMutex);memoryStore().clear();}@@ -57,18 +60,23 @@ bool store(const std::string& account, const std::string& secret);bool load(const std::string& account, std::string& secret);bool erase(const std::string& account);bool available();+size_t maxEntry(); // the most one entry holds (0: no limit)} // namespace os-bool store(const std::string& account, const std::string& secret) {+namespace {++// One entry, in memory (tests) or the OS keychain.+bool put(const std::string& account, const std::string& secret) {if (gMemory) {+ if (gMemoryMaxEntry && secret.size() > gMemoryMaxEntry) return false;std::lock_guard lock(gMemoryMutex);memoryStore()[account] = secret;return true;}- return !disabledByEnv() && os::store(account, secret);+ return os::store(account, secret);}-bool load(const std::string& account, std::string& secret) {+bool get(const std::string& account, std::string& secret) {if (gMemory) {std::lock_guard lock(gMemoryMutex);auto it = memoryStore().find(account);@@ -76,16 +84,96 @@ bool load(const std::string& account, std::string& secret) {secret = it->second;return true;}- return !disabledByEnv() && os::load(account, secret);+ return os::load(account, secret);}-bool erase(const std::string& account) {+bool del(const std::string& account) {if (gMemory) {std::lock_guard lock(gMemoryMutex);memoryStore().erase(account);return true;}- return disabledByEnv() || os::erase(account);+ return os::erase(account);+}++size_t maxEntry() { return gMemory ? gMemoryMaxEntry.load() : os::maxEntry(); }++// A secret longer than one entry holds (Windows: 2560 bytes; two long GitHub tokens are more) is split: the account's+// own entry holds kSplitMark + the part count, and "<account>#1".."#N" hold the parts. A short secret stays one entry,+// as before, so what earlier versions stored still loads.+constexpr const char* kSplitMark = "\x01sf-split:";+constexpr int kMaxParts = 16;++std::string partName(const std::string& account, int i) { return account + "#" + std::to_string(i); }++// The part count the account's entry names (0: not split).+int splitParts(const std::string& head) {+ const std::string mark = kSplitMark;+ if (head.compare(0, mark.size(), mark) != 0) return 0;+ const int n = std::atoi(head.c_str() + mark.size());+ return n > 0 && n <= kMaxParts ? n : 0;+}++void wipe(std::string& s) {+ std::fill(s.begin(), s.end(), '\0');+ s.clear();+}++// Removes "<account>#from".."#to" (parts a longer secret left behind).+void dropParts(const std::string& account, int from, int to) {+ for (int i = from; i <= to; ++i) del(partName(account, i));+}++int storedParts(const std::string& account) {+ std::string head;+ const int n = get(account, head) ? splitParts(head) : 0;+ wipe(head);+ return n;+}++} // namespace++bool store(const std::string& account, const std::string& secret) {+ if (!gMemory && disabledByEnv()) return false;+ const int before = storedParts(account);+ const size_t cap = maxEntry();+ if (!cap || secret.size() <= cap) {+ if (!put(account, secret)) return false;+ dropParts(account, 1, before);+ return true;+ }+ const size_t n = (secret.size() + cap - 1) / cap;+ if (n > size_t(kMaxParts)) return false;+ for (size_t i = 0; i < n; ++i)+ if (!put(partName(account, int(i) + 1), secret.substr(i * cap, cap))) return (dropParts(account, 1, int(n)), false);+ if (!put(account, kSplitMark + std::to_string(n))) return (dropParts(account, 1, int(n)), false);+ dropParts(account, int(n) + 1, before);+ return true;+}++bool load(const std::string& account, std::string& secret) {+ if (!gMemory && disabledByEnv()) return false;+ std::string head;+ if (!get(account, head)) return false;+ const int n = splitParts(head);+ if (!n) {+ secret = std::move(head);+ return true;+ }+ std::string joined, part;+ for (int i = 1; i <= n; ++i) {+ if (!get(partName(account, i), part)) return (wipe(joined), false);+ joined += part;+ wipe(part);+ }+ secret = std::move(joined);+ return true;+}++bool erase(const std::string& account) {+ if (!gMemory && disabledByEnv()) return true;+ dropParts(account, 1, storedParts(account));+ return del(account);}bool available() { return gMemory || (!disabledByEnv() && os::available()); }@@ -131,6 +219,7 @@ bool erase(const std::string& account) {}bool available() { return true; }+size_t maxEntry() { return CRED_MAX_CREDENTIAL_BLOB_SIZE; }#elif defined(__linux__)@@ -234,6 +323,7 @@ bool erase(const std::string& account) {}bool available() { return secretLib().ok; }+size_t maxEntry() { return 0; }#elif defined(__APPLE__)@@ -307,6 +397,7 @@ bool erase(const std::string& account) {}bool available() { return true; }+size_t maxEntry() { return 0; }#else // another OS: nothing is kept between sessions.@@ -314,6 +405,7 @@ bool store(const std::string&, const std::string&) { return false; }bool load(const std::string&, std::string&) { return false; }bool erase(const std::string&) { return true; }bool available() { return false; }+size_t maxEntry() { return 0; }#endifdiff --git a/src/core/Keychain.h b/src/core/Keychain.hindex ddf07ad9..9fcf24eb 100644--- a/src/core/Keychain.h+++ b/src/core/Keychain.h@@ -9,6 +9,7 @@// prompt): prefer worker threads. SF_KEYCHAIN=none turns the keychain off (render farms, CI).#pragma once+#include <cstddef>#include <string>namespace sf::keychain {@@ -19,7 +20,8 @@ bool erase(const std::string& account); // true when// Whether this computer has a keychain SculptForge can use (Linux: libsecret is installed).bool available();-// Tests: an in-memory keychain instead of the real one, so no test reads or writes the user's.-void useMemoryForTests(bool on);+// Tests: an in-memory keychain instead of the real one, so no test reads or writes the user's. maxEntry: the most one+// entry holds (0: no limit; 2560 acts like Windows Credential Manager, where longer secrets are split across entries).+void useMemoryForTests(bool on, size_t maxEntry = 0);} // namespace sf::keychaindiff --git a/src/core/MemberBuilds.cpp b/src/core/MemberBuilds.cppindex b53ad562..4d6d48b3 100644--- a/src/core/MemberBuilds.cpp+++ b/src/core/MemberBuilds.cpp@@ -29,9 +29,9 @@ std::string formEncode(const std::string& s) {std::string str(const Json& j, const char* key) { return j[key].isString() ? j[key].asString() : std::string(); }-// Tokens are short printable strings; anything else is not a token.+// Tokens are printable strings of at most kMaxTokenLength (GitHub's newer tokens are ~520); anything else is not a token.bool tokenLike(const std::string& s) {- return !s.empty() && s.size() <= 512 &&+ return !s.empty() && s.size() <= kMaxTokenLength &&std::all_of(s.begin(), s.end(), [](char c) { return c > 32 && c < 127 && c != '"' && c != '\\'; });}diff --git a/src/core/MemberBuilds.h b/src/core/MemberBuilds.hindex 1785b3de..72887233 100644--- a/src/core/MemberBuilds.h+++ b/src/core/MemberBuilds.h@@ -27,6 +27,7 @@ inline constexpr const char* kReleasesUrl = "https://api.github.com/repos/islandinline constexpr const char* kUserUrl = "https://api.github.com/user";inline constexpr const char* kAssetUrlPrefix = "https://api.github.com/repos/islandmed/sculptforge-insiders/releases/assets/";inline constexpr const char* kKeychainAccount = "member-builds"; // (core/Keychain.h)+inline constexpr size_t kMaxTokenLength = 4096; // longest access/refresh/device code accepted (GitHub: ~520 today)// The member API URLs the app may call with the token: the release list, one asset by number, the signed-in user.bool isMemberApiUrl(const std::string& url);diff --git a/tests/test_self_update.cpp b/tests/test_self_update.cppindex 311915f5..b74b8571 100644--- a/tests/test_self_update.cpp+++ b/tests/test_self_update.cpp@@ -8,6 +8,7 @@#include "ai/Http.h"#include "core/Ed25519.h"+#include "core/Keychain.h"#include "core/MemberBuilds.h"#include "core/SelfUpdate.h"#include "core/Sha256.h"@@ -565,6 +566,61 @@ TEST(member_builds_device_flow_answers) {CHECK(parseLogin(R"({"login":"<script>"})").empty());}+// GitHub's newer tokens are ~520 characters and may grow: up to kMaxTokenLength parse, store (split across entries+// where one entry is too small, as on Windows), load and go into the header; longer is refused.+TEST(member_builds_long_tokens) {+ using namespace sf::member;+ const std::string a520 = "ghs_" + std::string(516, 'A'), r4000 = "ghr_" + std::string(3996, 'b');+ const std::string a4096 = "ghu_" + std::string(4092, 'c'), tooLong = "ghu_" + std::string(4093, 'd');+ std::string err;+ for (const auto& [access, refresh] : {std::pair{a520, r4000}, std::pair{r4000, a520}, std::pair{a4096, a4096}}) {+ Tokens t;+ CHECK(parseTokenReply(R"({"access_token":")" + access + R"(","refresh_token":")" + refresh ++ R"(","expires_in":28800,"token_type":"bearer"})",+ 0, t, err) == TokenReply::Ok);+ CHECK(t.access == access && t.refresh == refresh);+ CHECK(headersFor(kUserUrl, t.access)[0] == "Authorization: Bearer " + access);+ for (size_t cap : {size_t(0), size_t(2560), size_t(1000)}) {+ keychain::useMemoryForTests(true, cap);+ CHECK(keychain::store(kKeychainAccount, tokensToSecret(t)));+ std::string secret;+ Tokens back;+ CHECK(keychain::load(kKeychainAccount, secret) && tokensFromSecret(secret, back));+ CHECK(back.access == access && back.refresh == refresh);+ }+ }+ Tokens t;+ CHECK(parseTokenReply(R"({"access_token":")" + tooLong + R"(","token_type":"bearer"})", 0, t, err) == TokenReply::Error);+ CHECK(parseTokenReply(R"({"access_token":"ghu_x","refresh_token":")" + tooLong + R"(","token_type":"bearer"})", 0, t,+ err) == TokenReply::Error);+ DeviceCode c;+ CHECK(parseDeviceCode(R"({"device_code":")" + a520 + R"(","user_code":"WDJB-MJHT","verification_uri":"https://github.com/login/device"})",+ 0, c, err));+ CHECK(!parseDeviceCode(R"({"device_code":")" + tooLong + R"(","user_code":"WDJB-MJHT","verification_uri":"https://github.com/login/device"})",+ 0, c, err));+ Tokens back;+ CHECK(!tokensFromSecret(R"({"access":")" + tooLong + R"("})", back));++ // Split entries: what earlier versions stored (one entry) still loads; a shorter secret replaces a split one and+ // leaves no parts behind; erase removes every part.+ keychain::useMemoryForTests(true, 2560);+ const std::string old = R"({"access":"ghu_short","refresh":"ghr_short"})";+ CHECK(keychain::store(kKeychainAccount, old));+ std::string got, part;+ CHECK(keychain::load(kKeychainAccount, got) && got == old && tokensFromSecret(got, back) && back.access == "ghu_short");+ const std::string big(9000, 'x');+ CHECK(keychain::store(kKeychainAccount, big) && keychain::load(kKeychainAccount, got) && got == big);+ CHECK(keychain::load(std::string(kKeychainAccount) + "#4", part) && !keychain::load(std::string(kKeychainAccount) + "#5", part));+ CHECK(keychain::store(kKeychainAccount, std::string(3000, 'y')) && keychain::load(kKeychainAccount, got) && got == std::string(3000, 'y'));+ CHECK(!keychain::load(std::string(kKeychainAccount) + "#3", part));+ CHECK(keychain::store(kKeychainAccount, old) && keychain::load(kKeychainAccount, got) && got == old);+ CHECK(!keychain::load(std::string(kKeychainAccount) + "#1", part));+ CHECK(keychain::store(kKeychainAccount, big) && keychain::erase(kKeychainAccount));+ CHECK(!keychain::load(kKeychainAccount, got) && !keychain::load(std::string(kKeychainAccount) + "#1", part));+ CHECK(!keychain::store(kKeychainAccount, std::string(2560 * 17, 'z'))); // (more parts than allowed: refused)+ keychain::useMemoryForTests(true);+}+TEST(member_builds_release_list) {using namespace sf::member;const char* list = R"([@@ -624,9 +680,11 @@ TEST(self_update_live_github_redirect) {}#if defined(_WIN32)-#include "core/Keychain.h"-// Windows Credential Manager: store, read back, replace, erase (a test entry, not the member sign-in's).+// Windows Credential Manager itself (the tests otherwise use the in-memory keychain): store, read back, replace, erase,+// and a secret over its 2560-byte entry limit (two long GitHub tokens), split across entries. A test entry, not the+// member sign-in's.TEST(self_update_keychain_windows) {+ keychain::useMemoryForTests(false);const std::string account = "test-self-update";keychain::erase(account);std::string got;@@ -635,7 +693,17 @@ TEST(self_update_keychain_windows) {CHECK(keychain::load(account, got) && got == "{\"access\":\"ghu_test\"}");CHECK(keychain::store(account, "second"));CHECK(keychain::load(account, got) && got == "second");- CHECK(keychain::erase(account) && !keychain::load(account, got));+ member::Tokens t;+ t.access = "ghu_" + std::string(4092, 'a');+ t.refresh = "ghr_" + std::string(4092, 'b');+ CHECK(keychain::store(account, member::tokensToSecret(t)));+ member::Tokens back;+ CHECK(keychain::load(account, got) && member::tokensFromSecret(got, back) && back.access == t.access && back.refresh == t.refresh);+ CHECK(keychain::store(account, "short again") && keychain::load(account, got) && got == "short again");+ CHECK(!keychain::load(account + "#1", got));+ CHECK(keychain::store(account, member::tokensToSecret(t)));+ CHECK(keychain::erase(account) && !keychain::load(account, got) && !keychain::load(account + "#1", got));CHECK(keychain::erase(account)); // (nothing there: still fine)+ keychain::useMemoryForTests(true);}#endif