Firebase-ios-sdk: Firestore fails to load root certificates in a share extension

Created on 13 Feb 2019  路  7Comments  路  Source: firebase/firebase-ios-sdk

[READ] Step 1: Are you in the right place?

  • For issues or feature requests related to __the code in this repository__
    file a Github issue.

    • If this is a __feature request__ make sure the issue title starts with "FR:".

  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Xcode version: 10.1 (10B61)
  • Firebase SDK version: 5.16.0
  • Firebase Component: Using FirebaseAnalytics (5.5.0)
    Using FirebaseAuth (5.3.0)
    Using FirebaseAuthInterop (1.0.0)
    Using FirebaseCore (5.2.0)
    Using FirebaseDatabase (5.1.0)
    Using FirebaseFirestore (1.0.0)
    Using FirebaseInstanceID (3.4.0)

Here is the top part of my podfile:

# Uncomment this line to define a global platform for your project
 platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'GoogleSignIn'


target 'QueueUpShareExtension' do

  # Pods for QueueUpShareExtension
  pod 'Firebase/Core'
  pod 'Firebase/Auth'
  pod 'GoogleSignIn'

end

[REQUIRED] Step 3:

I'm working in an XCode ios Application Extension (Share Extension). I'm able to authenticate just fine but when I try to get documents or add a document within the same method, it's throwing the exception stack below. Does this have something to do with how I'm instantiating FirestoreSettings?

Steps to reproduce:

2019-02-12 23:48:58.769317-0500 QueueUpShareExtension[2043:7385258] *** Assertion failure in std::string firebase::firestore::remote::LoadGrpcRootCertificate()(), /Users/macmoto/Dropbox/AppDevelopment/FlutterApps/queue_up/ios/Pods/FirebaseFirestore/Firestore/core/src/firebase/firestore/remote/grpc_root_certificate_finder_apple.mm:81
2019-02-12 23:48:58.792134-0500 QueueUpShareExtension[2043:7385258] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED: Could not load root certificates from the bundle. SSL cannot work. (expected path)'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000110e2c1bb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010fe12735 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000110e2bf42 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000010f25d940 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
    4   QueueUpShareExtension               0x000000010b39b7e5 _ZN8firebase9firestore4util8internal4FailEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 533
    5   QueueUpShareExtension               0x000000010b39bea2 _ZN8firebase9firestore4util8internal4FailEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEES4_ + 1538
    6   QueueUpShareExtension               0x000000010b382c96 _ZN8firebase9firestore6remote23LoadGrpcRootCertificateEv + 118
    7   QueueUpShareExtension               0x000000010b3748d0 _ZNK8firebase9firestore6remote14GrpcConnection13CreateChannelEv + 96
    8   QueueUpShareExtension               0x000000010b3743eb _ZN8firebase9firestore6remote14GrpcConnection16EnsureActiveStubEv + 267
    9   QueueUpShareExtension               0x000000010b377045 _ZN8firebase9firestore6remote14GrpcConnection12CreateStreamEN4absl11string_viewERKNS0_4auth5TokenEPNS1_18GrpcStreamObserverE + 85
    10  QueueUpShareExtension               0x000000010b3fb9c5 _ZN8firebase9firestore6remote11WriteStream16CreateGrpcStreamEPNS1_14GrpcConnectionERKNS0_4auth5TokenE + 101
    11  QueueUpShareExtension               0x000000010b3e1cdf _ZN8firebase9firestore6remote6Stream26ResumeStartWithCredentialsERKNS0_4util8StatusOrINS0_4auth5TokenEEE + 351
    12  QueueUpShareExtension               0x000000010b3e6b8e _ZZZN8firebase9firestore6remote6Stream18RequestCredentialsEvENK3$_0clERKNS0_4util8StatusOrINS0_4auth5TokenEEEENKUlvE_clEv + 142
    13  QueueUpShareExtension               0x000000010b3e6aed _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZZN8firebase9firestore6remote6Stream18RequestCredentialsEvENK3$_0clERKNS4_4util8StatusOrINS4_4auth5TokenEEEEUlvE_EEEvDpOT_ + 45
    14  QueueUpShareExtension               0x000000010b3e67b9 _ZNSt3__110__function6__funcIZZN8firebase9firestore6remote6Stream18RequestCredentialsEvENK3$_0clERKNS3_4util8StatusOrINS3_4auth5TokenEEEEUlvE_NS_9allocatorISE_EEFvvEEclEv + 41
    15  QueueUpShareExtension               0x000000010b222c16 _ZNKSt3__18functionIFvvEEclEv + 102
    16  QueueUpShareExtension               0x000000010b16adce _ZN8firebase9firestore4util10AsyncQueue15ExecuteBlockingERKNSt3__18functionIFvvEEE + 478
    17  QueueUpShareExtension               0x000000010b16d957 _ZZN8firebase9firestore4util10AsyncQueue4WrapERKNSt3__18functionIFvvEEEENK3$_0clEv + 39
    18  QueueUpShareExtension               0x000000010b16d91d _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZN8firebase9firestore4util10AsyncQueue4WrapERKNS_8functionIFvvEEEE3$_0EEEvDpOT_ + 45
    19  QueueUpShareExtension               0x000000010b16d6d9 _ZNSt3__110__function6__funcIZN8firebase9firestore4util10AsyncQueue4WrapERKNS_8functionIFvvEEEE3$_0NS_9allocatorISB_EES7_EclEv + 41
    20  QueueUpShareExtension               0x000000010b222c16 _ZNKSt3__18functionIFvvEEclEv + 102
    21  QueueUpShareExtension               0x000000010b1a4e31 _ZZN8firebase9firestore4util8internal13DispatchAsyncEPU28objcproto17OS_dispatch_queue8NSObjectONSt3__18functionIFvvEEEENK3$_0clEPv + 33
    22  QueueUpShareExtension               0x000000010b1a4e08 _ZZN8firebase9firestore4util8internal13DispatchAsyncEPU28objcproto17OS_dispatch_queue8NSObjectONSt3__18functionIFvvEEEEN3$_08__invokeEPv + 24
    23  libdispatch.dylib                   0x0000000110b6254b _dispatch_client_callout + 8
    24  libdispatch.dylib                   0x0000000110b6901c _dispatch_lane_serial_drain + 720
    25  libdispatch.dylib                   0x0000000110b69b5f _dispatch_lane_invoke + 401
    26  libdispatch.dylib                   0x0000000110b729a8 _dispatch_workloop_worker_thread + 645
    27  libsystem_pthread.dylib             0x0000000111eb9fd2 _pthread_wqthread + 980
    28  libsystem_pthread.dylib             0x0000000111eb9be9 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Relevant Code:

 if let _ = FirebaseApp.app() {

            // [START setup]
            let settings = FirestoreSettings()

            Firestore.firestore().settings = settings
            // [END setup]
            self.db = Firestore.firestore()

            //TODO: Change signin method later to something more secure
             Auth.auth().signIn(withEmail: "[email protected]", password: "f5ibZscPolrL@NC6eI62xQNIf") { (user, error) in

                if let error = error {
                    print(error.localizedDescription)
                }
                else
                {
                    self.db.collection("queue_item").getDocuments() { (querySnapshot, err) in
                        if let err = err {
                            print("Error getting documents: \(err)")
                        } else {
                            for document in querySnapshot!.documents {
                                print("\(document.documentID) => \(document.data())")
                            }
                        }
                    }
                    /*
                    var ref: DocumentReference? = nil
                    ref = self.db.collection("queue_item").addDocument(data: [
                        "url": urlToSave,
                        "timesQueued": 1,
                        "title": titleToSave,
                        "subtitle": "",
                        "cleared": false,
                        "commentFromQueuer": commentToSave!,
                        "viewed": true,
                        "queuedForUID": _currentUID,
                        "createdByUID": _currentUID,
                        "createdAt": Date()

                    ]) { err in
                        if let err = err {
                            print("Error adding Queue Item: \(err)")
                        } else {
                            print("Queue Item added with ID: \(ref!.documentID)")
                        }
                    }*/
                }
            }
         }

        // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
        self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
firestore extensions

Most helpful comment

This doesn't have anything to do with how you've instantiating FirestoreSettings, which is entirely unrelated. The issue is that very early in Firestore initialization, we load a certificate bundle. That bundle needs to be available to find with NSBundle.

Your Podfile doesn't actually include FirebaseFirestore or Firebase/Firestore so it's not clear exactly how you're getting Firestore, but you clearly are getting it because your code is compiling :-).

2177 is primarily about how Carthage-based builds run into trouble when the bundle isn't available where the code expects it. If you're using CocoaPods you should be getting the resources you need automatically. In particular, look for gRPCCertificates.bundle in the FirebaseFirestore.framework.

If you see gRPCCerticates.bundle in your build, the next step would be add a call to Firestore.enableLogging(true) and report back the log lines you see related to certificate loading.

All 7 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

Duplicate of #2177

This doesn't have anything to do with how you've instantiating FirestoreSettings, which is entirely unrelated. The issue is that very early in Firestore initialization, we load a certificate bundle. That bundle needs to be available to find with NSBundle.

Your Podfile doesn't actually include FirebaseFirestore or Firebase/Firestore so it's not clear exactly how you're getting Firestore, but you clearly are getting it because your code is compiling :-).

2177 is primarily about how Carthage-based builds run into trouble when the bundle isn't available where the code expects it. If you're using CocoaPods you should be getting the resources you need automatically. In particular, look for gRPCCertificates.bundle in the FirebaseFirestore.framework.

If you see gRPCCerticates.bundle in your build, the next step would be add a call to Firestore.enableLogging(true) and report back the log lines you see related to certificate loading.

This doesn't have anything to do with how you've instantiating FirestoreSettings, which is entirely unrelated. The issue is that very early in Firestore initialization, we load a certificate bundle. That bundle needs to be available to find with NSBundle.

Your Podfile doesn't actually include FirebaseFirestore or Firebase/Firestore so it's not clear exactly how you're getting Firestore, but you clearly are getting it because your code is compiling :-).

2177 is primarily about how Carthage-based builds run into trouble when the bundle isn't available where the code expects it. If you're using CocoaPods you should be getting the resources you need automatically. In particular, look for gRPCCertificates.bundle in the FirebaseFirestore.framework.

If you see gRPCCerticates.bundle in your build, the next step would be add a call to Firestore.enableLogging(true) and report back the log lines you see related to certificate loading.

Thank you, Gil! Simply adding "pod 'Firebase/Firestore'" to both places in the podfile and then running pod install did the trick! Working perfectly now.

"pod 'Firebase/Firestore'" to both places in the podfile ? I find only one Podfile add get "pod 'Firebase/Firestore'" added. still error
Screenshot 2019-09-30 22 25 13

"Both places" likely means both target specifications within the Podfile.

@burkaslarry "Both places in the Podfile" refers back to the Podfile posted in the issue description, where the author happened to include the dependencies twice.

If you're having difficulty please create a new issue, fully describing your environment and what you're trying to do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skuske picture skuske  路  3Comments

professorbk picture professorbk  路  3Comments

lorenzofiamingo picture lorenzofiamingo  路  3Comments

PierBover picture PierBover  路  3Comments

jaschaio picture jaschaio  路  3Comments