src: move crypto_bio/clienthello to crypto ns

Currently, node_crypto_bio and node_crypto_clienthello are not in the
crypto namespace but simply in the node namespace. Not sure if this was
intentional or not, but I think it would make sense to move them to be
consistent.

PR-URL: https://github.com/nodejs/node/pull/13957
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Daniel Bevenius 2017-06-28 09:30:30 +02:00
parent 93683c616b
commit 08109a3ca1
7 changed files with 25 additions and 13 deletions

View File

@ -27,6 +27,7 @@
#include <string.h> #include <string.h>
namespace node { namespace node {
namespace crypto {
const BIO_METHOD NodeBIO::method = { const BIO_METHOD NodeBIO::method = {
BIO_TYPE_MEM, BIO_TYPE_MEM,
@ -488,4 +489,5 @@ NodeBIO::~NodeBIO() {
write_head_ = nullptr; write_head_ = nullptr;
} }
} // namespace crypto
} // namespace node } // namespace node

View File

@ -32,6 +32,7 @@
#include "v8.h" #include "v8.h"
namespace node { namespace node {
namespace crypto {
class NodeBIO { class NodeBIO {
public: public:
@ -156,6 +157,7 @@ class NodeBIO {
Buffer* write_head_; Buffer* write_head_;
}; };
} // namespace crypto
} // namespace node } // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

View File

@ -28,6 +28,7 @@
#include "util-inl.h" #include "util-inl.h"
namespace node { namespace node {
namespace crypto {
inline void ClientHelloParser::Reset() { inline void ClientHelloParser::Reset() {
frame_len_ = 0; frame_len_ = 0;
@ -74,6 +75,7 @@ inline bool ClientHelloParser::IsPaused() const {
return state_ == kPaused; return state_ == kPaused;
} }
} // namespace crypto
} // namespace node } // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

View File

@ -23,6 +23,7 @@
#include "node_crypto_clienthello-inl.h" #include "node_crypto_clienthello-inl.h"
namespace node { namespace node {
namespace crypto {
void ClientHelloParser::Parse(const uint8_t* data, size_t avail) { void ClientHelloParser::Parse(const uint8_t* data, size_t avail) {
switch (state_) { switch (state_) {
@ -244,4 +245,5 @@ bool ClientHelloParser::ParseTLSClientHello(const uint8_t* data, size_t avail) {
return true; return true;
} }
} // namespace crypto
} // namespace node } // namespace node

View File

@ -30,6 +30,7 @@
#include <stdlib.h> // nullptr #include <stdlib.h> // nullptr
namespace node { namespace node {
namespace crypto {
class ClientHelloParser { class ClientHelloParser {
public: public:
@ -133,6 +134,7 @@ class ClientHelloParser {
const uint8_t* tls_ticket_; const uint8_t* tls_ticket_;
}; };
} // namespace crypto
} // namespace node } // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

View File

@ -138,10 +138,10 @@ void TLSWrap::NewSessionDoneCb() {
void TLSWrap::InitSSL() { void TLSWrap::InitSSL() {
// Initialize SSL // Initialize SSL
enc_in_ = NodeBIO::New(); enc_in_ = crypto::NodeBIO::New();
enc_out_ = NodeBIO::New(); enc_out_ = crypto::NodeBIO::New();
NodeBIO::FromBIO(enc_in_)->AssignEnvironment(env()); crypto::NodeBIO::FromBIO(enc_in_)->AssignEnvironment(env());
NodeBIO::FromBIO(enc_out_)->AssignEnvironment(env()); crypto::NodeBIO::FromBIO(enc_out_)->AssignEnvironment(env());
SSL_set_bio(ssl_, enc_in_, enc_out_); SSL_set_bio(ssl_, enc_in_, enc_out_);
@ -170,7 +170,7 @@ void TLSWrap::InitSSL() {
SSL_set_accept_state(ssl_); SSL_set_accept_state(ssl_);
} else if (is_client()) { } else if (is_client()) {
// Enough space for server response (hello, cert) // Enough space for server response (hello, cert)
NodeBIO::FromBIO(enc_in_)->set_initial(kInitialClientBufferLength); crypto::NodeBIO::FromBIO(enc_in_)->set_initial(kInitialClientBufferLength);
SSL_set_connect_state(ssl_); SSL_set_connect_state(ssl_);
} else { } else {
// Unexpected // Unexpected
@ -178,7 +178,7 @@ void TLSWrap::InitSSL() {
} }
// Initialize ring for queud clear data // Initialize ring for queud clear data
clear_in_ = new NodeBIO(); clear_in_ = new crypto::NodeBIO();
clear_in_->AssignEnvironment(env()); clear_in_->AssignEnvironment(env());
} }
@ -310,7 +310,9 @@ void TLSWrap::EncOut() {
char* data[kSimultaneousBufferCount]; char* data[kSimultaneousBufferCount];
size_t size[arraysize(data)]; size_t size[arraysize(data)];
size_t count = arraysize(data); size_t count = arraysize(data);
write_size_ = NodeBIO::FromBIO(enc_out_)->PeekMultiple(data, size, &count); write_size_ = crypto::NodeBIO::FromBIO(enc_out_)->PeekMultiple(data,
size,
&count);
CHECK(write_size_ != 0 && count != 0); CHECK(write_size_ != 0 && count != 0);
Local<Object> req_wrap_obj = Local<Object> req_wrap_obj =
@ -356,7 +358,7 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
} }
// Commit // Commit
NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_); crypto::NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_);
// Ensure that the progress will be made and `InvokeQueued` will be called. // Ensure that the progress will be made and `InvokeQueued` will be called.
wrap->ClearIn(); wrap->ClearIn();
@ -674,7 +676,7 @@ void TLSWrap::OnAllocImpl(size_t suggested_size, uv_buf_t* buf, void* ctx) {
} }
size_t size = 0; size_t size = 0;
buf->base = NodeBIO::FromBIO(wrap->enc_in_)->PeekWritable(&size); buf->base = crypto::NodeBIO::FromBIO(wrap->enc_in_)->PeekWritable(&size);
buf->len = size; buf->len = size;
} }
@ -737,7 +739,7 @@ void TLSWrap::DoRead(ssize_t nread,
} }
// Commit read data // Commit read data
NodeBIO* enc_in = NodeBIO::FromBIO(enc_in_); crypto::NodeBIO* enc_in = crypto::NodeBIO::FromBIO(enc_in_);
enc_in->Commit(nread); enc_in->Commit(nread);
// Parse ClientHello first // Parse ClientHello first
@ -808,7 +810,7 @@ void TLSWrap::EnableSessionCallbacks(
"EnableSessionCallbacks after destroySSL"); "EnableSessionCallbacks after destroySSL");
} }
wrap->enable_session_callbacks(); wrap->enable_session_callbacks();
NodeBIO::FromBIO(wrap->enc_in_)->set_initial(kMaxHelloLength); crypto::NodeBIO::FromBIO(wrap->enc_in_)->set_initial(kMaxHelloLength);
wrap->hello_parser_.Start(SSLWrap<TLSWrap>::OnClientHello, wrap->hello_parser_.Start(SSLWrap<TLSWrap>::OnClientHello,
OnClientHelloParseEnd, OnClientHelloParseEnd,
wrap); wrap);

View File

@ -38,10 +38,10 @@
namespace node { namespace node {
// Forward-declarations // Forward-declarations
class NodeBIO;
class WriteWrap; class WriteWrap;
namespace crypto { namespace crypto {
class SecureContext; class SecureContext;
class NodeBIO;
} }
class TLSWrap : public AsyncWrap, class TLSWrap : public AsyncWrap,
@ -172,7 +172,7 @@ class TLSWrap : public AsyncWrap,
StreamBase* stream_; StreamBase* stream_;
BIO* enc_in_; BIO* enc_in_;
BIO* enc_out_; BIO* enc_out_;
NodeBIO* clear_in_; crypto::NodeBIO* clear_in_;
size_t write_size_; size_t write_size_;
typedef ListHead<WriteItem, &WriteItem::member_> WriteItemList; typedef ListHead<WriteItem, &WriteItem::member_> WriteItemList;
WriteItemList write_item_queue_; WriteItemList write_item_queue_;