[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] libevent-2.0 and openssl filter



On Wed, Nov 04, 2009 at 07:25:32PM +0200, tuna@xxxxxxxx wrote:
 [...]
> I quickly (so I might be wrong) went through your bufferevent_openssl
> module. Seems nice but for SSL underlying protocol only, right? 
> I guess it would indeed require much work to expose BIO so we could set
> the BIO we want. But here is what I had in mind, for instance this
> pseudo-code:

Oh, I see.  You don't want to use SSL, you just want to use an EVP and
a BIO for an ad-hoc encryption scheme.

Before we get too far into this ... are you sure this is really what
you want?  With the scheme you describe below, there is no way to
prevent man-in-the-middle attacks, there is no data authentication,
you may be vulnerable to replay and truncation attacks, and you need
to roll your own key negotiation (which is notoriously difficult).
Using SSL/TLS means that all of these cryptography problems will get
solved for you.  Trying to solve them yourself -- or leaving them
unaddressed -- is (IMO) asking for trouble.

That aside, let's figure out how you would do this, if it were a good
idea.

> /*We assum fd is a socket fd, base is an already set up struct
> event_base etc...*/
> struct bufferevent *bev;
> if (do_we_want_ciphering())
> {
> 	/*We initiate the BIO we want*/
> 	BIO *bio = BIO_new(BIO_s_socket());
> 
> 	EVP_CIPHER = /*we set up our cipher, with its required
> 	parameters ...*/
> 
> 	BIO_set_cipher(/*the cipher we want*/)
> 	BIO_set_fd(bio, fd ....);

I don't think this would work; BIO_set_cipher only behaves correctly
for a BIO created with the BIO_f_cipher() filtering method.  So you'd
have to say something like

    BIO *fd_bio = BIO_new(BIO_s_socket());
    BIO *cipher_bio = BIO_new(BIO_f_cipher());
    
    BIO_set_fd(fd_bio, fd, ...);
    BIO_set_cipher(cipher_bio, ...);
    BIO_push(cipher_bio, fd_bio); /* unless I have this backwards */


> 	/*Here we "inject" our BIO into a bufferevent so we will
> 	almost never deal again with BIO API itself. I.e.: while
> 	getting/setting buffer content from bufferevent, it will be
> 	decrypted/encrypted automtically.*/
> 
> 	bev = bufferevent_BIO_new(base, bio, ...);

Ah!  No, we don't support that right now.  I wouldn't be opposed to
adding patch that did it, if somebody writes a good well-tested one,
but the code in bufferevent_openssl.c is written (for performance) to
use an SSL rather than an arbitrary BIO.

It wouldn't be _too_ hard to implement a variant that took a BIO.  I
spend 30 mintues hacking together an untested proof-of-concept
version, and uploaded it to the tracker at
https://sourceforge.net/tracker/?func=detail&aid=2892126&group_id=50884&atid=461324
, but it needs more TLC before it's ready for prime-time.  Somebody
(not me) should take the time to get it ready and cleaned up if they
care.

[We still want the default behavior to be using an SSL rather than a
BIO_f_ssl(); SSL code is often performance-critical, and adding an
unnecessary layer of indirection to the SSL case will not make us
friends.]

yrs,
-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.