|
13 | 13 | // limitations under the License.
|
14 | 14 |
|
15 | 15 | #include "app/src/secure/user_secure_darwin_internal.h"
|
| 16 | +#include <functional> |
| 17 | +#include "app/src/assert.h" |
| 18 | +#include "app/src/base64.h" |
16 | 19 |
|
17 | 20 | #import <Foundation/Foundation.h>
|
18 | 21 | #import <Security/Security.h>
|
|
23 | 26 |
|
24 | 27 | // Prefix and suffix to add to keychain service name.
|
25 | 28 | static const char kServicePrefix[] = "";
|
| 29 | +static const char kServiceSeparator[] = "."; |
26 | 30 | static const char kServiceSuffix1[] = ".firebase.";
|
27 | 31 | static const char kServiceSuffix2[] = "";
|
28 |
| -// For example: com.my_company.my_app.firebase.auth, com.my_company.my_app.firebase.iid |
| 32 | +// For example: |
| 33 | +// com.my_company.my_app.firebase_project_id.process_name_hash.firebase.auth |
| 34 | +// com.my_company.my_app.firebase_project_id.process_hash.firebase.iid |
29 | 35 |
|
30 | 36 | static const int kMaxAllowedKeychainEntries = INT_MAX;
|
31 | 37 |
|
32 | 38 | // Prefix and suffix for the key for NSUserDefaults. domain and service are inserted in the middle.
|
33 | 39 | static const char kUserDefaultsPrefix[] = "com.google.firebase.";
|
| 40 | +static const char kUserDefaultsSeparator[] = "."; |
34 | 41 | static const char kUserDefaultsSuffix[] = ".has_secure_data";
|
35 |
| -// For example: com.google.firebase.auth.com.my_company.my_app.has_secure_data |
| 42 | +// For example: |
| 43 | +// com.google.firebase.com.my_company.my_app.firebase_project_id.process_hash.auth.has_secure_data |
| 44 | + |
| 45 | +static std::string GetProcessId() { |
| 46 | + std::string process_name = [[NSProcessInfo processInfo] processName].UTF8String; |
| 47 | + size_t hash = std::hash<std::string>()(process_name); |
| 48 | + std::string process_name_hash_binary(reinterpret_cast<const char*>(&hash), sizeof(hash)); |
| 49 | + std::string output; |
| 50 | + bool hash_encode_success = internal::Base64Encode(process_name_hash_binary, &output); |
| 51 | + FIREBASE_ASSERT(hash_encode_success); |
| 52 | + return output; |
| 53 | +} |
36 | 54 |
|
37 | 55 | UserSecureDarwinInternal::UserSecureDarwinInternal(const char* domain, const char* service)
|
38 | 56 | : domain_(domain) {
|
39 |
| - service_ = std::string(kServicePrefix) + service + std::string(kServiceSuffix1) + domain + |
40 |
| - std::string(kServiceSuffix2); |
41 |
| - user_defaults_key_ = |
42 |
| - std::string(kUserDefaultsPrefix) + service + "." + domain + std::string(kUserDefaultsSuffix); |
| 57 | + std::string process_id = GetProcessId(); |
| 58 | + service_ = std::string(kServicePrefix) + service + std::string(kServiceSeparator) + process_id + |
| 59 | + std::string(kServiceSuffix1) + domain + std::string(kServiceSuffix2); |
| 60 | + user_defaults_key_ = std::string(kUserDefaultsPrefix) + service + kUserDefaultsSeparator + |
| 61 | + process_id + kUserDefaultsSeparator + domain + |
| 62 | + std::string(kUserDefaultsSuffix); |
43 | 63 | }
|
44 | 64 |
|
45 | 65 | UserSecureDarwinInternal::~UserSecureDarwinInternal() {}
|
|
0 commit comments