You can send a [rest] request to server with c++ the same way the browser would do. The php script could answer with the content of the cookie which is plain text. |
I think in this scenario it should be done the other way around: Send an "authorization token" (I won't call it "cookie" to avoid confusion) via REST/HTTP request to server and let the server check (in it's database) the validity. If the server answers "positive" the application is allowed to run, otherwise it will exit with error.
Of course, the connection must be protected by HTTP
S, and the server's TLS certificate should be
pinned in the client program, so that a "malicious" customer cannot trivially redirect the request to a bogus server that always responds "positive" for
all requests
without actually checking the authorization token 😏
Another great
client-side HTTP(S) library is
libcurl:
https://curl.se/libcurl/c/https.html
(The
server-side part of the REST-API could probably written with a bunch of lines PHP code)
The question would be: How to identify the client? I.e. you need the relation to the client. The request client IP-address could be such an identifier. |
An IP address is neither specific to a single user (because of NAT, any number of users could be hiding behind a single "public" IP address), nor is the IP address of a certain user always fixed. Most users use a "dial-up" connection that changes its IP address at least every 24 hours. IP address is
not a good identifier.
Better send an "authorization token" along with the REST/HTTP request, either as query-string parameter or as a custom request header (e.g. "
X-Auth-Token" header). The "authorization token" could be computed from the customer's license key, e.g. via SHA-256 hash function or via HMAC-SHA256 and some "secret" key.