Firebase - Access secured Realtime Database via GSM - firebase

this is my first question, so let if I did something wrong, I´ll rework it.
This Issue
For accessing a FBRD protected via Security Rules, the user has to be authorized and authenticated.
Authorization: Done via setting up Security Rules -> OK
Authentication: Done via Google OAuth2 access tokens or Firebase ID tokens as per Firebase Authenticate Doku
There are several libraries I found but sadly non of them is applicable for my use-case:
running on an µC
support of GSM (no Wifi)
What I achieved
Posting Data via https REST to FBRD with API-KEY and SECRET. This is just an interim workaround which I want to get rid off, since SECRET should not be stored of µC source code and the user µC in this case should only have limited access as per Security Rules.
What I tried without success
Wifi Library: Firebase-ESP-Client
Example: EMail
Info: There was already a discussion on GSM. Outome was, no GSM support
My question
Has somebody solved this issue or could help in doing so?
I´m not a security expert but I think APIs for token generation and exchange are needed. Or with other word how get the token exchange and needed for sign-in-email-password realized on µC?
Thanks in advance
Build Errors due to Wifi connection
Firebase Arduino Client Library for ESP8266 and ESP32/src/wcs/esp32/FB_TCP_Client.h:43:0,
Firebase Arduino Client Library for ESP8266 and ESP32/src/common.h:39,
Firebase Arduino Client Library for ESP8266 and ESP32/src/Utils.h:37,
Firebase Arduino Client Library for ESP8266 and ESP32/src/signer/Signer.h:37,
Firebase Arduino Client Library for ESP8266 and ESP32/src/Firebase.h:45,
Firebase Arduino Client Library for ESP8266 and ESP32/src/Firebase_ESP_Client.h:41,

Related

Secure communication between Flutter App and Web PHP

I'm learning Flutter myself and need some expert guidance on the right way to do what I want.
I would like to allow the user of my Flutter application to securely send some sensitive data (e.g. email, phone number, name etc.) to my PHP based website (with REST API) and then, after some time, I would like to send a reply (e.g. . text) from my website to the sender's device and displaying it on the User's screen.
I suspect I should use Firebase Cloud Messaging for this - am I right?
I found tutorials that explain how to send data from Flutter-> FCM and from PHP(curl)-> FCM. But I can't find the tutorial explaining how to send data from Flutter-> FCM-> PHP?
Firebase Cloud Messaging is typically used to send messages from the server to the application, when the user may not be actively using it. While it can be used to send messages from the client to a server, it is much less common for that.
That's because calling a PHP API from your Flutter app is no different than retrieving any data from the internet, and can be accomplished in a multitude of ways. One of the simpler approaches is documented in Flutter's fetching data from the internet page and uses the http package.

Communication between Firestore and ESP32

I am doing a project to identify people via RFID in ESP32. When performing the identification, the ESP must consult the data referring to the identified RFID TAG and display the related data on a display (name, city, date of birth).
However, I am not able to understand how I carry out this communication between ESP and Firestore. Can anyone help me?
Thanks!
The intended method of talking to the Google Cloud from an ESP32 is through the IoT Core. Note that this will not get you a direct connection to the Firestore - you'd have to write some cloud side code to translate MQTT messages into database queries and responses. This shouldn't be very difficult, though.
Otherwise you can send HTTPS queries directly to the Firebase REST API. Read the Google documentation for that.
If you are using ESP-IDF framework for your development you can use this ESP-IDF component to communicate with Firestore (this component uses Firestore REST API via HTTPS):
https://github.com/kaizoku-oh/firestore.git
Here is also an example using RFID and Firestore components that you can change according to your needs:
https://github.com/kaizoku-oh/firestore-rfid-node.git

How do I invoke a google cloud function through HTTPS request using a SIM800

I have an express app running on firebase functions. I have tested invoking the function from my browser to write data to my database and it works perfectly fine. I also set the "Cloud Functions Invoker" permission to "allUsers".
My problem is, I need to send sensor data collected on an Arduino UNO to my cloud firestore through a SIM800 GPRS module (Making an HTTP request to my firebase function). I have tried AT+HTTPSSL=1 to enable SSL, but when sending the request I get a 606 response, which means "SSL alert message with a level of fatal result in the immediate termination of the connection" according to the SIM800 Series_SSL_Application Note_V1.01 documentation.
I have tried sending requests to an HTTP server hosting a PHP script and it worked fine, and from there I am able to use curl to do an HTTPS request to my firebase function, and it works fine, but it takes minutes to refresh my database, which is undesired.
Please let me know if there is a way to invoke a Google cloud function using the mentioned hardware. If not, what would you do in my situation?
Thanks in advance!

Firebase Cloud Messaging (FCM) notifications doesn't work on devices behind proxy. Is there any alternative way to solve it?

Our Android application is working over 2000 devices on field. This is a corporate app, not published on Google Play and we are managing our operations via these devices. Most important point for us: All of our client Android devices are behind proxy. (We have already take all actions on Firebase document warning about "If your organization has a firewall...")
We are testing to adapt FCM to our app for receiving notifications. We are using HTTP Protocol, sending Post requests to https://fcm.googleapis.com/fcm/send URL address, so our choice is Downstream HTTP Messages (JSON) and we are sending data messages both via Postman and also via our .Net desktop app. Firebase Cloud Messaging notifications are working successfully when device is connected to Internet via independent WiFi. It is also working successfully when device is connected to Internet via mobile network operator SIM card (No Proxy). But these methods are not a solution for us, because all of our devices are working behind proxy.
Is Firebase Cloud Messaging notifications not working on devices behind proxy? I found some bad news about FCM and behind proxy devices, but I am not sure. We want to use FCM notifications, however 3rd party extra apps is not a good solution for us. Because we are managing too many devices on field and we have also security issues. Is there any alternative solution to solve this issue about proxy?
I have received an answer from Firebase support team about this question. The answer is below:
Please note that FCM do not support Proxy at the moment, however we
will take a note of this and we could consider it moving forward. I
can't give you a definite timeline for this, rest assured your
feedback has been acknowledged. We are constantly working on providing
developers a more friendly experience hence your inputs are greatly
appreciated.
We have spent some effort and time with our app development and network team about this Proxy issue. Please note that FCM do not support Proxy at this time. I hope they can support Proxy in the future, because FCM have many benefits.
If you took the actions described in if your organization has a firewall
then the devices should be able to receive the messages.
https://firebase.google.com/docs/cloud-messaging/server#response
Please note that those action have to be taken in the network where the devices are connected, not in the network where the notification is sent.
Please note that as of 2019 Firebase has some Proxy Support, at least using Java or Node.js, see this Article about it: https://medium.com/faun/firebase-accessing-firestore-and-firebase-through-a-proxy-server-c6c6029cddb1
In case the Link is down, this is an example for Java configuration, all credits go to Hiranya Jayathilaka who wrote this great Tutorial (many thanks!)
String myProxyHost = "localhost"; // REPLACE
int myProxyPort = 3128; // REPLACE
InetSocketAddress address = new InetSocketAddress(myProxyHost, myProxyPort);
HttpTransport transport = new NetHttpTransport.Builder()
.setProxy(new Proxy(Proxy.Type.HTTP, address))
.build();
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
builder.setHttpTransport(transport);
// ... further configuration ...
Addition:
I have tried this solution and setting the HttpTransport only proxies requests to "fcm.googleapis.com", which is not sufficient in my case, because the Firebase Sdk first retrieves an Authorization Token from "accounts.google.com".
To Proxy requests to "accounts.google.com" also, I had to use System-Properties like this:
System.setProperty("https.proxyHost", proxyHost);
System.setProperty("https.proxyPort", String.valueOf(proxyPort));
System.setProperty("com.google.api.client.should_use_proxy", "true");

Should I deploy Firebase Cloud Messaging server myself?

I've read the document about FCM, but I wonder if I should deploy a FCM server myself. Does the google cloud platform not provide FCM server? Or do I must implemented my own FCM server refering to the official reference implementation, gcm-playgroud?
It depends. (How's that for an answer?)
By "server", I'm assuming you mean, "Code I will be running on the server level to communicate with the FCM service". And honestly, the answer depends on whether or not you need extra functionality that's not supplied by the Firebase Notifications panel.
You can do a lot with Firebase Notifications, including sending scheduled messages, or sending messages to individual users, topics, or Audiences. But that is work that is done manually. If you just want to send the occasional promotional message to your users, you shouldn't need a server.
On the other hand, maybe you've got a messaging app and you want to send a notification to your user anytime they receive a new message. Well, that's clearly something that needs to be automated, and that requires some server-side code. So for that, you will need to set up your own server that communicates with FCM.

Resources