|
15 | 15 | #include "app_check/src/desktop/debug_provider_desktop.h" |
16 | 16 |
|
17 | 17 | #include <cstdint> |
| 18 | +#include <cstdio> |
| 19 | +#include <cstdlib> |
18 | 20 | #include <map> |
19 | 21 | #include <memory> |
20 | 22 | #include <string> |
21 | 23 | #include <utility> |
22 | 24 |
|
| 25 | +#include "app/src/uuid.h" |
| 26 | + |
23 | 27 | #include "app/rest/response.h" |
24 | 28 | #include "app/rest/transport_builder.h" |
25 | 29 | #include "app/rest/transport_curl.h" |
@@ -111,27 +115,52 @@ void DebugAppCheckProvider::GetLimitedUseToken( |
111 | 115 | GetTokenInternal(true, completion_callback); |
112 | 116 | } |
113 | 117 |
|
| 118 | +firebase::internal::Uuid GenerateDebugToken |
| 119 | + |
114 | 120 | void DebugAppCheckProvider::GetTokenInternal( |
115 | 121 | bool limited_use, |
116 | 122 | std::function<void(AppCheckToken, int, const std::string&)> |
117 | 123 | completion_callback) { |
118 | | - // Identify the user's debug token |
119 | | - const char* debug_token_cstr; |
120 | | - if (!debug_token_.empty()) { |
121 | | - debug_token_cstr = debug_token_.c_str(); |
122 | | - } else { |
123 | | - debug_token_cstr = std::getenv("APP_CHECK_DEBUG_TOKEN"); |
| 124 | + if (debug_token_.empty()) { |
| 125 | + if (std::getenv("APP_CHECK_DEBUG_TOKEN")) { |
| 126 | + debug_token_ = std::getenv("APP_CHECK_DEBUG_TOKEN"); |
| 127 | + } else { |
| 128 | + // Generate UUID |
| 129 | + firebase::internal::Uuid uuid; |
| 130 | + uuid.Generate(); |
| 131 | + char uuid_str[37]; |
| 132 | + snprintf(uuid_str, sizeof(uuid_str), |
| 133 | + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 134 | + uuid.data[0], uuid.data[1], uuid.data[2], uuid.data[3], |
| 135 | + uuid.data[4], uuid.data[5], uuid.data[6], uuid.data[7], |
| 136 | + uuid.data[8], uuid.data[9], uuid.data[10], uuid.data[11], |
| 137 | + uuid.data[12], uuid.data[13], uuid.data[14], uuid.data[15]); |
| 138 | + debug_token_ = uuid_str; |
| 139 | + } |
124 | 140 | } |
125 | 141 |
|
126 | | - if (!debug_token_cstr) { |
127 | | - completion_callback({}, kAppCheckErrorInvalidConfiguration, |
128 | | - "Missing debug token"); |
129 | | - return; |
| 142 | + static bool logged_token = false; |
| 143 | + if (!logged_token && !debug_token_.empty()) { |
| 144 | + logged_token = true; |
| 145 | + std::string app_id = app_->options().app_id(); |
| 146 | + std::string project_id = app_->options().project_id(); |
| 147 | + std::string message = std::string("\nWARNING: Firebase App Check debug token: ") + debug_token_ + "\n\n" + |
| 148 | + "To use this token for app debugging, register it with your project.\n\n" + |
| 149 | + "You can do so in the Firebase Console: \n" + |
| 150 | + "https://console.firebase.google.com/project/" + project_id + "/appcheck/apps?selectedAppId=" + app_id + " \n\n" + |
| 151 | + "Or using the Firebase CLI: \n" + |
| 152 | + "firebase appcheck:debugtokens:create " + debug_token_ + " --app " + app_id + "\n\n" + |
| 153 | + "Note: To keep your project secure, please revoke and delete this token using the \n" + |
| 154 | + "Firebase Console or the CLI (`firebase appcheck:debugtokens:delete`) when you finish debugging.\n\n" + |
| 155 | + "Warning: This debug token is a secret and should not be shared or uploaded to source code.\n\n" + |
| 156 | + "Debug Token Guide: https://firebase.google.com/docs/app-check/ios/debug-provider\n" + |
| 157 | + "Firebase CLI install instructions: https://firebase.google.com/docs/cli\n"; |
| 158 | + firebase::LogWarning("%s", message.c_str()); |
130 | 159 | } |
131 | 160 |
|
132 | 161 | // Exchange debug token with the backend to get a proper attestation token. |
133 | 162 | auto request = std::make_shared<DebugTokenRequest>(app_); |
134 | | - request->SetDebugToken(debug_token_cstr); |
| 163 | + request->SetDebugToken(debug_token_); |
135 | 164 | request->SetLimitedUse(limited_use); |
136 | 165 |
|
137 | 166 | // Use an async call, since we don't want to block on the server response. |
|
0 commit comments