Skip to content

Commit cb2f6e9

Browse files
authored
Sending authentication token for crashlytics and session (#12383)
1 parent 7147ecc commit cb2f6e9

25 files changed

+233
-56
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
3+
- [fixed] Force validation or rotation of FIDs for FirebaseSessions.
4+
15
# 10.22.0
26
- [changed] Removed calls to statfs in the Crashlytics SDK to comply with Apple Privacy Manifests. This change removes support for collecting Disk Space Free in Crashlytics reports.
37
- [fixed] Fixed FirebaseSessions crash on startup that occurs in release mode in Xcode 15.3 and other build configurations. (#11403)

Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@property(nonatomic, readonly) NSOperationQueue *operationQueue;
2929
@property(nonatomic, readonly) FIRCLSFileManager *fileManager;
3030
@property(nonatomic, copy) NSString *fiid;
31+
@property(nonatomic, copy) NSString *authToken;
3132

3233
- (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report
3334
dataCollectionToken:(FIRCLSDataCollectionToken *)dataCollectionToken

Crashlytics/Crashlytics/Controllers/FIRCLSReportUploader.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ - (void)prepareAndSubmitReport:(FIRCLSInternalReport *)report
9595
// urgent mode. Since urgent mode happens when the app is in a crash loop,
9696
// we can safely assume users aren't rotating their FIID, so this can be skipped.
9797
if (!urgent) {
98-
[self.installIDModel regenerateInstallIDIfNeededWithBlock:^(NSString *_Nonnull newFIID) {
98+
[self.installIDModel regenerateInstallIDIfNeededWithBlock:^(
99+
NSString *_Nonnull newFIID, NSString *_Nonnull authToken) {
99100
self.fiid = [newFIID copy];
101+
self.authToken = [authToken copy];
100102
}];
101103
} else {
102104
FIRCLSWarningLog(
@@ -186,7 +188,8 @@ - (void)uploadPackagedReportAtPath:(NSString *)path
186188
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:path
187189
googleAppId:self.googleAppID
188190
installIDModel:self.installIDModel
189-
fiid:self.fiid];
191+
fiid:self.fiid
192+
authToken:self.authToken];
190193

191194
GDTCOREvent *event = [self.googleTransport eventForTransport];
192195
event.dataObject = adapter;

Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
4444
* - Concern 2: Whatever the FIID is, we should send it with the Crash report so we're in sync with
4545
* Sessions and other Firebase SDKs
4646
*/
47-
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid))block;
47+
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid, NSString *authToken))block;
4848

4949
@end
5050

Crashlytics/Crashlytics/Models/FIRCLSInstallIdentifierModel.m

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,45 @@ - (NSString *)generateInstallationUUID {
9898

9999
#pragma mark Privacy Shield
100100

101-
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid))block {
101+
- (BOOL)regenerateInstallIDIfNeededWithBlock:(void (^)(NSString *fiid, NSString *authToken))block {
102102
BOOL __block didRotate = false;
103+
NSString __block *authTokenComplete = @"";
104+
NSString __block *currentIIDComplete = @"";
103105

104-
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
106+
// Installations Completions run async, so wait a reasonable amount of time for it to finish.
107+
dispatch_group_t workingGroup = dispatch_group_create();
105108

106-
// This runs Completion async, so wait a reasonable amount of time for it to finish.
109+
dispatch_group_enter(workingGroup);
107110
[self.installations
108-
installationIDWithCompletion:^(NSString *_Nullable currentIID, NSError *_Nullable error) {
109-
// Provide the IID to the callback. For this case we don't care
110-
// if the FIID is null because it's the best we can do - we just want
111-
// to send up the same FIID that is sent by other SDKs (eg. the Sessions SDK).
112-
block(currentIID);
111+
authTokenWithCompletion:^(FIRInstallationsAuthTokenResult *_Nullable tokenResult,
112+
NSError *_Nullable error) {
113+
authTokenComplete = tokenResult.authToken;
114+
dispatch_group_leave(workingGroup);
115+
}];
113116

117+
dispatch_group_enter(workingGroup);
118+
[self.installations
119+
installationIDWithCompletion:^(NSString *_Nullable currentIID, NSError *_Nullable error) {
120+
currentIIDComplete = currentIID;
114121
didRotate = [self rotateCrashlyticsInstallUUIDWithIID:currentIID error:error];
115122

116123
if (didRotate) {
117124
FIRCLSInfoLog(@"Rotated Crashlytics Install UUID because Firebase Install ID changed");
118125
}
119-
dispatch_semaphore_signal(semaphore);
126+
dispatch_group_leave(workingGroup);
120127
}];
121128

122-
intptr_t result = dispatch_semaphore_wait(
123-
semaphore, dispatch_time(DISPATCH_TIME_NOW, FIRCLSInstallationsWaitTime));
129+
intptr_t result = dispatch_group_wait(
130+
workingGroup, dispatch_time(DISPATCH_TIME_NOW, FIRCLSInstallationsWaitTime));
131+
124132
if (result != 0) {
125133
FIRCLSErrorLog(@"Crashlytics timed out while checking for Firebase Installation ID");
126134
}
127135

136+
// Provide the IID to the callback. For this case we don't care
137+
// if the FIID is null because it's the best we can do - we just want
138+
// to send up the same FIID that is sent by other SDKs (eg. the Sessions SDK).
139+
block(currentIIDComplete, authTokenComplete);
128140
return didRotate;
129141
}
130142

Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
- (instancetype)initWithPath:(NSString *)folderPath
3636
googleAppId:(NSString *)googleAppID
3737
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
38-
fiid:(NSString *)fiid;
38+
fiid:(NSString *)fiid
39+
authToken:(NSString *)authToken;
3940
@end

Crashlytics/Crashlytics/Models/Record/FIRCLSReportAdapter.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ @interface FIRCLSReportAdapter ()
3030

3131
@property(nonatomic, strong) FIRCLSInstallIdentifierModel *installIDModel;
3232
@property(nonatomic, copy) NSString *fiid;
33+
@property(nonatomic, copy) NSString *authToken;
3334

3435
@end
3536

@@ -38,13 +39,15 @@ @implementation FIRCLSReportAdapter
3839
- (instancetype)initWithPath:(NSString *)folderPath
3940
googleAppId:(NSString *)googleAppID
4041
installIDModel:(FIRCLSInstallIdentifierModel *)installIDModel
41-
fiid:(NSString *)fiid {
42+
fiid:(NSString *)fiid
43+
authToken:(NSString *)authToken {
4244
self = [super init];
4345
if (self) {
4446
_folderPath = folderPath;
4547
_googleAppID = googleAppID;
4648
_installIDModel = installIDModel;
4749
_fiid = [fiid copy];
50+
_authToken = [authToken copy];
4851

4952
[self loadMetaDataFile];
5053

@@ -156,6 +159,7 @@ - (google_crashlytics_Report)protoReport {
156159
report.installation_uuid = FIRCLSEncodeString(self.installIDModel.installID);
157160
report.firebase_installation_id = FIRCLSEncodeString(self.fiid);
158161
report.app_quality_session_id = FIRCLSEncodeString(self.identity.app_quality_session_id);
162+
report.firebase_authentication_token = FIRCLSEncodeString(self.authToken);
159163
report.build_version = FIRCLSEncodeString(self.application.build_version);
160164
report.display_version = FIRCLSEncodeString(self.application.display_version);
161165
report.apple_payload = [self protoFilesPayload];

Crashlytics/Protogen/nanopb/crashlytics.nanopb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828

29-
const pb_field_t google_crashlytics_Report_fields[10] = {
29+
const pb_field_t google_crashlytics_Report_fields[11] = {
3030
PB_FIELD( 1, BYTES , SINGULAR, POINTER , FIRST, google_crashlytics_Report, sdk_version, sdk_version, 0),
3131
PB_FIELD( 3, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, gmp_app_id, sdk_version, 0),
3232
PB_FIELD( 4, UENUM , SINGULAR, STATIC , OTHER, google_crashlytics_Report, platform, gmp_app_id, 0),
@@ -36,6 +36,7 @@ const pb_field_t google_crashlytics_Report_fields[10] = {
3636
PB_FIELD( 10, MESSAGE , SINGULAR, STATIC , OTHER, google_crashlytics_Report, apple_payload, display_version, &google_crashlytics_FilesPayload_fields),
3737
PB_FIELD( 16, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, firebase_installation_id, apple_payload, 0),
3838
PB_FIELD( 17, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, app_quality_session_id, firebase_installation_id, 0),
39+
PB_FIELD( 19, BYTES , SINGULAR, POINTER , OTHER, google_crashlytics_Report, firebase_authentication_token, app_quality_session_id, 0),
3940
PB_LAST_FIELD
4041
};
4142

Crashlytics/Protogen/nanopb/crashlytics.nanopb.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ typedef struct _google_crashlytics_Report {
6161
google_crashlytics_FilesPayload apple_payload;
6262
pb_bytes_array_t *firebase_installation_id;
6363
pb_bytes_array_t *app_quality_session_id;
64+
pb_bytes_array_t *firebase_authentication_token;
6465
/* @@protoc_insertion_point(struct:google_crashlytics_Report) */
6566
} google_crashlytics_Report;
6667

@@ -84,12 +85,13 @@ typedef struct _google_crashlytics_Report {
8485
#define google_crashlytics_Report_installation_uuid_tag 5
8586
#define google_crashlytics_Report_firebase_installation_id_tag 16
8687
#define google_crashlytics_Report_app_quality_session_id_tag 17
88+
#define google_crashlytics_Report_firebase_authentication_token 19
8789
#define google_crashlytics_Report_build_version_tag 6
8890
#define google_crashlytics_Report_display_version_tag 7
8991
#define google_crashlytics_Report_apple_payload_tag 10
9092

9193
/* Struct field encoding specification for nanopb */
92-
extern const pb_field_t google_crashlytics_Report_fields[10];
94+
extern const pb_field_t google_crashlytics_Report_fields[11];
9395
extern const pb_field_t google_crashlytics_FilesPayload_fields[2];
9496
extern const pb_field_t google_crashlytics_FilesPayload_File_fields[3];
9597

Crashlytics/UnitTests/FIRCLSContextManagerTests.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ - (void)test_notSettingSessionID_protoHasNilSessionID {
7575
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
7676
googleAppId:@"TestGoogleAppID"
7777
installIDModel:self.installIDModel
78-
fiid:@"TestFIID"];
78+
fiid:@"TestFIID"
79+
authToken:@"TestAuthToken"];
7980

8081
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, @"");
8182
}
@@ -92,7 +93,8 @@ - (void)test_settingSessionIDMultipleTimes_protoHasLastSessionID {
9293
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
9394
googleAppId:@"TestGoogleAppID"
9495
installIDModel:self.installIDModel
95-
fiid:@"TestFIID"];
96+
fiid:@"TestFIID"
97+
authToken:@"TestAuthToken"];
9698
NSLog(@"reportPath: %@", self.report.path);
9799

98100
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);
@@ -110,7 +112,8 @@ - (void)test_settingSessionIDOutOfOrder_protoHasLastSessionID {
110112
FIRCLSReportAdapter *adapter = [[FIRCLSReportAdapter alloc] initWithPath:self.report.path
111113
googleAppId:@"TestGoogleAppID"
112114
installIDModel:self.installIDModel
113-
fiid:@"TestFIID"];
115+
fiid:@"TestFIID"
116+
authToken:@"TestAuthToken"];
114117
NSLog(@"reportPath: %@", self.report.path);
115118

116119
XCTAssertEqualObjects(adapter.identity.app_quality_session_id, TestContextSessionID2);

0 commit comments

Comments
 (0)