Scenario:
I have a webserver running php, I want to be able to be able to securely send a request to a separate server running nodejs and get a response back. The node server will never need to send anything to the webserver by itself, e.g notifications/updates. So I don't think I need the 2 way communications that websockets would provide.
PHP sends a request to node, node processes the request, sends back data (most likely in JSON), php continues with it's script using the returned data.
Problem
I own the server running node, but the webserver is out in the wild. I need a way of making sure that any requests that come in to the node server are actually from the webserver not someone/something else, and I need the request and response data to be encrypted.
I have gathered I don't want to rely on something simple like checking ip addresses, I know that the webserver and the node sever will have to both have some shared secret information/algorithms to encode data. I could have a go at implementing this myself, but I know this problem is already solved with some encryption protocol / libraries. I'm familiar with the concepts of encryption and keys, but I have never had to implement them.
Question
- What is the best way to go about this?
- What kind of encryption should/can I use, that is both supported by php and nodeJs?
- What would be the potential security threats, if any?