firebase / firebase-admin-java

Firebase Admin Java SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
540 stars 267 forks source link

Unable to send firebase notification via server. #933

Closed Sufiyan-Salman closed 6 months ago

Sufiyan-Salman commented 6 months ago

Environment

The problem I have a springboot project and added firebase dependency and all related things. When I run the project locally, everything works fine. I then deploy on the remote server, I get the exception which I will share below. I am using firebase admin sdk to send notifications. The code for sending is:

try {
    messagingService.send(message);
    logger.info("Firebase notification sent to user: "+user.getUsername());
    saveLog(true, "Notification Sent", pushNotificationLog);
    return true;
}catch (FirebaseMessagingException e) {
    logger.info("Firebase did not send notification to user: "+user.getUsername()+ " Error Message: "+e.getMessage());
    saveLog(false, e.getMessage(), pushNotificationLog);
    return false;
}

Steps to reproduce: I don't know what we can do to reproduce as it is happening with my server, I guess.

As soon as I do the same on my remote server after deploying my code, I get the exception while sending the notification, this is what it says: Error Message: Unknown error while making a remote service call: Error getting access token for service account: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext), iss: firebase-adminsdk-b12345@abc1-c1235.ibm.gserviceaccount.com

Screenshot from 2024-03-19 15-28-16

I have go daddy certificate.

google-oss-bot commented 6 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

Sufiyan-Salman commented 6 months ago

Now to narrow down this issue even more, I got a lead, which is: I wrote the following line in my docker file and faced the issue because this. ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","-Djavax.net.ssl.keyStore=/opt/java/openjdk/lib/security/cacerts","-Djavax.net.ssl.keyStorePassword=cheit","-Djdk.tls.client.protocols=TLSv1.2", "/app.jar"]

When I changed the above line to the one below, it worked. ENTRYPOINT ["java","-jar","-Djava.security.egd=file:/dev/./urandom","-Djdk.tls.client.protocols=TLSv1.2", "/app.jar"] This shows that cacerts file has some issue, but it only appears when I use firebase. What can I do to resolve this?

Sufiyan-Salman commented 6 months ago

The path which was leading to cacerts file was wrong as there was no such path in my container, I changed it as per mine and it worked. How I reached to the error? "-Djavax.net.debug=all", I added this in entrypoint which gave me logs for reqs and in that I saw the error of file not found.