Skip to content

Commit 6ee9fb1

Browse files
tniessenbengl
authored andcommitted
src: make SecureContext fields private
These fields should not be public. Only ctx_ is used outside of the class itself, and should be accessed through the ctx() function instead. PR-URL: #43173 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 598c1f1 commit 6ee9fb1

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/crypto/crypto_common.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ long VerifyPeerCertificate( // NOLINT(runtime/int)
154154

155155
bool UseSNIContext(
156156
const SSLPointer& ssl, BaseObjectPtr<SecureContext> context) {
157-
SSL_CTX* ctx = context->ctx_.get();
157+
SSL_CTX* ctx = context->ctx().get();
158158
X509* x509 = SSL_CTX_get0_certificate(ctx);
159159
EVP_PKEY* pkey = SSL_CTX_get0_privatekey(ctx);
160160
STACK_OF(X509)* chain;
@@ -218,7 +218,7 @@ const char* GetServerName(SSL* ssl) {
218218
}
219219

220220
bool SetGroups(SecureContext* sc, const char* groups) {
221-
return SSL_CTX_set1_groups_list(sc->ssl_ctx(), groups) == 1;
221+
return SSL_CTX_set1_groups_list(sc->ctx().get(), groups) == 1;
222222
}
223223

224224
const char* X509ErrorCode(long err) { // NOLINT(runtime/int)

src/crypto/crypto_context.h

+14-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SecureContext final : public BaseObject {
4141
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
4242
static SecureContext* Create(Environment* env);
4343

44-
SSL_CTX* ssl_ctx() const { return ctx_.get(); }
44+
const SSLCtxPointer& ctx() const { return ctx_; }
4545

4646
SSLPointer CreateSSL();
4747

@@ -55,14 +55,6 @@ class SecureContext final : public BaseObject {
5555
SET_MEMORY_INFO_NAME(SecureContext)
5656
SET_SELF_SIZE(SecureContext)
5757

58-
SSLCtxPointer ctx_;
59-
X509Pointer cert_;
60-
X509Pointer issuer_;
61-
#ifndef OPENSSL_NO_ENGINE
62-
bool client_cert_engine_provided_ = false;
63-
EnginePointer private_key_engine_;
64-
#endif // !OPENSSL_NO_ENGINE
65-
6658
static const int kMaxSessionSize = 10 * 1024;
6759

6860
// See TicketKeyCallback
@@ -72,10 +64,6 @@ class SecureContext final : public BaseObject {
7264
static const int kTicketKeyNameIndex = 3;
7365
static const int kTicketKeyIVIndex = 4;
7466

75-
unsigned char ticket_key_name_[16];
76-
unsigned char ticket_key_aes_[16];
77-
unsigned char ticket_key_hmac_[16];
78-
7967
protected:
8068
// OpenSSL structures are opaque. This is sizeof(SSL_CTX) for OpenSSL 1.1.1b:
8169
static const int64_t kExternalSize = 1024;
@@ -137,6 +125,19 @@ class SecureContext final : public BaseObject {
137125

138126
SecureContext(Environment* env, v8::Local<v8::Object> wrap);
139127
void Reset();
128+
129+
private:
130+
SSLCtxPointer ctx_;
131+
X509Pointer cert_;
132+
X509Pointer issuer_;
133+
#ifndef OPENSSL_NO_ENGINE
134+
bool client_cert_engine_provided_ = false;
135+
EnginePointer private_key_engine_;
136+
#endif // !OPENSSL_NO_ENGINE
137+
138+
unsigned char ticket_key_name_[16];
139+
unsigned char ticket_key_aes_[16];
140+
unsigned char ticket_key_hmac_[16];
140141
};
141142

142143
} // namespace crypto

src/crypto/crypto_tls.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ int TLSExtStatusCallback(SSL* s, void* arg) {
295295

296296
void ConfigureSecureContext(SecureContext* sc) {
297297
// OCSP stapling
298-
SSL_CTX_set_tlsext_status_cb(sc->ctx_.get(), TLSExtStatusCallback);
299-
SSL_CTX_set_tlsext_status_arg(sc->ctx_.get(), nullptr);
298+
SSL_CTX_set_tlsext_status_cb(sc->ctx().get(), TLSExtStatusCallback);
299+
SSL_CTX_set_tlsext_status_arg(sc->ctx().get(), nullptr);
300300
}
301301

302302
inline bool Set(
@@ -1303,20 +1303,20 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
13031303
p->sni_context_ = BaseObjectPtr<SecureContext>(sc);
13041304

13051305
ConfigureSecureContext(sc);
1306-
CHECK_EQ(SSL_set_SSL_CTX(p->ssl_.get(), sc->ctx_.get()), sc->ctx_.get());
1306+
CHECK_EQ(SSL_set_SSL_CTX(p->ssl_.get(), sc->ctx().get()), sc->ctx().get());
13071307
p->SetCACerts(sc);
13081308

13091309
return SSL_TLSEXT_ERR_OK;
13101310
}
13111311

13121312
int TLSWrap::SetCACerts(SecureContext* sc) {
1313-
int err = SSL_set1_verify_cert_store(
1314-
ssl_.get(), SSL_CTX_get_cert_store(sc->ctx_.get()));
1313+
int err = SSL_set1_verify_cert_store(ssl_.get(),
1314+
SSL_CTX_get_cert_store(sc->ctx().get()));
13151315
if (err != 1)
13161316
return err;
13171317

13181318
STACK_OF(X509_NAME)* list =
1319-
SSL_dup_CA_list(SSL_CTX_get_client_CA_list(sc->ctx_.get()));
1319+
SSL_dup_CA_list(SSL_CTX_get_client_CA_list(sc->ctx().get()));
13201320

13211321
// NOTE: `SSL_set_client_CA_list` takes the ownership of `list`
13221322
SSL_set_client_CA_list(ssl_.get(), list);

0 commit comments

Comments
 (0)