|
20 | 20 |
|
21 | 21 | #include "Firestore/core/src/firebase/firestore/util/filesystem.h"
|
22 | 22 | #include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
|
| 23 | +#include "Firestore/core/src/firebase/firestore/util/log.h" |
23 | 24 | #include "Firestore/core/src/firebase/firestore/util/statusor.h"
|
24 | 25 |
|
25 | 26 | #import "Firestore/Source/Core/FSTFirestoreClient.h"
|
|
34 | 35 | using util::StringFormat;
|
35 | 36 |
|
36 | 37 | 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 | + |
47 | 59 | HARD_ASSERT(
|
48 | 60 | 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."); |
50 | 62 |
|
51 | 63 | StatusOr<std::string> certificate = ReadFile(Path::FromNSString(path));
|
52 | 64 | HARD_ASSERT(
|
|
0 commit comments