Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1806 from rdkcentral/development/SecureSockets
* [SSL] Integrate OpenSSL behind C++ wrappers for Key/Certificate and a Certificate Store. Client code: class WebClient : public Web::WebLinkType<Crypto::SecureSocketPort, Web::Response, Web::Request, WPEFramework::Core::ProxyPoolType<Web::Response>&> { ... } WebClient webConnector(Core::NodeId("catfact.ninja", 443)); webConnector.Link().Root(Crypto::CertificateStore::Default()); uint32_t result = webConnector.Open(10000); if (result != Core::ERROR_NONE) { printf("Could not open the connection, error: %d\n", result); } else { printf("Waiting for a number of seconds for the result!\n"); SleepMs(5000); printf("The answer should be in by now, lets close it!\n"); webConnector.Close(100) } Server/Client code: void OpeningSecuredServerPort() { Crypto::Certificate certificate(_T("D:/domotica/src/ca_certficates/onsite.crt")); Crypto::Key key(_T("D:/domotica/src/ca_certficates/onsite.key"), _T("")); Crypto::Certificate CA(_T("D:/domotica/src/ca_certficates/rootCA.pem")); Crypto::CertificateStore store; store.Add(CA); const Core::NodeId localNode(localHostName, tcpServerPort, Core::NodeId::TYPE_IPV4); // This is a listening socket as result of using SocketServerType which enables listening Crypto::SecureSocketServerType<WebSocketServer<SecureStream, sendBufferSize, receiveBufferSize>> server(certificate, key, localNode /* listening node*/); if (server.Open(maxWaitTimeMs) == Core::ERROR_NONE) { // Time to open a Client, see if I can get some data :-) WebSocketClient<SecureStream> client(webSocketURIPath, webSocketProtocol, webSocketURIQuery, webSocketOrigin, false, true, rawSocket, localNode.AnyInterface(), localNode, sendBufferSize, receiveBufferSize, "WebSocketClient"); client.Link().Root(store); if (client.Open(3000) == Core::ERROR_NONE) { std::basic_string<uint8_t> message(request, sizeof(request)); // Seems we have connections, now exchange a message client.Submit(message); // Sleep for some time so we can send and receive it :-) SleepMs(1000); WebSocketClient<SecureStream>::Message response = client.Response(); printf("%s\n\n", response.c_str()); client.Close(Core::infinite); } } } * [REFACTOR] The constructors are fixed, use them fixed.
- Loading branch information