Now when running the program, no console prompt to accept certificate, but still I do not get response from the server site and then after a while (around 60sec) Poco::Net::SSLConnectionUnexpectedlyClosedException is thrown. So what is the problem ?
I'm not familiar with certificate issues, openSSL configuration or SSL so any help is appreciated. The code below:
- Code: Select all
int HTTPSConnection::init(const std::string& userName,
const std::string& password)
using Poco::Net::Context;
Poco::SharedPtr<Poco::Net::ConsoleCertificateHandler> pCert =
new Poco::Net::ConsoleCertificateHandler(false);
Context::Ptr pContext = new Context(Context::CLIENT_USE, "", "", "C:\\openSSL\\bin\\PEM\\cacert.pem",
Context::VERIFY_RELAXED, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Poco::Net::SSLManager::instance().initializeClient(0, pCert, pContext);
try
{
Poco::URI uri(URL);
Poco::Net::HTTPClientSession *client =
Poco::Net::HTTPSessionFactory::defaultFactory().createClientSession(uri);
// init request
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_1_0);
std::string day = setRequestContentType(request);
initRequest(userName, password, PATH_INIT, Poco::Net::HTTPRequest::HTTP_POST, request);
// build handshake msg
std::stringstream msg;
msg << getMessageHeader(day);
msg << HANDSHAKE;
msg << getMessageFooter(day);
int len;
len = msg.str().length();
request.setContentLength(len);
request.write(std::cout);
std::cout << msg.str();
// send request + msg using HTTP client
std::ostream& os = client->sendRequest(request);
os << msg;
os.flush();
// receive response and parse it
Poco::Net::HTTPResponse response;
std::ostringstream result;
std::istream& is = client->receiveResponse(response);
len = is.gcount();
Poco::StreamCopier::copyStream(is, result);
response.write(std::cout);
std::cout << is;
if (response.getStatus() == response.HTTP_OK)
{
parse(result);
}
else
{
std::cout << "Login failed to Server\n";
return 1;
}
}
catch(Poco::Net::ConnectionRefusedException &)
{
std::cout << "Connection refused by Server\n";
return 1;
}
catch(Poco::Exception &e)
{
std::cout << e.name() << " thrown.\n";
std::cout << e.message() << "\n";
return 1;
}
catch(std::exception &e)
{
std::cout << e.what() << "\n";
return 1;
}
return 0;





