Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Get rid of the binding code, except for the basic class which we're s…
Browse files Browse the repository at this point in the history
…till using for File/Pid watch. no more binding bag.
  • Loading branch information
jakedouglas committed Oct 28, 2009
1 parent dc3e84b commit 2b05a12
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 136 deletions.
90 changes: 2 additions & 88 deletions ext/binder.cpp
Expand Up @@ -19,107 +19,21 @@ See the file COPYING for complete licensing information.


#include "project.h" #include "project.h"


#define DEV_URANDOM "/dev/urandom"


map<unsigned long, Bindable_t*> Bindable_t::BindingBag;


/********************************
STATIC Bindable_t::CreateBinding
********************************/

unsigned long Bindable_t::CreateBinding()
{
// XXX use atomic_t to prevent thread-safety issues
static unsigned long num = 0;
while(BindingBag[++num]);
return num;
}

#if 0
string Bindable_t::CreateBinding()
{
static int index = 0;
static string seed;

if ((index >= 1000000) || (seed.length() == 0)) {
#ifdef OS_UNIX
int fd = open (DEV_URANDOM, O_RDONLY);
if (fd < 0)
throw std::runtime_error ("No entropy device");

unsigned char u[16];
size_t r = read (fd, u, sizeof(u));
if (r < sizeof(u))
throw std::runtime_error ("Unable to read entropy device");

unsigned char *u1 = (unsigned char*)u;
char u2 [sizeof(u) * 2 + 1];

for (size_t i=0; i < sizeof(u); i++)
sprintf (u2 + (i * 2), "%02x", u1[i]);

seed = string (u2);
#endif


#ifdef OS_WIN32
UUID uuid;
UuidCreate (&uuid);
unsigned char *uuidstring = NULL;
UuidToString (&uuid, &uuidstring);
if (!uuidstring)
throw std::runtime_error ("Unable to read uuid");
seed = string ((const char*)uuidstring);

RpcStringFree (&uuidstring);
#endif

index = 0;


}

stringstream ss;
ss << seed << (++index);
return ss.str();
}
#endif

/*****************************
STATIC: Bindable_t::GetObject
*****************************/

Bindable_t *Bindable_t::GetObject (const unsigned long binding)
{
map<unsigned long, Bindable_t*>::const_iterator i = BindingBag.find (binding);
if (i != BindingBag.end())
return i->second;
else
return NULL;
}



/********************** /**********************
Bindable_t::Bindable_t Bindable_t::Bindable_t
**********************/ **********************/


Bindable_t::Bindable_t() Bindable_t::Bindable_t():
Binding(NULL)
{ {
Binding = Bindable_t::CreateBinding();
BindingBag [Binding] = this;
} }





/*********************** /***********************
Bindable_t::~Bindable_t Bindable_t::~Bindable_t
***********************/ ***********************/


Bindable_t::~Bindable_t() Bindable_t::~Bindable_t()
{ {
BindingBag.erase (Binding);
} }


5 changes: 0 additions & 5 deletions ext/binder.h
Expand Up @@ -23,11 +23,6 @@ See the file COPYING for complete licensing information.


class Bindable_t class Bindable_t
{ {
public:
static unsigned long CreateBinding();
static Bindable_t *GetObject (const unsigned long);
static map<unsigned long, Bindable_t*> BindingBag;

public: public:
Bindable_t(); Bindable_t();
virtual ~Bindable_t(); virtual ~Bindable_t();
Expand Down
35 changes: 3 additions & 32 deletions ext/ed.cpp
Expand Up @@ -301,32 +301,6 @@ ConnectionDescriptor::~ConnectionDescriptor()
#endif #endif
} }


/*********************************************
STATIC: ConnectionDescriptor::CloseConnection
*********************************************/

void ConnectionDescriptor::CloseConnection (const unsigned long binding, bool after_writing)
{
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
EventableDescriptor *ed = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
if (ed)
ed->ScheduleClose (after_writing);
}

/***********************************************
STATIC: ConnectionDescriptor::ReportErrorStatus
***********************************************/

int ConnectionDescriptor::ReportErrorStatus (const unsigned long binding)
{
// TODO: This is something of a hack, or at least it's a static method of the wrong class.
// TODO: Poor polymorphism here. We should be calling one virtual method
// instead of hacking out the runtime information of the target object.
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
if (cd)
return cd->_ReportErrorStatus();
return -1;
}


/*********************************** /***********************************
ConnectionDescriptor::_UpdateEvents ConnectionDescriptor::_UpdateEvents
Expand Down Expand Up @@ -994,7 +968,7 @@ void ConnectionDescriptor::StartTls()
if (SslBox) if (SslBox)
throw std::runtime_error ("SSL/TLS already running on connection"); throw std::runtime_error ("SSL/TLS already running on connection");


SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, GetBinding()); SslBox = new SslBox_t (bIsServer, PrivateKeyFilename, CertChainFilename, bSslVerifyPeer, this);
_DispatchCiphertext(); _DispatchCiphertext();
#endif #endif


Expand Down Expand Up @@ -1657,11 +1631,8 @@ STATIC: DatagramDescriptor::SendDatagram


int DatagramDescriptor::SendDatagram (const unsigned long binding, const char *data, int length, const char *address, int port) int DatagramDescriptor::SendDatagram (const unsigned long binding, const char *data, int length, const char *address, int port)
{ {
DatagramDescriptor *dd = dynamic_cast <DatagramDescriptor*> (Bindable_t::GetObject (binding)); // this is blank because we got rid of GetObject. This shouldn't have been static anyway. wtf?
if (dd) return -1;
return dd->SendOutboundDatagram (data, length, address, port);
else
return -1;
} }




Expand Down
3 changes: 0 additions & 3 deletions ext/ed.h
Expand Up @@ -146,9 +146,6 @@ class ConnectionDescriptor: public EventableDescriptor
ConnectionDescriptor (int, EventMachine_t*); ConnectionDescriptor (int, EventMachine_t*);
virtual ~ConnectionDescriptor(); virtual ~ConnectionDescriptor();


static void CloseConnection (const unsigned long, bool);
static int ReportErrorStatus (const unsigned long);

int SendOutboundData (const char*, int); int SendOutboundData (const char*, int);


void SetConnectPending (bool f); void SetConnectPending (bool f);
Expand Down
1 change: 0 additions & 1 deletion ext/project.h
Expand Up @@ -132,7 +132,6 @@ static inline int inotify_rm_watch (int fd, __u32 wd) { return syscall (__NR_ino


#include "binder.h" #include "binder.h"
#include "em.h" #include "em.h"
#include "epoll.h"
#include "sigs.h" #include "sigs.h"
#include "ed.h" #include "ed.h"
#include "files.h" #include "files.h"
Expand Down
10 changes: 4 additions & 6 deletions ext/ssl.cpp
Expand Up @@ -208,7 +208,7 @@ SslContext_t::~SslContext_t()
SslBox_t::SslBox_t SslBox_t::SslBox_t
******************/ ******************/


SslBox_t::SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, const unsigned long binding): SslBox_t::SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, ConnectionDescriptor *cd):
bIsServer (is_server), bIsServer (is_server),
bHandshakeCompleted (false), bHandshakeCompleted (false),
bVerifyPeer (verify_peer), bVerifyPeer (verify_peer),
Expand All @@ -233,8 +233,8 @@ SslBox_t::SslBox_t (bool is_server, const string &privkeyfile, const string &cer
assert (pSSL); assert (pSSL);
SSL_set_bio (pSSL, pbioRead, pbioWrite); SSL_set_bio (pSSL, pbioRead, pbioWrite);


// Store a pointer to the binding signature in the SSL object so we can retrieve it later // Store a pointer to ConnectionDescriptor in the SSL object so we can retrieve it later
SSL_set_ex_data(pSSL, 0, (void*) binding); SSL_set_ex_data(pSSL, 0, (void*) cd);


if (bVerifyPeer) if (bVerifyPeer)
SSL_set_verify(pSSL, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, ssl_verify_wrapper); SSL_set_verify(pSSL, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, ssl_verify_wrapper);
Expand Down Expand Up @@ -433,7 +433,6 @@ ssl_verify_wrapper


extern "C" int ssl_verify_wrapper(int preverify_ok, X509_STORE_CTX *ctx) extern "C" int ssl_verify_wrapper(int preverify_ok, X509_STORE_CTX *ctx)
{ {
unsigned long binding;
X509 *cert; X509 *cert;
SSL *ssl; SSL *ssl;
BUF_MEM *buf; BUF_MEM *buf;
Expand All @@ -442,14 +441,13 @@ extern "C" int ssl_verify_wrapper(int preverify_ok, X509_STORE_CTX *ctx)


cert = X509_STORE_CTX_get_current_cert(ctx); cert = X509_STORE_CTX_get_current_cert(ctx);
ssl = (SSL*) X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); ssl = (SSL*) X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
binding = (unsigned long) SSL_get_ex_data(ssl, 0); ConnectionDescriptor *cd = (ConnectionDescriptor*) SSL_get_ex_data(ssl, 0);


out = BIO_new(BIO_s_mem()); out = BIO_new(BIO_s_mem());
PEM_write_bio_X509(out, cert); PEM_write_bio_X509(out, cert);
BIO_write(out, "\0", 1); BIO_write(out, "\0", 1);
BIO_get_mem_ptr(out, &buf); BIO_get_mem_ptr(out, &buf);


ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject(binding));
result = (cd->VerifySslPeer(buf->data) == true ? 1 : 0); result = (cd->VerifySslPeer(buf->data) == true ? 1 : 0);
BUF_MEM_free(buf); BUF_MEM_free(buf);


Expand Down
2 changes: 1 addition & 1 deletion ext/ssl.h
Expand Up @@ -57,7 +57,7 @@ class SslBox_t
class SslBox_t class SslBox_t
{ {
public: public:
SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, const unsigned long binding); SslBox_t (bool is_server, const string &privkeyfile, const string &certchainfile, bool verify_peer, ConnectionDescriptor*);
virtual ~SslBox_t(); virtual ~SslBox_t();


int PutPlaintext (const char*, int); int PutPlaintext (const char*, int);
Expand Down

0 comments on commit 2b05a12

Please sign in to comment.