Skip to content

Commit 16af0f1

Browse files
authored
Prefer roots.pem from gRPC-C++, but fall back to Firestore bundled ones if necessary (#2106)
gRPC-C++ versions up to and including 0.0.3, and also 0.0.5, don't bundle `roots.pem` in the podspec. gRPC-C++ 0.0.4 and, presumably, the currently not-yet-released 0.0.6 do. Firestore currently also bundles this file under the same bundle name, which leads to build errors when both Firestore and gRPC-C++ try to add the file into the build (only shows during archiving). For transition, this PR: * renames the Firestore bundle to avoid naming clash; * changes the loading code so that it first tries to load certificates bundled with gRPC-C++ (versions 0.0.4 and 0.0.6+), but falls back to those bundled with Firestore if necessary. At a later point, Firestore should be changed to not bundle the certificates altogether.
1 parent 54659e8 commit 16af0f1

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

FirebaseFirestore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
5050

5151
# TODO(varconst): remove once https://github.com/grpc/grpc/pull/16962 makes it
5252
# into a release.
53-
s.resource_bundles = { 'gRPCCertificates' => ['Firestore/etc/roots.pem'] }
53+
s.resource_bundles = { 'gRPCCertificates-Firestore' => ['Firestore/etc/roots.pem'] }
5454

5555
s.dependency 'FirebaseAuthInterop', '~> 1.0'
5656
s.dependency 'FirebaseCore', '~> 5.1'

Firestore/core/src/firebase/firestore/remote/grpc_root_certificate_finder_apple.mm

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "Firestore/core/src/firebase/firestore/util/filesystem.h"
2222
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
23+
#include "Firestore/core/src/firebase/firestore/util/log.h"
2324
#include "Firestore/core/src/firebase/firestore/util/statusor.h"
2425

2526
#import "Firestore/Source/Core/FSTFirestoreClient.h"
@@ -34,19 +35,30 @@
3435
using util::StringFormat;
3536

3637
std::string LoadGrpcRootCertificate() {
37-
// TODO(varconst): uncomment these lines once it's possible to load the
38-
// certificate from gRPC-C++ pod.
39-
// NSBundle* bundle = [NSBundle bundleWithIdentifier:@"org.cocoapods.grpcpp"];
40-
// HARD_ASSERT(bundle, "Could not find grpcpp bundle");
41-
42-
// `mainBundle` may be nil in certain cases (e.g., unit tests).
43-
NSBundle* bundle = [NSBundle bundleForClass:FSTFirestoreClient.class];
44-
HARD_ASSERT(bundle, "Could not find Firestore bundle");
45-
NSString* path =
46-
[bundle pathForResource:@"gRPCCertificates.bundle/roots" ofType:@"pem"];
38+
// Try to load certificates bundled by gRPC-C++ if available (depends on
39+
// gRPC-C++ version).
40+
// Note that `mainBundle` may be nil in certain cases (e.g., unit tests).
41+
NSBundle* bundle = [NSBundle bundleWithIdentifier:@"org.cocoapods.grpcpp"];
42+
NSString* path;
43+
if (bundle) {
44+
path =
45+
[bundle pathForResource:@"gRPCCertificates.bundle/roots" ofType:@"pem"];
46+
}
47+
if (path) {
48+
LOG_DEBUG("Using roots.pem file from gRPC-C++ pod");
49+
} else {
50+
// Fall back to the certificates bundled with Firestore if necessary.
51+
LOG_DEBUG("Using roots.pem file from Firestore pod");
52+
53+
bundle = [NSBundle bundleForClass:FSTFirestoreClient.class];
54+
HARD_ASSERT(bundle, "Could not find Firestore bundle");
55+
path = [bundle pathForResource:@"gRPCCertificates-Firestore.bundle/roots"
56+
ofType:@"pem"];
57+
}
58+
4759
HARD_ASSERT(
4860
path,
49-
"Could not load root certificates from the bundle. SSL won't work.");
61+
"Could not load root certificates from the bundle. SSL cannot work.");
5062

5163
StatusOr<std::string> certificate = ReadFile(Path::FromNSString(path));
5264
HARD_ASSERT(

0 commit comments

Comments
 (0)