Question

I built openssl and POCO library for android. In my app I am trying to use SSL. The problem is when I create the handler, it hangs and never returns. It happens regardless of which type of certificate handler I use. What could be going wrong here?

My code:

Poco::Net::initializeSSL();
// Creating this handler is where it hangs.
SharedPtr<Poco::Net::InvalidCertificateHandler> pCert = new AcceptCertificateHandler(false);
//It never gets to this line.
Context::Ptr pContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
Était-ce utile?

La solution 2

I actually got this to work by building POCO using Android make files (.mk) instead of using the standalone toolchain like I was. I don't know what the difference was but it works properly now.

Autres conseils

Oh wow someone else on SO doing POCO/SSL on Android. Welcome to hell :P

Anyway, it's confusing that you would have it hang there - I assume you've validated with prints? Perhaps your calling thread is being killed off from the Android side? Obviously you shouldn't be calling this from the UI thread so there's that.

If none of that is at issue then I'm not sure what the problem is. My init SSL is pretty much exactly yours:

Poco::Net::initializeSSL();
Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> accept_cert_handler =
    new Poco::Net::AcceptCertificateHandler(false);
Poco::SharedPtr<Poco::Net::PrivateKeyPassphraseHandler> console_handler =
    new Poco::Net::KeyConsoleHandler(false);
Poco::Net::Context::Ptr context =
    new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "",
    Poco::Net::Context::VERIFY_NONE, 9, true,
    "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");     

Poco::Net::SSLManager::instance().
    certificateHandlerFactoryMgr().
    setFactory("accept_handler",
    new Poco::Net::CertificateHandlerFactoryImpl<AcceptCertificateHandler>());

Poco::Net::SSLManager::instance().initializeClient(console_handler, 
                                                   accept_handler,
                                                   context);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top