c - mixing openssl API and BSD sockets API -


i'm writing client must deal both ordinary http protocol , https secure connections. ordinary http connections, should use basic socket i/o functions such send(), recv() , on. https connections, should use ssl_read(), ssl_write , other functions openssl library. use following approach:

if (ishttps) {     /* use openssl calls */     ssl_write(); } else {     /* use basic socket i/o functions */     send(); } 

but think not way, not easy code way. suggestion on this? there better way?

what describe traditional api model using openssl. ssl object owns socket , performs i/o on it, have use ssl_read() , ssl_write() functions when performing secure i/o.

openssl has newer api model using bio structures instead. can create bio object socket , associate ssl object when need secure i/o, , use bio_...() functions (bio_read(), bio_write() etc) handle actual i/o. in secure mode, bio functions use ssl functions internally you:

bio = bio_new_connect(...); // host/ip , port if (ishttps)     bio_set_ssl(bio, ssl, ...);  // alternatively: if (ishttps) {     bio = bio_new_ssl_connect(sslctx);     bio_set_connect_hostname(...); // host/ip , port     ...     } else     bio = bio_new_connect(...); // host/ip , port  bio_do_connect(bio); ...      bio_read(bio, ...); ...      bio_write(bio, ...); ...      bio_free(bio); 

this bio api 1 use if want perform own socket i/o (ie, overlapped/asynchronous sockets), letting openssl handle security it. create bio links 2 memory buffers together. can read inbound data socket 1 buffer , have openssl consume using bio_read(), , write outgoing data using bio_write(). outgoing data openssl generates put in other buffer, can write socket needed.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -