C++ programming for HTTPS - c++

I am a C++ programmer new to HTTPS. I need to write a COM based windows service in C++ which can handle HTTPS requests. But for that I would need to understand how the technologies and protocol fit together.
I understand this is a very open ended question but my intent is to find some documentation that introduces a C++ programmer to HTTPS programming.
Thanks in advance.

Writing your own HTTP server is no minor undertaking (if you want to get everything right), and writing one to support SSL is even more difficult. You would be much better advised to use one of the many open source servers (see here for a list), many of which can be embedded in your c++ code. Personally, I have found Mongoose very easy to embed in C++ code.

The other option for windows vista/Windows Server 2008 or later is to use the IIS Hostable core. For client versions this is available even in home basic, though IIS is not.
This does basically all the work of the HTTP and HTTPS protocols for you and all that is left to do is write the callback functions which define what to send out over the pipe.

Related

HTML5 desktop application and C++ business logic

I have a question related to HTML5 as a desktop application replacement.
At present time my company developed a WinCE application in C++ language with a GUI in C++, that receives and sends messages to the Business Logic layer via sockets (C++ Windows App).
We would like to port this SW on Linux but to realize a cross compilable SW.
The whole application run on a single embedded PC (both BL and GUI) .
About presentation layer we was investigating the HTML5 possible solution, however I have some doubts.
In fact I read that some browsers supports the feature of web sockets, but it seems that this kind of sockets aren't generic TCP/UDP sockets, but are further specialized and their implementation is provided in server side classes, like Socket.IO (Java e node.js) and Jetty (Java).
So is there someone that can provide me some feedback about how/if it is possible to use HTML5 as presentation layer and send/receive updates from/to GUI via sockets to a application running on the same host machine as the web page?
I hope this question fulfill the requirements of the stackexchange "style" and rules, I made my best to be as clear as possible.
Best regards.
Giovanni Parodi
Nothing stops you from having your frontend and backend on same host talking via WebSocket over loopback.
I assume you are unwilling to port your backend to a different language, so you will need a C++ WebSocket implementation. I haven't followed what Microsoft provides in this area, but when using Boost/ASIO, I'd recommend to look at WebSocket++.
Further, WebSocket is still relatively low-level (send message bidirectionally). So you might want something higher-level. You might want to look at WAMP (The WebSocket Application Messaging Protocol), which provides you with RPC and PubSub messaging patterns. Using this, you can plug/exchange your frontend (e.g. have a native Android) talking to same, unchanged backend - same for backend. Decoupling.
There are clients and router(read: server) implementations for various languages.
Btw: WebSocket is supported by Chrome, Firefox and IE (beginning with version 10) -- and other browsers.
I'd need to know more about the specific side-conditions and requirements to give more hints ..
Disclosure: I am original author of Autobahn, WAMP and work for Tavendo.

Supporting Web Services from a Win/MFC/C++ App

I am looking for the best way to add support for a REST based Web Service to an MFC C++ Application. This is legacy code that has been around a long time.
I need to have the Application provide the Web Service. I've researched this, and the articles are about consuming Web Services in a C++ App. I envision having to monitor a port and respond to the HTTP requests. It would probably make more sense to tie in with WCF and IIS, but I am not sure how to move forward.
I already have a tool of "making" this App into a Windows Service. I realize it would be better to have a "real" app, and this is what I have to work with. There is so much logic in this code and we are limited in development time, so we are taking the fastest approach possible. We also cannot use DCOM, as the Web Service will be called by a Linux based system.
Any suggested articles would be much appreciated.
For C++ you can test two libraries WSF/C and gSoap, another alternative is to develop it with C# and WCF , and communicate between C# and C++ using C++\CLI.
I use the Poco Net c++ library for this as it supports both HTTP client and server functionality. I considered various other libraries including Boost based stuff, but other than Poco I struggled to find everything I needed in one tidy package. It also has some easy to use mutex support which became essential for me as soon as I added a web server front-end to what had previously been a simple single threaded console app. Poco is cross platform but I mainly use it windows and it has served me well to date. I'm not very clued up on MFC so I don't know how it would get on in that department though.

Calling c/c++ library from webserver

I am pretty new to web programming.I am developing a HTML5 based user interface which is supposed to use a middle ware written in C/C++.How can I do this?
I do not want to use any browser specific feature/library to communicate with the middle ware. Can we do the same at the server side and then send back the information to the browser? If so how can I achieve this communication with the middle ware at the server side?
Thanks in advance for the reply.
Note : I am planning to use Tomcat as the server in loop back.
As suggested above, you could use CGI (e.g., perl scripts) as a middle-man between the Tomcat server and your C++ middleware. What I also think might work well, and am planning on using myself in the near future, is to use boost::asio, and take the example HTTP server and modify it to use your middleware. You could then communicate between the Tomcat server and the C++ server using AJAX with JSON.
There is also something called pion server http://www.pion.org/projects/pion-network-library
It allows you to write the entire server in your own C++, with most of the common tasks abstracted away.
The Wt "web toolkit" library (pronounced "witty") may be of interest. Essentially all web-aspects are taken care of this, so absolutely no middleware. Here is an intro, quoting from the website:
The API is widget-centric and uses well-tested patterns of desktop GUI
development tailored to the web. To the developer, it offers
abstraction of web-specific implementation details, including
client-server protocols, event handling, graphics support, graceful
degradation (or progressive enhancement), and URL handling.
Unlike many page-based frameworks, Wt was designed for creating
stateful applications that are at the same time highly interactive
(leveraging techinques such as WebSockets and Ajax to their fullest)
and accessible (supporting plain HTML browsers), using automatic
graceful degradation or progressive enhancement. Things that are
natural and simple with Wt would require an impractical amount of
effort otherwise: switching widgets using animations, while being
perfectly indexed by search robots with clean URLs, or having a
persistent chat widget open throughout, that even works in legacy
browsers like Microsoft Internet Explorer 6.
It can run with its own web server (based on a Boost component) or be linked against standard web server libraries.
I wrote a short blog post about how to integrate it with another C++ component I wrote (RInside, which permits to embed R inside C++ apps) and by joining the two, I had a simple 'webapp' exporting R functionality to the web.
You can further enhance it via Javascript but that is something I have not looked into in any detail.

How to connect a C++ program to a WCF Service?

In the place I work there are some software written in C# and some written in C++ (the most important ones). Some time ago we decided it would be a good idea to track any possible problem in the software, by sending stack trace and exception information over a web service. So I came with a WCF Service, that gets the information and store them on a database and send an automatic e-mail. It worked, we had to secure it through password, it's done, but now I want our other software, the one written in C++, to use this webservice (this software is used both on windows and linux, so we can't just make a call to another software in the user machine).
I've googled about it, and found this tutorial on how to use gSOAP, which so far didn't help me very much (lots of errors, it is not very detailed, and the web.config file is impossible to read). I was wondering if is there any other way to achieve this. In adition, since I'm using authentication on my webservice, it now has a wsHttpBinding (which AFAIK isn't supported by gSOAP).
Can you guys help me out?
Since your WCF service is in C# with .NET, and the only issue is getting the C++ application to be able to talk to it, one way is to follow the advice in REST / SOAP Endpoints for a WCF service and related articles.
Your C# programs continue to have the full SOAP access to your service.
Your C++ programs could do something like this for REST access:
"Browse" to the HTTP GET URL for the service command you wanted.
Then toss (or parse and use) whatever response came back.
It is a pretty minimal change to your WCF service to offer both SOAP and REST.
The REST ability opens your service to JavaScript as well as C++ clients.
You may need to restrict the interface to simple data, or class objects that are easy to parse in C++.
Will the machines running the C++ applications have the .NET Framework installed?
Check out: Create WCF service for unmanaged C++ clients

Lightweight HTTP/HTTPS server in C++ (not C)

I need to build a lightweight http server for my application basically it's a server which listen to a port and outputs a status information on requests, https, other functionality. But I would like to know first if something like this existe in C++, for linux and open source.
Does anyone know a program like that?
Thanks.
EDIT: It should be able to support high load.
If you can use boost, the asio library provides an http example. It does not use SSL, but asio can use OpenSSL very easily.
If you want to handle high loads I would suggest following:
Use proper web server with all goodies it comes with like Lighttpd, Nginx or Apache (in that order).
It would do great job in serving static files and handle your application. And they are very lightweight.
Write an Application in C++ using proper web framework - CppCMS - that is designed for high loads
Connect Web Application to the server via FastCGI or SCGI protocol (in this order).
Disclaimer: I'm the author of CppCMS
A quick google search for "C++ web application framework" shows things called CppCMS and something else called WT. That might get you started.
Or, as Sam already answered: boost.asio comes with a HTTP example that may be sufficient if your needs are simple. (Real HTTP request handling is actually surprisingly complex: http://webmachine.basho.com/diagram.html )
See thttpd. Supposibly the fastest open source file server on all machines with a single CPU.
If not using HTTPS, it's about a two hour exercise to write a static file server.