// Takes a string or buffer and loads it into a BIO.
// Caller responsible for BIO_free_all-ing the returned object.
static BIO* LoadBIO(Handle<Value> v) {
- BIO *bio = BIO_new(NodeBIO::GetMethod());
+ BIO* bio = NodeBIO::New();
if (!bio) return NULL;
HandleScope scope(node_isolate);
root_cert_store = X509_STORE_new();
for (int i = 0; root_certs[i]; i++) {
- BIO *bp = BIO_new(NodeBIO::GetMethod());
+ BIO* bp = NodeBIO::New();
if (!BIO_write(bp, root_certs[i], strlen(root_certs[i]))) {
BIO_free_all(bp);
conn->Wrap(args.This());
conn->ssl_ = SSL_new(sc->ctx_);
- conn->bio_read_ = BIO_new(NodeBIO::GetMethod());
- conn->bio_write_ = BIO_new(NodeBIO::GetMethod());
+ conn->bio_read_ = NodeBIO::New();
+ conn->bio_write_ = NodeBIO::New();
SSL_set_app_data(conn->ssl_, conn);
namespace node {
-BIO_METHOD NodeBIO::method_ = {
+const BIO_METHOD NodeBIO::method = {
BIO_TYPE_MEM,
"node.js SSL buffer",
NodeBIO::Write,
};
+BIO* NodeBIO::New() {
+ // The const_cast doesn't violate const correctness. OpenSSL's usage of
+ // BIO_METHOD is effectively const but BIO_new() takes a non-const argument.
+ return BIO_new(const_cast<BIO_METHOD*>(&method));
+}
+
+
int NodeBIO::New(BIO* bio) {
bio->ptr = new NodeBIO();
class NodeBIO {
public:
- static inline BIO_METHOD* GetMethod() {
- return &method_;
- }
-
NodeBIO() : length_(0), read_head_(&head_), write_head_(&head_) {
// Loop head
head_.next_ = &head_;
~NodeBIO();
- static int New(BIO* bio);
- static int Free(BIO* bio);
- static int Read(BIO* bio, char* out, int len);
- static int Write(BIO* bio, const char* data, int len);
- static int Puts(BIO* bio, const char* str);
- static int Gets(BIO* bio, char* out, int size);
- static long Ctrl(BIO* bio, int cmd, long num, void* ptr);
+ static BIO* New();
// Allocate new buffer for write if needed
void TryAllocateForWrite();
return static_cast<NodeBIO*>(bio->ptr);
}
- protected:
+ private:
+ static int New(BIO* bio);
+ static int Free(BIO* bio);
+ static int Read(BIO* bio, char* out, int len);
+ static int Write(BIO* bio, const char* data, int len);
+ static int Puts(BIO* bio, const char* str);
+ static int Gets(BIO* bio, char* out, int size);
+ static long Ctrl(BIO* bio, int cmd, long num, void* ptr);
+
// NOTE: Size is maximum TLS frame length, this is required if we want
// to fit whole ClientHello into one Buffer of NodeBIO.
static const size_t kBufferLength = 16 * 1024 + 5;
+ static const BIO_METHOD method;
class Buffer {
public:
Buffer head_;
Buffer* read_head_;
Buffer* write_head_;
-
- static BIO_METHOD method_;
};
} // namespace node
void TLSCallbacks::InitSSL() {
// Initialize SSL
- enc_in_ = BIO_new(NodeBIO::GetMethod());
- enc_out_ = BIO_new(NodeBIO::GetMethod());
+ enc_in_ = NodeBIO::New();
+ enc_out_ = NodeBIO::New();
SSL_set_bio(ssl_, enc_in_, enc_out_);